There is a better, quicker way to do this which is to clone your entire drive onto a new drive.
You can do this with a tool like GParted, but there is also a command line tool that will get the job done as well. This tool is ddrescue. Now with ddrescue you will have to have your new disc partitioned (it will not partition for you). In this article I am going to show you how to get your dying Linux drive cloned onto a new drive.
Installation of ddrescue:
apt-get install ddrescue gparted
Paritioning your new drive:
After you installed the new drive reboot your server. Then do the following:
- Start GParted.
- Create a partition scheme on the new drive identical with the old drive.
- Save the new partition scheme and you are ready to clone.
Cloning the drive:
Let’s say your old drive was /dev/sda and your new drive is /dev/sdb. To make the clone you would issue the following command:
ddrescue -v /dev/sda /dev/sdb
NOTE: After the last update the ddrescue command was moved to dd_rescue so..the correct command is:
dd_rescue -v /dev/sda /dev/sdb
And the output will look like this:
root@debian:~# dd_rescue -v /dev/sda /dev/sdb
dd_rescue: (info): about to transfer 0.0 kBytes from /dev/sda to /dev/sdb
dd_rescue: (info): blocksizes: soft 65536, hard 512
dd_rescue: (info): starting positions: in 0.0k, out 0.0k
dd_rescue: (info): Logfile: (none), Maxerr: 0
dd_rescue: (info): Reverse: no , Trunc: no , interactive: no
dd_rescue: (info): abort on Write errs: no , spArse write: if err
dd_rescue: (info): ipos: 490496.0k, opos: 490496.0k, xferd: 490496.0k
errs: 0, errxfer: 0.0k, succxfer: 490496.0k
+curr.rate: 64725kB/s, avg.rate: 16468kB/s, avg.load: 8.3%
Depending upon the size of your disk, this can take some time. You should be ready now to boot into that new drive.
Check the new disk for errors:
Do that with the following command:
e2fsck -fp /dev/sdb1