You are here: Home Personal My Blog Fedora 15 Boot Optimization (from 45 to 26 seconds)

Fedora 15 Boot Optimization (from 45 to 26 seconds)

by Harald Hoyer last modified May 24, 2011 03:11 PM
This article shows how to reduce boot time, especially for a computer with a slow spinning disk.

If you want to run Fedora 15 on a slow spinning disk, then you have to customize it a bit, to get fast boot times.

First we choose a manual disk layout and use primary partitions and format them with ext4. In my case this results in:

sda1 ext4 /boot
sda2 swap
sda3 ext4 /

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), I measure 45 seconds from the grub menu to the graphical login screen. To get the grub menu, just hold down <ALT> in the boot phase. 45 seconds is a little bit slow compared to the other distributions. systemd-analyse gives me the output: Startup finished in 5585ms (kernel) + 5509ms (initrd) + 21847ms (userspace) = 32942ms

The next step is to disable the initramfs, because the kernel can boot from an ext4 partition without it. Because I know how to rescue my system, I can set the root device directly to sda3 and tell the kernel which filesystem type to use. My /etc/grub.conf looks like this:

title Fedora (2.6.38.6-26.rc1.fc15.i686.PAE)
root (hd0,0)
kernel /vmlinuz-2.6.38.6-26.rc1.fc15.i686.PAE ro root=/dev/sda3 rootfstype=ext4 rhgb quiet
#    initrd /initramfs-2.6.38.6-26.rc1.fc15.i686.PAE.img

Rebooting gives 40 seconds to the login screen. systemd-analyse prints:  Startup finished in 7897ms (kernel) + 21470ms (userspace) = 29367ms

Because I don't use any LVM, RAID or encrypted devices, I can safely turn off all fedora-* services. Additionally I turn off the plymouth boot splash, because I want speed and not eye candy. To turn off these services, you have to use the /dev/null softlink mechanism, because these services cannot be disabled by "systemctl disable". A bonus with that mechanism is, that no rpm %post script turns them on automatically, without me knowing :-)

# cd /lib/systemd/system
# for i in fedora-* plymouth-*; do sudo ln -s /dev/null /etc/systemd/system/$i;done

Now the boot time is down to 37 seconds. systemd-analyse prints: Startup finished in 7894ms (kernel) + 17992ms (userspace) = 25887ms

From now on, you really have to know what you are doing and how to revert your actions. To compare Fedora 15 with e.g. Ubuntu, I will now turn off all services except sshd. The result will be a Linux system without mail, firewall, printing and selinux security.

$ for i in abrt-ccpp abrt-oops cups mdmonitor netfs nfslock pcscd portreserve rpcbind rpcgssd rpcidmapd sendmail smolt ip6tables iptables sandbox selinux; do sudo chkconfig $i off;done

To disable selinux, edit /etc/selinux/config and/or add "selinux=0" to the kernel command line. My /etc/grub.conf now looks like this:

title Fedora (2.6.38.6-26.rc1.fc15.i686.PAE)
root (hd0,0)
kernel /vmlinuz-2.6.38.6-26.rc1.fc15.i686.PAE ro root=/dev/sda3 rootfstype=ext4 selinux=0
#    initrd /initramfs-2.6.38.6-26.rc1.fc15.i686.PAE.img

A reboot shows, that we are now down to a nice 26 seconds. systemd-analyse prints: Startup finished in 6157ms (kernel) + 12048ms (userspace) = 18206ms

Because I turned off selinux, I can also remove some packages :-)

# sudo yum remove $(rpm -qf --qf '%{name}\n' /etc/init.d/auditd /lib/systemd/system/{abrtd.service,mcelog.service})

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 disk activity (useful for e.g. a slow flash disk).

My resulting /etc/fstab looks like this:

/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

A reboot gives still 26 seconds, systemd-analyse: Startup finished in 6121ms (kernel) + 12772ms (userspace) = 18894ms

To see the difference readahead makes for the system, I turn it off temporarily and reboot

# cd /lib/systemd/system
# for i in *readahead*; do systemctl disable $i;done
rm '/etc/systemd/system/default.target.wants/systemd-readahead-collect.service'
rm '/etc/systemd/system/default.target.wants/systemd-readahead-replay.service'

Without readahead it takes 32 seconds to be able to login. systemd-analyse says: Startup finished in 6125ms (kernel) + 10992ms (userspace) = 17118ms

As we can see it's real 26 versus 32 seconds. The output of systemd-analyse would be misleading, if we only relied on that!!

So, because I like 26 seconds more, I turn on readahead again :-) To check, if readahead has an updated list, do a "ls -l /.readahead" to see the timestamp and check the return status of readahead ("systemctl status systemd-readahead-collect.service"). There might be a selinux related bug, because with selinux turned on, the collector always returned with error status 1 in my testing.

# cd /lib/systemd/system 
# for i in *readahead*; do systemctl enable $i;done

For the reference here is the list of services, that are started:

# LANG=C chkconfig --list|fgrep 5:on

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

cpuspeed           0:off    1:on    2:on    3:on    4:on    5:on    6:off
sshd               0:off    1:off    2:on    3:on    4:on    5:on    6:off
# systemctl
boot.automount            loaded active waiting       boot.automount
dev-hugepages.automount   loaded active waiting       Huge Pages File System Automount Point
dev-mqueue.automount      loaded active waiting       POSIX Message Queue File System Automount Point
proc-sys...misc.automount loaded active waiting       Arbitrary Executable File Formats File System Automount Point
sys-kern...ebug.automount loaded active waiting       Debug File System Automount Point
sys-kern...rity.automount loaded active waiting       Security File System Automount Point
sys-devi...ock-sdb.device loaded active plugged       Flash_HS-CF
sys-devi...ock-sdc.device loaded active plugged       Flash_HS-COMBO
sys-devi...d-card1.device loaded active plugged       SB Live! EMU10k1
sys-devi...net-em1.device loaded active plugged       82540EM Gigabit Ethernet Controller
sys-devi...da-sda1.device loaded active plugged       ST380011A
sys-devi...da-sda2.device loaded active plugged       ST380011A
sys-devi...da-sda3.device loaded active plugged       ST380011A
sys-devi...ock-sda.device loaded active plugged       ST380011A
sys-devi...ock-sr0.device loaded active plugged       PIONEER_DVD-RW_DVR-105
sys-devi...d-card0.device loaded active plugged       82801EB/ER (ICH5/ICH5R) AC'97 Audio Controller
sys-devi...y-ttyS1.device loaded active plugged       /sys/devices/platform/serial8250/tty/ttyS1
sys-devi...y-ttyS2.device loaded active plugged       /sys/devices/platform/serial8250/tty/ttyS2
sys-devi...y-ttyS3.device loaded active plugged       /sys/devices/platform/serial8250/tty/ttyS3
sys-devi...y-ttyS0.device loaded active plugged       /sys/devices/pnp0/00:08/tty/ttyS0
sys-devi...ock-md0.device loaded active plugged       /sys/devices/virtual/block/md0
sys-devi...ty-tty0.device loaded active plugged       /sys/devices/virtual/tty/tty0
sys-devi...ty-tty1.device loaded active plugged       /sys/devices/virtual/tty/tty1
sys-devi...y-tty10.device loaded active plugged       /sys/devices/virtual/tty/tty10
sys-devi...y-tty11.device loaded active plugged       /sys/devices/virtual/tty/tty11
sys-devi...y-tty12.device loaded active plugged       /sys/devices/virtual/tty/tty12
sys-devi...ty-tty2.device loaded active plugged       /sys/devices/virtual/tty/tty2
sys-devi...ty-tty3.device loaded active plugged       /sys/devices/virtual/tty/tty3
sys-devi...ty-tty4.device loaded active plugged       /sys/devices/virtual/tty/tty4
sys-devi...ty-tty5.device loaded active plugged       /sys/devices/virtual/tty/tty5
sys-devi...ty-tty6.device loaded active plugged       /sys/devices/virtual/tty/tty6
sys-devi...ty-tty7.device loaded active plugged       /sys/devices/virtual/tty/tty7
sys-devi...ty-tty8.device loaded active plugged       /sys/devices/virtual/tty/tty8
sys-devi...ty-tty9.device loaded active plugged       /sys/devices/virtual/tty/tty9
-.mount                   loaded active mounted       /
home-harald-.gvfs.mount   loaded active mounted       /home/harald/.gvfs
media.mount               loaded active mounted       Media Directory
sys-fs-f...nections.mount loaded active mounted       /sys/fs/fuse/connections
tmp.mount                 loaded active mounted       /tmp
systemd-...d-console.path loaded active waiting       Dispatch Password Requests to Console Directory Watch
systemd-...word-wall.path loaded active waiting       Forward Password Requests to Wall Directory Watch
accounts-daemon.service   loaded active running       Accounts Service
acpid.service             loaded active running       ACPI Event Daemon
atd.service               loaded active running       Job spooling tools
avahi-daemon.service      loaded active running       Avahi mDNS/DNS-SD Stack
console-...daemon.service loaded active running       Console Manager
console-...-start.service loaded active exited        Console System Startup Logging
cpuspeed.service          loaded active exited        LSB: processor frequency scaling support
crond.service             loaded active running       Command Scheduler
dbus.service              loaded active running       D-Bus System Message Bus
getty@tty2.service        loaded active running       Getty on tty2
getty@tty3.service        loaded active running       Getty on tty3
getty@tty4.service        loaded active running       Getty on tty4
getty@tty5.service        loaded active running       Getty on tty5
getty@tty6.service        loaded active running       Getty on tty6
hwclock-load.service      loaded active exited        Apply System Clock UTC Offset
irqbalance.service        loaded active running       irqbalance daemon
NetworkManager.service    loaded active running       Network Manager
prefdm.service            loaded active running       Display Manager
rc-local.service          loaded active exited        /etc/rc.local Compatibility
remount-rootfs.service    loaded active exited        Remount Root FS
rsyslog.service           loaded active running       System Logging Service
rtkit-daemon.service      loaded active running       RealtimeKit Scheduling Policy Service
smartd.service            loaded active running       Self Monitoring and Reporting Technology (SMART) Daemon
sshd.service              loaded active running       LSB: Start up the OpenSSH server daemon
system-s...yboard.service loaded active running       System Setup Keyboard
systemd-logger.service    loaded active running       Stdio Syslog Bridge
systemd-...ollect.service loaded active exited        Collect Read-Ahead Data
systemd-...replay.service loaded active exited        Replay Read-Ahead Data
systemd-...pi-vfs.service loaded active exited        Remount API VFS
systemd-sysctl.service    loaded active exited        Apply Kernel Variables
systemd-...-setup.service loaded failed failed        Recreate Volatile Files and Directories
systemd-...ssions.service loaded active exited        Permit User Sessions
systemd-...-setup.service loaded active exited        Setup Virtual Console
udev-trigger.service      loaded active exited        udev Coldplug all Devices
udev.service              loaded active running       udev Kernel Device Manager
avahi-daemon.socket       loaded active listening     Avahi mDNS/DNS-SD Stack Activation Socket
dbus.socket               loaded active running       D-Bus System Message Bus Socket
syslog.socket             loaded active running       Syslog Socket
systemd-initctl.socket    loaded active listening     /dev/initctl Compatibility Named Pipe
systemd-logger.socket     loaded active running       Stdio Syslog Bridge Socket
systemd-shutdownd.socket  loaded active listening     Delayed Shutdown Socket
udev.socket               loaded active listening     udev Kernel Device Manager Socket
dev-sda2.swap             loaded active active        /dev/sda2
basic.target              loaded active active        Basic System
cryptsetup.target         loaded active active        Encrypted Volumes
getty.target              loaded active active        Login Prompts
graphical.target          loaded active active        Graphical Interface
local-fs.target           loaded active active        Local File Systems
multi-user.target         loaded active active        Multi-User
network.target            loaded active active        Network
sockets.target            loaded active active        Sockets
sound.target              loaded active active        Sound Card
swap.target               loaded active active        Swap
sysinit.target            loaded active active        System Initialization
syslog.target             loaded active active        Syslog
time-sync.target          loaded active active        System Time Synchronized
systemd-...ead-done.timer loaded active elapsed       Stop Read-Ahead Data Collection 10s After Completed Startup
systemd-...es-clean.timer loaded active waiting       Daily Cleanup of Temporary Directories

 

For the reference here is the dmesg output.

Related content
File Fedora 15 dmesg

result with ssd

Avatar Posted by ssldan at May 24, 2011 10:30 PM
Hello Harald, thanks for your effort,
mine result, without tweaking, except dropping a few unimportant services for me, are:
Startup finished in 1822ms (kernel) + 1713ms (initrd) + 8210ms (userspace) = 11746ms
However I administer a few laptops my friends are using, these almost all have slow 5400 rpm disks and I am curious would you suggest striping kernel image to just have support for particular build-in hardware - for specific machine? Of course I'll apply your findings on those first!

Fedora 15 Boot Optimization

Avatar Posted by Andabta at May 26, 2011 08:13 PM
Simple and effective!
Thanks, Master of Optimization, non only for speeding up the boot but also for the manner of stopping the services on the new systemd. ;)

thx

Avatar Posted by TIM at May 27, 2011 09:06 AM
this helped me to do from 27sec to 11sec :)

Why for i in fedora-* plymouth-*; do sudo ln -s /dev/null /etc/systemd/system/$i;done?

Avatar Posted by Sash at Jun 23, 2011 08:53 PM
Didn't work for me. But why don't you just remove "rhgb" from Kernel-Line in grub config?

what about luks

Avatar Posted by Aron at Jun 23, 2011 08:53 PM
Which services should I not disable to keep luks support?

Terribly useful

Avatar Posted by robert st.amour at Jul 21, 2011 06:05 AM
Thanx

Thank you

Avatar Posted by Lovely Person at Jul 21, 2011 06:06 AM
Hello Mr Harald,

thanks for your suggestion. My F15 system started taking longer time for booting after installing wine and other windows stuff in it. Later even though I removed wine but I could not get booting speed. But after following your suggestion, I got back system boot speed.

Thanks once again

Dracut

Avatar Posted by Tom at Sep 05, 2011 02:09 PM
I love the fact that the "dracut guy" comments out the initrd line in grub.conf! :)

Dracut

Avatar Posted by Harald Hoyer at Sep 05, 2011 02:10 PM
Hehe, sure :) Only use, what you need!

No initrd no worky

Avatar Posted by Chris at Sep 23, 2011 08:48 AM
When I comment out the initrd line and add root=/dev/sda3 rootfstype=ext4 (yes I do have my root partition on sda3) I just get a kernel panic. Do I need to build a custom kernel or something first?

Kernel panic

Avatar Posted by Toni at Nov 21, 2012 05:10 PM
Me too. I think that Dracut has success because his system has a dedicated /boot partition (/dev/sda1, so he can set root (hd0,0)), separated from / partition (/dev/sda3).

Damn!!!

Avatar Posted by CHamgamer at Oct 20, 2011 04:01 PM
After i did that instructions i've stuck in Welcome to emergency mode thing!!!!

Thank you

Avatar Posted by S@yaN at Oct 20, 2011 04:01 PM
Superb

I gat max benefit on my ASUX Netbook by disabling initrd . Fedora 15 is around 20 sec faster than the pre installed windows 7 Starter .
(Sayan Singapore)

Start services on demand?

Avatar Posted by Damian at Oct 29, 2011 10:13 AM
Thanks! I reduced the boot time from 37 seconds to 25, in an HP mini.

The only problem is that sometimes I mount a nfs share, and the system complains because rpcbind is not started. Is there a way of starting in "on-demand"?

faster boot

Avatar Posted by Fred Ora at Feb 11, 2012 06:35 PM
For a real speed improvement, change "defaults" in /etc/fstab to :

noatime,data=writeback,barrier=0,nobh
,errors=remount-ro

No "last access" writes for every read...

When there are errors... filesystem gets automagically set to read-only, so no losses.

;)
Fred Ora

Disabling selinux

Avatar Posted by Tomas Pruzina at Feb 11, 2012 06:36 PM
Disabling selinux for a few seconds speedup on production machine? Srsly?

I get it if one wants to push limits down, but on production machine that is just silly.

Nat that you people know how to configure selinux, but even with default rules it provides some nice degree of security.

Fast boot is not everything...

nice work

Avatar Posted by Vipin at Feb 11, 2012 06:36 PM
46 to 28 here.

thx

Avatar Posted by Andrej at Feb 11, 2012 06:36 PM
very good :D

Help in applying changes.

Avatar Posted by Hayden at Feb 11, 2012 06:38 PM
I did a default Fedora 64bit install. So i have sda sda1 and sda2. I want to apply thse changes but want to confirm that...

sda1 ext4 /boot = sda on my system?
sda2 swap = sda1 on my system?
sda3 ext4 / = sda2 on my system?

Is that correct on a default install where I wiped my entire drive and did a clean install.

My ls:
[hayden@hydn dev]$ ls
agpgart hpet network_throughput raw tty12 tty35 tty58 v4l
autofs hugepages null rfkill tty13 tty36 tty59 vcs
block initctl nvram root tty14 tty37 tty6 vcs1
bsg input oldmem rtc tty15 tty38 tty60 vcs2
btrfs-control kmsg port rtc0 tty16 tty39 tty61 vcs3
bus log ppp scd0 tty17 tty4 tty62 vcs4
cdrom loop0 ptmx sda tty18 tty40 tty63 vcs5
cdrw loop1 pts sda1 tty19 tty41 tty7 vcs6
char loop2 ram0 sda2 tty2 tty42 tty8 vcsa
console loop3 ram1 sg0 tty20 tty43 tty9 vcsa1
core loop4 ram10 sg1 tty21 tty44 ttyS0 vcsa2
cpu loop5 ram11 shm tty22 tty45 ttyS1 vcsa3
cpu_dma_latency loop6 ram12 snapshot tty23 tty46 ttyS2 vcsa4
disk loop7 ram13 snd tty24 tty47 ttyS3 vcsa5
dm-0 lp0 ram14 sr0 tty25 tty48 uinput vcsa6
dm-1 lp1 ram15 stderr tty26 tty49 urandom vga_arbiter
dm-2 lp2 ram2 stdin tty27 tty5 usbmon0 vg_hydn
dri lp3 ram3 stdout tty28 tty50 usbmon1 video0
dvd mapper ram4 systty tty29 tty51 usbmon2 watchdog
dvdrw mcelog ram5 tpm0 tty3 tty52 usbmon3 zero
fb media0 ram6 tty tty30 tty53 usbmon4
fb0 mem ram7 tty0 tty31 tty54 usbmon5
fd mqueue ram8 tty1 tty32 tty55 usbmon6
full net ram9 tty10 tty33 tty56 usbmon7
fuse network_latency random tty11 tty34 tty57 usbmon8

Thanks

Avatar Posted by movl at Mar 12, 2012 10:43 AM
I followed partially what you wrote and it worked. I believe the kernel panics without an initramfs because i2c* is compiled as a module, at least on my system.

Failed to mount lvm

Avatar Posted by Muchi at Jul 26, 2012 08:30 AM
Hi Harald, I made a stupid change on my system by symbol link fedora-* plymouth-* to /dev/null, while I am actually using LVM (now I know I am using LVM). Then the system would not start after mounting swap and root, it hanged at "[TIME] Timed out waiting for device dev-mapper-vg_kenshiro\x2dlv_home.device", followed by a bunch of failure of /home local file systems, graphical user interface, all due to dependency. I tried to reinstall initscripts, systemd-units, hoping to get those fedora-*storage* back and also plymouth* back. They are back now but I still mount home. Do you mind telling me how can I get things back? I appreciate it a lot!!!

revert

Avatar Posted by Harald Hoyer at Nov 21, 2012 05:10 PM
just remove the symbolic links in /etc/systemd/system

can i diable eye candy

Avatar Posted by gaurav at Nov 21, 2012 05:10 PM
can i diable eye candy in fedora 15..

Regards

Gaurav Linux Garg
http://tipswell.com

Add comment

You can add a comment by filling out the form below. Plain text formatting.

(Required)
Please enter your name.
(Required)
(Required)
(Required)
Enter the word