0

I have an internal 320GB SATA HDD which is showing signs of impending failure (errors while copying,SMART status etc.). I have another internal HDD available with me to which I would like to migrate the data. My current setup is as follows:

OS : Ubuntu 14.04
/dev/sda --> failing drive
/dev/sda1 --> mounted / ~20GB 50% free
/dev/sda2 --> mounted swap ~5GB
/dev/sda3 --> mounted /home/user ~250GB 80% free

Could someone explain what procedure I should follow to copy all data to the new drive so that I dont have to reinstall linux and reconfigure everything from scratch ?

TIA

  • gparted,partedmagic,clonezilla,drbl – cybernard Jul 21 '15 at 18:05
0

You can use dd

# dd if=/dev/sda of=/path/to/dump.bin bs=8M

This makes an image of /dev/sda as dump.bin. Note that "bs" refers to block size, and basically means how much does dd read/write at a time. You'd want to have a somewhat large block size to speed things up

When you get a new hard drive, you can dump the image back using the following command (assuming your new drive is /dev/sdb)

# dd if=/path/to/dump.bin of=/dev/sdb bs=8M

This will basically make your new drive a byte-by-byte clone of your old drive. Note that this also means any data in your new drive will be permanently erased!

However, the new drive much be at least the same size as the image.

You can also combine this command with compression tools such as gzip or bzip2 to achieve compression, which will compress a lot

If your hard drive is failing, this may not work, if there were errors while reading (or writing)

Also, if you're having trouble copying all of the disk, you can alternatively attempt to make a dump of only /dev/sda1 (which contains your system files), and attempt to copy your /home files on a file-by-file basis. On your new drive you can then recreate your partition layout manually and dump the file into the appropriate partition.

  • Will doing # dd if=/dev/sda1 of=/dev/sdb1 be enough if I only wanted to copy the system partition ? How would I ensure that the MBR and related information is written to the new disk ? – Jagadeesh Jul 20 '15 at 9:22
  • Yes, assuming both partitions are the same size (or sdb1 is bigger). The MBR is stored in the first 512 bytes of the hard disk, as far as I know, so you can use another dd command to dump that separately. Check the man page for more information. However, a bootloader includes more than just an MBR, and I haven't tried it before, so I'm not sure if it's going to work. – 9a3eedi Jul 21 '15 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.