Friday, January 6, 2012

Saving a Windows partition with dd and getting it to work again.

Situation: I had a failing hdd recently and thus tried to create a backup. There were four partitions, mostly sparse and an already existing secondary partition on the new drive that couldn't be resized. So I didn't have enough space to backup the disk as a whole, and I didn't have enough partitions to copy them one by one and resize them all (gparted). Long story short i ended up doing a
dd if=/dev/sda2 of=/dev/sdb2
mount /dev/sdb2 /mnt
dd if=/dev/sda3 of=/mnt/sda3
dd if=/dev/sda1 of=/mnt/sda1
For two partitions, most importantly the system partition. Now i had a really hard time getting it to boot. Fix: After lots (and lots) of trial and error this is what got me to the finish line:
  • I installed a Windows Vista
  • mounted this installation in gparted (/media/sdb1), rm -rf everything except files that looked boot related, most importantly /BOOT  (WINDOWS/Boot doesn't seem to be relevant)
  • mv  /media/sdb1/BOOT /media/sdb1/BOOT.bak
  • mount -o loop /mnt/sda1 /media/sda1 and cp -r /media/sda1/* /media/sdb1/
  • rm -rf /media/sdb1/BOOT/; mv /media/sdb1/BOOT.bak /media/sdb1/BOOT 
  • reboot into the Windows Vista installation cd and used the fix boot option
  • Boot into Windows again and fix drive letters (before you start up the SQLServer!)
  • Voila
Overall i was reminded of what a pain Windows can be. If the Fix boot doesn't help try this thread.
If you have the luxury of enough space just do a dd if=/dev/sda /dev/sdb!

What doesn't work:
  • dd of the disk image to the disk (blank cursor)
  • dd of the disk image to a new partition (blank cursor on boot)
  • Creating a partition and installing into it (wrong disk offset => blank cursor)
  • Installing Vista and overwriting the partition with a dd (blank cursor)
  • Deleting the partition, installing Vista and copying everything into it (Missing winload.exe)
  • Installing Vista and copying everything safe for WINDOWS/BOOT (MIssing winload.exe)
It's save to assume I tried a couple  more combinations and that every one of them took 4h's -> annoying holiday. Fuck you Windows!

No comments:

Post a Comment