Cloning


* * * Before you start, beware of privacy issues when cloning your usb key for others. Make sure that there is no private information such as instant messaging contacts, love letters, pin numbers for your ATM card, account/passwords, ... etc. in any partition of your usb key. Information wants to be free. Once it is released, you will never be able to recall it. * * *


Note: This page applies to version 08h or later. For older versions, see the legacy page.

usb keys created by mk-boot-usb can do asexual reproduction :-) That is, it can reproduce itself. I expect this (along with other non-technical endeavors I am engaged in such as talking to Taiwan's hardware manufacturers about producing diskless computers) to become a major headache for Microsoft. GRIN.

create nearly a dozen bootable usb keys in one shot

Identical USB Keys

If you have two or more identical usb keys (same model, same size), you can clone it easily by a single command: dd < /dev/sdx > /dev/sdy where /dev/sdx is the source key and /dev/sdy is the destination key. This works for any bootable key created by any scripts that come with many live cd's, not just those created by mk-boot-usb.

Does it work more generally, namely on usb keys of roughly the same size? I tried this on two usb keys of different brands, both of size roughly 2GB. The result was that grub loads partially and hangs after printing "grub ". After some googling, I still can't find any relevant document about why different models of usb keys boot differently, and would appreciate very much any pointers.

Cloning to a USB Key of Different Brand/Size

No problem. With a usb key created by mk-boot-usb, you can clone usb keys of different models and different sizes easily. Let's say you have created a bootable usb key X using mk-boot-usb and an empty usb key Y. I recommend booting into slax for doing the cloning job. If you boot into ubuntu or its variants, it had better live on a harddisk or usb key that is different from X (and of course different from Y). That is, you need 2 usb keys plus one running Linux system (maybe a desktop installation, maybe a third usb key) if you use an ubuntu variant to do the cloning.

If you are curious, please see the legacy page for problems with cloning using mk-boot-usb while running an ubuntu live system that lives on the source usb key X. In either case, I also recommend working in the text mode so that you don't have to worry about automatic mounting of removable devices. (You have to explicitly disable this when working in the GUI mode. See "Creating Your First Bootable USB Key" for details.) In order to swich to the text mode VT1 (virtual terminal 1), press Ctrl-Alt-F1. For slax, press Ctrl-Alt-F6 to switch to VT6. Again login with username "root" and password "toor" in the text mode.

  1. Assuming you have become root, give the command fdisk -s /dev/sd? and observe how many harddisks/usb keys have been recognized by your system, and what their sizes are.
  2. Let's say you guess that /dev/sdx is the source usb key X. Type fdisk -l /dev/sdx to list its layout and confirm that it is indeed usb key X.
  3. Type df to make sure that all partitions of /dev/sdx are mounted. Mk-boot-usb will try to mount the source partitions (and leave them mounted even after the script finishes), but I don't know why, mounting the partitions manually always works and yet mounting them from the script very often fails. I suspect it has to do with unionfs and/or aufs. Anyway, slax has all partitions mounted already when it boots, so you don't have to do anything except typing df to double check.
  4. Give the command mk-boot-usb -s /dev/sdx, and insert the destination usb key Y when prompted by mk-boot-usb. After pressing Enter, the cloning process will begin, and you can take a break for 10 minutes up to an hour. Get some exercise or get a cup of coffee. If everything goes smoothly, Y will be completely wiped out and become a clone of X when you come back.
  5. (version 11c and newer:) Finally, mbu-uuid /dev/sdy to fix the UUID entry in the destination usb key Y if one of the boot entries in your source usb key X uses the "root=UUID=..." option. I install SimplyMepis into my usb key as if installing into a harddrive, and so I need this. Please read "SSD optimizations on Linux" to reduce write operations and lengthen the life of your usb key if you do similar installations.

Additional notes:

  1. mk-boot-usb can clone from a smaller usb key to a larger usb key. Extra spaces are allocated to the first partition, the vfat data partition.
  2. Conversely, the first partition is shrunk when cloning from a larger usb key to a smaller usb key. So please make sure that the space actually allocated (the "Used" column printed by df) from the vfat data partition plus the sum of the sizes (the "1K-blocks" column printed by df) for all other partitions, is recognizably smaller than the size of the destination usb key. For example, supposing /dev/sdx is 8GB in size with a 5GB first partition (/dev/sdx1) and supposing /dev/sdy is 4GB in size, you can clone from /dev/sdx to /dev/sdy if you delete enough files from /dev/sdx1 so that it uses less than 1GB space. Otherwise mk-boot-usb will cowardly refuse to proceed.
  3. However, if the destination usb key is too large (larger than 32GB), then mk-boot-usb will also cowardly refuse to work because it does not want to destroy your system harddisk.
  4. Sometimes it may fail to mount a destination partition. This may result in mk-boot-usb writing into /tmp/mk-boot-usb/... of its own device and eventually fill up the file system. The remedy is to rm -rf /tmp/mk-boot-usb.

Batch Cloning

Here is my personal cloning practice for batch cloning into many usb keys:

  1. Create a shell script called clone.sh with the following content:
    	fdisk -s /dev/sd?
    	for d in x y z do echo -n "cloning into /dev/sd$d: "; date ; mk-boot-usb -b -v 1 -s /dev/sdw -d /dev/sd$d ; mbu-uuid /dev/sd$d ; done
    	date
    
    Of course you need to modify it a bit to reflect your usb key names.
  2. type script to start recording.
  3. type source clone.sh and leave it running for a few hours.
  4. type Ctrl-d to end recording. Everything that was printed to the terminal is now recorded in the file typescript.

This way you can clone many usb keys in one single batch, and have some information to debug if something went wrong. The information printed by fdisk -s /dev/sd? can be used to identify which usb key is which.

Let it Multiply

live long and prosper! My friend Chungyu says that I have created a Mr. Smith of the Matrix film. I think mk-boot-usb is also similar to the Borg of Star Trek :-) In addition, it is similar to Microsoft Word(s), which propagates itself among the citizens, either legally or illegally. But the main difference from either of these three, is that an mk-boot-usb bootable usb key leaves the decision of whether to clone to each human master instead of forcing itself upon the victims like these three. Microsoft tries to block linux and other free software in many ways. But linux, like life, finds its own way, and multiplies itself ;-) Please help it multiply and spread in Microsoft's barren kingdom. Live long and prosper.

* * * Finally, did I remind you to beware of privacy issues? * * *