Dear Toradex,
how can I list USB-connected mass storage devices within a Docker container, which were connected AFTER the container has been started?
Hardware and OS information:
I have a Verdin iMX8MP Q 4GB WB IT V1.1A embedded board together with Verdin Development Board V1.1E. The OS, which runs on the board is:
Linux 5.15.77-6.2.0+git.aa0ff7e3554e #1-TorizonCore SMP PREEMPT
If I plug-in a USB mass storage device to the base board, it gets automatically properly mounted into the file system into /media folder. If I unplug it, it gets unmounted.
The application we’re developing runs inside a Docker container. The OS inside the container is the same OS:
Linux 5.15.77-6.2.0+git.aa0ff7e3554e #1-TorizonCore SMP PREEMPT
Detailed description of the problem:
To list mass storage devices connected over USB port I use:
lsblk -p
This works great for those USB mass storage devices, which were connected to the base board at the time the contianer started. Here’s an output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS /dev/sda 8:0 1 1.9G 0 disk └─/dev/sda1 8:1 1 1.9G 0 part /mnt/USB DISK /dev/sdb 8:16 1 3.7G 0 disk └─/dev/sdb1 8:17 1 3.7G 0 part /mnt/UDISK /dev/mmcblk2 179:0 0 29.1G 0 disk └─/dev/mmcblk2p1 179:1 0 29.1G 0 part /etc/hosts /etc/hostname /etc/resolv.conf /mnt /dev/mmcblk2boot0 179:32 0 4M 1 disk /dev/mmcblk2boot1 179:64 0 4M 1 disk /dev/mmcblk1 179:96 0 1.8G 0 disk └─/dev/mmcblk1p1 179:97 0 1.8G 0 part /mnt/MT86PLUS /dev/zram0 253:0 0 0B 0 disk
Once I disconnect one USB mass storage device, the output looks like this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS /dev/sdb 8:16 1 3.7G 0 disk └─/dev/sdb1 8:17 1 3.7G 0 part /mnt/UDISK /dev/mmcblk2 179:0 0 29.1G 0 disk └─/dev/mmcblk2p1 179:1 0 29.1G 0 part /etc/hosts /etc/hostname /etc/resolv.conf /mnt /dev/mmcblk2boot0 179:32 0 4M 1 disk /dev/mmcblk2boot1 179:64 0 4M 1 disk /dev/mmcblk1 179:96 0 1.8G 0 disk └─/dev/mmcblk1p1 179:97 0 1.8G 0 part /mnt/MT86PLUS /dev/zram0 253:0 0 0B 0 disk
This is expected, the USB disk (/dev/sda) disappeared from the list.
Once I connect it back again, the output looks like this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS /dev/sda 8:0 1 1.9G 0 disk └─/dev/sda1 8:1 1 1.9G 0 part /dev/sdb 8:16 1 3.7G 0 disk └─/dev/sdb1 8:17 1 3.7G 0 part /mnt/UDISK /dev/mmcblk2 179:0 0 29.1G 0 disk └─/dev/mmcblk2p1 179:1 0 29.1G 0 part /etc/hosts /etc/hostname /etc/resolv.conf /mnt /dev/mmcblk2boot0 179:32 0 4M 1 disk /dev/mmcblk2boot1 179:64 0 4M 1 disk /dev/mmcblk1 179:96 0 1.8G 0 disk └─/dev/mmcblk1p1 179:97 0 1.8G 0 part /mnt/MT86PLUS /dev/zram0 253:0 0 0B 0 disk
The /dev/sda
(as well as /dev/sda1
) appear in the list again, however MOUNTPOINTS column is blank.
Funny fact is, that the mass storage device is actually mounted, because a folder does appear for it in /mnt
folder and I can browse it.
Note, that in the host operating system the lsblk
works as expected. That is, no matter how many times I connect/disconnect USB mass storage devices, lsblk
produces expected output.
What do I need it for?
I am writing a .NET 8.0 application, which will support data export functionality. If the user wants to perform data export, the application must list USB-connected mass storage devices and offer the user the one, where the data export will be stored.
In .NET I can use GetDrives()
method of System.IO.DriveInfo
class, however that method, too, seems to return only those “drives”, which were mounted at the time container started. The moment I disconnect a USB stick and re-connect it again, it won’t be returned in GetDrives()
method. I’m assuming, this is related to the information returned by lsblk -p
.
This forum post seemed relevant to the problem: Torizon Docker Container USB automount, but it did not help. I added these extra torizon packages to my container:
"usbview", "usbutils", "autofs", "udisks2", "systemd", "udiskie"
but it did not help.
- Is there a way to “fix” the output from
lsblk
? - Is there a different way to retrieve the list of currently mounted USB mass storage devices?
- I obviously do not want to do it by listing the content of
/mnt
folder. Besides the primary reason, which is, that it is not a way to do it, we want to give the user some more information about currently attached USB mass storage devices (such as the amount of free space).
- I obviously do not want to do it by listing the content of
- Are there maybe further Debian packages, which I should include for the container, that could fix the problem or provide me with the functionality I’m looking for?
- For exampe, I was experimenting with output from
lsusb
, giving it different command line arguments, but it does not produce output I’m looking for.
- For exampe, I was experimenting with output from
Thank you!
Best regards
Vladimir Gregor
Bee Mobile company