Ubuntu – the difference between “systemctl mask” and “systemctl disable”

bootplymouthsystemd

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.

Best Answer

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.