Skip to contentSkip to conversation

Parallel kernel loading and keystroke capture in GRUB2

DISCUSSION Vlad 3 participants 3 messages Nov 28, 2008 – Dec 1, 2008 2 messages not in the archive

lore
Share & tools
lore

Vlad

author
#0 lore raw

Hi,

In a recent demonstration of how to boot Linux in 5 seconds [1], PowerTOP developers did not use GRUB2, even though GRUB2 is a necessary component of any production and consumer Linux system or multi-boot environment. As I see it, the greatest disadvantage of GRUB2 is that it needlessly wastes the time in which it gives the user the chance to stall the boot sequence in order to make changes to the boot settings. Of course, having this option available is a necesity in case the user's hardware requires tweaking the parameters passed to the kernel. However, GRUB2 should be loading the default kernel during this time, instead of deferring this IO-bound task to after the timeout has elapsed.

I'm not familiar with the internals of GRUB2, but I assume that multi-threading is impossible. Given this limitation, I have devised the following chain of events which should minimize the time needed to boot the default kernel, while still giving the user a chance to change the boot settings:

1. Start accepting and recording user keystrokes (background task)
2. Print a message along the lines of "Press any key to change the boot settings". (background task)
3. Record the start time (ie. start_timestamp=0)
4. Mount the boot partition and read grub.conf
5. If a key has been pressed, display the boot settings. Else, start loading the default kernel into memory.
6. Record the time when the default kernel has finished loading (ie. kernel_loaded_timestamp=3)
7. If a key has been pressed, display the boot settings. Else, if the time expended so far is less than the "timeout" variable set in grub.conf (ie. timeout=10), keep displaying the message and accepting keystrokes for the remainder of the time. Else, execute the default kernel which has previously been loaded to memory. In pseudo-code, this would be:

if (keystroke_detected){
     display_boot_settings();
} else if (kernel_loaded_timestamp - start_timestamp < timeout){
     keep_displaying_intro_message(timeout - (kernel_loaded_timestamp - start_timestamp));
} else {
     execute(default_kernel);
}

8. Once the timeout period has elapsed, if a key has been pressed, display the boot settings. Else boot the default kernel.

The advantage of this scheme is that the time-consuming parts of mounting the boot partition, reading grub.conf and loading the default kernel are done roughly in _parallel_ to the user seeing the intro message. This scheme also ensures that the user's keystrokes do not fall through the cracks, because they are checked before booting the default kernel at steps 5, 7 and 8.

As GRUB2 is currently set up, time is just wasted displaying the "Press any key to change the boot settings" message because GRUB2 is doing nothing beside awaiting user input. Instead, GRUB2 should be doing all the necessary preparations for actually booting the default kernel during this time.

Since popular Linux distros typically display the GRUB2 intro message for 30 seconds, the time being wasted here is astronomical compared to how fast the Linux environment can actually boot. Changing GRUB2 as described above would ensure that no time is wasted while users are given a chance to change their boot settings.

Thanks,
Vlad

[1] http://lwn.net/Articles/299483

#2 lore raw
In reply to a message not in the archive

Arjan van de Ven wrote, on 2008-11-29 02:06:

Quoted 15 lines
Quoted 13 lines · Vlad

Hi,

In a recent demonstration of how to boot Linux in 5 seconds [1], PowerTOP developers did not use GRUB2, even though GRUB2 is a necessary component of any production and consumer Linux system or multi-boot environment. As I see it, the greatest disadvantage of GRUB2 is that it needlessly wastes the time in which it gives the user the chance to stall the boot sequence in order to make changes to the boot settings. Of course, having this option available is a necesity in case the user's hardware requires tweaking the parameters passed to the kernel. However, GRUB2 should be loading the default kernel during this time, instead of deferring this IO-bound task to after the timeout has elapsed.

Quoted 7 lines

we used grub 1.

Quoted 2 lines

Since popular Linux distros typically display the GRUB2 intro message for 30 seconds,

I'm not aware of mainstream distributions using grub2 yet. Also, I'm not aware of any distro using 30 seconds as timeout, the longest I've seen is 5 seconds.

Debian GNU/Linux offers grub2 as an option on installation.

Arthur.

#4 lore raw
In reply to a message not in the archive
Quoted 28 lines · Auke
Quoted 15 lines · Arthur Marsh

Arjan van de Ven wrote, on 2008-11-29 02:06:

Quoted 14 lines
Quoted 13 lines · Vlad

Hi,

In a recent demonstration of how to boot Linux in 5 seconds [1], PowerTOP developers did not use GRUB2, even though GRUB2 is a necessary component of any production and consumer Linux system or multi-boot environment. As I see it, the greatest disadvantage of GRUB2 is that it needlessly wastes the time in which it gives the user the chance to stall the boot sequence in order to make changes to the boot settings. Of course, having this option available is a necesity in case the user's hardware requires tweaking the parameters passed to the kernel. However, GRUB2 should be loading the default kernel during this time, instead of deferring this IO-bound task to after the timeout has elapsed.

Quoted 8 lines
Quoted 6 lines

we used grub 1.

Quoted 2 lines

Since popular Linux distros typically display the GRUB2 intro message for 30 seconds,

I'm not aware of mainstream distributions using grub2 yet. Also, I'm not aware of any distro using 30 seconds as timeout, the longest I've seen is 5 seconds.

Debian GNU/Linux offers grub2 as an option on installation.

Debian also offers the kitchen sink, including anvil and builtin laser microscope.

Quoted 6 lines

It's fine that they do, but I doubt that debian or any of the other distributions will want to offer grub2 as DEFAULT bootloader at installation time.

Until that happens grub2 is an experiment and certainly not interesting for fast boot purposes. I would personally stay far away from grub2.

grub2 is enabled in the debian installer by default given some conditions are met (if I understand correctly, only when installing on some EFI-based systems). There was a proposal to make grub2 default for lenny, but apparently it didn't make it.

Signature · 1 line
  Felipe Sateler