-1

Here I created a lxc container in the host operating system, Ubuntu 22.04, whose os is the same as the host's, on a Raspberry Pi.

I want to access(r/w) files of a usb disk in the lxc container so I try to mount the device into the container following the tutorials found in the internet including some answers of questions in Stackoverflow. Sadly, all of them failed.

Here are the datails.

This is the usb device:

Bus 001 Device 007: ID 14cd:1212 Super Top microSD card reader (SY-T18)

I have mounted it into the host system.

As what those tutorials say, I add two sentences into the config of the instance of the lxc container as follows:

lxc.cgroup.devices.allow = c 189:* rwm
lxc.mount.entry = /dev/bus/usb/001/007 dev/bus/usb/001/007 none bind,optional,create=dir

And this is the whole config

lxc.rootfs.path = dir:/dockers/regular/rootfs
lxc.uts.name = regular
lxc.arch = armhf

# Network configuration
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:61:b2:40


lxc.cgroup.devices.allow = c 189:* rwm

lxc.mount.entry = /dev/bus/usb/001/007 dev/bus/usb/001/007 none bind,optional,create=dir

Then I start the container and check out /dev, there is a directory /dev/bus/usb/001/007 (there's no such dir before I edit the config).

However, in the lxc container I couldn't find the usb device in /dev and it failed when I tried to mount the usb device via its name (like sda1) or UIID.

It means the config editing worked that I can find the /dev/bus/usb/001/007 in the container. But still I can't access the usb device.

Bella Wang
  • 39
  • 3

1 Answers1

0

You issue could be easily related to the lxc.mount.entry line you are using:

lxc.mount.entry = /dev/bus/usb/001/007 dev/bus/usb/001/007 none bind,optional,create=dir

Replacing create=dir by create=file should actually solve your issues. In addition, make sure that the /dev/bus/usb/001/007 device node on your lxc host has all the necessary rw permissions by potentially doing a

chmod a+rw /dev/bus/usb/001/007

before starting up your lxc container.

Jens Maus
  • 21
  • 1
  • 3