Skip to main content

Avoid systemd's emergency mode on mount failure

·226 words·2 mins

My NAS runs NixOS. All its configuration is controlled via a declarative system. This includes mount points.

After creating a new file system and mounting it, I typically run nixos-generate-config. This creates a file that captures all hardware related aspects of the system, including which filesystems are mounted and where. This is then used to generate /etc/fstab.

Unfortunately, nixos-generate-config can be a bit overeager at times. Like when it captures transient mounts created by docker. Come the next reboot, these mounts no longer work and the system enters an emergency mode. On my system, the root account is apparently locked (could very well be, but that sure wasn’t a concious decision). This means I cannot activate the emergency console… Tough luck!

This had not happened for a long time, but today it bit me once again. I knew I could force systemd to continue booting but how exactly had faded to the back of my mind. A quick visit to Google later, I discovered that systemd services and targets can be masked via the kernel command line. So, for a future me, or you, if ever you get locked out of your system because systemd wants to enter emergency mode, simply mask the emergency service and target like by adding the following options to your kernel command line:

  2. systemd.mask=emergency.service

And then go fix your fstab!