Ubuntu – steps to create DD image file from usb and restore image to a DIFFERENT usb

bootddlive-usbusb

I have successfully (file created, ubuntu does NOT issue any error messages) created an image from an entire persistent ubuntu live usb.(sdc1) – the file ubuntu1.img is 4.3gb so it is reasonable to believe that the command

/media/images/tst# dd if=/dev/sdc1 of=/media/images/tst/ubuntu1.img

is correctly formatted and made a valid image of usb drive.

So ……i try to put the image onto a newly fat32 formated usb. both the original usb and the new usb have 2 partitions, the first partition on both usbs is ubuntu live. the partition being copied to on the new usb is a little bigger than the original usb partition copied (so size should not be a problem).

dd command to copy image onto usb (i cd to the folder where ubuntu1.img is located)

/media/images/tst# dd if=ubuntu1.img of=/dev/sdc1

this process also displays no errors, after about 20minutes the result is

8388607+1 records in

8388607+1 records out

4294967295 bytes (4.3 GB) copied, 1615.69 s, 2.7 MB/s

BUT … the usb is useless bios complains about missing GRLDR

i have tried with ubuntu, kali, backtrack, slax, and one or two other linux distros. i have tried with multiple pcs all of which boot from live usb without problem. The only way i have found to copy a linux live usb reliably, is in windows :((

if anyone has successfully used dd to copy a linux live usb (any) distro to an image file, then from same image file to a new usb ………PLEASE share some wisdom – thank you in advance for reading and taking the time to reply

Best Answer

You cloned "sdc1" which is a single partition however it sounds like you are attempting to clone an operating system which means you also need the boot-programs.

The location of that information will vary depending on how you have things setup. For example if you are using an MBR partition table then it's stored in the drive MBR, if you are using GPT with BIOS then it's stored in the drive's protected MBR, if you are using GPT with UEFI then it's stored on the ESP, and if you are chain-loading then you could have boot-data on a partition MBR, and the drive MBR.

DD can be used to clone MBR sectors, or an ESP. Alternatively you could just clone the entire drive to save yourself the trouble of making multiple images. I personally recommend avoiding the cloning of MBRs as I've only tried it once, and without success. ESPs or entire drives have always worked fine for me no problem.

My examples below use the creation of an image, and then restoring from it since that's the approach that you are using, but for the record if you can connect both usb sticks to the computer at once you can directly clone from 1 to the other without making an image.

Steps:

Backup Drive MBR & Partition Table:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/dev/sda of=/media/location/backup.img bs=512 count=1".

Restore Drive MBR:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/media/location/backup.img of=/dev/sda bs=446 count=1".

Backup Partition MBR & Partition Table:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/dev/sda1 of=/media/location/backup.img bs=512 count=1".

Restore Partition MBR:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/media/location/backup.img of=/dev/sda1 bs=446 count=1".

Backup An ESP:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/dev/sda1 of=/media/location/backup.img".

[This process is exactly the same as cloning any other partition.]

Restore An ESP:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/media/location/backup.img of=/dev/sda1".

Backup A Partition:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/dev/sda1 of=/media/location/backup.img".

Restore A Partition:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/media/location/backup.img of=/dev/sda1".

[RECOMMENDED ACTION] Backup A Drive:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/dev/sda of=/media/location/backup.img".

[RECOMMENDED ACTION] Restore A Drive:

  1. In terminal type "sudo -i".

  2. In terminal type "dd if=/media/location/backup.img of=/dev/sda".

Notes:

  • It's recommended that DD be run as root, not sudo as otherwise interruptions could potentially occur. On Ubuntu this is difficult given you cannot login as root.

  • When restoring MBRs you can use 512 or 446. 446 will just restore the MBR (where your boot-strap code & boot-loader are written). 512 will restore the MBR and the partition table.

  • You don't have to make an image; you can clone directly from source to destination.

Sources:

Additional Resources:

Related Question