Live USB mount without restart


#1

Hi,
I’d like to be able to mount USB drives inside a container (using LXC and not LXD) from the host without having to restart it. I’m currently using udev rules to do some processing on it but would like to gain some time on startup of a daemon I have inside the container.

I’m currently sharing a folder between my host and LXC and mount the drive on it when inserting it but can’t see the content without restarting it. Sorry if the topic has already been answered, I haven’t found what I’m looking for.

I’m currently using LXC 2.0.9.


(Stéphane Graber) #2

To have that mount propagate to the container, you’d need the path on the host to be marked as MS_SHARED.

Something like this should work, this assumes that /mnt in this case is shared with your container:

mount -o bind /mnt /mnt
mount --make-rshared /mnt
lxc-start -n your-container
mkdir /mnt/blah
mount /dev/sdX2 /mnt/blah

In this case, that blah directory and mount should propagate to the container thanks to the bind-mount and rshared flag.


#3

That’s exactly what I needed !

Merci pour la réponse rapide.