Reducing boot time

Published July 24, 2020

One of the things I try to avoid is complete reboots. Its not because they’re particularly slow, its just that they cause a disruption in my work flow. You have to close everything you’re working on, reboot and then open them up again. Its a pain in the arse. While most of the time the reboots are for new kernel updates, which are fairly regular on Arch. It does happen, however, that every now and then I end up changing some configuration what involves me rebooting a lot in a short amount of time. Hence why it can be useful to reduce overall boot time.

Using systemd-analyze, I had a reported boot time of 30s, with the overall time fairly evenly split between firmware, loader, kernel and user-space. Reducing the units loaded on start-up started off straight-forward, removing the units I didn’t need. This was able to remove about a second, however there were still a few units which were causing a very elongated boot time. NetworkManager-wait-online.service alone accounted for 5s. Removing these and enabling services which were loaded automatically further reduced the overall time from 6 to 3 seconds. Although this is better, I still am not thrilled with this as it could be better.

Setting fast-boot to auto in the BIOS managed to knock off a few seconds, but I still had GRUB to contend with. The thing is that most of the time I boot into the same configuration, being Arch with stable kernel. GRUB has an ability to only show up if a certain key is pressed, and otherwise to boot into a preselected configuration. Setting my GRUB config to include the following enables the GRUB menu only when escape is pressed after the BIOS loads. This also allows the previous entry to be booted if nothing else changes.

GRUB_DEFAULT="saved"
GRUB_SAVEDEFAULT="true"
GRUB_TIMEOUT="0"
GRUB_HIDDEN_TIMEOUT="0"
GRUB_HIDDEN_TIMEOUT_QUIET="true"
GRUB_TIMEOUT_STYLE="countdown"

Using all of this, I managed to get rid of another few seconds. The remaining unoptimised time is coming from loading the initramfs. Swapping the udev hook in /etc/mkinitcpio.conf for systemd was further able to reduce the boot time. Again, there’s probably more I can do to further reduce this.

With all of this, I was able to get systemd-analyze’s time down to 15s. 6.5s for firmware, 0.8 in boot-loader, 0.9 is kernel, 2.9s in initrd and 4s in user-space. Although the time is stating 15s, it feels more like 5 until I get to a login prompt. I may turn to other profilers to further improve the time as this generally doesn’t seem accurate. Nonetheless, its a sizable improvement on an already decent boot time. Its nothing brag-worthy yet, not under 3s, but well on its way.