Recommended way to define a bind mount

Does /etc/config/fstab allow for bind mounts? I am mounting a partition defined in /etc/config/fstab currently and would like to define a 2nd mount point from a directory under it to another on my filesystem. I did not see how I could define a mount by a directory, it seems to want only a UUID.

config mount
	option uuid 'xxx'
	option enabled '1'
	option target '/mnt/mmcblk0p3'

In /etc/rc.local I think it is as simple as:

if [ mountpoint -q /mnt/mmcblk0p3 ]; then
  mount -o bind /mnt/mmcblk0p3/lxc /srv/lxc
fi

Looks like block doesn't support bind mounts.
You can also use symlinks or block hotplug.

config mount
	option device '/dev/mmcblk0p3'
	option enabled '1'
	option target '/srv/lxc'

a device mount will work, but not sure a bind will !

I guess using the code in my /etc/rc.local is what I need for the bind... it is odd to me that the code actually works because /etc/rc.local gets run AFTER everything else in the init process as I understand it. If that is true, I do not understand how my LXC is able to start since it is getting called by /etc/init.d/lxc-auto which should start before the filesystem is mounted, no? Must be some race condition allowing it to work just by chance where the /etc/rc.local mounts the bind mount before lxc-auto starts the container. Is that right?

@hnyman ?

Note that the init system is partially asynchronous. The START priority order just specifies the order where each service is started, but there is no guarantee that all earlier services have completed their init process before the next ones are started.

rc.local run with priority 95 by "/etc/init.d/done". It is currently not quite last, and sadly several services compete trying to "be the last".
LXC is apparently one of those: START 99 :frowning:

1 Like

Why don't you use a symlink?

2 Likes

I could use a symlink I think unless something in lxc requires a mount. Since my /etc/rc.local stuff is working, I will just stick with it.

You can mount inside lxc (kmod for openwrt may be required to be installed like for nfs), or use a bind in lxc config (an exemple from one of my own lxc file config)

lxc.mount.entry = /srv/SHARE /srv/lxc/myDMX/rootfs/mnt/SHARE none bind,create=dir 0 0

just had to create /srv/lxc/myDMX/rootfs/mnt/SHARE before lxc-start !

Thanks @erdoukki. I knew about bind mounts in the LXC. I should just simplify my setup and just use /mnt/mmcblk0p3/lxc/ in my config and not even mess with the bind mount.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.