Saturday, October 18, 2008

Copying a hard disk with Knoppix

I slapped together a computer for my parents a couple of years ago. They really only surf the net, so it did not need to be to impressive. I had a 20 GB hard drive I was going to stick in it, but I dropped and broke it.... I ended up putting an extra 8 GB drive in it instead. With XP installed, it didn't take long before that was filled up and there was hardly any swap space left (something that Window's OSes seem to need a lot of for some reason...).

Anyways, I finally got around to getting a 30 GB hard drive for them. I didn't feel like reinstalling everything, so I figured I'd try copying their old hd with "dd". I used a Knoppix 5.1 disk and this page as a reference:

http://www.nilbus.com/linux/disk-copy.php


What's needed
  • Some flavor of Linux on a bootable CD (Knoppix 5.1 in this case)
  • dd
  • gparted and it's dependencies
  • a new hard disk
Steps
  1. Shutdown and unplug everything and put in the new hard drive (I switched the original to slave and made the new one master at this point)

  2. Boot up the PC and get into the Setup mode (usually by pressing F2, Delete, or some other key).

  3. Make sure everything looks savvy with the new hd. While in there, be sure it's set to boot from the CD first. Also, if you don't have a floppy drive, be sure it is disabled in the bios, otherwise gparted will hang while trying to access it.

  4. Save and boot to Knoppix

  5. Once Knoppix is up, fire up gparted and format the new drive to NTFS (I don't think this is necessary because of the way we will use dd, but I did it anyways. Besides, gparted gave me the peace of mind to know I was working with the correct partitions). You really should reboot after this to be sure the kernal picks up the new partition correctly, but I didn't (as noted early, I probably didn't need to format it anyways).

  6. Once that is done, start an xterm and do:

    dd if=/dev/hdb of=/dev/hda

  7. One thing I didn't do was enable dma on the hard drives. I had read that would make it faster, but oh well. dd will run for quite some time. NOTE: If you use the wrong device for "if" or "of", you could really screw yourself!!!

    While dd is running, it won't give any status. But, from another xterm, you can send the USR1 signal to the dd process and it displays a status:

    kill -USR1 3274 (or whatever pid)

  8. After about 2000 seconds, all 8+ GB of the old drive was copied over. Since I used "/dev/hdb" as the infile, the MBR and all that good stuff was also copied to /dev/hda. So, I fired up gparted again and was happy to see that /dev/hda now had a primary partition the exact same size of the original. I rebooted at this point.

  9. Once rebooted back into Knoppix, fired up gparted one more time and expanded the /dev/hda1 partition to fill the entire 30 GB disk.

  10. Finally, I rebooted again and was very happy to see that Windows was starting up. XP wanted to do a chkdisk since the partition size increaesed, so I let that take place. Once it was back into Windows, I defragged

So, I was very happy to see that dd worked so well. Once again, a free Linux-based solution worked as well or better than some commercial software!

No comments: