I had a requirement to boot a USB disk (a Hitachi SimpleDrive) on a machine I rarely log into via the GUI. In the good old days, I’d hack up a udev script to do it.
In Fedora, with the advent of systemd, I googled and quickly became horribly confused about how it should work.
I found some stuff about systemd and automount, but the idea of a system.automount unit file scared me and I *really* didn’t want to have to learn too much more about systemd, just in order to mount a disk (I guess I’m putting off the inevitable since, professionally, I support Oracle Linux and I imagine it will eventually start to use systemd).
I found the man page for systemd.mount(5) and read:
Mount units may either be configured via unit files, or via /etc/fstab
(see fstab(5) for details).
When reading /etc/fstab a few special mount options are understood by
systemd which influence how dependencies are created for mount points
from /etc/fstab. If comment=systemd.mount is specified as mount option,
then systemd will create a dependency of type Wants from either
local-fs.target or remote-fs.target, depending whether the file system
is local or remote. If comment=systemd.automount is set, an automount
unit will be created for the file system. See systemd.automount(5) for
I obviously hadn’t drunk enough coffee, so I couldn’t seem to grok this, and had to read http://0pointer.de/blog/projects/blame-game.html:
Well, systemd possesses magic powers, in form of the comment=systemd.automount mount option in /etc/fstab. If you specify it, systemd will create an automount point at /home and when at the time of the first access to the file system it still isn’t backed by a proper file system systemd will wait for the device, fsck and mount it.
UUID=d0e1f72d-c56e-4239-ae79-277af99ada7a /simpledrive ext4 defaults,comment=systemd.automount 1 2
On reboot, I got dumped to a systemd console, and I thought maybe it was because the volume was being mounted before it was ready, so I added noauto, to let systemd pick it up later:
UUID=d0e1f72d-c56e-4239-ae79-277af99ada7a /simpledrive ext4 noauto,defaults,comment=systemd.automount 1 2
Still failed, but this time I got to see an error, and ran:
# systemctl status automount.simpledrive
and it told me something about a resource. I figured out I’d misunderstood this line by Lennart:
If you specify it, systemd will create an automount point
and that I needed to manually create /simpledrive:
# mkdir /simpledrive
# systemctl status simpledrive.automount
Active: active (running) since Mon, 03 Dec 2012 10:25:00 +0000; 1h 51min ago
and on reboot, the drive is mounted:
systemd-1 on /simpledrive type autofs (rw,relatime,fd=44,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
/dev/sdd1 on /simpledrive type ext4 (rw,relatime,data=ordered)