99

I want to improve the boot time of my Ubuntu GNOME 16.04 by disabling plymouth services when booting up. I've found two answers on how to do it on various websites namely:

# systemctl disable plymouth-quit-wait.service 
# systemctl mask plymouth-quit-wait.service 

I can't execute either of the above unless I know what they do.

Zanna
  • 70,465
mhm
  • 1,302

3 Answers3

141

If a service is enabled, then there is a symlink somewhere in

/etc/systemd/system

to a unit file, most often somewhere in

/lib/systemd/system

Helpfully, when you enable a service, the full paths of the created link and target will be printed to stdout.

Disabling the service deletes the symlink, so the unit file itself is not affected, but the service is not loaded at the next boot, when systemd reads /etc/systemd/system.

However, a disabled service can be loaded, and will be started if a service that depends on it is started; enable and disable only configure auto-start behaviour for units, and the state is easily overridden.

A masked service is one whose unit file is a symlink to /dev/null. This makes it "impossible" to load the service, even if it is required by another, enabled service.

When you mask a service, a symlink is created from /etc/systemd/system to /dev/null, leaving the original unit file elsewhere untouched. When you unmask a service the symlink is deleted.

However, I have noticed that these commands are not always honoured.

When I try to mask most services, it fails:

$ sudo systemctl mask bluetooth.service
Failed to execute operation: Invalid argument

Of course, I stopped the service first. @Anwar suggests masking is only possible for non-critical services.

Unmasking a masked service, unless I masked it myself, also fails (silently). I believe this is because there is no unit file for the service anywhere, except in the form of a symlink to /dev/null, this time in /lib/systemd/system:

$ file $(locate fuse.service)
/lib/systemd/system/fuse.service: symbolic link to /dev/null
$ sudo systemctl unmask fuse.service
$ systemctl status fuse
● fuse.service
   Loaded: masked (/dev/null; bad)
   Active: inactive (dead)

I'm not the only one having this problem

To actually unmask the masked service x11-common, I had to delete the symlink to /dev/null and sudo apt-get install --reinstall x11-common && sudo systemctl daemon-reload. Now when I query it with systemctl status x11-common I see the service has a nice green circle and is loaded and active (exited) although it has no unit file.

For further reference this article on How to Use Systemctl may be of some use.

Zanna
  • 70,465
  • 1
    Hmm, I get systemctl status x11-common ● x11-common.service Loaded: masked (/dev/null; bad) Active: inactive (dead). Is that bad? But I'm on Debian, not Ubuntu. Anyway, nice explanation. Thank you. – Faheem Mitha Jul 20 '17 at 03:21
  • @FaheemMitha I'm not sure the service is needed - my system seems to work without it. No experience with Debian though, sorry! – Zanna Jul 20 '17 at 04:11
  • after you mask, how do you unmask??? What if you mask somthing that you need for bootup and then cannot bootup because it is masked? How would you unmask that so you can bootup? – Joshua Robison Jan 18 '24 at 06:10
  • @JoshuaRobison Perhaps mask fails silently on most services in order to prevent such problems! – Zanna Jan 18 '24 at 11:55
46

It is pretty simple.

  • systemctl start, systemctl stop: starts (stops) the unit in question immediately;
  • systemctl enable, systemctl disable: marks (unmarks) the unit for autostart at boot time (in a unit-specific manner, described in its [Install] section);
  • systemctl mask, systemctl unmask: disallows (allows) all and any attempts to start the unit in question (either manually or as a dependency of any other unit, including the dependencies of the default boot target). Note that marking for autostart in systemd is implemented by adding an artificial dependency from the default boot target to the unit in question, so "mask" also disallows autostarting.

Ref.: systemctl(1).

More: Lennart Poettering (2011-03-02). "The Three Levels of Off". systemd for Administrators. 0pointer.de.

intelfx
  • 1,178
16

In short,

  • disable makes the unit disabled during boot. But that unit can be started anytime after boot.

  • mask disables the unit completely. It can't be started without unmasking. That automatically implies it will fail during boot.

Anwar
  • 76,649
  • 1
    I am curious - do mask and unmask work for you? (I totally understand if you don't want to test!) – Zanna Aug 25 '16 at 20:43
  • 1
    @Zanna yes. That does work. I've tested before again tested just now. with postgresql@9.5-main.service service. – Anwar Aug 26 '16 at 05:01
  • Hmm I gotta work out why it doesn't work for me. I know I'm not the only one – Zanna Aug 26 '16 at 05:10
  • 1
    May be it works for non-critical services. It's still new I think. btw, your answer was more informative. It was helpful – Anwar Aug 26 '16 at 05:13
  • @Anwar Re: "it will fail during boot". It's true it will not load and is inactive (dead) but a masked service does not block services that depend on it. If it had truly failed, it would block these services. – Andrew Straw Jan 06 '22 at 22:13