
So Whilst working on LXC containers in proxmox I have needed to mount different hardware every now and then, eg the need to pass through physical devices. So in order to do this you would need to know a thing or two about how linux mounts hardware in the first place.
Things to note
- Identify Major and Minor Device Numbers using
ls -la- ls -la: in the output of the ls -la command you get have the Major and Minor versions
- Identify SCSI Devices or Disk Devices using
lsscsi -gorlsusb - Update lxc Container config eg:
/etc/pve/lxc/1XX.conf
shell> ls -la
brw-rw---- 1 root disk 8, 0 Oct 14 13:26 /dev/sda
The 8, 0 represent the major and minor device numbers of /dev/sda. These numbers are crucial in the Linux device management subsystem.
The first number identifies the driver associated with the device. For example, all SCSI hard drives are associated with the major number 8, so /dev/sda, /dev/sdb, /dev/sdc, etc., will all have 8 as their major number. This tells the kernel which driver is responsible for managing this device.
The second number identifies a specific instance of a device managed by a driver. For SCSI hard drives, the minor number determines the particular drive. So:
/dev/sda has a minor number of 0
/dev/sdb has a minor number of 1
/dev/sdc has a minor number of 2
... and so on.
These major and minor numbers are important when manually working with device files, especially when creating them or setting up permissions, and are important when doing passthrough setups as they grant the correct access by identifying the correct device.
Mounting a Regular Disk
So I have connected a usb harddrive, and have identified the disk on the Proxmox host as /dev/sda and with lsscsi -g, it shows up as /dev/sda /dev/sg0.
Then modifying the container’s configuration (e.g.,
/etc/pve/lxc/101.conf) to grant access to both/dev/sdaand/dev/sg0:lxc.cgroup2.devices.allow: b 8:0 rwm lxc.cgroup2.devices.allow: c 21:0 rwm lxc.mount.entry: /dev/sda dev/sda none bind,optional,create=file lxc.mount.entry: /dev/sg0 dev/sg0 none bind,optional,create=fileNote: the target, eg the path within the lxc begins without a slash! it is
devnot/devOptionally one can add a mount entry so it is automounted when the lxc container starts:
mp0: /dev/sda,mp=/mnt/mydiskNow just restart the container:
pct stop 101 pct start 101
Mounting a Blu-ray Drive
So we have mounted a disk, but what about a Bluray player?
Using lsscsi -g and lsusb, I can identify the Blu-ray drive and its associated USB device:
[2:0:0:0] cd/dvd Bluray XXX-XXXX-U E101 /dev/sr0 /dev/sg1
Bus 002 Device 003: ID 0411:55aa Bluray External Drive
For the Bluray Blu-ray drive, the LXC config (/etc/pve/lxc/101.conf) entries would be:
lxc.cgroup2.devices.allow: c 189:130 rwm
lxc.cgroup2.devices.allow: c 11:0 rwm
lxc.cgroup2.devices.allow: c 21:1 rwm
lxc.mount.entry: /dev/sr0 dev/sr0 none bind,optional,create=file
lxc.mount.entry: /dev/sg1 dev/sg1 none bind,optional,create=file
lxc.mount.entry: /dev/bus/usb/002/003 dev/bus/usb/002/003 none bind,optional,create=file
lxc.cgroup2 entries control which devices the container has permission to access. The format is:
[b|c] major:minor rwmbdenotes block devices like hard drives.cdenotes character devices like USB devices.rwmdenotes to read/write/mount./dev/sr0and/dev/sg1represent SCSI devices./dev/bus/usb/002/003is the USB bus and device ID for the Blu-ray drive.
The lxc.mount.entry lines denote which devices should be mounted to the container’s filesystem and how.
- bind means we’re attaching a specific device/file from the host to the container.
- optional ensures the container starts even if the device isn’t present.
- create=file or create=dir tells LXC to create the respective file or directory if it doesn’t exist.
Differences between /dev/sr0, /dev/sg1, and the USB device ID:
/dev/sr0: Represents the SCSI CD/DVD-ROM devices. It’s essential for reading/writing data to/from the Blu-ray drive./dev/sg1: Generic SCSI devices. They provide a way to send generic SCSI commands to a device.- USB Bus and Device ID (
/dev/bus/usb/002/003): Represents the USB connection of the device. It’s essential for direct USB interactions and utilities that rely on USB specifics.
Here’s a breakdown of the entries:
In many scenarios, only the /dev/sr0 node is required for basic CD/DVD operations (e.g., reading a disc, burning data). However, certain advanced utilities, especially ones related to Blu-ray functionality, might require access to the raw SCSI device (/dev/sg1) or even the USB device node as seen in my example above.
If you’re only performing basic operations, and you don’t have any utilities that interface with the drive at a USB level, then you might be able to omit the /dev/bus/usb/002/003 entry.
Buy Me a Coffee