Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 6418  / 3 Years ago, wed, november 3, 2021, 10:19:58

I currently have a failing hard drive which is the only hard drive in the machine. I have just bought a new hard drive to replace it, and my plan is to copy the contents of the old drive onto the new one, and then replace the old drive in the machine with the new one.



I presumably can't just copy the whole directory structure (or can I)? What do I need to do to manage this, assuming it is possible? Is there a utility to do this for me? (The old drive is hopefully good for a few more hours.)



(I hope by this means to keep all the software and configuration files as they are, to avoid having to re-install everything. Can that be done?)


More From » backup

 Answers
7

Yes, a 100% exact copy of your HDD is possible, and it would preserve all your files, data and system configurations intact. And, as you've already correctly guessed, simply copying files over won't work. (it can be done, but not worth the trouble of doing it right)



A HD cloner tool is your best bet. There are dozens available.




  • Is the new hard drive larger than the old one?

  • Do you have any Ubuntu bootable CD / USB key?



If so, I recommend the good old dd. Its a one-liner, rudimentary, ancient solution for cloning a HDD. But it works, and its amazingly easy. dd is also pre-installed in Ubuntu.




  • Boot using your Live CD or USB stick

  • Using System > Administration > gparted (Disk Utility also works), take note which is your old and which is your new hard drive (sda, sdb, etc).



enter image description here




  • Checked? Great!

  • Now check them again:



enter image description here




  • Ready?

  • Now Triple check it. I mean it! dd will have no mercy if you use the wrong letters. dd is commonly known as "d isk d estroyer" for a reason!



From now on, Ill assume the old is /dev/sdX and the new is /dev/sdY. Check your actual values! (did I say that already?)




  • Using Terminal, issue the granddaddy of all HDD cloners:



    sudo dd if=/dev/sdX of=/dev/sdY bs=1M

  • bs=1M is optional, only to improve performance. The best value depends on your drives/cache/cpu/ram. Commonly used values are 4K, 64K, 1M, 16M. Try for yourself in a 1GB test (add count=256K, 16K, 1K, 64 respectively). For my machine, anything from 4K to 32M leads to very similar results.


  • If you want to monitor the copy, you may try this fancy version:



    sudo su - # neccessary to get correct pid
    dd if=/dev/sdX of=/dev/sdY bs=1M & pid=$!
    while kill -USR1 $pid 2>/dev/null; do sleep 10; done



It will output dd's progress every 10 seconds.




  • Now go grab a lunch. Or better, go to sleep. It will take long ;)



Post-copy procedures:




  • Remove the old drive

  • Install the new one in the same connector as the old (so you dont need to reconfigure BIOS)

  • Boot and check that everything is fine

  • Since dd makes an exact copy, partitions will be the same size. If new hdd is much larger than the old one, use gparted to expand partitions to claim the unused space.


[#44790] Thursday, November 4, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gerrin

Total Points: 347
Total Questions: 109
Total Answers: 121

Location: Tanzania
Member since Fri, Oct 29, 2021
3 Years ago
;