Difference between revisions of "HowTo Put Multiple Live Images On One USB Memory Stick"

From NST Wiki
Jump to navigationJump to search
(Copy Files From ISO To USB Memory Stick (NST, Fedora))
(Create Grub 2 Configuration)
Line 124: Line 124:
 
= Copy ISO Files (Debian, Ubuntu, ...) =
 
= Copy ISO Files (Debian, Ubuntu, ...) =
  
= Create Grub 2 Configuration =
+
= Create GRUB 2 Configuration =
 +
 
 +
To simplify the process of maintaining the GRUB 2 configuration file for the USB memory stick, we will:
 +
 
 +
* Create individual text files with a ''.men'' extension for each distro included on the USB memory stick.
 +
* Create a top level script which we can run that will search for all of these ''.men'' files and join them into our master GRUB 2 configuration file.
  
 
== Create Menu Entry Files ==
 
== Create Menu Entry Files ==
 +
 +
Unfortunately, creating GRUB 2 menu entries is distribution specific. So, we will use the following strategies:
 +
 +
* Add example menu configurations to this Wiki page (see the [[#Example Menu Configuration|Example Menu Configuration]] section below.
 +
* Use Google to search for examples of GRUB 2 distribution specific menu configuration entries.
 +
* Examine the contents of ISO files (looking for syslinux/isolinux configuration entries in particular).
  
 
== Create Script To Join Menu Entry Files ==
 
== Create Script To Join Menu Entry Files ==
 +
 +
Every time a new distribution is added to the USB memory stick, a new menu entry file should also be create having a file extension of "''.men''". You can create a top level '''create-grub-cfg''' script which will join these menu files together and write them to the master '''boot/grub2/grub.cfg''' configuration file.
 +
 +
First, set some variables to identify the label of your USB memory stick and a mount point (you might need to adjust these):
 +
 +
LABEL=multboot
 +
MPT=/mnt/vfat
 +
 +
Next, mount the USB memory stick and create the '''create-grub-cfg''' script it's root directory using the following commands:
 +
 +
  [ -d ${MPT} ] || mkdir -p ${MPT}
 +
  mount LABEL=${LABEL} ${MPT}
 +
  cat >| ${MPT}/create-grub-cfg <<SEOF
 +
#!/bin/bash
 +
 +
cat >| boot/grub2/grub.cfg <<EOF
 +
# Global GRUB 2 options can be set here
 +
set timeout=-1
 +
set default=0
 +
EOF
 +
 +
for f in \$(find . -name "*.men"); do
 +
  echo "Adding: \${f}";
 +
  cat "\${f}" >> boot/grub2/grub.cfg;
 +
done
 +
SEOF
 +
chmod +x ${MPT}/create-grub.cfg
 +
umount ${MPT}
  
 
== Run Script ==
 
== Run Script ==
 +
 +
After adding a new distribution to your USB memory stick, you will want to re-build your GRUB 2 configuration file.
 +
 +
First, set some variables to identify the label of your USB memory stick and a mount point (you might need to adjust these):
 +
 +
LABEL=multboot
 +
MPT=/mnt/vfat
 +
 +
Next, mount the USB memory stick and run the '''create-grub-cfg''' script  from the top level directory of your USB memory stick:
 +
 +
  [ -d ${MPT} ] || mkdir -p ${MPT}
 +
  mount LABEL=${LABEL} ${MPT}
 +
  (cd ${MPT} && ./create-grub-cfg)
 +
  umount ${MPT}
  
 
= Test =
 
= Test =

Revision as of 11:48, 13 September 2012

Overview

The livecd-iso-to-disk program is used by Fedora based distributions (like NST) to transfer the contents of a Live ISO image to a USB memory stick. The livecd-iso-to-disk program works well and offers some extra features (such as persistent storage). However, it is primarily used when you want to put a single Fedora based distribution onto a USB memory stick.

It is often desirable to create a USB memory stick with multiple Live images to choose from (NST 32 bit, NST 64 bit, Ubuntu, Debian, ...). To accomplish this, you must:

  • Create a primary bootable partition on a USB memory stick.
  • Format the partition as FAT 32 (if you want easy access to the files from non Linux based systems).
  • Install the GRUB 2 boot loader onto the USB memory stick.
  • Transfer ISO images (Debian based distros) or contents from the ISO for other distributions (Fedora based distros).

WARNING: Know What You Are Doing

The partitioning and formatting steps of this process assume that you know what you are doing. If you are new to Linux, make sure you understand how to identify the device entry associated with your USB memory stick (like: /dev/sdx). If you blindly copy/paste commands from this page you will likely destroy data on your system.

We have chosen to use /dev/sdx and /dev/sdx1 in our examples below as this device probably won't be present on your system to reduce the chance of a data destruction. You will need to substitute the device entry of your USB memory stick for this value.

Prepare Your USB Memory Stick

You only need to perform these steps once. In other words, skip the USB preparation section when you want to add additional distributions to your USB memory stick.

Partition Your USB Memory Stick

You can use fdisk, gparted or one of the many other partition tools to partition your memory stick. A single primary partition marked as bootable works well.

Here's an example of what fdisk will show if you have a single primary partition marked as bootable (substitute the device entry of your USB memory stick for the /dev/sdx shown below):

[root@cayenne ~]# fdisk -l /dev/sdx

Disk /dev/sdx: 15.6 GB, 15606349824 bytes
255 heads, 63 sectors/track, 1897 cylinders, total 30481152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000230dd

   Device Boot      Start         End      Blocks   Id  System
/dev/sdx1   *          34    30481118    15240542+   c  W95 FAT32 (LBA)
[root@cayenne ~]#

Create A File System And Label

The following command demonstrates how to create a FAT 32 file system on partition /dev/sdx1 with a label of "multboot" (you will need to adjust this command based on the device entry for your partition):

[root@cayenne ~]# mkfs.vfat -F 32 -n multboot /dev/sdx1

Install GRUB 2 Boot Loader

The following command demonstrates how to mount your partition and install the GRUB 2 boot loader (again, you will need to change /dev/sdx for your USB memory stick):

[root@cayenne ~]# [ -d /mnt/vfat ] || mkdir /mnt/vfat 
[root@cayenne ~]# mount LABEL=multboot /mnt/vfat
[root@cayenne ~]# grub2-install --force --no-floppy --root-directory=/mnt/vfat /dev/sdx
[root@cayenne ~]# umount /mnt/vfat

At this point you should have a bootable USB memory stick. It would be a good idea to verify this by booting from the USB memory stick and make sure that you can at least get to GRUB 2.

Copy Files From ISO To USB Memory Stick (NST, Fedora)

The following demonstrates how to:

  • Create a boot area (live/nst/16/i686/) for a 32 bit installation of the NST distribution on your USB memory stick.
  • Install the necessary files from the NST ISO image into the boot area.
  • How to create a menu entry file that will be used in a GRUB 2 configuration file to load this image at boot time.

First, let's set some variables which you may need to adjust based on your system. These variables include the label assigned to your USB memory stick partition, a directory to be used as a mount point, a live directory to copy the NST files to and the location of the NST ISO image to get the files from. You can repeat this process many times by adjusting these values:

LABEL=multboot
MPT=/mnt/vfat
ARCH=i686
RELEASE=2.16.0-4104
SDIR=live/nst-${RELEASE}.${ARCH}
LDIR=${MPT}/${SDIR}
ISO=/tmp/nst-${RELEASE}.${ARCH}.iso

If you set the variables above correctly, you should be able to copy/paste the commands which follow.

The 7z command can be used to inspect and extract files contained in ISO images. For example, you can run the following to list the files contained in your ISO image:

7z l ${ISO}

The following commands will mount your USB memory stick and create a sub-directory to hold the files necessary to boot this image:

[ -d ${MPT} ] || mkdir -p ${MPT}
mount LABEL=${LABEL} ${MPT}
mkdir -p ${LDIR}/LiveOS

The following will extract the necessary files from your ISO image and install them into the proper location on your USB memory stick:

cd ${LDIR}
7z e ${ISO} isolinux/initrd0.img isolinux/vmlinuz0 isolinux/memtest
cd LiveOS
7z e ${ISO} "LiveOS/*"
cd ..

The following command will create a list of menu entries which will be used later when creating a configuration file for GRUB 2:

cat >| menuentry.men <<EOF
menuentry "NST ${RELEASE} ${ARCH} Live - Console" {
 linux /${SDIR}/vmlinuz0 root=LABEL=${LABEL} rootfstype=vfat live_dir=/${SDIR}/LiveOS ro liveimg systemd.unit=multi-user.target
 initrd /${SDIR}/initrd0.img
}

menuentry "NST ${RELEASE} ${ARCH} Live - Graphical Desktop" {
 linux /${SDIR}/vmlinuz0 root=LABEL=${LABEL} rootfstype=vfat live_dir=/${SDIR}/LiveOS ro liveimg systemd.unit=graphical.target
 initrd /${SDIR}/initrd0.img
}

menuentry "NST ${RELEASE} ${ARCH} Live - Server (Serial ttyS0 at 57600)" {
 linux /${SDIR}/vmlinuz0 root=LABEL=${LABEL} rootfstype=vfat live_dir=/${SDIR}/LiveOS ro liveimg console=tty0 console=ttyS0,57600n8 systemd.unit=multi-user.target
 initrd /${SDIR}/initrd0.img
}

menuentry "Memory Test" {
 linux /${SDIR}/memtest
}
EOF

After you are done installing your various Fedora based ISO distributions, you can unmount the USB memory stick.

cd
umount ${MPT}

Copy ISO Files (Debian, Ubuntu, ...)

Create GRUB 2 Configuration

To simplify the process of maintaining the GRUB 2 configuration file for the USB memory stick, we will:

  • Create individual text files with a .men extension for each distro included on the USB memory stick.
  • Create a top level script which we can run that will search for all of these .men files and join them into our master GRUB 2 configuration file.

Create Menu Entry Files

Unfortunately, creating GRUB 2 menu entries is distribution specific. So, we will use the following strategies:

  • Add example menu configurations to this Wiki page (see the Example Menu Configuration section below.
  • Use Google to search for examples of GRUB 2 distribution specific menu configuration entries.
  • Examine the contents of ISO files (looking for syslinux/isolinux configuration entries in particular).

Create Script To Join Menu Entry Files

Every time a new distribution is added to the USB memory stick, a new menu entry file should also be create having a file extension of ".men". You can create a top level create-grub-cfg script which will join these menu files together and write them to the master boot/grub2/grub.cfg configuration file.

First, set some variables to identify the label of your USB memory stick and a mount point (you might need to adjust these):

LABEL=multboot
MPT=/mnt/vfat

Next, mount the USB memory stick and create the create-grub-cfg script it's root directory using the following commands:

 [ -d ${MPT} ] || mkdir -p ${MPT}
 mount LABEL=${LABEL} ${MPT}
 cat >| ${MPT}/create-grub-cfg <<SEOF
#!/bin/bash

cat >| boot/grub2/grub.cfg <<EOF
# Global GRUB 2 options can be set here
set timeout=-1
set default=0
EOF

for f in \$(find . -name "*.men"); do
  echo "Adding: \${f}";
  cat "\${f}" >> boot/grub2/grub.cfg;
done
SEOF
chmod +x ${MPT}/create-grub.cfg
umount ${MPT}

Run Script

After adding a new distribution to your USB memory stick, you will want to re-build your GRUB 2 configuration file.

First, set some variables to identify the label of your USB memory stick and a mount point (you might need to adjust these):

LABEL=multboot
MPT=/mnt/vfat

Next, mount the USB memory stick and run the create-grub-cfg script from the top level directory of your USB memory stick:

 [ -d ${MPT} ] || mkdir -p ${MPT}
 mount LABEL=${LABEL} ${MPT}
 (cd ${MPT} && ./create-grub-cfg)
 umount ${MPT}

Test