...making Linux just a little more fun!

<-- prev | next -->

Booting Knoppix from a USB Pendrive via Floppy

By Ben Okopnik

There's a certain theme that runs through the Linux community, a sense of invulnerability with which we endow our perception of our systems. Terms like "bullet-proof" and "rock-solid", and phrases like "you could run it on a toaster" abound - silly if considered in the bright light of day, and dangerous when looked at from a certain perspective. What if someone called you on it? Would you actually be able to set up a PC with Linux, fire a 44-Magnum round at it, and expect it to bounce off? Would you expect a PC to break in two along a cleavage line if you struck it with a geological hammer? Do you really think that plugging a CD into the bread slot of a toaster will make it pop up a cool GUI a few seconds later? Of course not...

...but, well, still. There's so much that Linux does so well, so many avenues that it opens that looked to be permanently shut, that even in the hopeless cases we still harbor a bit of hope. Just a touch of a sense that maybe, just maybe, just possibly there's some magic extra, some little advantage that will let us overcome broken hardware, missing cables, outdated equipment... hey, don't some of those Linux floppy firewall distros run without a monitor or even a hard drive? If they can do it, why not us?

The thing that keeps it going is that on a few occasions - not all, but a few - there are those little successes that set us up for the next time. Whether this is a good thing or a bad thing, I refuse to judge; I'm as much of a success junkie as most other geeks, and am unrepentant about it - am, in fact, always happy to boast about the fact (although, as they say, "it ain't boasting if you can do it".) All the more so if recounting the experience can help others learn a fun new method, or a cool way to accomplish something useful. Hence, this article.

The Challenge

My fiancée was interested in trying Linux - her opinion regarding OSes being that Micr0s0ft should have stopped when the going was good (that being defined as some time around the release of DOS 5.0.) Since they hadn't, and since neither Micr0s0ft Bob nor the dancing paperclips had lived up to their promise - which she hadn't believed anyway - she was quite happy to try an OS that was bullet-proof and solid as a rock... erm. Well, you know what I mean, anyway.

However, there was A Problem. To be more precise, a long series of problems, compounded by the circumstances. For one thing, her laptop - an aging Sony VAIO F590K - did not have a working CD-ROM drive (goodbye, quick and easy chance of booting Knoppix - or most of the other LiveCD distros...) For another, she is the editor of a monthly newsletter for space activists, and must have uninterrupted access to a powerful graphic program as well as a DTP (desktop publisher program) - having her computer out of service for any length of time was not an option. What she really wanted was a chance to play with Linux on her machine, where the feel of the keyboard and all the controls was familiar and comfortable for her (and I heartily agreed, on the principle that, in a properly-designed experiment, only the factor under test should change while all else is held equal.) To complicate things a bit further, we live on a sailboat at anchor, and our Net access is therefore less than stellar - and is quite slow. Things were looking pretty grim.

By this point, I had considered a number of options, and had rejected almost as many as I'd considered. What remained were some dim possibilities - perhaps booting a minimal floppy-based Linux environment with a VNC client while I ran a VNC server elsewhere on our LAN (clunky and restricted by the artifacts of VNC itself), or maybe setting up the Cygwin X server on Wind0ws (Terra Incognita to me since I'd never done anything with Cygwin, along with a good bit of apprehension related to how it would work and what kind of problems it would introduce into the process - on top of those created by KDE's cluelessness with regard to the X networking paradigm), or... or... wait, how about booting Knoppix from a flash drive? I seemed to recall that I had read something about this, somewhere - perhaps even a success story? - and I was perfectly willing and able to search the Net for an answer. The details of the necessary process were a bit of a muddle in my head, but given time and resources, that would shake out.

The Approach

Googling around the Web refined my list of remaining ideas even further, knocking out several of the possibilities - as an example, several of the live distros failed to include either the GIMP or OOffice, both of which had been decided on as necessities - and focusing the choice down to Knoppix and a few similar distros. Knoppix, as the most-commonly used example of the genre, seemed to be the final answer - but how was I to get it to the VAIO? The flash drive that I had, a 1GB Geek Squad pendrive, would hold the image with room left over, but the machine had no option for booting from flash - and a quick scan of Sony's site showed that there were no BIOS updates to fix this.

About that time, I recalled that someone in the Answer Gang had mentioned Puppy Linux in the recent past - and that the site had a discussion on how to make it boot from flash by using a floppy. Hurrah!... well, Puppy doesn't contain GIMP or OOffice (although it does have Scribus), but the fact that people are booting USB-based Linux images via floppy was encouraging; this is what I was looking for.

FLASH! Uh-huh...

I read the FAQ very carefully, and got a very definite... headache. For whatever reason, right at that moment my brain simply refused to accomodate the necessary information - I'm sure that it had nothing to do with the way it was presented, just that I didn't quite get it. More searching produced the Boot KNOPPIX from an USB Memory Stick FAQ - which helped a bit but still didn't get me where I wanted to go. More research, including posting to The Answer Gang (thanks, guys!)... and then I ran across Fabian Franz' script for booting Knoppix 3.4. It didn't work, of course - I didn't expect it to, since Knoppix has changed quite a bit since those days - but by this point, I understood the process and the structure of the Knoppix image well enough that I could follow the logic all the way through.

Combining the information from the above FAQ and the script finally made it all click. The Knoppix CD consists of a number of files, of which only one really mattered to what I needed: the "miniroot". To be exact, the miniroot is a compressed bootable image within the Knoppix image - it is, in fact, the part that makes the Knoppix CD bootable - so tweaking the files inside it consisted of the following steps:

  1. Mount the Knoppix image
  2. Decompress the miniroot into a temporary file
  3. Mount the miniroot
  4. Modify the files in it
  5. Recompress it
  6. Create a loop-mounted file
  7. Copy the miniroot into it
  8. Make it bootable
  9. Write it to a floppy

Since the miniroot was larger than 1.44MB, the size it needed to be in order to fit on a floppy, the easiest "diet" for it consisted of mercilessly ripping out all the modules that were not needed for booting. The SCSI modules could go... so could the CD-related ones... the important thing to remember was that the miniroot's job is to simply boot a very basic Linux environment and immediately turn control over to Knoppix - which still had every bell and whistle it came with (the Knoppix image itself remained untouched; the miniroot being tweaked was only a copy.) If it became necessary, I'd get a crowbar and start ripping out other bits... fortunately, this was not required, since removing all modules other than the "usb"- and "hci"-related ones left the miniroot below critical mass.

At this point, I ran into another problem... but this one was small enough to be laughable. My laptop has no floppy drive, and the VAIO had nothing resembling '/bin/dd' - and I couldn't think of anything other than DOS's "debug.exe" that would write a raw image to a floppy. Yikes! Would I actually have to remember that ancient command set to do this simple job?... oh, right - the Debian project has "rawrite.exe" in its "tools/" subdirectory. Whew. A few seconds to burn the floppy, and... that familiar Knoppix logo glowed on the VAIO screen. [1]

No Wasted Effort

After going through all this - it was an on-again, off-again project that stretched over a number of weeks - I decided that there were other Linux folks out there who would like to do this (NO, not the struggle and the headache - the floppy/USB boot, of course!) The traditional *nix method to propagate knowledge - notice that it worked well in my case - is a script; the one presented below is a heavily-modified version of the one by Fabian Franz. It allows you to specify a directory containing the Knoppix image(s) as a command-line argument, or in the user configuration section in the script itself, and creates a file called "boot.img" that can be burned to a floppy to make a bootable environment that passes control to a USB device. NOTE: I've tested it as thoroughly as I could on my own machine, but make no guarantees in regard to anything else. If it breaks, you get to keep both pieces. Yes, you are welcome to contact me with suggestions or bug reports; no, I don't know how to fix [pick issue of the day here] in Knoppix. I'm just a guy whose fiancée wants to play with the stuff.

A downloadable file version of this script can be found here. Enjoy, and happy Linuxing!

# Created by Ben Okopnik on Thu Mar 17 23:56:31 EST 2005
# Many thanks to Fabian Franz, whose original script gave me the idea of
# how it's all supposed to work.
# This script creates a boot floppy that passes control to a USB PenDrive
# containing a Knoppix CD image. No CDROM, no problem!

############## User configuration section ###############################

# Set this to the directory where the Knoppix image lives, or specify the
# directory as a command-line argument.

############## End of user config section ###############################

  printf "$@\n"
  exit 1

  [ -d "$TMPDIR" ] && rm -rf $TMPDIR

# Validation tests
[ $UID -ne 0 ] && abort "Root privileges are required to run this script."
[ -d "$KNOPPIX_DIR" ] || abort "$KNOPPIX_DIR is not a directory."
[ -z "`ls $KNOPPIX_DIR|grep -i 'knoppix.*iso'`" ] && 
	abort "Knoppix image not found in $KNOPPIX_DIR."

# Create temp dir, get rid of it on exit
TMPDIR=`mktemp -dp /tmp/ make_floppy.XXXXXX`
trap "clean_exit" EXIT

# Jump into TMPDIR and prepare it for the coming ops
mkdir knoppix floppy miniroot old_miniroot

# Choose and mount the Knoppix image
printf "Please choose one of the following images:\n"
select choice in $KNOPPIX_DIR/K*.iso; do break; done
mount $choice knoppix -o loop

# Decompress the miniroot from the mounted image's boot dir
gunzip -c knoppix/boot/isolinux/minirt24.gz > minirt24

# "Back up" and mount the miniroot
mv minirt24 minirt24.old
mount -o loop minirt24.old old_miniroot

# Create the file which will contain the new miniroot; format it as a DOS
# FS and mount it
dd if=/dev/zero of=minirt24 bs=4M count=1
mke2fs -L "KNOPPIX Miniroot" -b 1024 -N 8192 -O none -F -q -m 0 minirt24
mount -o loop minirt24 miniroot

# Copy the USB-related modules from the old miniroot to the new one
mkdir -p miniroot/modules/scsi
for n in `ls old_miniroot/modules/scsi|egrep 'usb|hci'`
	cp old_miniroot/modules/scsi/"$n" miniroot/modules/scsi

# Copy everything except the "scsi" dir from the old miniroot to the new
# one
rm -rf old_miniroot/modules/scsi
cp -af old_miniroot/* miniroot/

# Unmount both
umount old_miniroot
umount miniroot

# Compress the miniroot again
gzip -9 minirt24

# Create a 1.44MB file which will contain the boot image, format it as a
# DOS FS, and mount it.
dd if=/dev/zero of=$TMPDIR/boot.img bs=1k count=1440
mkdosfs $TMPDIR/boot.img
mount -t msdos boot.img floppy -o loop

# Grrr... "mount" weirdness requires waiting, then remounting in order to
# have it read-writeable. Perhaps the 'mount' maintainer should get a bug
# report?
sleep 2
mount floppy -o remount,rw

# Copy the required files from Knoppix's boot dir to the image we're building
FILES="boot.msg f2 f3 german.kbd isolinux.cfg linux24 logo.16"
(cd knoppix/boot/isolinux/; cp -f $FILES $TMPDIR/floppy/)

# Copy the new miniroot into it - we're almost done!
cp minirt24.gz floppy/

# Rename and tweak the config file to conform to the SYSLINUX usage
mv floppy/isolinux.cfg floppy/syslinux.cfg
[ -n "$LANGUAGE" ] && perl -pi -e "s/lang=de/lang=$LANGUAGE/g" floppy/syslinux.cfg
[ -n "$LANGUAGE" ] && perl -pi -e "s/lang=us/lang=$LANGUAGE/g" floppy/syslinux.cfg

# A little cleanup...
umount knoppix
umount floppy

# Make the image bootable! Since it's not an actual device, 'syslinux' is
# going to complain - but we're tough and can handle it.
syslinux boot.img 2>/dev/null

# Put the boot image back where we started
cp -i boot.img $ORIG_DIR

printf "The boot diskette can now be created with 'dd if=boot.img of=/dev/fd0'.\n"

There's still the issue of the very strange-looking mouse pointer in Knoppix on the VAIO: it looks like a 100x100px square of TV interference. I'm told that tweaking the X configuration file will fix this, but I have not yet had the time to devote to it. Perhaps the fact of having written this article will provide sufficient motivation...


picture Ben is the Editor-in-Chief for Linux Gazette and a member of The Answer Gang.

Ben was born in Moscow, Russia in 1962. He became interested in electricity at the tender age of six, promptly demonstrated it by sticking a fork into a socket and starting a fire, and has been falling down technological mineshafts ever since. He has been working with computers since the Elder Days, when they had to be built by soldering parts onto printed circuit boards and programs had to fit into 4k of memory. He would gladly pay good money to any psychologist who can cure him of the recurrent nightmares.

His subsequent experiences include creating software in nearly a dozen languages, network and database maintenance during the approach of a hurricane, and writing articles for publications ranging from sailing magazines to technological journals. After a seven-year Atlantic/Caribbean cruise under sail and passages up and down the East coast of the US, he is currently anchored in St. Augustine, Florida. He works as a technical instructor for Sun Microsystems and a private Open Source consultant/Web developer. His current set of hobbies includes flying, yoga, martial arts, motorcycles, writing, and Roman history; his Palm Pilot is crammed full of alarms, many of which contain exclamation points.

He has been working with Linux since 1997, and credits it with his complete loss of interest in waging nuclear warfare on parts of the Pacific Northwest.

Copyright © 2005, Ben Okopnik. Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 116 of Linux Gazette, July 2005

<-- prev | next -->