Clone your Linux disk with ddrescue
What do you do when you KNOW your hard disk is failing but you're not ready to do a re-install or lose any of that precious data? Obviously the first solution is to always have a backup of your data. This is great, but it doesn't solve the issue of having to re-install the operating system which would then lead to having to install all of your applications to get your PC back where it was.
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
The first step in this process is to install ddrescue. To do this follow these steps:
- Open up a terminal window.
- Issue the command sudo apt-get install ddrescue
- Issue the command sudo apt-get install gparted
That's it. You will notice I installed gparted as well. This will make the partitioning of the drives much easier for you. You can, of course,Â partitionÂ a drive via the command line, but using a tool like gparted is far easier.
Paritioning your new drive
What you need to do is shut down your machine, install your new drive, and reboot your machine. Once you have your machine booted with the new drive powered up do the following:
- Fire up GParted.
- Create a partition scheme on the new drive that is identical to the old drive. If there is space remaining on the new drive, that's fine (you can resize the partitions with Gparted later).
- Save the new partition scheme and you are ready to clone.
- Make note of the precise drive letters assigned to the two drives (you do not want to clone the new drive onto the old drive now do you?).
Cloning the drive
Okay, it's go time. Open up a terminal window. Remember the exact letters of your drives earlier? 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:
sudo ddrescue -v /dev/sda /dev/sdb
Depending upon the size of your disk, this can take some time. But once it is complete you should be ready to boot into that new drive. Go ahead and shut down and then unplug the old drive. Now reboot the machine and it should boot. Once it completes the boot you shouldÂ Â take a precautionary step and check the new disk for errors. Do that with the following command:
e2fsck -fp /dev/sdb1
If it gives you any complaint about the disk not being found issue the commandÂ mount without any arguments. This will show you if the drive retained the same letter (sdb). If not, then make the correction in the command above.
Finally, if you need, you can fire up GParted and resize those partitions. You can't actually run GParted on a mounted drive, so what you should do is download and use the GParted Live CD which will allow you to resize the partitions to what you need.
The paths to getting your Linux disk cloned are many. Some are easier than others, some are more proven. Do you have a different method of cloning a drive? If so, share it with your fellow Ghacks readers.Advertisement