2

After I used dd to clone a 120 gb hard disk to new empty 320 gb hard disk, the new disk cannot be booted. And fdisk tell me the partition table is no valid and Gparted just cannot edit the partitions.(I supposed I need to create a new partition on empty space)

The command I used to clone disks is:

dd if=/dev/sda1 of=/dev/sdb

Any way to restore the partition table? or what is wrong with my way to clone disk?

Kurt Liu
  • 123
  • 1
  • 3

2 Answers2

6

With that command, you're cloning a partition to a disk, which is skipping the partition table.

Try this:

$ dd if=/dev/sda of=/dev/sdb
EEAA
  • 109,363
  • 18
  • 175
  • 245
2

The partition table is contained within the first 512 bytes of the disk (which are called MBR - Master Boot Record).

dd if=/dev/sda of=/dev/sdb bs=512 count=1 would copy them.

As ErikA says, either copy MBR + partition individually, or simply the whole disk to the other disk

3molo
  • 4,330
  • 5
  • 32
  • 46
  • I am wondering how can I clone swap partition? would this command be correct? sudo dd if=/dev/sdc2(swap partition in old hard disk) of=/dev/sda2(empty partition in new hard disk) bs=5MB – Kurt Liu May 04 '11 at 14:30
  • @Kurt there isn't really a point to cloning a swap partition, just create a new swap partition with `mkswap`, use `swapon` to activate it, use `swapoff` to deactivate the old partition (at this point anything stored in it will move to RAM or the other partition) and then edit `/etc/fstab` to set the new partition as swap permanently. – DerfK May 04 '11 at 16:19
  • *Attention*: this is only true for legacy boot, which is getting rarer and rarer nowadays - modern OSes commonly use GPT partitioning and UEFI boot. – Cadoiz Jan 20 '21 at 01:22