Linux – Mount Block Device in LXD

containerslinuxlxcmount

I have been experimenting with LXD on Ubuntu Server 16.04 and i'm trying to figure out how to mount a linux block device from the host in the container. I was able to successfully add the device using the command:

lxc config device add test sdb1 unix-block path=/dev/sdb1

When i attach to the container and run ls /dev/ i can see that sdb1 exists but i am unable to mount it within the container.

I have tried running mount /dev/sdb1 testdir/ but I get the error:
mount: permission denied

Am I setting this up correctly? If so how would I mount inside to container?

Best Answer

the container usually maps its UIDs on top of the hosts UID 100000 (which would map to the UID of the containers "root" user), so I guess you need to make sure this uid is on the host system allowed to mount the block device.

EDIT

perhaps this blog helps you with the problem: http://www.forshee.me/2016/02/22/container-mounts-in-ubuntu-1604.html