Mount block device on boot using systemd in coreos

bootcoreosmountsystemd

I am mounting /dev/vdb1 to /media/esdata using the following systemd unit:

The unit is located at /etc/systemd/system/media-esdata.mount:

[Unit]
Description=Mount cinder volume
Before=docker.service
[Mount]
What=/dev/vdb1
Where=/media/esdata
Options=defaults,noatime,noexec

but this does not get started on reboot. I cannot seem to enable this unit either:

$ sudo systemctl enable media-esdata.mount
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).

What can I do to always have /media/esdata available?

Best Answer

You can add [Install] field in the media-esdata.mount, systemctl enable will create the link for you:

[Unit]
Description=Mount cinder volume
Before=docker.service

[Mount]
What=/dev/vdb1
Where=/media/esdata
Options=defaults,noatime,noexec

[Install]
WantedBy=docker.service

When enabling the mount unit, you should see the following message:

$ sudo systemctl enable media-esdata.mount
Created symlink /etc/systemd/system/docer.service.wants/media-esdata.mount → /etc/systemd/system/media-esdata.mount.
Related Topic