Automount block device inside container / fstab not working

Hi,

I have a ZVOL created on the host and partitioned so that I end up with /dev/zd0p1 which I’ve then formatted with ext4 . I have exported this to a container with:

lxc config device add spike-test1 testvol unix-block path=/dev/zd0p1

this works fine and on the container I can mount /dev/zd0p1 and write to it no problem.

However I cannot get it to mount when the container is started, even if I put it in /etc/fstab it won’t automatically mount (it uses defaults option so it implies auto and mount at boot).

what am I missing? both host and container are ubuntu 16.04, lxd 2.16.

thanks,

Spike

Pretty sure that’s a known systemd issue…

https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1713086

yep, that looks like it. will try to find a manual workaround in the meantime, maybe systemd can be forced to do the mounts or something.

fwiw I solved the problem by creating a systemd mount file for my device. The core issue seems to be with systemd-fstab-generator which is in charge of creating necessary mount unit files from fstab and is not working.

In my case I added the following to /etc/systemd/system/nethomes.mount:

[Unit]
Description=Mount NetHomes ZVOL

[Mount]
What=/dev/zd0p1
Where=/nethomes
Type=ext4
Options=defaults,usrquota

[Install]
WantedBy=multi-user.target

I then enabled it with systemctl enable nethomes.mount and after restarting the container the zvol was correctly mounted. Please note, the filename must match your mountpoint to work.

I referred to these two links to figure out systemd stuff (I’m completely new to it):

hope this helps somebody until the bug is fixed