PC Restore

The procedures here are to be used when replacing the primary hard drive if no factory CD/DVD was ever created/provided and the drive is too cooked to repair.

This page assumes a computer with a hidden partition on the primary drive containing a factory restore image that can usually be invoked by pressing F10 during boot; except in our case, the drive is being replaced because it's too cooked

The only tools needed are the standard Linux tools fdisk, dd, and hdparm.

The idea is to salvage the Master Boot Record (MBR - absolute sector 0) and the factory restore partition (usually the first one and MS-DOS Fat-32). The second partition on the drive will probably be the main partition and probably only part of it will be recoverable.

There are two techniques that can be tried to recover data from the main partition. The first is to buy and use SpinRite by Gibson Research (grc.com). The second is to mount the drive and try to copy all those important files that were not important enough to back up on a regular basis :)

The MBR is 512 bytes long (exactly one sector) and contains both code and data. The code comes first and is loaded into memory along with the location and size of the 4 allowable primary partitions, after which the bootstrap loader jumps to the code. (Disassemble it to see how it works. There's not much to it, it simply examines the four partition tables and loads the first bootable one it finds into memory and execs it).

No extended partition information is contained in the MBR. Once the old MBR is placed on the new drive, obviously the location and size of the original partitions is no longer important (unless the new drive is the same size as the old one -- doubtful) and so can be deleted using fdisk. Deleting partitions with fdisk doesn't actually delete partitions, just their meta data in the MBR.

OK, Here we go. Fill in the blanks as you come to them :)

Copy the parameters from the old drive (fdisk -l)
device, start, stop, id, etc
Check to be sure the old MBR looks OK, especially the last word (55aa) two bytes (aa55)
hdparm --read-sector 0 /dev/sdx
Save the old MBR
dd if=/dev/sdx of=mbr.img bs=512 count=1
Save the factory restore partition
dd if=/dev/sdx1 of=restore.img
Save other partitions if possible
Same as above
Or save particular files
mount the partition, use cp
Remove the old drive
Install the new drive
Put the old MBR on the new drive
dd if=mbr of=/dev/sdx
Delete the partitions (they apply to the old drive and will be replaced)
fdisk /dev/sdx then d to delete a partition, etc
Create the restore partition, same size and type as the old one
fdisk /dev/sdx new partition, change system ID, write changes
Put the factory restore partition on the new drive
dd if=restore.img of=/dev/sdx1
Create the remaining partitions
consult the old parameters
Reboot the computer
Press F10 to start the factory restore

Send mail to the Webmaster

logo This site best viewed with a browser
Warning: This is a Debian centric site
Many thanks to Debra and Ian Murdock for making Debian possible
First created Apr 22, 2008 ~ Last revised August 24, 2009

Valid XHTML 1.0 Strict Valid CSS!