Creating Your First Bootable USB Key
Creating Your First Bootable USB Key
Thanks to Eating for posting an article with pictures detailing the entire process. 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 open a terminal and become root. (Ubuntu:
sudo bash) Then disable automatic mounting of usb
disks. In ubuntu 7.10 for example, you would go to system =>
preference => removable media, and uncheck everything. In ubuntu
8.04, you need to give the command
user "ubuntu" (not as root), go to
apps/nautilus/preferences, and uncheck media_automount
Say you have a 1GB usb key and you want to put into the usb key Damn Small Linux 4.4.10 and slax 6.1.2 (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 key is _not_ attached to the computer. Then extract the downloaded file at the root directory, and run it:
cd / tar xzf ~/mk-boot-usb-12a.tgz mk-boot-usb
Mk-boot-usb will ask you to insert the key. Please do so, and wait a few seconds for the LED on the key to flash and stop flashing. If file manager windows suddenly pop up, then you have not disabled automatic mounting of usb keys. 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 key you want to wipe out.
Next mk-boot-usb will display a partial listing of the files it finds in your usb key. Make sure that this is indeed the key you want to wipe out. It then determins the true size of the usb key (in MB) and ask you to type in a list of numbers. By default, mk-boot-usb set aside 24MB as the boot partition, and the numbers you type must add up to the true size minus the size of the boot partition. It will refuse to proceed if the arithmetic is not exact. This is to ensure that you are wiping out the right usb key. (or at least one that happens to have exactly the same size :-) ) Let's say it shows that the size is 978MB, which leaves 954MB for you to use. Then you would type something like:
654 60 240
Leading and/or trailing spaces are ignored. Once you agree to proceed, it will create a primary vfat partition of size 654MB, where it will install grub and ttylinux, plus two ext2 logical partitions of sizes 60MB and 240MB each, and a bootable primary partition of size 16MB. (Ext3 is too slow for usb keys.) Note: actual allocated sizes may be slightly different from what you specify since space is allocated by units of 8032.5 KB.
Now you can test your bootable usb key by typing
/dev/sdy (or whichever device you are processing) if you
have qemu installed. Note about usb-booting on a real computer:
bootable usb keys created by mk-boot-usb are often recognized
as harddisks. So please try the "harddisk priority" menu in
the BIOS if you don't see your usb key in other boot menus. The usb
key will then boot into ttylinux. Congratulations! Now you have
your own first bootable usb key. Of course, with its bare command
line interface, ttylinux is not a very interesting distribution for
daily use. That's why we need the next section.
In fact you can use mk-boot-usb in batch mode to avoid all the questions. Please read the first few pages of the source code, where the options are commented. Be very careful in batch mode, especially with the -d option. Extremely dangerous!
Installing Live CD's of Your Choice into Other Partitions
For DSL just copy everything on the live CD into one of the appropriate empty partition of the usb key, and modify /boot/grub/menu.lst in the first partition of the usb key. Note that with grub syntax, the first primary partition is called (hd0,0) when this very key is being booted, and its first logical partition is called (hd0,4). This is about all that you need to modify. The required commands look like the following, but you will likely have to modify the paths:
mount /dev/scd9 /media/cdrom # see your /etc/fstab mount /dev/sdy5 /media/tmp5 cd /media/cdrom cp -a . /media/tmp5 umount /dev/scd9 umount /dev/sdy5
If you are copying from an iso image file instead of from a real
cdrom disc, then replace the first command by something like:
mount -o loop dsl-4.2.5.iso /media/cdrom
Ditto for slax. 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! Please make sure to follow instructions in the "slax" page so that your usb key can easily clone itself.
Notes about ubuntu CD's: (1) There is a hidden directory /.disk on the cdrom. Make sure not to leave it out when copying it to your usb partition. (2) With a few additional steps described in Live CD Persistence (go directly to the section 'Creating the "casper-rw" File System'), you can make your ubuntu read-write even though it is copied from a live CD. That is, you can install new packages on it as if you were using a harddisk installation! There is a bug in ubuntu 8.04's initrd that makes persistence unusable. Use ubuntu 8.04.1 instead. (3) When booting from qemu, an ubuntu partition on a usb key 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.
Installing a Live System into the USB key
This section is for advanced users.
The installed linux need not be a CD image. You can do a regular
installation (as if you were installing it into a harddrive) into
the usb key. For example, I keep a tar ball of a clean SimplyMepis
11 image that was previously installed on a harddrive.
The image is then uncompressed into
an empty partition (of size 6G) of a usb key treated by
mk-boot-usb. Then I give
tune2fs -l /dev/sdx5 | grep
UUID and modify (1) etc/fstab in the /dev/sdx5 partition (2)
menu.lst in the /dev/sdx4 partition accordingly. Finally, one should
follow instructions in this article: SSD
optimizations on Linux to prevent the usb key from excessive
wear due to frequent write
- Most updated version of this page: http://www.cyut.edu.tw/~ckhung/p/mk-boot-usb/use.en.php; the version you're reading: April 29 2012 09:58:43.
- Author: Chao-Kuei Hung at Chaoyang University Information Management Department
- Save our Earth; please reduce printing, make use of the unprinted side, and recycle.
- You are welcome to distribute this document in accordance with the Creative Commons Attribution-ShareAlike License or the Free Document License.