Cloning & mounting an old hard drive

29 December 2012

Over the last few days I have been looking through a stack of old hard drives, one of which was a Windows98 installation from my undergrad days. Although I had already got a copy of the files from the drive, I decided that I would do an entire-disk clone so I could try out some physical-to-virtual conversions. Unlike my fileserver panic a few years ago this was not a caffeine-fuelled data-recovery operation, so I took the effort to record the commands I used.

Imaging the disk

First attempt was using dd, which got tripped up by bad sectors. Not too surprising as the drive itself was quite likely around a decade old:

# dd if=/dev/sdb | gzip -9 > win98.img.gz dd: reading `/dev/sdb': Input/output error 806464+0 records in 806464+0 records out 412909568 bytes (413 MB) copied, 82.9523 s, 5.0 MB/s

Next move was to use ddrescue. I am not sure of the differences between ddrescue and the similar tool dd_rescue, and I suspect on some distributions they are actually the same program. A quick Google bought up a brief guide, and I duly did my first-pass run:

# ddrescue /dev/sdb sdb.img sdb.log Press Ctrl-C to interrupt Initial status (read from logfile) rescued:         0 B,  errsize:       0 B,  errors:       0 Current status rescued:    8700 MB,  errsize:    4096 B,  current rate:        0 B/s   ipos:   412912 kB,   errors:       1,    average rate:    2464 kB/s   opos:   412912 kB,     time from last successful read:     2.1 m Finished

A log is kept of the recovery process, so it is possible to retry the reading of very problematic blocks in a "try harder" mode, and in this case I set the retry count to three rather than the default zero:

# ddrescue -r 3 /dev/sdb sdb.img sdb.log Press Ctrl-C to interrupt Initial status (read from logfile) rescued:     8700 MB,  errsize:    4096 B,  errors:       1 Current status rescued:     8700 MB,  errsize:    4096 B,  current rate:        0 B/s   ipos:    412911 kB,   errors:       1,    average rate:        0 B/s   opos:    412911 kB,     time from last successful read:     1.7 m Retrying bad sectors... Retry 1

Mounting the image

Since the image is of an entire disk rather than just a partition, you have to give an offset to the partition to the mount command. Again, credit where due, you first have to find out the start offsets (highlighted in bold):

# parted sdb.img GNU Parted 2.2 Using /tmp/sdb.img Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) unit Unit? [compact]? B (parted) print Model: (file) Disk /usr/local/tmp/sdb.img: 8700346368B Sector size (logical/physical): 512B/512B Partition Table: msdos Number  Start   End          Size         Type     File system  Flags  1      32256B  8694120959B  8694088704B  primary  fat32        boot, lba

From there, it should be fairly familiar:

# mount -o ro,loop,offset=32256 sdb.img /mnt/tmp/