Make Linux Boot Faster by Disabling Unnecessary Services

More and more operating systems become bloated with lots of services that run in the background. While they may not use much CPU time, they increase boot time and RAM usage.

Some Linux distributions include “everything but the kitchen sink,” in an effort to make user life easier. This makes things such as file sharing or printing work out of the box. Unfortunately, the only way to do this is to include hundreds of utilities so that everyone finds something they need.

Fortunately though, open-source operating systems give you the power and freedom to do as you see fit. This means you can disable or remove anything you don’t need. The first option, how to disable services, will be explored here. When you disable, rather then remove, components, there’s less risk of permanently breaking things. And you can go back to the way it was before by simply re-enabling a service if you notice something useful stopped working.

Analyze the Time It Takes for Each Service to Load

Most Linux-based operating systems have migrated to Systemd. Among the suite of utilities it includes, there is a program that lets you analyze how fast your system boots. Specifically, it shows you the total time required to boot and the time it takes for each service to load. Note that some services load in parallel. So, if one requires two seconds to load and the other three seconds, it doesn’t necessarily mean five seconds are required in total. It may be much less than that.

Open a terminal emulator and enter this command:

systemd-analyze-startup-time

This shows how long it takes for the Linux kernel and base system services to load, which means it doesn’t account for the time your graphical interface requires to boot up. To put it another way, this shows you how much time is required, from the moment the kernel is loaded until you are dropped to the Linux console, which looks like what is depicted below.

systemd-analyze-console

If you didn’t have a graphical interface installed, this is what you would be greeted with on your screen.

However, you can also see the time required by the graphical interface to initialize with this command:

systemd-analyze-graphical-target

This shows that the graphical user interface loaded in 2.126 seconds. This doesn’t account for the time required to load desktop utilities. To enable/disable those, launch your desktop environment startup manager.

Finally, probably the most useful command for the purpose of this tutorial is:

systemd-analyze-blame

You can navigate the list with your arrow keys or PAGE UP and PAGE DOWN. Press q to quit.

Use systemctl to Disable Unnecessary Services

As you can see in the previous picture, the snapd service takes 1.295 seconds to load. On an SSD, this is negligible. But on a hard disk, these kinds of times would be in the orders of multiple seconds, and they would add up to a lot in the end. Also, on an SSD many things load in parallel with incredible efficiency. On a hard disk it’s very hard for services to load in parallel. The read heads that float on the disk platters have to move from sector to sector, so it’s almost impossible to truly read data in parallel.

To simplify, imagine this: if on an SSD you would see five services that require one second to boot, it’s likely that the total time required to load all of these might be less than 1.2 seconds. If, on a hard disk, you see the same five services initialize in one second, it’s likely that the total load time is way above five seconds.

Say you don’t need the snapd service, which provides access to containerized application snaps. You can disable it with this command:

But, if you reboot, you will notice the snap daemon is still running. That’s because other dependencies may launch it, even if it’s disabled. Try to see what those may be:

systemd-analyze-grep-snap

snapd.seeded.service and snapd.socket are the culprits here. A child service can request to launch its parent service. When you disable one, you just tell it to not automatically start at boot by itself. But there is a brute-force method to get around this issue.

Use systemctl to Mask a Service

This basically makes the service file null so that applications have no way to start the service.

In most cases it’s not this complicated to disable a service. This example has been chosen to show you how to deal with trickier scenarios. In this case, snapd.seeded.service and snapd.socket should be disabled or masked, too.

The following shows the improved boot time.

systemd-analyze-improved-boot-time

Conclusion

From 4.078, boot time was reduced to 3.452 seconds, which amounts to a decrease of ~15%. Not too bad, considering just one service was disabled, and this is on an SSD. On a hard disk it’s much easier to get much more significant results.

In this particular example, more services could have been disabled with a command like: sudo systemctl mask avahi-daemon.service ModemManager.service thermald.service pppd-dns.service.

If you prefer a graphical application to manage your services, you can take a look at the Systemd Manager project. You will be limited in what you can do with it, though, since the command line offers much more flexibility.

9 comments

  1. “This means you can disable or remove anything you don’t need.”
    That assumes that one KNOWS what is needed and what is not. Disabling services willy-nilly could lead to the disabling of the system.

    From my Windows days I remember that there are sites that help determine what services/apps can be disabled. I know of no analogous sites for Linux.

    “Most Linux-based operating systems have migrated to Systemd.”
    It may be possible that because of its penchant to control everything, it is systemd that is causing the slow boots. Besides, while “most Linux-based operating systems have migrated to Systemd”, there are still quite a few that use other init software. Will you write a follow up article on inits other than systemd?.

  2. Do you know of a listing that would tell us what services are safe, maybe, and ‘do not touch’. Think most of us would like to try, but do not have the knowledge to disable or delay services, and doubt that you have the time to hold our hands.

    1. Well, first there’s googling. If you search for the service and can’t find info about what it does, chances are it’s something important, core to the OS that no one is talking about.

      As far as the command line goes, here’s an example for the Debian family:

      systemctl cat libvirtd.service

      This will list the contents of the service file. Here, I will find this line: ExecStart=/usr/sbin/libvirtd $libvirtd_opts

      Now I can search and see which package installed that file:

      dpkg -S /usr/sbin/libvirtd

      And finally, with the output of that command I can see what the package does:

      apt show libvirt-daemon

      And I can even simulate the removal of the package to see what other dependent packages would be removed:

      apt -s remove libvirt-daemon

      There’s no easy way to tell you what you need and what you don’t. It really depends on your use case.

  3. I check open port and closed that open port. Closed port means stop service. One distro i think solyd come with init 1 port always listen. I use laptop stand alone so saned, cups, avahi daemon must go. Some distro come with so many service start as default.

  4. In my Windoze days I had an app that delayed starting up services, and I could set delay times for each. It worked fairly well. It cut a minute off boot time and slowly added them in after I was reading my email or playing solitaire or whatever.

  5. Good afternoon,

    28.300s apt-daily.service
    20.913s plymouth-quit-wait.service

    these 2 services takes a lot of boottime. Is it safe to mask these 2 services?
    They take appr. 60% of my boottime.

    waiting for your answer,
    regards
    Wim dekkers

    1. The first service will automatically update your package manager database. And, depending on what utilities you have installed, it may also upgrade certain packages, e.g., automatic security upgrades.

      If those services run in the background, then there’s no point in removing them. I mean those may be waiting for something in the background, even after your desktop is already displayed. So they don’t really make your computer boot 28 seconds later. For example, the APT service may simply wait to get an Internet connection.

      If however, you do feel they cause a delay for you, read this: https://askubuntu.com/questions/800479/ubuntu-16-04-slow-boot-apt-daily-service

      If you mask the apt service then remember to “sudo apt update && sudo apt upgrade” manually and periodically.

      I say, only mask them if they really do slow down boot. Otherwise, leave them on, they’re useful. Use the timer on your phone and see if there’s a difference between them active and inactive. Difference means more than 20% time difference. If on one boot you get 40 seconds and on another you get 39, it’s not really a difference. You’ll always get small differences, even when booting the exact same services multiple times.

      You may be able to shave off some seconds off your boot time if you disable boot loading screens. The plymouth service is usually active on computers where graphical boot animations/images/progress bars are used (although it can have other purposes as well).

      Use “apt –purge autoremove [name-of-package]” to get rid of what you don’t need. –purge also removes configuration files associated with the package.

      1. –purge is actually – – purge, two minus signs one after another (without a space between them). The comment section autocorrects consecutive minuses to a dash or something.

  6. Thanks Alexandru.

    I delete the plymouth service concerning the Budgie Desktop. I installed Budgie some time ago, but I did not use it anymore.

    I saves appr. 10 sec in boottime.
    Thanks

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.