Version 0.6
Copyright © 2007,2008 by Zack Smith
Introduction
Many technically-inclined people have formed a keen interest in
booting from flash.
It is indeed an appealing idea, perhaps due to:
- The fact that many computers (even relatively old ones) are bootable from flash.
- The fact that flash thumbdrives are now commonplace.
- The cheapness and large capacity of such drives.
- Possession of unused or underused older-generation flash cards such as CompactFlash that are no longer useful in most cameras.
- A geeky desire to experiment with tech gear.
- A geeky desire to run Linux on every concieveable computer.
There are many pages on the Web that offer tantalizing clues
on how to create a bootable flash drive, however
none of them describes the procedure with clear, step-by-step
instructions. Many actually link to other
pages effectively saying "he knows better than me", or "use that
utility program", but
these other pages typically either don't exist or offer no
real explanation either,
or the utilities don't run properly.
I created this page to explain, once and for all,
how to create a bootable
live Linux flash drive in clear steps, and not
merely a flash-based Linux installation drive.
This drive is intended to supercede the hard drive,
either for the purpose of recovery or to replace it.
Equipment
Target (boot) system
I will be booting the flash drive in a 150 MHz Thinkpad 560e laptop.
It's the perfect notebook for taking to a cafe or library
because it cost me $30 used, although it lacks
a hard drive.
I am booting from a tiny 48MB CompactFlash card that is in a
16-bit PCMCIA adapter, which is plugged into a
The 560e's BIOS permits booting from a flash card in the PCMCIA slot.
This laptop has no USB ports.
Host system
My host system for preparing the flash drive
is a desktop that is running Slackware 12 (Linux 2.6 kernel).
I've placed the 48 MB CompactFlash card in a
USB 2.0 CompactFlash adapter, which appears as /dev/sda.
The Steps
You will need to log in as root.
1. Unmount the flash card if necessary.
If you previously modified /etc/fstab to automount /dev/sda, type:
2. Wipe the flash card.
Let's start clean. Remove any useful data from the flash card first
because we will wipe it using this command:
dd if=/dev/zero of=/dev/sda
|
3. Partition the flash card.
We need to create two partitions. The boot partition and
the root partition, so:
(You can also use cfdisk if you prefer a simpler user interface.)
Fdisk may start up by complaining about the boot sector,
because it's all zeroes. That's fine.
Create a primary 4 megabyte partition using 'n'.
Use the 't' command to set it to type 1, which is FAT12.
Set it to bootable using the 'a' command.
Then, create a second primary partition (number 2)
using 'n' and leave its
type alone since the default is Linux ext2/ext3 and that's what we
want.
Type 'w' to write the partition information
to the flash disk.
4. Format the partitions.
mkdosfs -F12 /dev/sda1
mkfs.ext3 /dev/sda2
|
5. Create the boot sector.
LILO will tell you that it backed up the original boot sector
in /boot. Since we had wiped the disk previously, that
sector is not useful; you can delete it.
6. Install the SYSLINUX bootloader.
It simply works.
7. Find or create a suitable kernel.
Depending on which processor your target
system has, you may not be able to use your
host system's kernel. For instance, my
host is a Pentium III, and I had previously created a kernel
compiled just for that CPU. The stock kernel
was for a Pentium Pro, I believe.
Both are too new for my laptop's Pentium I MMX.
If you've never compiled your own kernel,
now is not the time to be a wuss!
Creating a kernel is no more difficult
than making coffee over a campfire.
Here is what you do, using the example of
creating kernel 2.6.20.21, which is more reliable
than 2.6.23.
cd /usr/src
ftp ftp.kernel.org
cd pub/linux/kernel/v2.6
bin
mget linux-2.6.20.21*bz2
bye
tar jxfv linux-2.6.20.21*bz2
cd linux-2.6.20.21
make menuconfig
|
...Whereupon you will look at all the curious and
interesting options that you can select or not.
Examine all the options' details for your edification and
enrichment.
The goal should be to create a small kernel
that has all the drivers you will need,
and none that you don't.
If the kernel contains all the drivers,
there will be no need for an initrd (initial RAM disk),
whose purpose is to provide drivers.
Once you have a nice set of options,
exit, saving the configuration, and then
type "make".
When the compilation is complete, your kernel will be
arch/i386/boot/bzImage.
In my case, I clearly need support for PCMCIA
for the flash and I need to support the older non-SMP CPU
and perhaps APM power management.
My target system doesn't support AGP, USB, Firewire, framebuffer
graphics, Ethernet, wireless and the like.
8. Copy the suitable kernel into /dev/sda1
In my case, I have a directory /usb already created that I use for
accessing USB drives.
mount /dev/sda1 /usb
cp /usr/src/linux-2.6.*/arch/i386/boot/bzImage /usb/bzimage.i
|
9. Create a SYSLINUX config file
Here is mine. Note that I am telling SYSLINUX that
the root filesystem is in /dev/hdc2, which is the
PCMCIA IDE drive, i.e. the CompactFlash card.
Partition 2 (hdc2) is of course the Linux ext3 filesystem.
default bzimage.i
prompt 1
timeout 1200
display message.txt
F1 message.txt
label bzimage.i
kernel bzimage.i
append vga=6 root=/dev/hdc2 load_ramdisk=0 ro SLACK_KERNEL=bimage.i
|
10. Install Linux
This is the part that could require the most time.
You need to have your Linux installation DVD or CD
handy. Plug the flash card into your host computer
and boot the host with the Linux install disk
in the optical drive.
Select your target to install onto as simply
the same /dev/sda2 as above.
In the case of Slackware, which I use,
they ask what the target drive is and the installation
disc's kernel supports USB flash adapters.
What takes time is selecting which specific
packages (e.g. RPMs) to put into the 2nd flash partition.
Unless your flash card is 4 gigs or more,
you will want to save any megabytes you can.
In the case of my 48MB flash disk, very little
could fit except Slackware's A series packages
and a few important libraries.
I later used a 1 GB CompactFlash to install important
parts of Slackware's A, AP, D, L, X and XAP series
in about 700 megabytes.
I specifically left out junk that I don't need,
like the GNU Ada compiler, Common Lisp, tape drive
programs, CD/DVD software (my system has no optical drive)
and the like.
From this experience, I believe that a 2 gig flash drive
would be ideal, 4 gigs would allow for media files
enough to entertain, or if you have serious work to do, A-DATA makes a
16 gig CompactFlash card that costs about $80 via Newegg.
|
11. Tweaking
After installing Linux you will
have to edit your /etc/fstab, since the installation
process will assume that whatever your flash
card was called on the host, that's the same as what
it will be called on the target, which is probably
not true.
12. Testing
Now boot from flash and see how it works.
It will be a little strange to use a computer with
no hard drive noise.
Still, it works great, even in my case using
a 16-bit adapter with 700 kB/sec throughput.
I've set up both a 48 MB rescue disk
and a 1 GB everyday use disk successfully.
Links
|
|