HowTo Put Multiple Live Images On One USB Memory Stick

From NST Wiki
Revision as of 10:58, 13 September 2012 by Paul Blankenbaker (talk | contribs) (Copy Files From ISO (NST, Fedora))
Jump to navigationJump to search

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
SDIR=live/nst-${RELEASE}.${ARCH}
LDIR=${MPT}/${SDIR}
ISO=/mnt/ext3/opt/nst-${RELEASE}.${ARCH}.iso

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} # To see contents of 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=multboot ${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

Create Menu Entry Files

Create Script To Join Menu Entry Files

Run Script

Test