How do I clone a USB stick including partitions?

Solution 1:

Yes, this is very easy. Of course, the target drives need to be at least as large as the source drive.

Then, having both source and target drive connected, use something like fdisk -l, lsblk or whatever to identify the device names (like /dev/sdb) for each. Make absolutely sure you get the order right!

To clone directly from drive to drive, use this command:

dd if=/dev/source of=/dev/target bs=1M

Alternatively, if you have enough space on your internal drive, you could create an image first, making creation of multiple copies easier:

dd if=/dev/source of=/home/me/image.img bs=1M

Then, use the image to create clones:

dd if=/home/me/image.img of=/dev/target bs=1M

This way, you could provision multiple drives at the same time, provided one target drive doesn’t already saturate the USB bandwidth.

If the target drive is larger, you might want to enlarge the last partition afterwards, using parted or another suitable tool. Do note that you cannot resize partitions between other partitions if you copy the whole structure.

Solution 2:

You can use dd https://en.wikipedia.org/wiki/Dd_(Unix)

Example:dd if=/dev/sdc of=/dev/sdd bs=1M

if is the source device. Use the device name not the partition (the number at the end is the partition, for example /dev/sdc1).

of is the destination device.

Be VERY careful with this command. It will completly wipe the destination device.