2008-01-01 Fixing Ubuntu Boot
I've had Ubuntu on my desktop machine for some time now. It had been a RedHat machine since birth, but I'd let it stagnate until it was just too far behind to easily upgrade to Fedora, and I'm more of a Debian fan anyway so I just bought a new hard drive and started fresh. When I originally installed Ubuntu, I was unable to boot any of the stock kernels. At the time, I shrugged this off and built my own kernel from source. This has worked fine for me ever since.
But lately I've needed to add some very basic features that I omitted in the original configuration (like USB and APCI support) and rebuilding my source kernel every time (and applying all of the necessary additional drivers) has started to become tedious, so I've decided to revisit the issue of getting the stock kernels to boot. The problem was the IDE support. For whatever reason, the stock kernels as installed couldn't see my IDE hard drives. They would get to the point where they were "waiting for the root filesystem" and then just hang there.
So the first challenge was to figure out what it was waiting on. The boot scripts for the stock kernels are all in initrd files (RAM disk images that get loaded before the kernel even looks at the root filesystem) so I thought I'd take a look through them for starters.
I discovered that the initrd files are all just gzipped CPIO files (an archive format similar to "tar"). At first I tried to mount them as loopback devices and load them into ramdisks - that didn't work. But then it occurred to me that I could just expand them (with "cpio --extract < uncompressed-initrd-file"). I found that the shell script that was waiting for the root filesystem was just checking the device filesystem for the presence of the entry passed in as the root device during boot ("/dev/hda5" in my case). If it didn't find it after 180 seconds it would pop up a limited shell to allow the user to attempt to resolve the problem. I just hadn't waited long enough.
So I rebooted and waited, and sure enough after a few minutes I got a "busy box" shell. As suspected, there was no /dev/hda5 entry or entries for anything resembling a hard disk. I booted back into my home-rolled kernel and took a look at the logs and found the driver being used to address the IDE interface - it appeared to be using a compiled-in version of via82cxxx.
I rebooted back into the stock kernel, let it time out to the shell and loaded this driver by hand ("modprobe via82cxxx"). Still no hard drive devices. On a hunch, I also loaded "ide-generic" and that's when I hit pay dirt - the kernel spit out a few messages indicating that it had initialized my hard drives and now there were hda and hdb devices in /dev. Success! I exited out of the busy box shell and the kernel completed its boot.
So now the question was how to get the stock kernels to load up these drivers automatically on startup. A little searching and I discovered something interesting - the initrd images are not deployed with the kernel, as I had expected, but are generated when the kernel is installed! Very nice, since I didn't want to have to do any hacks that would get clobbered the next time I upgraded the kernel.
The information that I learned this from was out of date, and suggested the use of the mkinitrd program to generate the images. It turns out the current way to do this is with the initramfs-tools package. You can edit the "/etc/initramfs-tools/modules" file and identify extra modules that you want loaded before the kernel looks for the root filesystem.
The full command to do this is as follows:
# update-initramfs -k all -u
This rebuilds all of the initrd images in /boot with whatever changes you have made locally to any of the startup scripts, including "modules".
So now my stock kernels are all bootable. I still have some work to do. X doesn't come up yet, I am still unable to load the legacy NVIDIA drivers. But I'm writing this up anyway because it's a good case study in how to resolve these kinds of problems and because I couldn't find the details of how to make this happen spelled out anywhere.
I'm a little disappointed that Ubuntu, which bills itself as "the Linux distro for the masses" didn't figure all of this stuff out for me when I first installed it. Hopefully newer versions have worked all of this out.
I am also disappointed that I wasn't able to discover the answer to this in any kind of a FAQ. It looks like a lot of people on the forums were experiencing this kind of problem, and nobody was giving them any "RTFM" links.