- How to allow software access to any USB devices?
- 2 Answers 2
- USB storage devices
- Auto-mounting with udisks
- Manual mounting
- Getting a kernel that supports usb_storage
- Identifying device
- Mounting USB memory
- Allow writing by regular users
- As normal user with fstab
- Mount tools
- Troubleshooting
- No USB storage devices are detected
- Device not shutting down after unmounting all partitions
- Device is detected but does not register as mountable
- How to Manually Mount/UnMount a USB Device on Ubuntu
- How to mount a USB drive on Ubuntu
- How to unmount a USB drive on Ubuntu
- Search
- About This Site
- Latest Tutorials
How to allow software access to any USB devices?
I have a libusb-based program that can’t open USB devices on a freshly installed Ubuntu because it lacks permissions. This solution will probably work for me, but it requires manually specifying each and every device — and I have quite a few. So I tried this (in a file /etc/udev/rules.d/41-cvs-permissions.rules ):
I’ve omitted VID and PID, hoping that it will simply apply the rule to ALL devices. It definitely has some effect, but the effect is rather weird: instead of detecting 5 devices that it can’t open, libusb only detects 2 now — both are USB host controllers, not actual devices. How to achieve what I want?
IMHO udev is frustratingly opaque and poorly documented: I think you may need to use attribute SUBSYSTEMS (plural) rather than SUBSYSTEM (singular). Someone might be able to give a better analysis if you edit your question to include the output of udevadm info —attribute-walk /dev/xxx where /dev/xxx is the actual devpath of your device.
@steeldriver: I don’t see my device having a /dev/ entry, so I don’t know how to invoke udevadm on it. All I have is bus, dev. number, VID and PID as shown by lsusb (and name).
2 Answers 2
The way I deal with USB devices is to give a specific group access to all of them.
echo 'SUBSYSTEM=="usb", MODE="0660", GROUP="plugdev"' > /etc/udev/rules.d/00-usb-permissions.rules udevadm control --reload-rules
Essentially what this does is grant read and write access for any usb device to members of the plugdev group.
Every linux user is a member of at least one, and possibly more groups. So if for instance your username was violetg you could do: sudo usermod -a -G plugdev violetg to add yourself to the plugdev group, which would in turn give you access to usb devices (after logging out and back in again).
I agree that making rule match using VID/PID is not a definite solution. But you can much multiple devices in same rule without targeting blindly all USB devices the way you did. Example using DRIVER name ( usb-storage , usbhid . ) or KERNEL name ( tty* , sd* . ) even using minimal regex ( sd[a-z]5* , usb* ).
You should look for similarities in their attributes.
- Remove all those devices
- Save the current list of devices in /dev
$ colordiff /tmp/dev_list0.txt /tmp/dev_list.txt 85a86,87 > sdc > serial 89a92,93 > sg4 > sg5 93a98 > sr1 194a200,201 > ttyUSB0 > ttyUSB1
udevadm info --attribute-walk --name=/dev/ttyUSB0
Do the same for all devices you want. If you can’t figure out how, please upload their udevadm info —attribute-walk —name=. output and link them to your question.
Note that, not all USB devices create a node in /dev . Some you have look for them in SYSFS tree /sys . Then check their attributes using —path
udevadm info --attribute-walk --path=.
Using same steps as above you can check which device nodes created by monitoring udev events:
USB storage devices
This document describes how to use the popular USB memory sticks with Linux. However, it is also valid for other devices such as digital cameras that act as if they were just a USB storage device.
If you have an up-to-date system with the standard Arch kernel and a modern desktop environment, your device should just show up on your desktop, with no need to open a console.
Auto-mounting with udisks
This is the easiest and most frequently used method. It is used by many desktop environments, but can be used separately too.
See Udisks for detailed information, including list of mount helpers.
Manual mounting
Note: Before you decide that Arch Linux does not mount your USB device, be sure to check all available ports. Some ports might not share the same controller, preventing you from mounting the device.
Getting a kernel that supports usb_storage
If you do not use a custom-made kernel, you are ready to go, for all Arch Linux stock kernels are properly configured. If you do use a custom-made kernel, ensure it is compiled with SCSI-Support, SCSI-Disk-Support and usb_storage. If you use the latest udev, you may just plug your device in and the system will automatically load all necessary kernel modules.
Identifying device
The first thing one needs to access a storage device is its identifier assigned by kernel. See File systems#Identify existing file systems for details.
Newly plugged-in devices are usually shown in the journal.
Mounting USB memory
If mount does not recognize the file system of the device you can try to use the -t argument, see mount(8) for details. If mounting does not work, you can try to recreate the file system or even repartition the disk.
Allow writing by regular users
If you want non-root users to be able to write to the USB stick, you can issue the following command:
# mount -o gid=users,fmask=113,dmask=002 /dev/sda1 /mnt/usbstick
If it does not work, make sure that the file system is mountable and writable as root, see the previous section for details.
As normal user with fstab
See FAT#Writing to FAT32 as normal user if you want normal user to do the mount/unmount action.
Mount tools
Multiple mount tools facilitate mounting as a regular user.
Troubleshooting
No USB storage devices are detected
If you have connected your USB storage device and it is not listed by lsblk but appears in the journal without being assigned a block device, see General troubleshooting#Cannot use some peripherals after kernel upgrade.
Also ensure that your BIOS has both XHCI Handoff and EHCI Handoff enabled, but this is usually not an issue with most modern devices.
Device not shutting down after unmounting all partitions
This article or section needs expansion.
Reason: Please advise how to automatically shut down devices after unmounting (Discuss in Talk:USB storage devices)
Failure to power off a device might result in:
- a hard disk drive not parking its head, making a faint scratching sound while spinning out and degrading the device [2], or
- a solid-state drive (especially older) not flushing its cache buffers or updating its mapping tables, and losing data [3].
When you unmount the partitions, the device is still powered on. You should ask the system to turn it off first in order to safely remove it: [4]
# echo 1 > /sys/block/disk_name/device/delete
If you use udisks, you can use these commands: [5]
$ udisksctl unmount -b /dev/sdXY $ udisksctl power-off -b /dev/sdX
Device is detected but does not register as mountable
udev is shipped with a default set of rules, found in /usr/lib/udev/rules.d/ , including one for ignoring some specific devices for various reasons. Some hardware devices, such as digital cameras, portable recorders, etc., may format usb storage in a way that results in the ignore rules to be triggered. You can check if one of these rules was applied with the following command and then find the corresponding conditions in the defaults:
$ udevadm info --attribute-walk --name=device_name | grep UDISKS_IGNORE
If this is the case and your device has this property set to «1», you can override it with a custom rule, following the udev page.
How to Manually Mount/UnMount a USB Device on Ubuntu
When you connect a USB drive to our system, it is usually mounted automatically and a directory with your user name is created under the media folder. You can also access it through your system’s file manager. Unfortunately, this is not always the case; sometimes, you need to manually mount the USB drive in your system to access it.
In this tutorial, we will explain how to manually mount and unmount a USB drive to your system. The commands and steps described in this article will work on any recent Ubuntu version including Ubuntu 22.04.
How to mount a USB drive on Ubuntu
Let us follow these steps to mount a USB drive manually to your system:
Step1: Plug in the USB drive to an available port.
Step2: Run the following command as sudo in your Terminal application in order to check the available storage devices on your system and the file system they are using:
Your USB device will usually be listed at the end of the output mostly as sdb-(number). In our case it is listed as sdb1, running a FAT32 file system.
Step3: Create a mount point for your USB device through the following command:
$ sudo mkdir /media/[mountPointName]
Note: The name of your mount point can not include spaces; you can seperate the words through an underscore ‘_’.
The mount point will now be created.
Step4: Now we shall mount the USB storage device to the mount point that we created. We will use the following command in order to mount a FAT32 device:
$ sudo mount -t vfat /dev/sdb1 /media/USB -o [securityoption]
The security option is mandatory and allows you to give/gain access to the USB by specifying one of the following values for permission;
In this example, I am giving access control to a user (the current user) by specifying the user id:
For NTFS, use the following command:
$ sudo mount -t ntfs-3g /dev/sdb1 /media/USB
Step5: Your USB has now been mounted. You can access it through your media folder.
You can also access USB through the file manager. In the following image, the 16 GB Volume listed right above Other Locations is my mounted USB storage.
How to unmount a USB drive on Ubuntu
If you have mounted a USB manually, it is best to even unmount it manually.
Step1: Use the following command in order to unmount your USB:
In the above command, specify the mount point if it is something other than the ‘USB’ mount point I have used.
Your USB will be unmounted from your system:
Step2: You will need to remove the USB mount point directory manually as follows if you don’t plan to reuse it in the future:
Step3: Unplug the USB from your system.
After following the steps described in this article, you will be successfully able to mount and unmount a USB storage device to and from your system. This will help you if your system fails to automatically make the USB available for access and use.
Search
About This Site
Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.