1

I don't understand how dd treats partition tables when copying a full disk.

I backed up my whole disk (which had multiple partitions) using sudo dd if=/dev/sdb conv=sync,noerror bs=64K | gzip -c > /media/notsdb/backfile.img.gz

Now I have a brand new disk without a partition table that I want to put these partitions onto. The reverse command should be gunzip -c /media/notsdb/backfile.img.gz | sudo dd of=/dev/sdb conv=sync,noerror bs=64K. Does this make sense and do I have to put a partition table onto the disk first? (The operation takes 10 hours so I'd like to know before I do it)

Thanks, Craig

0

2 Answers 2

2

Copy it over, then use gparted (or similar) to resize / move partitions - dd will simply recreate the old partition scheme, as it is a bitwise copy & applies no 'intelligence' to the operation.

This only works if the new disk is the same size or larger!

0

As Mark Williams says, the dd commands you've specified will replicate the old partition table, which you can then modify if necessary.

One caveat, though: If the disk uses the GUID Partition Table (GPT), as most disks do on modern computers, the partition table is replicated at both the start and end of the disk. If the target disk is not exactly the same size as the original, the resulting restored disk may need minor repairs. IIRC, parted, GParted, and similar tools will notice if the new disk is bigger than the original and offer to make repairs. If you use my own GPT fdisk (gdisk, sgdisk, or cgdisk), you can manually repair the problem by typing x to go to the experts' menu, typing e to relocate the backup data structures to the end of the disk, and then typing w to save the changes.

If the new disk is smaller than the original, then the backup partition table on a GPT disk will be lost, necessitating a similar recovery procedure. Worse, on either a GPT disk or an MBR disk, the final partition (or even multiple partitions) might be damaged or lost entirely. There's nothing that can be done about this, really; at best, you'll be able to resize the final partition to fit and then do a filesystem repair (with fsck) to try to recover as much data as possible.

Note that these size issues can crop up even if the disks differ in size by even just a single sector. Disks marketed as being the same size (say, 2TB) may differ from each other in size by significantly more than that. If you plan to buy a replacement disk of the "same" size as the original, check the first original's size accurate to the sector and look up the technical specs on any potential replacement to be sure it's as large as or bigger than the original.

You must log in to answer this question.

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