Cloning


* * * Before you start, beware of privacy issues when cloning your usb stick 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. 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 sticks 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 sticks in one shot

Identical Sticks

If you have two or more identical usb sticks (same model, same size), you can clone it easily. First run mk-boot-usb to make one of them bootable and customize it as much as you wish. Make sure (or ask your friend who gave you the 1st bootable stick) to follow instructions in the slax page so that your usb stick can easily clone itself. 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. This works for any bootable stick 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 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!.

Cloning to a Stick of Different Brand/Size

No problem. With a usb stick created by mk-boot-usb, you can clone usb sticks of different models and different sizes easily. Let's say you have created a bootable stick X using mk-boot-usb and an empty stick Y. I recommend either:

  1. booting into some debian based system (such as ubuntu) or slackware based system (such as slax) that does not live on stick X, or
  2. booting into slax if stick X is your only Linux system.

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 stick 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 Stick" 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/memory sticks have been recognized by your system, and what their sizes are.
  2. Let's say you guess that /dev/sdx is the source stick X. Type fdisk -l /dev/sdx to list its layout and confirm that it is indeed stick 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 stick Y when prompted by mk-boot-usb. After pressing Enter, the cloning process will begin, and you can take a break for 10 or 20 minutes. 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.

Additional notes:

  1. mk-boot-usb can clone from a smaller stick to a larger stick. Extra spaces are allocated to the first partition, the vfat data partition.
  2. Conversely, the first partition is shrunk when cloning from a larger stick to a smaller stick. 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 stick. 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 stick 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.

Batch Cloning

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

  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 ; done
    	date
    
    Of course you need to modify it a bit to reflect your usb stick 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 sticks 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 stick is which.

Let it Multiply

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 stick 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.

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


mk-boot-usb

  1. intro
  2. use
  3. slax
  4. clone
  5. discuss
  6. advocacy

appendix

other lang