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?

MentalBlister
  • 41
  • 1
  • 1
  • 2
  • 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 '10 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 – MentalBlister May 12 '10 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 – Hubert Kario Jan 18 '13 at 11:48

4 Answers4

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

Jaime
  • 71
  • 1
  • 4
  • 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 04 '19 at 12:30
5

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

kinokijuf
  • 118
  • 14
Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
  • Is this correct? dd if=/dev/sda of=/dev/sdb bs=512 count=1 – MentalBlister May 12 '10 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. – Ignacio Vazquez-Abrams May 12 '10 at 22:38
  • it shouldn't wipe the partition table. something like `dd if=/dev/sda of=/tmp/thumbdrive.img bs=512` would create a file, and then you could use that file to make X clones of your thumb drive, with `dd if=/tmp/thumbdrive.img of=/dev/sda bs=512` – cpbills May 12 '10 at 23:16
  • 3
    Everything past byte 440 is unique to the drive and should not be copied. And I speak not only from experience... http://en.wikipedia.org/wiki/Master_boot_record – Ignacio Vazquez-Abrams May 12 '10 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. – MentalBlister May 12 '10 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 '10 at 00:38
  • Sharing, no. But if you already have partitions that you don't want to affect then just take the part before the table. – Ignacio Vazquez-Abrams May 13 '10 at 01:04
  • It's probably easier to just make the partition and write a standard boot-sector all in one command; checkout `man fdisk` for your OS's exact command. On mine `fdisk -BI /dev/da0` would put one partition with a standard boot-sector on the first USB device. – Chris S May 13 '10 at 02:45
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.

Andrew
  • 8,002
  • 3
  • 36
  • 44
  • The devices are not the same, though they are supposed to be the same size 8 GB. – MentalBlister May 13 '10 at 03: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 '10 at 02: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. – toxicantidote Jul 30 '21 at 00: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.

BillThor
  • 27,737
  • 3
  • 37
  • 69