For a while now, my main desktop machine has been making a bit of a squeaking noise, which I quickly identified as the hard disk. When it first started happening I bought a new disk but then it just sat there for a few months until this past weekend. Adding a disk to an existing system is no big deal, but replacing one is a bit of a pain. Besides copying files to the new disk, you have to make sure the MBR (Master Boot Record) and partition boot records are set up correctly. Since I was replacing a 40GB disk with a 120GB I wanted to resize the partitions as well, so a simple block-for-block copy wouldn’t work. This created significant potential for error. The most annoying part was running GRUB to set up the new disk for booting, because I had this crazy idea that I wanted to test booting off the new disk before I physically replaced the old disk in my tight small-form-factor case and closed it up (until then the new disk was just kind of hanging out of an open case). GRUB had tons of options and even an interactive boot-time command line, so I figured I’d be able to prepare the new disk and then do a couple of test reboots to make sure everything was working. That simply didn’t work; when I tried booting from the new disk I either got a screen full of the word “GRUB” repeating over and over, or the system just kind of sat there. Occasionally I’d get “read error” or some similarly terse error message. That provided a bit of variety but really wasn’t very helpful. To a certain extent this was just the sort of system tweaking I had expected, but what made it annoying was the poor quality of the GRUB manual. Here’s the description of the “map” command.

Command: map to_drive from_drive

Map the drive from_drive to the drive to_drive. This is necessary when you chain-load some operating systems, such as DOS, if such an OS resides at a non-first drive. Here is an example:

grub> map (hd0) (hd1)
grub> map (hd1) (hd0)

The example exchanges the order between the first hard disk and the second hard disk. See also DOS/Windows.

OK, great. Now here’s the critical question: is the identifier for either from_drive or to_drive interpreted at the time GRUB is run to set up the disk, at the time the “map” command is issued during the boot process, or at the last moment when GRUB actually tries to boot an OS? If the user guesses wrong, they might do something that either doesn’t work or – far worse – modifies the wrong disk and leaves them with an unbootable system. I went through several iterations of this, always wondering whether I was trashing my system. Eventually I just gave up on the “map” command entirely, and instead modified “” (for which the documentation was even less useful) to lie about which disk was hd0.

Then I hit another snag. I’ve been dealing with SCSI and Fibre Channel for a while, and they’re generally far more complicated than IDE, but at least it’s familiar complexity. I naively thought that “hd0″ would always refer to the first disk that was found, but that’s apparently not the case. It always refers to the system’s “primary master” even if it’s not present, so my new disk was “hd1″ even if it was the only one in the system. This was probably behind most of my boot-testing failures. To do a real test, then, I not only had to physically disable the old disk (which I had been doing by removing its power) but I also had to move the jumper on the new drive so it would be master (which I hadn’t been doing). Once I realized that, I was quickly able to get first Linux and then Windows booting.

Do you want to know the really funny part? After all that, the noise is still there. It was probably one of the fans all along. I now have a larger and slightly faster disk, plus the old disk sitting in a USB/Firewire enclosure that I had also bought a while ago (this is a great form of backup even if it’s too expensive to do often), but my computer still squeaks.