How do I clone a USB stick including partitions?

34,546

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.

Share:
34,546

Related videos on Youtube

codefactor
Author by

codefactor

Updated on September 18, 2022

Comments

  • codefactor
    codefactor over 1 year

    I have several USB flash drives, and one of them has an installation of Ubuntu with several partitions. I want to make the other USB drives exactly the same as that one (to share with family and friends), everything down to the partitions and formatting should be identical. This flash disk will be basically a utility disk that anyone might want, so I may make lots of copies.

    I also have a much smaller USB flash drive (4gb) which is an Ubuntu boot disk. I have 3 USB ports, so I would like to boot with the small one, plug in 2 larger USB drives and make a complete clone of the utility disk - overwriting everything that may be on the existing disk. It can be assumed that the one being copied to will be at least as large, and is most likely empty (or filled with junk to be deleted).

    Is that possible using free software on Ubuntu?

  • user1757247
    user1757247 about 5 years
    You can add to the command status=progress to see the progress while dd is copying.
  • Daniel B
    Daniel B about 5 years
    status=progress is unfortunately not available on all (most, even) versions of dd.