SL4 and SL5: Live System on USB flash drive


IMPORTANT: This description is valid for SL4 and SL5 only. For SL6 see Create Live USB.


In order to boot from a USB drive your BIOS has to support booting from an USB device and you need to install a bootloader like grub or syslinux on it.

The following description uses syslinux as bootloader and assumes that the USB memory stick is on /dev/sdb. A similar setup can also be done with grub as bootloader. Please note, you must be root to execute most of the following commands. If you don't have a running Linux system, you can do the whole procedure out of a running SL LiveCD/DVD.

WARNING: If you change the wrong MBR or if you format the wrong partition, you can destroy your system, which can leave to complete data loss!

Please make sure that you know which device corresponds to your USB memory stick (e.g. /dev/sda or /dev/sdb) !!!
The following description assumes that the usb stick is on /dev/sdb.

To boot from USB memory is not a trivial task. Whether it works or not can depend on the MBR and on the partition of your stick, on the USB memory stick itself and on the BIOS of your PC.


Format the USB stick

On Windows

There is a useful tool from HP which allows you to format your USB memory stick. Unfortunately it runs only under Windows. Download the HP USB Disk Storage Format Tool from ftp://ftp.compaq.com/pub/softpaq/sp27001-27500/SP27213.exe. Choose as file system FAT (not FAT32) and format the stick. I have to admit that I had more success using the HP tool than doing it under Linux.

On Linux

Check on which device (dev/sd?) your USB memory stick is recognized by the system. If you have only IDE disks, it will be most probably appear on /dev/sda otherwise it can be on /dev/sdb or higher. See

# tail -f /var/log/message

while you plug in the USB memory stick. The USB device should also be visible by the command

# fdisk -l

First you have to overwrite the master boot record (MBR) of your USB flash drive.
Caution: Overwriting the wrong MBR (for example the one of your hard disk) can leave to complete data loss! If you are unsure, please back up your MBR(s) to a file and copy this file to a safe place (floppy disk, other USB memory stick, ...). For example to write the MBR of the first SATA disk (/dev/sdb) to a file mbr_sdb.bin, run:

# dd if=/dev/sdb of=/tmp/mbr_sdb.bin bs=512 count=1

Create a Windows 95/98 MBR on USB memory stick, using ms-sys (http://ms-sys.sourceforge.net). Ms-sys is available on recent SL LiveCD/DVDs or you can take the rpm for el4 from http://dag.wieers.com/packages/ms-sys/.

# ms-sys --mbr95b /dev/sdb
Windows 95B/98/98SE/ME master boot record successfully written to /dev/sdb

Then create a FAT16 partition on the USB flash drive:

# fdisk /dev/sdb

Create a new partition (enter n): Choose Primary partition (enter p), Partition number (enter 1). The size of the partition should be at least as larger as the LiveCD/DVD you want to install on the USB device. Afterwards, change the type (enter t) of first partition (enter 1) to W95 FAT16 LBA (enter e), and make first partition active (enter a and select 1). Before writing the partition table to the USB flash drive (enter w), you can print the changed settings (enter p).

Now format the first partition (/dev/sdb1) as FAT16. If you like, you can set a label with option -n

# mkdosfs -n SL-LiveCD /dev/sdb1

Note, this is all done without mounting the partition.


Make the USB memory stick bootable using syslinux

You should have now something like:

# fdisk -l /dev/sdb

Disk /dev/sdb: 1006 MB, 1006632960 bytes
31 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 1922 * 512 = 984064 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         747      717836    e  W95 FAT16 (LBA)

Important: The first partition is active (marked with *) and is a FAT16 partition: ID "e".

Now the syslinux boot loader has to be installed on the first FAT partition:

# syslinux /dev/sdb1

If you get the error "Cluster sizes larger than 16K not supported", try to use a more recent version of syslinux. Syslinux can be downloaded from kernel.org: http://www.kernel.org/pub/linux/utils/boot/syslinux/. I have successfully used syslinux > 3.11. Download, unpack and compile syslinux by executing "make". You will find the syslinux binary in the folder unix:

# wget http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.11.tar.gz
# tar xfvz syslinux-3.11.tar.gz
# cd syslinux-3.11
# make
# cd unix
# ./syslinux /dev/sdb1

This should create a file "ldlinux.sys" in the sdb1 partition.

Now try to boot from the USB memory stick. If this works you should see someting like:

SYSLINUX 3.11 2005-09-02 EBIOS Copyright (C) 1994-2005 H. Peter Anvin
Could not find kernel image: linux
boot:

Congratulation, you USB stick is no bootable!

If you get "boot failed", "Missing operation system", "Boot error" or just nothing, try to redo the above steps - also try to format the stick under Windows as described above.


Copy LiveCD data

First mount the partition. Under Scientific Linux /dev/sdb1 will be mountable under /media/"something".

or do it manually:

# mkdir -p /mnt/usbdisk
# mount /dev/sdb1 /mnt/usbdisk

Since your have already installed syslinux on the USB memory stick before, you should see

# ll /mnt/usbdisk
total 12
-r-xr-xr-x  1 root root 8236 Apr 27 21:23 ldlinux.sys

Either mount the LiveCD/DVD directly or just mount the ISO image of the LiveCD/DVD:

# mkdir -p /mnt/iso
# mount -o loop livecd_SL54_gnome_2009-11-20.iso /mnt/iso

By the way, if you are doing this on a running LiveCD system, the CD is already mounted under /livecd/live/livecd/hdc, assuming your CD-ROM is the third IDE device (hdc).

Now copy everything from the CD/DVD to the USB flash drive:

# cp -rv /mnt/iso/* /mnt/usbdisk/

In contrast to grub, syslinux can not access the kernel and the initial RAM disk in the "boot" folder. Therefore you have to move the "boot"-files to the root folder of the USB flash drive:

# cd /mnt/usbdisk/
# mv boot/* .

Rename isolinux.cfg to syslinux.cfg and delete the path "boot/" in syslinux.cfg, splash.cfg and help*.txt:

# mv isolinux.cfg syslinux.cfg
# sed -i "s|boot/||" syslinux.cfg
# sed -i "s|boot/||" splash.cfg
# sed -i "s|boot/||" help*.txt

You can also remove the isolinux.bi_, isolinux.bin and isolinux.boot files:

# rm isolinux.*

Now everything should be ready for booting the USB flash drive. The most important files on the USB flash drive are:

|-- base
|   |-- bin.mo
|   |-- etc.mo
|   |-- ....
|-- ...
|-- help1.txt
|-- help2.txt
|-- ...
|-- initrd.gz
|-- ldlinux.sys
|-- livecd.sgn
|-- memtest
|-- splash.cfg
|-- splash.lss
|-- syslinux.cfg
|-- vmlinuz

Finally, unmount the USB flash drive and the LiveCD iso image

# cd
# umount /mnt/usbdisk
# umount /mnt/iso

Create a writable partition on the USB flash drive to store changes permanently

Normally all data that you have created or any software you have installed since the LiveCD was booted, are lost when you shutdown the system, even if the LiveCD is running from USB key. To save the changes permanently use the "changes=" boot parameter. For information about persistent LiveCD see also Persistent LiveCD.

Please note: The following procedure only works for LiveCD/DVD's created after 2008-08-01 !

Please make sure that you know which device corresponds to your USB memory stick (e.g. /dev/sda or /dev/sdb) !!!

First you need some free space on your USB memory stick which is not used by the first partition (/dev/sdb1). Either you have already taking this into account when you created the first partition or you can try to resize your first partition with parted.

# parted /dev/sdb
...
Using /dev/sdb
(parted) resize
Partition number? 1
Start?  [0.0308]?
End?  [1983.9995]? 1890
...
(parted) quit

If you get errors during the use of parted, just type "i" for Ignore and do not change the file system to FAT32 - leave it as FAT.

Now create a ext3 partition on /dev/sdb:

# fdisk /dev/sdb

Create new partition (n): Primary partition (p), Partition number (2) and choose an appropriate size for the partition.

Format /dev/sdb2:

# mkfs.ext3 /dev/sdb2

Maybe you want to disable automatic filesystem check for this partition:

# tune2fs -c 0 /dev/sdb2

To create the directory "my_changes" on /dev/sdb2:

# mkdir -p /mnt/usbdisk2
# mount /dev/sdb2 /mnt/usbdisk2
# mkdir /mnt/usbdisk2/my_changes

The folder name "my_changes" has to be defined in syslinux.cfg using the boot parameter "changes=my_changes".

If not yet done, mount the first partion of the USB stick again:

# mount /dev/sdb1 /mnt/usbdisk

Edit syslinux.cfg in /mnt/usdisk and add changes=my_changes to the append line(s)

# cd /mnt/usbdisk
# emacs syslinux.cfg
...
append changes=my_changes max_loop=32 initrd=initrd.gz .....

Or even more advanced

# emacs syslinux.cfg
...
append changes=my_changes kb=sg-latin1 pw=mypassword max_loop=32 initrd=initrd.gz .....

See boot parameters for more options.




Last modified: Friday, 18-Mar-2011 13:11:09 CET by Urs Beyerle