4

Using 'dd' to clone a USB drive

-cfdisk:

resized the destination partition to be of same size

made the partition bootable

same 'type' ext3

ran 'mkfs.ext3' after exit cfdisk

then

dd if=dev/sda1 of=/dev/sdb1

result booting: Missing operating system.

The source USB device boots on multiple laptops

USB destination filesystem looks the same....

Any idears?

3
  • 2
    Why are you gooing through all the effort to setup partitions and filesystems? Just copy the entire disk. dd if=/dev/sda of=/dev/sdb
    – Zoredache
    May 12, 2010 at 21:16
  • You are probably right, but this is the result...the 2nd USB is slightly smaller in size dd if=/dev/sda of=/dev/sdb dd: writing to `/dev/sdb': No space left on device 15654849+0 records in 15654848+0 records out 8015282176 bytes (8.0 GB) copied, 3430.66 s, 2.3 MB/s May 12, 2010 at 23:47
  • then you have to first resize the partition on the originating drive soi that it won't end after the end of the device after clone, after that it's just simple dd if=/dev/sda of=/dev/sdb bs=8192 and ignoring the error Jan 18, 2013 at 11:48

4 Answers 4

7

I recently had to clone a 32gb trancend thumbdrive onto another. My drive is a multiboot with additional software so I didn't want to just copy all files on the FS. DD was a clear choice, but I was on windows.

I had cygwin installed and did the following.

first I had to figure out what /dev/sdX device my f: volume was. To do so run this command in cygwin. (TIP: Make sure you start cygwin with admin privs.. *Right click on cygwin and "Run as Administrator")

cat /proc/partitions

which should output:

   8 0 3813383838 sda
   8 1       4031 sda3 C:\
   8 15  30588303 sdb 
   8 15  30588303 sdb1 E:\
   8 21  30530020 sdc
   8 22  30530020 sdc1 F:\

etc... Here you can clearly see for me to clone my F: drive to my E: drive I'd issue the following command.

dd if=/dev/sdc of=/dev/sdb bs=8M

My image was 32gb.. and I didn't want to just sit and wait with a blinking cursor.. I wanted to see progress so I installed "pv" in cygwin.

dd if=/dev/sdc | pv | dd of=/dev/sdb bs=8M

Hope this helps

1
  • 2
    To follow the progress of the copy, no need to use pv, just add the status=progress option to your command : dd if=/dev/sdc of=/dev/sdb bs=8M status=progress
    – Mickski
    Mar 4, 2019 at 12:30
5

You copied the partition, but not the MBR. Copy the first 446 bytes of the device itself.

8
  • Is this correct? dd if=/dev/sda of=/dev/sdb bs=512 count=1 May 12, 2010 at 22:25
  • No, that will wipe the partition table as well. And I'm not psychic, so I don't know if those are the correct devices. You're definitely on the right track though. May 12, 2010 at 22:38
  • 3
    Everything past byte 440 is unique to the drive and should not be copied. And I speak not only from experience... en.wikipedia.org/wiki/Master_boot_record May 12, 2010 at 23:44
  • 1
    As the story goes....did dd if=/dev/sda of=/dev/sdb bs=512 count=1, tried booting from it...All I got was 'GRUB' So then tried example from first comment of Zoredache above: result --> cfdisk /dev/sdb "FATAL ERROR Bad primary partition 1: Partition ends after end-of-disk Press any key to exit cfdisk back to my Pretty good friend Google. May 12, 2010 at 23:54
  • 1
    'should not' be copied? you're cloning the thumb drive, i've done similar things in the past, and granted it's been a long time, but i don't seem to remember any issues of two thumb drives sharing the same MBR, bit for bit. MentalBlister: DROP THE count=1 you're only copying the first 512 bytes with count=1 get rid of the count parameter completely.
    – cpbills
    May 13, 2010 at 0:38
1

If the drives are the same size, why not just clone the entire drive?

dd if=/dev/sda of=/dev/sdb bs=(whatever) count=(whatever)

I've used this to clone HP ThinState configuration disks for HP thin clients that "don't work" with devices over 2GB - so long as I have a small enough drive to use as a master, I can clone it onto e.g. a 4GB drive and the thin client will happily boot from it.

Edit: Reading the above on "unique" IDs in/near the MBR, I don't see a problem with cloning an identical device if it's truly a clone - as long as you don't try to copy things between the two.

3
  • The devices are not the same, though they are supposed to be the same size 8 GB. May 13, 2010 at 3:34
  • Use the smaller of the two as the master and the unfilled space won't matter. Using the larger of the two as the master... could have problems.
    – Andrew
    May 17, 2010 at 2:46
  • I've run in to this same issue, where two 64GB drives are actually 62.8GB and 63.4GB respectively. They have the same interface (USB3) and are the same brand. Jul 30, 2021 at 0:35
0

You can use sfdisk to backup the partition table, then copy th boot sector (first block). Then restore the partition table with sfdisk. If you are using a DOS MBR, then the mbr program will write the MBR code onto the USB for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .