Why is GRUB 2 booting so slowly

bootboot-loaderembeddedgrub2

I have a small custom embedded Linux distribution (created with OpenEmbedded), which boots with GRUB 1.99. The aim is to have it start up fast.

Currently it says:

GRUB loading.

for ~2+ seconds (this is probably unavoidable). Then:

Welcome to GRUB!

under it for a fraction of a second when it has finished loading.

(There is no menu or menu timeout.) It clears the screen, then:

Booting 'Disk'

for ~8 seconds. This delay seems like it should be avoidable. I'd very much like to know how to make it not delay here.

Then it continues on to:

Decompressing Linux... Parsing ELF... done.
Booting the kernel.

And then lots of fast scrolling text as the kernel boots.

The kernel image file is 1.8MB, and the disk image file is 16MB.

The grub.cfg file looks like:

set default="0"
set timeout=0

menuentry "Disk" {
    set root=(hd0,1)
    linux /boot/Disk.kernel parport=0x378,7,3 ramdisk_size=16384 root=/dev/ram rw
    initrd /boot/Disk.ext2
}

In another boot disk I have (on a Compact Flash card), I have exactly the same kernel, and a different disk image file, which 20MB. The config file is also identical, except that ramdisk_size=20480. This one has an extremely long delay of 69 seconds at that same point. Why is it so much longer? Thankfully, I don't need to use that boot disk often. But it would be nice to fix that one too, since presumably the delay is caused by the same thing.

How do I fix this delay? What is it doing? How does one go about debugging a bootloader? Is it worth looking into a lighter weight bootloader like SYSLINUX instead? Will deleting some of the unused GRUB 2 modules improve it? (How does one find which modules are unused?)

Summary

All of the following have the exact same Linux 3.2 kernel:
Flash disk A on computer X: 16MB image, GRUB 1.99, boot delay is ~8s; disk A's read speed is 20MB/s.
Flash disk B on computer X: 20MB image, GRUB 1.99, boot delay is 69s; disk B's read speed is 20MB/s.

Flash disk C on computer Y: 16MB image, GRUB 0.97, boot delay is.. extremely quick; disk C's read speed is 16MB/s.
Note that computer Y is similar to computer X, but a bit slower.
(The monitor is not even fast enough to show any GRUB screens at all. From the point of the BIOS screen disappearing to the Linux kernel loading screen first appearing, it shows 4.76s of blank screen – but the Linux kernel has already been loading for at least 1.5s by that time, so it's more like 3.2s at a maximum for GRUB to do its thing. This includes GRUB itself loading and BIOS deciding which drive to boot from, etc.)
Unfortunately GRUB 0.97 like that instance is not able to be repeatably built like that, so it doesn't seem like a feasible option (although it would be nice).

How do I make GRUB 2 fast??

Best Answer

EDIT: It seems that GRUB2 is the problem in this case, after all. I'm keeping my original answer below just for reference and as an explanation for similar problems people may have.


The boot delay you are referring to is the time needed for the kernel and initramfs image to be loaded to RAM. The blame is not on bootloader, it is on the size of your kernel/initramfs and storage (CF card) throughput.

You can easily test the speed of your storage using either dd (if you have it installed on your embedded system) or cat. Just substitute /dev/sda1 below with the name of the block device representing the boot partition on that system (you can usually check that using the mount command).

  • using dd: dd if=/dev/sda1 of=/dev/null
  • using cat + time: time cat /dev/sda1 > /dev/null

(In the second case, you'd need to calculate the rate manually.)

If your root partition is too large to wait for the commands to finish, just press Ctrl+C after some time (but not less than about one minute, to make the test reliable).

Related Question