Archive for June 23rd, 2008

Laptop hard disk replacement, part two

Way back in May I had a hard disk in my laptop fail, and after the warranty replacement disk showed up it took me a few days to get around to doing the replace. It didn’t get off to a very good start though…

In the past when I’ve done this kind of recovery I copied the details of the partition table and copied each partition in turn off the failed drive. This time however in my haste (or something) I imaged the entire 80GB in a single file by using dd pointing at the disk device node (/dev/sda, say) instead of each partition.

When it came to restore, this brought me undone. I tried the reverse of what I’d done to create the image, just dd to the disk device node, but at around the point where the first partition would have ended it failed with an I/O error.

Assuming that I did actually have a valid image of the entire drive, I needed to find a utility that would treat a disk file as an image of an entire drive, partition table and all. Then, theoretically, I could copy each partition out of the source file in the same way I was used to.

As usual, the lazyweb came through for me. I found a beaut utility called kpartx, apparently part of multipath-tools. I also found some blog posts describing how to use the tool for what I needed. What kpartx does by itself is scan a block device or normal file (significant, as I’m sure when I first used it I had to use losetup) and create device-mapper mappings to the partitions it finds. kpartx was just what I needed!

This blog post describes the process I went through (and no losetup here either). For me, I let kpartx create device-mapper nodes for the partitions in the disk image, and then used dd to copy from each of those partitions to the real partitions in the new disk (carefully created using fdisk to match the originals). Then I set up grub on the new disk, and installed it into the laptop. It worked first go!

So now on its third hard drive, this Sony Vaio (same one with the weird wireless issue in Hardy) gets yet another lease on life. The battery is almost expired though, so I think it won’t be long before it goes to the Old Hardware Shelf…

Edit: I realised my confusion about losetup. kpartx uses losetup under the covers if it detects that you’re trying to work on a disk file instead of a block device. When you use the -a or -l switches to kpartx, if it needs to it straps up a loop device for you and automatically works on that; running kpartx with the -d removes not only the device-mapper nodes but the loopback node as well.

Don’t you hate it when defaults change?

Sometimes when working with computers and networks (as with most things in life) the thing that causes the most problem is the last thing you suspect–or often something you never suspected. I had a reminder of this the other day, when a moderately complex task I’d set myself looked to be scuppered for absolutely no reason I could fathom.

I’ve got a system here that is a host for a virtualisation environment I run. I dedicated a couple of network cables to the adapters owned by the virtualised system, and a third one was attached to the host’s IP stack. To get connectivity for another system, I had to steal the host’s cable though–which wasn’t a problem as the operation of the system works more-or-less entirely from the console rather than over the network. Just for grins, however, I decided to set up connectivity to the host by routing through the virtualised environment it hosts.

Having established the tunnel connection between the virtualiser and the host stack, I set about configuring the special details required to support routing through this system. After a few tries at getting it right, I was rewarded with successful pings between the systems on my LAN and the hosts system on its routed connection. So I jumped onto the console of the machine and light up Firefox, but got an error page. I realised I hadn’t set DNS resolution–on the LAN, the machine was having resolv.conf configured by DHCP, so now I had to do it manually.

Okay, so DNS resolver now correctly set, let’s see Firefox WIN! Oh. Fail.

When I hit Try Again or Reload, the page would instantly refresh. This was starting to look like no routing problem. I used dig to test name resolution, and it told me it was being rejected. I looked at my dns.conf… Nope, so subnet restrictions coded there…

So I hit the lazyweb, and it didn’t take too long before I found a forum post that led me to this. In BIND 9.4.1-P1, ISC basically changed the default behaviour of a couple of query filtering settings. This had the effect of rejecting some requests that were previously accepted, such as those from non-local subnets. A reconfiguration of my DNS server gave me success at last.

Hooray for persistence! Now, someone hand me some Cat-5 so I can make a cable and plug this thing back in properly. :)

Tags: ,