2020-05-19 18:20:18 +02:00
|
|
|
+++
|
|
|
|
title = "Fedora Boot Optimization"
|
|
|
|
date = 2013-11-13T10:12:04+00:00
|
|
|
|
+++
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
This article shows how to reduce boot time for Fedora 17, but the recipe can also be applied to 18, 19 and 20.
|
|
|
|
|
|
|
|
The target is to get a fast booting system with NetworkManager running and gdm displaying the login
|
|
|
|
screen as fast as possible.
|
|
|
|
|
|
|
|
<!-- more -->
|
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
The system I use here is a Lenovo T420s (2x2x Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz)
|
|
|
|
with an INTEL SSDSA2BW160G3L harddrive.
|
2020-05-19 18:20:18 +02:00
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
First we choose a manual disk layout and use primary partitions and format them with ext4.
|
2020-05-19 18:20:18 +02:00
|
|
|
In my case this results in:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
sda1 ext4 /boot
|
2020-05-19 18:20:18 +02:00
|
|
|
sda2 swap
|
|
|
|
sda3 ext4
|
|
|
|
```
|
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
After the first boot, setup of the user, etc. and 2 reboots (always reboot 2 times,
|
|
|
|
before taking the measurement, because readahead needs to adapt to the changed boot process).
|
2020-05-19 18:20:18 +02:00
|
|
|
First we update everything.
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ sudo yum update
|
|
|
|
```
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
After the reboots, I get:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ systemd-analyze
|
|
|
|
Startup finished in 1413ms (kernel) + 2911ms (initramfs) + 10593ms (userspace) = 14918ms
|
|
|
|
```
|
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
Because I don't use any LVM, RAID or encrypted devices, I can safely turn off all nearly all
|
2020-05-19 18:20:18 +02:00
|
|
|
`fedora-\*storage\*` services. To turn off these services, we use the `systemctl mask` command.
|
|
|
|
A bonus with that mechanism is, that no rpm %post script turns them on automatically.
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ cd /lib/systemd/system
|
|
|
|
$ for i in fedora*storage* lvm2-monitor.* mdmonitor*.*; \
|
|
|
|
do sudo systemctl mask $i; \
|
|
|
|
done
|
|
|
|
```
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
On Fedora 17, it seems there are still some SysV initscripts left, so we turn them off:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ for i in livesys livesys-late spice-vdagentd;\
|
|
|
|
do sudo chkconfig $i off;\
|
|
|
|
done
|
|
|
|
```
|
|
|
|
|
|
|
|
Seems like we saved half of the time in userspace:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ systemd-analyze
|
|
|
|
Startup finished in 1640ms (kernel) + 6556ms (userspace) = 8197ms
|
|
|
|
```
|
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
From now on, you really have to know what you are doing and how to revert your actions.
|
|
|
|
To compare Fedora with e.g. Ubuntu, I will now turn off all services except NetworkManager.
|
|
|
|
The result will be a Linux system without mail, firewall, printing, the abrt tools, avahi,
|
2020-05-19 18:20:18 +02:00
|
|
|
some mountpoints, rsyslog, irqbalance, and selinux security.
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ cd /lib/systemd/system
|
|
|
|
$ for i in abrt*.service auditd.service avahi-daemon.* \
|
|
|
|
bluetooth.* dev-hugepages.mount dev-mqueue.mount \
|
|
|
|
fedora-configure.service fedora-loadmodules.service \
|
|
|
|
fedora-readonly.service ip6tables.service \
|
|
|
|
iptables.service irqbalance.service mcelog.service \
|
|
|
|
rsyslog.service sendmail.service sm-client.service \
|
|
|
|
sys-kernel-config.mount sys-kernel-debug.mount; do \
|
|
|
|
sudo systemctl mask "$i"; \
|
|
|
|
done
|
|
|
|
```
|
|
|
|
|
|
|
|
To disable selinux (only for measurements!), edit `/etc/selinux/config` and add `selinux=0`
|
|
|
|
to the kernel command line.
|
|
|
|
|
|
|
|
My `/etc/grub2.cfg` now looks like this:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```
|
|
|
|
linux /vmlinuz-3.3.7-1.fc17.x86_64 root=/dev/sda3 rootfstype=ext4 libahci.ignore_sss=1 raid=noautodetect selinux=0
|
|
|
|
initrd /initramfs-3.3.7-1.fc17.x86_64.img
|
|
|
|
```
|
|
|
|
|
|
|
|
Now we are really fast!
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ systemd-analyze
|
|
|
|
Startup finished in 1329ms (kernel) + 1596ms (userspace) = 2926ms
|
|
|
|
```
|
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
I also like the idea of automounting (systemd's automount feature was an idea of mine :-).
|
|
|
|
So I turn /boot in a "mount on demand" mountpoint. Also having /tmp as a tmpfs is one way to reduce
|
2020-05-19 18:20:18 +02:00
|
|
|
disk activity (useful for e.g. a slow flash disk). My resulting /etc/fstab looks like this:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```
|
|
|
|
/dev/sda3 / ext4 defaults 1 1
|
|
|
|
/dev/sda1 /boot ext4 noauto,comment=systemd.automount 1 2
|
|
|
|
/dev/sda2 swap swap defaults 0 0
|
|
|
|
tmpfs /tmp tmpfs defaults 0 0
|
|
|
|
```
|
|
|
|
|
|
|
|
This only saved a little bit of time, but still:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ systemd-analyze
|
|
|
|
Startup finished in 1342ms (kernel) + 1426ms (userspace) = 2769ms
|
|
|
|
```
|
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
Because NetworkManager is started also by the graphical login target,
|
2020-05-19 18:20:18 +02:00
|
|
|
I can remove it from the multi-user target and it will be started in parallel to the gdm login screen.
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ sudo rm /etc/systemd/system/multi-user.target.wants/NetworkManager.service
|
|
|
|
```
|
|
|
|
|
|
|
|
This will shave of a few milliseconds:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ systemd-analyze
|
|
|
|
Startup finished in 1323ms (kernel) + 1279ms (userspace) = 2603ms
|
|
|
|
```
|
|
|
|
|
|
|
|
To see the difference readahead makes for the system, I turn it off temporarily and reboot
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ cd /lib/systemd/system
|
|
|
|
$ for i in *readahead*; do sudo systemctl mask $i;done
|
|
|
|
```
|
|
|
|
|
|
|
|
Which will give us:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ systemd-analyze
|
|
|
|
Startup finished in 1336ms (kernel) + 1210ms (userspace) = 2547ms
|
|
|
|
```
|
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
This time is a little bit misleading. Although it seems faster, the real time until the login screen
|
2020-05-19 18:20:18 +02:00
|
|
|
is displayed is taking longer. So a fair comparison would involve a **stopwatch**.
|
|
|
|
|
2023-09-14 16:09:49 +02:00
|
|
|
To turn off plymouth, because we want speed and not eye candy, I remove plymouth completely
|
2020-05-19 18:20:18 +02:00
|
|
|
and regenerate the initramfs to get rid of it.
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ sudo yum remove 'plymouth*'
|
|
|
|
$ sudo dracut -f
|
2023-09-14 16:09:49 +02:00
|
|
|
```
|
2020-05-19 18:20:18 +02:00
|
|
|
|
|
|
|
After a reboot we get the stunning result of:
|
2023-09-14 16:09:49 +02:00
|
|
|
|
2020-05-19 18:20:18 +02:00
|
|
|
```console
|
|
|
|
$ systemd-analyze
|
|
|
|
Startup finished in 612ms (kernel) + 499ms (initramfs) + 1330ms (userspace) = 2443ms
|
|
|
|
```
|
|
|
|
|
|
|
|
The nice thing about `systemctl mask` is, that you can always unmask it via `systemctl unmask`
|
|
|
|
and only enable those default services, which you really need.
|
|
|
|
|
|
|
|
Now, **turn selinux back on**, edit `/etc/selinux/config` and remove `selinux=0` from the kernel command line.
|
|
|
|
You really don't want to trade some seconds for security!
|
|
|
|
|
|
|
|
Have fun and happy rebooting!
|
|
|
|
|
|
|
|
And don't forget to reboot twice to let the readahead optimization kick in!
|