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 gconf-editor as
user "ubuntu" (not as root), go to
apps/nautilus/preferences, and uncheck media_automount
media_automount_open.
Say you have a 1GB usb key and you want to put into the usb key Damn Small Linux 4.2.5 and slax 6.0.7 (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-08g.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 16MB 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 970MB, 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 qemu
-usb /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.
Ttylinux's login id is 'root' and password
'root' (both without quotes). 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 4.2.5 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 6.0.7. 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.
You could also do the copying from Windows if you have explore2fs or ext2fsd but I would be very nervous about allowing Microsoft Windows to mess with my linux partitions.
Installing a Live System into the USB key
Please skip this section if you are a novice linux user.
Let's say you use Ubuntu daily on your desktop and you would like to install it to a usb key. First of all you need a usb key 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 key you just created!) and copy everything from your Ubuntu partition into one of the key's empty ext2 partitions. (ext3 is too slow) By now you also know that /boot/grub/menu.lst on the usb key's first partition has to be modified.
The remaining steps involve modifying /etc/fstab of the target partition of the usb key:
- Root device should be specified by UUID or LABEL since you don't know its true name in a mobile environment.
- Mount /var and /tmp as tmpfs.
- Remove most static entries.
- Add 'noatime' to the options.
Anything else? Your comments please.
- Most updated version of this page: http://people.ofset.org/~ckhung////p/mk-boot-usb/use.en.php; the version you're reading: September 28 2008 10:44:39.
- 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.
![[rss feed]](/~ckhung//i/rss.png)
![[Don't upgrade to docx]](/~ckhung//i/n7/no-docx.png)
![[support creative commons]](/~ckhung//i/cc.png)
