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:
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:
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
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.