Dracut | Grub | Speed up boot by Specifying a Boot Device AND Kernel Command Line

Hi,

I’ve been reading in the https://man.archlinux.org/man/dracut.8.en MAN page that I can use two options to speed up my boot process:

  1. Specifying the root Device
This is the only option dracut really needs to boot from your root partition. Because your root partition can live in various environments, there are a lot of formats for the root= option. The most basic one is root=<path to device node>:

root=/dev/sda2

Because device node names can change, dependent on the drive ordering, you are encouraged to use the filesystem identifier (UUID) or filesystem label (LABEL) to specify your root partition:

root=UUID=19e9dda3-5a38-484d-a9b0-fa6b067d0331

or

root=LABEL=myrootpartitionlabel

To see all UUIDs or LABELs on your system, do:

# ls -l /dev/disk/by-uuid

or

# ls -l /dev/disk/by-label


  1. Speeding up the Boot Process


If you want to speed up the boot process, you can specify as much information for dracut on the kernel command as possible. For example, you can tell dracut, that you root partition is not on a LVM volume or not on a raid partition, or that it lives inside a specific crypto LUKS encrypted volume. By default, dracut searches everywhere. A typical dracut kernel command line for a plain primary or logical partition would contain:

rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0

This turns off every automatic assembly of LVM, MD raids, DM raids and crypto LUKS.

Of course, you could also omit the dracut modules in the initramfs creation process, but then you would lose the possibility to turn it on on demand.

I do have a SWAP File which is configured to allow for Suspend then Hibernate.

Question:

If you are using GRUB to boot, how do I enable these two configuratoin options?

@dalto @Scotty_Trees

Thought I would give you a little ping. I have been going through the various System Boot threads with Dracut configuration. So better safe then sorry and talk to you and not break my system

The things you are referencing above are things that go in the options line which comes from /etc/kernel/cmdline.

Take a look at your /etc/kernel/cmdline. It is likely that the first thing is already there.

The second set of things you can add to that same file. Just make sure that you don’t need any of them because you are disabling support for them.

After modifying that file, sun sudo reinstall-kernels

1 Like

Hi Dalto,

Thanks for your feedback. I was looking in the /etc/kernel directory and this is what I see:

~ took 2s 
❯ cd /etc/kernel               

/etc/kernel🔒 
❯ ls -al
total 20
drwxr-xr-x   3 root root  4096 Jul 14  2021 .
drwxr-xr-x 112 root root 12288 Feb 16 12:14 ..
drwxr-xr-x   2 root root  4096 May 18  2021 install.d

So no file called ‘cmdline’.

Oh, I didn’t read your message closely enough. You are using grub.

In that case, the information for #2 is the same but the location is /etc/default/grub

For #1, it is a little trickier. It is possible the root= line will be in there but it is also possible it is being added by grub-mkconfig.

If it isn’t there, take a look at /boot/grub/grub.cfg and see if the root= line is specified there.

Not to worry. You are right I am using GRUB. I have been reading and learning (best thing about being part of the community with supportive people like you).

So I found two other references which I think might work … but ofcourse second set of eyes always helps.

  1. dracut is capable of embedding the kernel parameters in the initramfs, thus allowing to omit them from the boot loader configuration. See dracut#Kernel command line options

    Source:
    https://wiki.archlinux.org/title/Kernel_parameters

  2. Kernel command line options

Kernel command line options can be placed in a .conf file in /etc/dracut.conf.d/, and set via the kernel_cmdline= flag. Dracut will automatically source this file and create a 01-default.conf file and place it inside the initramfs directory /etc/cmdline.d/. For example, your kernel command line options file could look like:

/etc/dracut.conf.d/cmdline.conf

kernel_cmdline=“rd.luks.uuid=luks-f6c738f3-ee64-4633-b6b0-eceddb1bb010 rd.lvm.lv=arch/root rd.lvm.lv=arch/swap root=/dev/arch/root rootfstype=ext4 rootflags=rw,relatime”

Source:
https://wiki.archlinux.org/title/Dracut#Kernel_command_line_options

If I am reading the references above correctly it looks like I can move the following lines out of the /etc/default/grub and use the following solution:

  1. Create cmdline.conf file in the dracut directory.
sudo touch /etc/dracut.conf.d/cmdline.conf
  1. Edit the /etc/dracut.conf.d/cmdline.conf
sudo nano /etc/dracut.conf.d/cmdline.conf
  1. Get Root Partition configuration configuration information and put into the “kernel_cmdline” of the “/etc/dracut.conf.d/cmdline.conf” file.

The below configuration line assumes your root partition is:

  • Not on a LVM volume.
  • Not on a raid partition
  • Does not lives inside a specific crypto LUKS encrypted volume.
kernel_cmdline="rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0"
  1. I can then remove the same references from /etc/default/grub/

Do you think this is a good best practice?

1 Like

This step is not needed. The file will be created either way in the next step you have listed.

I am not sure if it is a best practice but it is certainly an option.

There are a few things you would want to test

  • Will the system boot properly?
  • Does grub-mkconfig add any options that are duplicates in that case?
  • What does /proc/cmdline look like before and after?
  • Does it actually help in an appreciable way?
1 Like

Hi Dalto,

So just finished my testing, and these are my observations:

  1. The system is always aware which is the root drive even when it is not explicity defined.
cat /proc/cmdline                        
BOOT_IMAGE=/boot/vmlinuz-linux-zen root=UUID=715c2972-1a51-4d73-89a0-86ea7bb5aa7f rw resume=UUID=715c2972-1a51-4d73-89a0-86ea7bb5aa7f resume_offset=36151296..
  1. Tried moving the “resume=UUID=715c2972-1a51-4d73-89a0-86ea7bb5aa7f resume_offset=36151296…” line out of GRUB to the /etc/dracut.conf.d/cmdline.conf.

I noticed that the hibernation functionality was not able to find the hibernation file when I moved the configuration to the /etc/dracut.conf.d/cmdline.conf file. So I had to keep this in the GRUB configuration file.

  1. Use kernel_cmdline=“rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0” to try to speed up the boot.

From using the “systemd-analyze” command I notice under 2 second faster boot. So it is possible that on a single drive laptop with docking station the dracut method already tunes for this condition.

Cold Boot:

❯ systemd-analyze                          
Startup finished in 13.820s (firmware) + 1.763s (loader) + 812ms (kernel) + 979ms (initrd) + 3.812s (userspace) = 21.188s 
graphical.target reached after 3.811s in userspace.

Reboot:

❯ systemd-analyze                        
Startup finished in 7.137s (firmware) + 3.814s (loader) + 855ms (kernel) + 1.533s (initrd) + 3.523s (userspace) = 16.864s 
graphical.target reached after 3.522s in userspace.

So in my case I am not implementing this configuration change. Maybe if I get more complicated hardware I can try again. Thank you for your guidance.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.