K.Mandla's blog of Linux experiences

No, really: The initrd is too big

A while back I remember seeing news around the ‘net about Linus Torvalds voicing concern over the growing size of the kernel. Things like that are usually non-issues for me and I think they are for most end-users, but it’s the first thing I thought of when I put Ubuntu onto a 2Gb 4200rpm drive and dropped it into a Pentium with 32Mb of memory in it.

For the longest time now, my mental limbo-pole for Ubuntu on any computer has been 32Mb: Without 32Mb in the machine, the installer program twitched and flailed uncontrollably until you finally took it off life support and cut the power. You could, conceivably run Ubuntu on a machine with less memory than that, although dipping much lower — even by just 8Mb or so — left you in dangerous territory.

Or so I thought. I was pleased to find the random 16Mb stick of PC66 at the bottom of a box in my local recycling shop last week, and after a 12-hour marathon of memtest, it’s showing no defects whatsoever. But the aforementioned 2Gb hard drive with a clean installation of Ubuntu on it refused to start all the same. “The initrd is too big,” it said, quite politely.

I see elsewhere on the Internet where BIOS settings can come into play, but this time it might be that the initrd is just too big. How big can it be? I thought, and transplanted the drive (again … swapping drives is the story of my life) in an effort to find out. And the answer was 40Mb.

Good grief. I must be looking at that wrong. Discrepancies like that can only be explained as some mistake of mine. In any case, the error message was telling the truth. That is too big.

Now the size of a stock Linux kernel and the size of the initrd in a vanilla installation of Ubuntu 9.10 are not necessarily related, but I could swear this was never a problem before now. I am more-or-less certain that I have installed minimal Ubuntu systems on computers with only 32Mb of memory — some within the past couple of years — and they started up fine. And Debian runs without complaint on the machine, although I haven’t needed to check the size of the initrd in Debian, so it might be different. (It appears to be less than 8Mb for initrd.img-2.6.32-trunk-486.)

I suppose weight gain is the only excuse. Forty megabytes is considerable when your world is topped off by a 550Mhz Celeron, and no machine has more than 192Mb. But this world never has a need for more than about 24 of those 192Mb at any given time … unless of course, you’re trying to start up Ubuntu.

I’ll have to scrape around a little more and see if there is any way to carve down that 40Mb number, and maybe actually get the system working without having to swap memory chips as well as hard drives. I don’t hold out much hope though … 40Mb might be a stumbling block for a beat-up leftover 166Mhz Thinkpad, but to anyone else who’s not living in 1998, 40Mb here or there is nothing to voice concern over. Unless you are Linus.

That initrd probably contains modules for as much hardware as possible. Meaning you don’t need 98% of the stuff in there.
Your best route is to compile a custom kernel which has what you need for that particular machine and only that. If you compile everything statically (no modules), you’ll get an image of around 2.5MB.

I was hoping someone would check theirs and find a different number. I double- and triple-checked mine, but 40Mb still sounds unnaturally huge. I halfway suspect some sort of error in the installation. …

The initrd is likely that big because it has all modules included (it was made to suit almost any hardware configuration). So it has any possible driver for RAID or crypto libs or different hard disc controllers, etc.

Arch Linux gets around this by making two initrd images. One with *only* the modules you need based on your hardware and a “fallback” initrd with all the modules. You use the customized initrd for regular use but if it somehow gets misconfigured you can drop back to the fallback to boot and then fix the problem. I’ve never had to use the fallback, though.

Indeed. Compiling your own kernel having the filesystem type and appropriate hdd hardware drivers included rather than as modules negates the need for an initrd altogether, as well as speeding up boot times. I’m sure you know this though ;)

I remember using an alternative initrd tool called yaird which scans your hardware and includes only the modules required for your boot up, resulting in a much smaller initrd. Of course this does not solve the problem of the installer. http://packages.ubuntu.com/karmic/yaird