Mk-boot-usb: a Script to Create Multiple-Bootable USB Sticks

Chinese version


Summary

Mk-boot-usb is a perl script to create multiple-bootable usb sticks (usb keys / usb flash drives). It wipes out an entire usb stick, partitions it, creates file systems on it, installs grub, and installs a minimal linux on it. Mk-boot-usb is meant to speed up and lower the barrier of entry for creating bootable usb sticks. The usb stick will immediately become bootable (using the minimal linux), and more useful distributions can then be installed into other partitions manually simply by (1) copying any Live CD into each partition (2) modifying grub's configuration file.

This program will destroy all of your data in the usb stick. It may even destroy all of your data in the harddisk and/or those on any storage device attached to it if you are not careful! Additionaly, this program is written with absolutely no security consideration in mind. Please use it at your own risk.

For non-technical FLOSS advocactes, you can leave the technical details to your geeky friends and skip directly to the section: "How Can mk-boot-usb Help Your FLOSS Advocacy?"

Download

Please download here; md5sum: 5f7ada0f63e9826d74652cd7d791434b; change log.

Note that starting from version 08f, ttylinux is packaged along with mk-boot-usb. (Or rather, we should probably say that mk-boot-usb becomes an unofficial skin for ttylinux.) This avoids lots of hassles including the need for network, failing to mount loop file system on unionfs, and so forth.

License

This program is distributed under the terms of GNU General Public License, version 3 or later.

Requirement and Limits

The following utilities are used by mk-boot-usb: perl, sfdisk, mkfs (mkfs.vfat and mkfs.ext2), grub.

It is recommended that you also install qemu so that the usb stick can be immediately tested after it is processed.

Mk-boot-usb is developed on Edubuntu, the educational variant of ubuntu. There is report that running mk-boot-usb from fedora successfully installs grub and yet the resulting usb stick does not boot. Please report if you succeed or fail on distributions other than *ubuntu.

This program is written with absolutely no security consideration in mind

.

Interactive Usage

Thanks to Eating for posting two articles with pictures detailing the entire process: 1, 2. You may want to follow the textual directions on my page and look at the pictures in his two pages to make your installation smoother since my page will be constantly updated in accordance with the new releases (and since you probably don't read Chinese :-) ).

First please disable automatic mounting of usb disks. In ubuntu for example, you would go to system => preference => removable media, and uncheck everything. Then open a terminal and become root by typing sudo bash. In fedora it is probably just su, but see above note about fedora.

Say you have a 1GB usb stick and you want to put into the usb stick Damn Small Linux 4.2.5 and slax 6.0.0 (other than the default ttylinux). Mk-boot-usb's default grub boot menu happens to contain entries for these two distributions, and therefore they require the least of your efforts. These are recommended to users who try mk-boot-usb the very first time.

So we will allocate rougly 60MB and 240MB for them, respectively, leaving about 700MB for your usb as an ordinary storage device.

First make sure that this usb stick is _not_ attached to the computer. Then extract mk-boot-usb.tgz, cd into the directory, and run mk-boot-usb as follows:

        ./mk-boot-usb

Mk-boot-usb will ask you to insert the stick. Please do so, and wait a few seconds for the lcd on the stick to flash and stop flashing. If file manager windows suddenly pop up, then you have not disabled automatic mounting of usb sticks. Please press ctrl-c to abort, read the beginning of this section, disable it, and restart again. If no file manager windows suddenly pop up, you can then proceed to press enter and continue. Mk-boot-usb compares your /dev/sd* before and after the insertion to figure out which stick you want to wipe out.

Next mk-boot-usb will display a partial listing of the files it finds in your usb stick. Make sure that this is indeed the stick you want to wipe out. It then determins the true size of the usb stick (in MB) and ask you to type in a list of numbers that add up to the true size exactly. It will refuse to proceed if the sum does not equal to the total size exactly. This is to ensure that you are wiping out the right usb stick. (or at least one that happens to have exactly the same size :-) ) Let's say it shows 968 for the 1GB stick. Then you would type something like:

        668 60 240

Leading and/or trailing spaces are ignored. Once you agree to proceed, it will create a primary vfat partition of size 668MB, where it will install grub and ttylinux, plus two ext2 logical partitions of sizes 60MB and 240MB each. (Ext3 is too slow for usb sticks.)

Now you can test your bootable usb stick by typing qemu -usb /dev/sdz (or whichever device you are processing) if you have qemu installed. ttylinux's login id is 'root' and password 'root' (both without quotes).

Batch Usage

Please read the first page of the source code, where the options are commented. Be very careful in batch mode, especially with the -d option. Dangerous!

Installing Live CD's of Your Choice into Other Partitions

For DSL 4.2.5 just copy everything on the live CD into one of the appropriate empty partition of the usb stick, and modify /boot/grub/menu.lst in the first partition of the usb stick. Note that with grub syntax, the first primary partition is called (hd0,0) when this very stick is being booted, and its first logical partition is called (hd0,4). This is about all that you need to modify.

Ditto for slax 6.0.0. BTW, slax automatically records any changes you make during the session into the /slax/changes directory of its partition. Think about it: you copied from a live CD which packs 400MB worth of software into 200MB space, and yet now it works like it cared nothing about having had to deal with a read-only device in its prior incarnation! Slax just rocks!

Notes about ubuntu CD's: There is a hidden directory /.disk on the cdrom. Make sure not to leave it out when copying it to your usb partition. Also, when booting from qemu, an ubuntu partition on a usb stick created by mk-boot-usb manages to boot into the splash image but then drops to busybox. However, it successfully boots on a few of my real machines, including eeepc. Someone from ubuntu should really fix /casper/initrd.gz so that when it drops to busybox, there is at least some log for people to post questions for help. See this for details.

Notes about otg linux: This is a an educational Live DVD from Taiwan which was created using tux2live from a an ordinary, installed ubuntu. (And thus suffers from the same qemu problem described above.) I plan to distribute it to teachers since they compose of the majority of my speech audience. Thus it is included in the boot menu since version 08d. If you like otg-linux but mk-boot-usb does not work for you, you can try its own script for creating bootable usb: pc_hd-otg-ins.sh.

For other live CD's, you have to translate isolinux's (or syslinux's) configuration file syntax into grub's. Use DSL and slax entries as successful translation examples.

You could also do the copying from Windows if you have explore2fs or ext2fsd but I would be very nervous to allow Microsoft Windows to mess with my linux partitions.

Installing a Live System into the USB Stick

Let's say you use Ubuntu daily on your desktop and you would like to install it to a usb stick. First of all you need a usb stick with large enough memory (4GB is a reasonable size) since such a live system is not compressed like DSL and slax are. Secondly you have to boot from some other device (maybe from a live CD, or maybe from the slax partition of the usb stick you just created!) and copy everything from your Ubuntu partition into one of the stick's empty ext2 partitions. (ext3 is too slow) By now you also know that /boot/grub/menu.lst on the usb stick's first partition has to be modified.

The remaining steps involve modifying /etc/fstab of the target partition of the usb stick:

  1. Root device should be specified by UUID or LABEL since you don't know its true name in a mobile environment.
  2. Mount /var and /tmp as tmpfs.
  3. Remove most static entries.
  4. Add 'noatime' to the options.

Anything else? Your comments please.

Duplicating a Bootable USB Stick

If you have two or more identical usb sticks (same model, same size), you can make them all bootable easily. First run mk-boot-usb to make one of them bootable. Let's say this bootable one is /dev/sdx, and the other one is /dev/sdy. You can then use dd < /dev/sdx > /dev/sdy to copy everything, including the boot sector, to the other one.

Does it work more generally, namely on usb sticks of roughly the same size? I tried this on two usb sticks of different brands, both of size roughly 2GB. The result was that grub loads partially and hangs after printing "grub ". If anyone knows why it does not work please give me a hint. Thanks!.

Running mk-boot-usb from a usb Stick That it Creates

mk-boot-usb is self-reproductive. You can use mk-boot-usb to create a bootable usb stick, install otg linux (see above) on it, boot it, and run mk-boot-usb again to create more usb sticks. A note about copying the content from the live system: let's say the running partition of the usb stick is /dev/sdx81 and the partition of the new usb stick to receive files from otg-linux is /dev/sdy72. You don't need to (and can't) mount /dev/sdx81 since it is already mounted and hidden under the unionfs. Type du /live_media and you will see that this directory uses about the same amount of space as the otg-linux DVD. Just copy files from here to the mount point of /dev/sdy72. Next, you may want to put the 3 deb files qemu_*.deb, bochsbios_*.deb, vgabios_*.deb in your usb stick so that you can dpkg -i *.deb once otg boots up. This way you can use qemu even if there is no network access. You may also want to have a few short usb extension cords ready so that all usb ports can be fully utilized even when some of the usb sticks are too clumsy and would otherwise occupy more than one usb port.

Microsoft tries to block linux. But linux, like life, finds its own way, and multiplies itself ;-) Please help it multiply and spread in Microsoft's barren kingdom.

How Can mk-boot-usb Help Your FLOSS Advocacy?

Think about your next linux install-fest. Now you don't need to ask people to bring their desktop computer. Instead just ask them to bring a usb stick. And a notebook if they really wish to see it work immediately.

It doesn't even have to be a geek event like linux install-fest. You can demonstrate this in 10 minutes to your non-technical audience. For example, next time when you give a FLOSS speech (even to non computer science students), please ask the event correspondent to ask the audience to bring their own usb sticks. If you are lucky enough to have an assistant who is not too afraid of command line, s/he can help create a bootable stick for every person while you give the talk. Then ask the audience to test this usb stick on new computers they plan to buy. This will have at least two effects: (1) Make sure that the hardware supports linux well, including booting from usb. (2) Show the computer sales what is possible with linux. By the way please also distribute portable apps on the first partition.

That's what I will do anyway :-) That was the major motivation behind this work. Happy advocating.

Discussions?

I have no energy to maintain a full-blown software package and its corresponding maintainence system. However, your comments are most welcome. Please use the blog entry to leave your comments.


quick links:
my schedule
TW FS sched.
blog
this dir
upper dir
this@OFSET
this@CYUT
this@CYIM
this@STU
Chinese

[rss feed] [free speech flag] [Organization for Free Software in Education and Teaching] [Don't upgrade to office 2007] [viewable with any browser] [(striving to stay) xhtml 1.0 compliant] Valid CSS!