Installing 3 Linux CD on an USB flash drive
With the size of the current USB flash drives, it seems a bit ridiculous to have a USB flash drive for a single Linux CD... Why not, for example, put a SystemRescueCD, a 32 bits Ubuntu and as well as a 64 bits Ubuntu?
This installation procedure will tell you how to do this for 2 or 3 Linux ISO images (you can even install 41 ISO images on the same USB drive, provided that you install GRUB on the same partition as one of the CDs).
Installation procedure
Finding the device used by the USB flash drive
- Plug-in the USB flash drive.
To find out which device is used, use the dmesg | tail -n 50 command (as root).
[109779.538284] usb-storage: device found at 9 [109779.538290] usb-storage: waiting for device to settle before scanning [109784.530294] usb-storage: device scan complete [109784.532763] scsi 10:0:0:0: Direct-Access Generic Flash Disk 8.07 PQ: 0 ANSI: 2 [109784.533545] sd 10:0:0:0: Attached scsi generic sg3 type 0 [109784.555079] sd 10:0:0:0: [sdc] 4040704 512-byte logical blocks: (2.06 GB/1.92 GiB) [109784.573909] sd 10:0:0:0: [sdc] Write Protect is off [109784.573919] sd 10:0:0:0: [sdc] Mode Sense: 03 00 00 00 [109784.573925] sd 10:0:0:0: [sdc] Assuming drive cache: write through [109784.599541] sd 10:0:0:0: [sdc] Assuming drive cache: write through [109784.599553] sdc: sdc1 sdc2 sdc3 sdc4 [109785.182447] sd 10:0:0:0: [sdc] Assuming drive cache: write through [109785.182466] sd 10:0:0:0: [sdc] Attached SCSI removable disk
The device used here is sdc. Each time we will use it, it will therefore be called "/dev/sdc".
Please replace each occurence of /dev/sdc below by the correct device on your system.
Use gparted to format the USB flash drive
Use gparted to format the USB flash drive. Make a first 32MB FAT32 partition, then 3 partitions, each one slightly larger than the CD you want to copy.
In gparted, select the device corresponding to your USB flash drive.
Remove the existing partitions (
Everything on the USB key will be lost!). Make a first partition for GRUB (e.g. /dev/sdc1):
- New size: « 32MB ».
- Create as: « Primary partition ».
- File system: « fat32 ».
- Label: « GRUB ».
Make a second partition for your first CD (e.g. /dev/sdc2):
- New size: slightly larger than the 1st CD.
- Create as: « Primary partition ».
- File system: « fat32 ».
Make a third partition for your second CD (e.g. /dev/sdc3):
- New size: slightly larger than the 2nd CD.
- Create as: « Primary partition ».
- File system: « fat32 ».
Make a fourth partition for your third CD (e.g. /dev/sdc4):
- New size: slightly larger than the 3rd CD.
- Create as: « Primary partition ».
- File system: « fat32 ».
- Apply your changes.
As older BIOS might not be able to start a partition too far away, always put the smallest (or the more important) CD images first (e.g. a rescue CD).
SystemRescueCD installation
Download the SystemRescueCD ISO image.
Mount the target partition of your USB flash drive (e.g. with mount -t vfat /dev/sdc2 /mnt [replacing /dev/sdc2 by the name of your target partition]).
With an archive manager (like file-roller), copy the content of your ISO image to your target partition.
On the target partition, rename the isolinux folder to syslinux.
In syslinux, rename the isolinux.cfg file to syslinux.cfg.
Unmount the target partition of the USB flash drive (e.g. with umount /dev/sdc2).
Then, as root, make the target partition bootable with the following command (replacing /dev/sdc2 by the name of your target partition):
syslinux /dev/sdc2
Ubuntu CD installation
With the "Ubuntu Live USB creator" (usb-creator-gtk), install the Ubuntu ISO image on the target partition of your USB flash drive..
GRUB Installation
Once you will have installed your 3 CD images, you can start installing GRUB.
Download the latest revision (0.9x) of GRUB Legacy for i386 on the GRUB FTP server (e.g. grub-0.97-i386-pc.tar.gz).
Mount the first partition of your USB flash drive (e.g. with mount -t vfat /dev/sdc1 /mnt).
Uncompress the tar archive and copy the boot directory it contains to the first partition you just mounted.
Create a menu.lst file in boot/grub (on the first partition) :
timeout 120 color light-gray/black light-blue/black title NAME OF THE FIRST LINUX rootnoverify (hd0,1) makeactive chainloader +1 boot title NAME OF THE SECOND LINUX rootnoverify (hd0,2) makeactive chainloader +1 boot title NAME OF THE THIRD LINUX rootnoverify (hd0,3) makeactive chainloader +1 boot
- Just replace "NAME OF THE FIRST LINUX", "NAME OF THE SECOND LINUX" and "NAME OF THE THIRD LINUX" by a name for your CDs (e.g."SystemRescueCD 1.5.1" or "Ubuntu 9.10 (Karmic Koala) 32bit").
- Unmount the first partition of the USB flash drive.
- To install GRUB, type-in the following commands (as root) :
grub --batch --device-map=/dev/null <<FDT device (hd0) /dev/sdc root (hd0,0) setup (hd0) quit FDT
You will need to do this again if you update your CD images. Do not forget to replace /dev/sdc by the device name of your USB flash drive.
- If everything goes well, you should seen something like that:
# grub --batch --device-map=/dev/null <<FDT > device (hd0) /dev/sdc > root (hd0,0) > setup (hd0) > quit > FDT [ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename. ] grub> device (hd0) /dev/sdc grub> root (hd0,0) grub> setup (hd0) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/fat_stage1_5" exists... yes Running "embed /boot/grub/fat_stage1_5 (hd0)"... 16 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done. grub> quit
Your flash drive should now be set up. Enjoy.
Notes
GRUB disk naming
GRUB disks and partitions numbers starts from zero.
- (hd0) is the first (hard) drive.
- (hd1) is the second drive.
- ...
- (hd0,0) is the first partition of the first drive.
- (hd0,1) is the second partition of the first drive.
- (hd0,2) is the third partition of the first drive.
- ...
When you boot from a USB flash drive, the flash drive will always be the first disk for GRUB. The USB flash drive should therefore be named (hd0) in the GRUB configuration file (menu.lst).
Feedback
You can send me your comments and suggestions to <jean DASH philippe DOT guerard AT tigreraye DOT org>.
See also
The Disk partitioning Wikipedia article.
The Cylinder 1024 Wikipedia article.
How to create a GRUB boot floppy with the menu interface? (GRUB FAQ).
Load another boot loader to boot unsupported operating systems (GRUB manual).
Le Naming convention (GRUB manual).
The SystemRescueCD USB stick installation procedure.
It's not possible to go over 4 bootable (primary) partitions. (1)

