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

From NST Wiki
Jump to navigationJump to search
(Created page with "= 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 '''li...")
 
(WARNING: Know What You Are Doing)
 
(23 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
* Install the GRUB 2 boot loader onto the USB memory stick.
 
* 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).
 
* Transfer ISO images (Debian based distros) or contents from the ISO for other distributions (Fedora based distros).
 +
 +
= [[Image:Warning.png‎]] 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.
 +
 +
''Watch out for auto-mounting!'' The steps in this guide assume that your USB media is not already mounted (instructions are included for mounting and unmounting). If you are logged into a graphical desktop, it is quite common for USB media to be auto-mounted under the /media directory. If any of your USB memory stick partitions are mounted, you should take care to '''umount''' them prior to proceeding with the instructions in this guide.
  
 
= Prepare Your USB Memory Stick =
 
= Prepare Your USB Memory Stick =
  
= Copy Files From ISO (NST, Fedora) =
+
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.
  
= Copy ISO Files (Debian, Ubuntu, ...) =
+
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):
  
= Create Grub 2 Configuration =
+
[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.
 +
 
 +
= Add NST (Fedora) Live Distributions =
 +
 
 +
The following demonstrates how to:
 +
 
 +
* Create a boot area 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.
 +
 
 +
It should be noted that these steps can provide a template for many Fedora based distributions.
 +
 +
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" {
 +
  linux16 /${SDIR}/memtest
 +
}
 +
EOF
 +
 
 +
After you are done installing your various Fedora based ISO distributions, you can unmount the USB memory stick.
 +
 
 +
cd
 +
umount ${MPT}
 +
 
 +
= 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 =
 +
 +
At this point you should be able to test your USB memory stick.
 +
 +
* Make sure to '''umount''' your USB memory stick.
 +
* Physically remove it from your NST system.
 +
* Plug it into the PC you want to boot.
 +
* Power on the PC and perform the necessary BIOS Kung Fu keyboard sequence to boot from the USB memory stick.
 +
* Select which distribution you want to boot from the GRUB 2 menu.
 +
 +
= Other Distribution Specific Notes =
 +
 +
The following section details distribution specific installation instructions. In particular:
 +
 +
* Whether the ISO image can be copied and used directly (or whether files need to be extracted).
 +
* What (if any) specific files from the ISO distribution need to be extracted.
 +
* How to create the GRUB 2 menu entry for the distribution.
 +
 +
== RHEL 5 ==
 +
 +
WARNING: This section is still under construction (was able to get it working with syslinux - but am struggling in a GRUB 2 environment).
 +
 +
First, let's set some variables which you may need to adjust based on your system or version of RHEL 5. 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=x86_64
 +
RELEASE=5.8
 +
SDIR=live/rhel-${RELEASE}.${ARCH}
 +
LDIR=${MPT}/${SDIR}
 +
ISO=/tmp/rhel-server-${RELEASE}-${ARCH}-dvd.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}
 +
 +
The following will extract the necessary files from your ISO image and install them into the proper location on your USB memory stick and then copy the ISO image over as well:
 +
 +
(cd ${LDIR} && 7z e ${ISO} isolinux/initrd.img isolinux/vmlinuz)
 +
[ -d ${LDIR}/iso ] || mkdir -p ${LDIR}/iso
 +
ISONAME="$(basename ${ISO})"
 +
ISODST="${LDIR}/iso/${ISONAME}"
 +
[ -f ${ISODST} ] || cp -fp ${ISO} ${ISODST}
 +
 +
The following command will create a list of menu entries which will be used later when creating a configuration file for GRUB 2 (NOTE: You may need to change ''sdb1'' below):
 +
 +
cat >| ${LDIR}/menuentry.men <<EOF
 +
menuentry "RHEL ${RELEASE} ${ARCH} Install" {
 +
  linux /${SDIR}/vmlinuz load_ramdisk=1 initrd=/${SDIR}/initrd.img method=hd:sdb1:/${SDIR}/iso
 +
  initrd /${SDIR}/initrd.img
 +
}
 +
EOF
 +
 +
Now, let's rebuild the GRUB 2 configuration and unmount the USB memory stick.
 +
 +
cd ${MPT}
 +
./create-grub-cfg
 +
cd
 +
umount ${MPT}
 +
 +
== Ubuntu 12 Desktop ==
 +
 +
For Unbuntu, let's first set some variables related to the label on your USB memory stick, where to mount the USB memory stick and what release and architecture of Ubuntu you want to install (you may need to adjust these):
 +
 +
LABEL=multboot
 +
MPT=/mnt/vfat
 +
ARCH=i386
 +
RELEASE=12.04.1
 +
SDIR=live/ubuntu-${RELEASE}.${ARCH}
 +
LDIR=${MPT}/${SDIR}
 +
ISO=/tmp/ubuntu-${RELEASE}-desktop-${ARCH}.iso
 +
 +
The following commands will mount your USB memory stick and create a sub-directory to hold the files necessary to boot this image and copies the ISO image to the directory:
 +
 +
[ -d ${MPT} ] || mkdir -p ${MPT}
 +
mount LABEL=${LABEL} ${MPT}
 +
mkdir -p ${LDIR}
 +
[ -d ${MPT}/iso ] || mkdir -p ${MPT}/iso
 +
ISODST="$(mktemp --tmpdir=${MPT}/iso ubunXXXX.iso)"
 +
ISONAME="$(basename ${ISODST})"
 +
[ -f ${ISODST} ] || cp -fp ${ISO} ${ISODST}
 +
 +
The following command will create a list of menu entries which will be used later when creating a configuration file for GRUB 2:
 +
 +
cat >| ${LDIR}/menuentry.men <<EOF
 +
menuentry "Ubuntu ${RELEASE} ${ARCH} Live - Desktop" {
 +
  loopback loop /iso/${ISONAME}
 +
  linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/${ISONAME} noeject noprompt splash --
 +
  initrd (loop)/casper/initrd.lz
 +
}
 +
EOF
 +
 +
Now, let's rebuild the GRUB 2 configuration and unmount the USB memory stick.
 +
 +
cd ${MPT}
 +
./create-grub-cfg
 +
cd
 +
umount ${MPT}

Latest revision as of 09:28, 14 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.png 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.

Watch out for auto-mounting! The steps in this guide assume that your USB media is not already mounted (instructions are included for mounting and unmounting). If you are logged into a graphical desktop, it is quite common for USB media to be auto-mounted under the /media directory. If any of your USB memory stick partitions are mounted, you should take care to umount them prior to proceeding with the instructions in this guide.

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.

Add NST (Fedora) Live Distributions

The following demonstrates how to:

  • Create a boot area 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.

It should be noted that these steps can provide a template for many Fedora based distributions.

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" {
 linux16 /${SDIR}/memtest
}
EOF

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

cd
umount ${MPT}

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

At this point you should be able to test your USB memory stick.

  • Make sure to umount your USB memory stick.
  • Physically remove it from your NST system.
  • Plug it into the PC you want to boot.
  • Power on the PC and perform the necessary BIOS Kung Fu keyboard sequence to boot from the USB memory stick.
  • Select which distribution you want to boot from the GRUB 2 menu.

Other Distribution Specific Notes

The following section details distribution specific installation instructions. In particular:

  • Whether the ISO image can be copied and used directly (or whether files need to be extracted).
  • What (if any) specific files from the ISO distribution need to be extracted.
  • How to create the GRUB 2 menu entry for the distribution.

RHEL 5

WARNING: This section is still under construction (was able to get it working with syslinux - but am struggling in a GRUB 2 environment).

First, let's set some variables which you may need to adjust based on your system or version of RHEL 5. 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=x86_64
RELEASE=5.8
SDIR=live/rhel-${RELEASE}.${ARCH}
LDIR=${MPT}/${SDIR}
ISO=/tmp/rhel-server-${RELEASE}-${ARCH}-dvd.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}

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

(cd ${LDIR} && 7z e ${ISO} isolinux/initrd.img isolinux/vmlinuz)
[ -d ${LDIR}/iso ] || mkdir -p ${LDIR}/iso
ISONAME="$(basename ${ISO})"
ISODST="${LDIR}/iso/${ISONAME}"
[ -f ${ISODST} ] || cp -fp ${ISO} ${ISODST}

The following command will create a list of menu entries which will be used later when creating a configuration file for GRUB 2 (NOTE: You may need to change sdb1 below):

cat >| ${LDIR}/menuentry.men <<EOF
menuentry "RHEL ${RELEASE} ${ARCH} Install" {
 linux /${SDIR}/vmlinuz load_ramdisk=1 initrd=/${SDIR}/initrd.img method=hd:sdb1:/${SDIR}/iso
 initrd /${SDIR}/initrd.img
}
EOF

Now, let's rebuild the GRUB 2 configuration and unmount the USB memory stick.

cd ${MPT}
./create-grub-cfg
cd
umount ${MPT}

Ubuntu 12 Desktop

For Unbuntu, let's first set some variables related to the label on your USB memory stick, where to mount the USB memory stick and what release and architecture of Ubuntu you want to install (you may need to adjust these):

LABEL=multboot
MPT=/mnt/vfat
ARCH=i386
RELEASE=12.04.1
SDIR=live/ubuntu-${RELEASE}.${ARCH}
LDIR=${MPT}/${SDIR}
ISO=/tmp/ubuntu-${RELEASE}-desktop-${ARCH}.iso

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

[ -d ${MPT} ] || mkdir -p ${MPT}
mount LABEL=${LABEL} ${MPT}
mkdir -p ${LDIR}
[ -d ${MPT}/iso ] || mkdir -p ${MPT}/iso
ISODST="$(mktemp --tmpdir=${MPT}/iso ubunXXXX.iso)"
ISONAME="$(basename ${ISODST})"
[ -f ${ISODST} ] || cp -fp ${ISO} ${ISODST}

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

cat >| ${LDIR}/menuentry.men <<EOF
menuentry "Ubuntu ${RELEASE} ${ARCH} Live - Desktop" {
 loopback loop /iso/${ISONAME}
 linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/${ISONAME} noeject noprompt splash --
 initrd (loop)/casper/initrd.lz
}
EOF

Now, let's rebuild the GRUB 2 configuration and unmount the USB memory stick.

cd ${MPT}
./create-grub-cfg
cd
umount ${MPT}