30.06.2013 Views

HOWTO Boot Linux from a USB 2GB Pen Drive - Curtin University

HOWTO Boot Linux from a USB 2GB Pen Drive - Curtin University

HOWTO Boot Linux from a USB 2GB Pen Drive - Curtin University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>HOWTO</strong> <strong>Boot</strong> <strong>Linux</strong> <strong>from</strong> a <strong>USB</strong> <strong>2GB</strong> <strong>Pen</strong> <strong>Drive</strong><br />

Author: Leigh Harrison<br />

Date: 01.12.06<br />

File: usb_2gb_howto.odt<br />

Email: L.Harrison@curtin.edu.au<br />

Tel: +61 8 9266 4727<br />

<strong>HOWTO</strong> <strong>Boot</strong> <strong>Linux</strong> <strong>from</strong> a <strong>USB</strong> <strong>2GB</strong> <strong>Pen</strong> <strong>Drive</strong><br />

Leigh Harrison, December 2006<br />

Leigh Harrison, Dec 2006 Page 1 of 6


<strong>HOWTO</strong> <strong>Boot</strong> <strong>Linux</strong> <strong>from</strong> a <strong>USB</strong> <strong>2GB</strong> <strong>Pen</strong> <strong>Drive</strong><br />

Table of Contents<br />

1. Purpose.............................................................................................................................................3<br />

2. Scope................................................................................................................................................3<br />

3. Reference Documents.......................................................................................................................3<br />

4. Glossary............................................................................................................................................3<br />

4. Installation........................................................................................................................................4<br />

4.1 Obtain Knoppix..........................................................................................................................4<br />

4.2 Prepare the <strong>Pen</strong>drive..................................................................................................................4<br />

4.3 Partition the <strong>Drive</strong>......................................................................................................................4<br />

4.4 Install the syslinux <strong>Boot</strong>loader..................................................................................................5<br />

4.5 Mount the New Partition............................................................................................................5<br />

4.6 Copy Contents of Knoppix <strong>Boot</strong> Directory...............................................................................5<br />

4.7 Copy the Rest of the Knoppix CD.............................................................................................5<br />

4.8 Ready to <strong>Boot</strong>!...........................................................................................................................5<br />

4.9 Make the <strong>USB</strong> <strong>Pen</strong>drive Read/Write.........................................................................................6<br />

4.10 Installing Binaries....................................................................................................................6<br />

4.11 Further Work............................................................................................................................6<br />

4.11.1 mkdiskimage Settings......................................................................................................6<br />

Leigh Harrison, Dec 2006 Page 2 of 6


<strong>HOWTO</strong> <strong>Boot</strong> <strong>Linux</strong> <strong>from</strong> a <strong>USB</strong> <strong>2GB</strong> <strong>Pen</strong> <strong>Drive</strong><br />

1. Purpose<br />

This document describes the method of installing a bootable <strong>Linux</strong> operating system on a <strong>USB</strong> pen<br />

drive.<br />

2. Scope<br />

This method applies to a <strong>2GB</strong> <strong>USB</strong> pen drive but smaller memory sizes should still work with this<br />

methodology. The <strong>Linux</strong> OS used for the installation was Knoppix 5.01 Live CD.<br />

3. Reference Documents<br />

Doc No. Title Author Contact<br />

1. <strong>USB</strong> <strong>Pen</strong>drives and Distributions for Them – <strong>Linux</strong> Journal, June<br />

2006, pp 86-88<br />

Juan Marecelo<br />

Rodriguez<br />

www.linuxjournal.com<br />

2. <strong>Boot</strong>able <strong>USB</strong> Key www.knoppix.net/wiki/<strong>Boot</strong>able_US<br />

B_Key<br />

3. <strong>Linux</strong> in Nutshell, 2nd Ed., Oreilly Ellen Siever www.oreilly.com<br />

4. Glossary<br />

Term Meaning<br />

Knoppix A <strong>Linux</strong> OS distribution produced by Klaus<br />

Knopper, based on Debian <strong>Linux</strong>.<br />

See www.knopper.net/knoppix/index-en.html<br />

Leigh Harrison, Dec 2006 Page 3 of 6


<strong>HOWTO</strong> <strong>Boot</strong> <strong>Linux</strong> <strong>from</strong> a <strong>USB</strong> <strong>2GB</strong> <strong>Pen</strong> <strong>Drive</strong><br />

4. Installation<br />

4.1 Obtain Knoppix<br />

Download a copy of Knoppix 5.01 <strong>from</strong> http://www.knopper.net/knoppix-mirrors/index-en.html .<br />

Burn a CD <strong>from</strong> the iso image and check that it boots <strong>from</strong> a PC. you may have to change the BIOS<br />

boot sequence for this to happen.<br />

4.2 Prepare the <strong>Pen</strong>drive<br />

Insert the <strong>2GB</strong> <strong>USB</strong> pen drive as soon a the boot: message appears in the GRUB bootloader. This<br />

ensures that Knoppix will find it using autodetection.<br />

The “cheatcodes 1 ” are passed at the boot: message to set various parameters and start services. Do<br />

not use the toram cheatcode as this does not include the /boot directory, which is required by the<br />

pendrive.<br />

Login as root:<br />

su<br />

Followed by RETURN.<br />

Check the drive letter of the <strong>USB</strong> pendrive; it should be typically /dev/sda or similar.<br />

Try:<br />

dmesg grep ­i scsi<br />

or<br />

dmesg grep ­i usb<br />

or<br />

cat /proc/partitions<br />

Next, erase the <strong>USB</strong> pendrive. A word of caution: Make sure that you have correctly identified the<br />

device correctly. The next bit can wreak havoc with your hard-drive if you pick /dev/hda instead<br />

of /dev/sda, etc.<br />

Erase the pendrive (assuming your device is /dev/sda):<br />

dd if=/dev/zero of=/dev/sda<br />

This took about ten minutes on my Astone <strong>2GB</strong> pendrive and a “no space left on device” should<br />

appear when it's done.<br />

4.3 Partition the <strong>Drive</strong><br />

The <strong>USB</strong> pendrive can now be partitioned with the following command:<br />

mkdiskimage /dev/sda 0 256 63<br />

This also take some time to complete. The mkdiskimage command creates the master boot record,<br />

partition table and then partitions and formats the drive as a FAT16 partition. It sets up the image as<br />

a <strong>USB</strong>-HDD which most modern BIOS can handle. The reference document used the -4 option<br />

which set up the image as <strong>USB</strong>-ZIP. This is more universal than perhaps <strong>USB</strong>-HDD but it limits the<br />

1 http://www.knoppix.net/wiki/Cheat_Codes<br />

Leigh Harrison, Dec 2006 Page 4 of 6


<strong>HOWTO</strong> <strong>Boot</strong> <strong>Linux</strong> <strong>from</strong> a <strong>USB</strong> <strong>2GB</strong> <strong>Pen</strong> <strong>Drive</strong><br />

maximum image size to 1GB and it won't work on a <strong>2GB</strong> device!<br />

KDE may start a pop-window when the new partition is recognized. Simply close it.<br />

4.4 Install the syslinux <strong>Boot</strong>loader<br />

Install the syslinux bootloader on the new <strong>USB</strong> pendrive partition:<br />

syslinux ­s /dev/sda1<br />

A new file, ldlinux.sys is also installed.<br />

4.5 Mount the New Partition<br />

Mount the partition:<br />

mount /media/sda1<br />

Knoppix should have found the new partition by auto-detection and set up an entry in fstab.<br />

/dev/sda1 should be mounted at /media/sda1 .<br />

Check that only on file is present on the <strong>USB</strong> partition (ldlinux.sys).<br />

cd /media/sda1<br />

ls<br />

4.6 Copy Contents of Knoppix <strong>Boot</strong> Directory<br />

Copy the contents of the Knoppix boot directory onto the <strong>USB</strong> partition.<br />

cp ­av /cdrom/boot/isolinux/* .<br />

mv isolinux.cfg syslinux.cfg<br />

rm ­f isolinux.bin<br />

Ignore “failed to preserve ownership” error messages. These are due to the FAT file system which<br />

doesn't support file ownership.<br />

The reasons behind this sequence of commands are described in detail in 3.1, Reference No. 2.<br />

The Knoppix CD's boot directory is copied first to get it as near to the beginning of the drive as<br />

possible.<br />

4.7 Copy the Rest of the Knoppix CD<br />

Check that you are still in the /media/sda1 directory and copy the remaining items.<br />

cp ­av /cdrom/* .<br />

rm ­rf ./boot<br />

This takes some time to complete. The duplicate copy of the ./boot directory is removed.<br />

4.8 Ready to <strong>Boot</strong>!<br />

Unmount the <strong>USB</strong> pendrive.<br />

sync<br />

cd /<br />

umount /media/sda1<br />

sync<br />

Leigh Harrison, Dec 2006 Page 5 of 6


<strong>HOWTO</strong> <strong>Boot</strong> <strong>Linux</strong> <strong>from</strong> a <strong>USB</strong> <strong>2GB</strong> <strong>Pen</strong> <strong>Drive</strong><br />

Shutdown Knoppix and reboot the PC. Change the BIOS boot sequence so it boots <strong>from</strong> the <strong>USB</strong><br />

pendrive and save the settings. Allow the <strong>USB</strong> drive to boot up.<br />

4.9 Make the <strong>USB</strong> <strong>Pen</strong>drive Read/Write<br />

The default configuration for the Knoppix image is read only. It appears as a CD-ROM. However, it<br />

can be made read/write as follows:<br />

mount ­o remount,rw /cdrom<br />

mount ­­bind cdrom /media/sda1<br />

The /home/knoppix directory should now be made persistent so that data and settings can be<br />

saved. Under the <strong>Pen</strong>guin menu select Configure, Create Persistent. Select a useful size but don't<br />

use the all of the remaining of the space available on the pen drive, to allow for quick file copying<br />

etc. I had about 1.2 GB left and chose 684 kB but this is optional. The persistent home directory is<br />

reformatted as ext2. Reboot and select the persistent home directory during boot-up. All settings<br />

will be saved and files can be now stored in the /home/knoppix directory.<br />

4.10 Installing Binaries<br />

Binaries can be installed by copying *.tar.gz source files onto the pen drive and compiling in the<br />

usual way. Copy or move the source files <strong>from</strong> the root directory to the /home/knoppix directory.<br />

The source files can be untarred and installed as root <strong>from</strong> there in the usual way. Copy the binaries<br />

as the user knoppix 2 <strong>from</strong> the /usr/bin or /usr/local/bin (or wherever it's placed during the<br />

installation) to the /home/knoppix directory.<br />

4.11 Further Work<br />

4.11.1 mkdiskimage Settings<br />

I used the following settings which worked without any problems.<br />

Command c h s<br />

mkdiskimage /dev/sda1 0 256 63<br />

However, it is suggested in reference 2 that 255 heads be used “as it's slightly more compatible”.<br />

For pen drives which are greater than 2 GB it's suggested that FAT32 is used rather than FAT16.<br />

This requires the use of the -F option as follows:<br />

mkdiskimage ­F /dev/sda1 0 256 63<br />

2 If you do the copy as root you will have to change owner and group to knoppix.<br />

Leigh Harrison, Dec 2006 Page 6 of 6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!