Direkt zum Inhalt | Direkt zur Navigation

Benutzerspezifische Werkzeuge
Sektionen
Sie sind hier: Startseite Personal My Blog Fedora 17 Boot Optimization (from 15 to 2.5 seconds)

Fedora 17 Boot Optimization (from 15 to 2.5 seconds)

erstellt von Harald Hoyer zuletzt verändert: 02.06.2012 23:32
This article shows how to reduce boot time for Fedora 17.

The target is to get a fast booting system with NetworkManager running and gdm displaying the login screen as fast as possible.

The system I use here is a Lenovo T420s (2x2x Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz) with an INTEL SSDSA2BW160G3L harddrive.

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).

First we update everything, prelink for speed and install systemd-analyze.

$ sudo yum update
$ sudo /etc/cron.daily/prelink
$ sudo yum install systemd-analyze

After the reboots, I get:

# systemd-analyze
Startup finished in 1413ms (kernel) + 2911ms (initramfs) + 10593ms (userspace) = 14918ms

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/grub2.cfg looks like this:

 linux /vmlinuz-3.3.7-1.fc17.x86_64 root=/dev/sda3 rootfstype=ext4 quiet libahci.ignore_sss=1 raid=noautodetect
#       initrd /initramfs-3.3.7-1.fc17.x86_64.img

"raid=noautodetect" and "libahci.ignore_sss=1" saves some time for the kernel initialization.

Startup finished in 1640ms (kernel) + 13043ms (userspace) = 14684ms

Because I don't use any LVM, RAID or encrypted devices, I can safely turn off all nearly all fedora-*storage* services. Additionally I turn off the plymouth boot splash, because I want speed and not eye candy. 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.

$ cd /lib/systemd/system
$ for i in fedora*storage* plymouth-*.* lvm2-monitor.* mdmonitor*.*; do sudo systemctl mask $i;done

It seems there are still some SysV initscripts left, so we turn them off:

$ for i in livesys livesys-late spice-vdagentd ; do sudo chkconfig $i off;done

Seems like we saved half of the time in userspace:

Startup finished in 1640ms (kernel) + 6556ms (userspace) = 8197ms

From now on, you really have to know what you are doing and how to revert your actions. To compare Fedora 17 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, some mountpoints, rsyslog, irqbalance, and selinux security.

$ 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, edit /etc/selinux/config and add "selinux=0" to the kernel command line. My /etc/grub2.cfg now looks like this:

 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!

$ systemd-analyze
Startup finished in 1329ms (kernel) + 1596ms (userspace) = 2926ms

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

This only saved a little bit of time, but still:

$ systemd-analyze
Startup finished in 1342ms (kernel) + 1426ms (userspace) = 2769ms

Because NetworkManager is started also by the graphical login target, I can remove it from the multi-user target and it will be started in parallel to the gdm lo)gin screen.

$ sudo rm  /etc/systemd/system/multi-user.target.wants/NetworkManager.service

This will shave of a few milliseconds:

$ 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

$ cd /lib/systemd/system
$ for i in *readahead*; do sudo systemctl mask $i;done

Which will give us:

$ systemd-analyze 
Startup finished in 1336ms (kernel) + 1210ms (userspace) = 2547ms

This time is a little bit misleading. Although it seems faster, the real time until the login screen is displayed is taking longer. So a fair comparison would involve a stopwatch.

$ sudo dracut -f

Here is the time with readahead and the initramfs turned back on:

$ systemd-analyze 
Startup finished in 803ms (kernel) + 2217ms (initramfs) + 1018ms (userspace) = 4039ms

Of course, this can be optimzed also, when we build the initramfs without plymouth and in host-only mode.

$ sudo dracut -f -H -o plymouth

After a reboot we get the stunning result of:

$ systemd-analyze 
Startup finished in 612ms (kernel) + 499ms (initramfs) + 1330ms (userspace) = 2443ms

The nice thing about "systemctl mask" is, that you always unmask it via "systemctl unmask" and enable those default services, which you really need.

Have fun and happy rebooting!

And don't forget to reboot twice to let the readahead optimization kick in!

MacBook Air 4,2

Avatar Posted by hansvon at 30.05.2012 16:21
Thanks, I managed to go from ~12 seconds to 3.5s by:
- removing the initrd
- masking fedora*storage* plymouth-*.* lvm2-monitor.* mdmonitor*

https://dl.dropbox.com/u/14500830/boot.png

Good enough for me and everything is still loaded, including selinux.
Maybe try to understand why the kernel takes one second to load... but anyway...

Speed Up Boot Even Further.

Avatar Posted by Tohie at 30.05.2012 23:00
I suggest you take a look at e4rat (http://e4rat.sourceforge.net/) it speeds up boot more than readahead.

e4rat and systemd readahead

Avatar Posted by Solenskiner at 31.05.2012 08:35
IIRC, Lennart Poettering wants to include e4rats functionality into systemds readahead, as they have already done for btrfs.

e4rat

Avatar Posted by Anonymous at 15.06.2012 08:52
Do you success installing and runing e4rat on fedora 17 ? and how?

e4rat on Fedora 17

Avatar Posted by Simoon B. at 26.07.2012 08:41

fedora 17 guide

Avatar Posted by xiamx at 28.11.2012 13:20

2001ms boot time

Avatar Posted by Rammsdell at 31.05.2012 08:35
I managed to get a nearly flat 2 second boot time running on a patriot pyro SSD

http://i.imgur.com/2h0GP.png

Question.

Avatar Posted by Daniel O. at 31.05.2012 08:35
I don't have /etc/grub.conf file. How can I make it?

grub.conf

Avatar Posted by Ivan Prolugin at 31.05.2012 09:05
Maybe it is located at /boot/grub/grub.conf

grub

Avatar Posted by Harald Hoyer at 31.05.2012 09:11
it's /etc/grub2.cfg

grub

Avatar Posted by Nícolas at 01.06.2012 14:10
And what about if you edit /etc/default/grub instead to adjust these parameters?

[root@x ]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Fedora"
GRUB_DEFAULT=saved
GRUB_CMDLINE_LINUX="rd.md=0 rd.lvm=0 rd.dm=0 LANG=pt_BR.UTF-8 quiet SYSFONT=latarcyrheb-sun16 rhgb rd.luks=0 KEYTABLE=br-abnt2"


Cheers

blame

Avatar Posted by Eduardo at 01.06.2012 07:09
nice! just for curiosity, could you please post your `systemd-analyze blame` list?

OMG

Avatar Posted by Houge_Langley at 01.06.2012 07:47
So Great

A word of warning

Avatar Posted by Kåre Fiedler Christiansen at 01.06.2012 07:47
Be careful! Once you apply this in Fedora 17, the kernel packages will no longer update your grub configuration automatically.
See also bug https://bugzilla.redhat.com/show_bug.cgi?id=737370

They don't do it properly already

Avatar Posted by Sergio at 01.06.2012 14:49
After a kernel update the generated GRUB menu is messed up and we need to run grub2-mkconfig manually anyway.

systemd-analyze

Avatar Posted by Eduaro Maes at 01.06.2012 14:13
I tried to check the boot time in Fedora 16 (x64), but yum does not find the systemd-analyze. Perhaps because it x64?

RE: systemd-analyze

Avatar Posted by Mark at 01.06.2012 16:15
systemd-analyze is in the systemd package, you should already have it ( look for /usr/bin/systemd-analyze )

booting without an initramfs img

Avatar Posted by Endur at 01.06.2012 22:59
Hi, Harald,

Got a
kernel panic and
"please pass init= option"
if I pass root=/dev/sdaX rootfstype=ext4
as kernel args. Any ideas?
/usr is sda3
/boot is sda1
/ is sda5
/home is sda2

Any ideas?

Kind regards to Schwerin
from Erzgebirge

Endur

You must use an initrd

Avatar Posted by Colin Guthrie at 06.06.2012 15:58
If you have a separate /usr, then I'm afraid you have to use an initrd. This is the only supported method of having a separate /usr these days.

Fedora Crashed

Avatar Posted by V. Narayanan at 12.09.2012 08:52
Hi
When I tried...
The total fedora crashed...

systemctl default - did not worked and I am struggling hard to recover

These are dangerous commands ...
I thing, a warning shall have to be given before posting these commands

I want to undo systemctl mask, I do not know - how
Yours
VN

booting without an initramfs img

Avatar Posted by Endur at 01.06.2012 23:00
It seems that the error occurs because
/usr is an own partition...

/sbin is symlinked to /usr/sbin

may be it isn't mounted at this time...




booting without an initramfs img

Avatar Posted by Endur at 01.06.2012 23:00
May be I need /dev/console?

The fix is...

Avatar Posted by Endur at 02.06.2012 20:42
..(for me) was to have /usr on same partition as rootfs.

Disabling initrd

Avatar Posted by Nick G at 02.06.2012 23:29
I'm confused - you changed grub to boot the kernel directly instead of the initrd. You later use dracut to generate a new initrd but don't specify that you've reenabled it in grub?

Could you explain what it was you did? Did you reenable the initrd without plymouth etc - if so, could you not get back a few more ms by keeping it disabled?

What are the complications of that?

Disabling initrd, or not?

Avatar Posted by SimonB. at 26.07.2012 08:44
Like Nick G, I would also like some more detail on initrd or not. Which is supposedly faster?

Also, when I run without initrd I think I get ext4 fsck to run on every boot. I have a vague memory of reading somewhere (Poettering or Hoyer?) a complaint on fsck kicking in when running without initrd, I keep searching but find no references (from this decade).

Grub2 configuration file for initrdless

Avatar Posted by Peter Senna Tschudin at 04.06.2012 06:55
Hey Harold,

Great Article! But Grub2 is not that easy to configure. So, I made a configuration file for it to be placed at /etc/grub.d that creates entries for booting without initrd... Check it at:

https://github.com/petersenna/Fedora17-fastboot

Now it will keep working after Kernel update. :-)

[]'s

Peter

Help me ontime taken for network.

Avatar Posted by anil at 18.06.2012 07:48
I have managed to bring down boot time to 10 seconds from 20 seconds.
I still have this as a topper and taking 2 seconds. What can be done.

From systemd-analyze blame
  2528ms network.service

Grub2 configuration

Avatar Posted by GM at 08.03.2013 08:19
I tried doing that but was not able disable initrd

now can not boot!!!

Avatar Posted by tony at 18.06.2012 07:48
I typed some commands described here and now not only don't boot faster, even DON'T boot!! It's freeze (I'm writing from another pc) while booting and always have to force physically shut down
help me please!

Help me reduce time to bring up network.

Avatar Posted by anil at 18.06.2012 07:48
On my machine, brining network up takea a long time.
  2528ms network.service (from systemd-analze blame) What can be done. ?

Re: Help me reduce time to bring up network.

Avatar Posted by jjj at 04.06.2013 10:46
Disable the network.service, NetworkManager takes care of the network anyway.

Smart...

Avatar Posted by Jamed at 27.06.2012 09:18
You guys/girls are really smart, I just wanted to dual boot with Fedora to use something faster and smoother than windows 7, than I clicked this in google to try and increase my speed as I do with every OS, this looks incredibly complicated right now! But thanks anyway, I'm positive I can learn it (:

Awesome.

Avatar Posted by Chad at 12.09.2012 08:52
Hey, this guide is great. I didn't disable all the services listed. I like having Blutooth and a firewall but I did manage to shave 43% off my start up time. Boot is now 3.8 seconds and the computer goes from power button to browser in less than 13 seconds.

I know this isn't an option everyone will like, but instead of messing with grub2/initramfs, I installed extlinux/disabled initramfs. So much easier, and I believe faster.

Help.

Avatar Posted by MitUot at 12.09.2012 08:53
how to restore the state before executing two commands.....
This time is a little bit misleading. Although it seems faster, the real time until the login screen is displayed is taking longer. So a fair comparison would involve a stopwatch.

$ sudo dracut -f
Of course, this can be optimzed also, when we build the initramfs without plymouth and in host-only mode.

$ sudo dracut -f -H -o plymouth

Thanks!

Avatar Posted by Neil at 14.09.2012 13:03
Found this very very useful, thank you!!

Dual Booting Fedora 17 & Win XP

Avatar Posted by Onkaramurthy at 21.11.2012 16:56
Please anyone give me simple steps to make XP boot first and Fedora second

RAID in laptop

Avatar Posted by pr@x at 28.11.2012 13:20
Hi I have a samsung 830 ssd running in RAID mode since my laptop hp dv7t 7000 doesnt allow ahci mode. Please let me know which services are required for that.

953ms udev-settle.service
   638ms NetworkManager.service
   536ms systemd-logind.service
   481ms jexec.service
   459ms chronyd.service
   379ms lm_sensors.service
   338ms iptables.service
   311ms auditd.service
   309ms dbus.service
   298ms mcelog.service
   297ms akmods.service
   234ms irqbalance.service
   221ms systemd-user-sessions.service
   208ms systemd-readahead-replay.service
   202ms sm-client.service
   183ms systemd-readahead-collect.service
   148ms fedora-readonly.service
   148ms media.mount
   141ms udev-trigger.service
   112ms dev-hugepages.mount
    99ms sendmail.service
    93ms fedora-loadmodules.service
    83ms dev-mqueue.mount
    69ms fedora-storage-init.service
    67ms fedora-storage-init-late.service
    66ms systemd-sysctl.service
    66ms fedora-wait-storage.service
    63ms sys-kernel-debug.mount
    61ms systemd-tmpfiles-setup.service
    59ms systemd-remount-fs.service
    58ms sys-kernel-config.mount
    53ms lvm2-monitor.service
    46ms systemd-vconsole-setup.service
    42ms udisks2.service
    38ms tmp.mount
    34ms colord-sane.service
    25ms udev.service
    21ms colord.service
    21ms bluetooth.service
    20ms proc-sys-fs-binfmt_misc.mount
    14ms accounts-daemon.service
    13ms upower.service
     6ms rtkit-daemon.service
     5ms sys-fs-fuse-connections.mount

Incredulous

Avatar Posted by virtualeyes at 08.03.2013 08:18
How on earth do you get these boot times??

I have applied most of the above suggestions and still get @13 seconds power button to login.

Machine is a beast (Dell M4700 3840QM 16GB) compared to the one you have listed here.

Must be missing something:
systemd-analyze
Startup finished in 2905ms (kernel) + 4964ms (initrd) + 5305ms (userspace)


Thanks!!!

Avatar Posted by Gabriel at 08.03.2013 08:29
Startup finished in 831ms (kernel) + 1729ms (userspace) = 2561ms


Thanks dude! U r great! ;]

50% decrease in boot time

Avatar Posted by phanindra-fedora18 at 08.03.2013 08:29
Thanks, I decreased the boot time from 32 seconds to 16 seconds, i'm not sure about many other active services like iprinit.service iprupdate.service systemd-vconsole-setup.service systemd-remount-fs.service systemd-binfmt.service systemd-udev-trigger.service systemd-modules-load.service so I havent touched them, can I disable them too?

Gonzalez

Avatar Posted by German at 08.03.2013 08:30
Sick!! well done! I'll play with it. :-)
you're the man.

Fedora 18

Avatar Posted by tester at 08.03.2013 08:30
Now that Fedora 18 is out please update the article for the same as few commands and services have changed. tx

mask vs disable

Avatar Posted by A nony mouse at 08.03.2013 08:30
What is the reason for choosing mask over disable for systemctl? Afaicu systemd is supposed to take care of all dependencies itself so disable should be the safe way to go, allowing for systemd to still start an unit if other required units absolutely depend on it (while mask avoid starting an unit even in that case). Am I wrong?

Really???

Avatar Posted by Bill at 08.03.2013 08:31
So you are willing to turn off SELinux, full disc encryption, and remote logging services to save a few seconds booting? Why not just set the all your passwords to "" and set auto-login as root to save all the time as well?

While this does seem like a fun experiment, the idea of throwing out fundamental security features seems misguided.

re: Acceptance

Avatar Posted by virtualeyes at 05.04.2013 07:51
I have hit my limit, just over 5 seconds ;-)

Will just have to accept feeling envious of those who are achieving sub 3 second boot times, pretty unreal O_o

FWIW, dracut host-only vs. no initramfs are nearly equal, the latter faster by about 1 second.

I suspect several partition mount points are slowing things down a bit for me.

and then the realization that it's all nonesense as I tend to reboot once every 2 or 3 weeks...

failed to disable initramfs

Avatar Posted by Kiran at 20.04.2013 10:54
HI,

i tried disabling initramfs like from /boot/grub2/grub.cfg file and it smashed my system.

did i do anything wrong?

if i mess up ..

Avatar Posted by bab at 22.04.2013 08:24
If i mess up .. is there any way to revert (ie fire up the services on the next boot ?)

Fedora 18

Avatar Posted by caveman at 03.06.2013 10:45
Do you have anything for Fedora 18?

Add comment

Formatierung als einfacher Text. URLs werden in Links umgewandelt.

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