How can I automatically mount any USB flash drive on the same mount point?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I automatically mount any USB flash drive on the same mount point?
Hi,
In my case, I have a computer with several users, and it's possible that some of the participants will use their own USB keys to work on the machine in question.
How can I make sure that once the USB stick is plugged in, it's available in rw on all users, and that it doesn't mount in the current user's directory?
I've seen that it's possible to assign rules in the fstab configuration, but this requires (as far as I know) entering the corresponding UUID of the USB key, which isn't possible in my case as it's never the same keys.
To put it simply, I'd like it to work like Windows: when a USB key is plugged in, it's available to all users.
Find out what the kernel calls the usb drive by plugging it in and running
Code:
dmesg|tail -10
It's /dev/sdb on most setups, but not always. I once had a printer with a built-in disk drive and my kernel registered that as /dev/sdb and usb keys as /dev/sdc.
Whatever drive designation the kernel uses, use that in /etc/fstab. You don't have to use UUIDs.
The Linux systems I've used generally mount external devices under /media or /run directories not the user /home directory. If I understand your post, there will be several users on this computer and they will likely use their own usb sticks (multiple) and you want all of them to have total access to any usb to write to and/or delete anything on the usb, is that correct? If you give users write permissions, you give them permission to delete. What filesystem type would you expect to be on them? Would this be expected to vary? If you expect windows filesystems, the method will be a bit different.
Find out what the kernel calls the usb drive by plugging it in and running
Code:
dmesg|tail -10
It's /dev/sdb on most setups, but not always. I once had a printer with a built-in disk drive and my kernel registered that as /dev/sdb and usb keys as /dev/sdc.
Whatever drive designation the kernel uses, use that in /etc/fstab. You don't have to use UUIDs.
Hi,
Yes, it's /dev/sdb in my case too, Would you have an example of configuration for the file? Should I put something like /dev/sdbXX or maybe /dev/sdb* so that any plug-in key works?
Yes, it's /dev/sdb in my case too, Would you have an example of configuration for the file? Should I put something like /dev/sdbXX or maybe /dev/sdb* so that any plug-in key works?
Here is a line from my fstab:
Code:
/dev/sdb1 /media/usb vfat user,noauto 0 0
"user" means that anyone can mount a device but only the same person can unmount it. "noauto" prevents the startup scripts from trying to automatically mount a plugin device that isn't there.
I don't know if you can allow for different partitioning models. When you buy a memory stick, it typically has a single partition formatted as vfat because it's designed for Windows users. They probably wouldn't repartition the drive but a Linux user might.
The Linux systems I've used generally mount external devices under /media or /run directories not the user /home directory. If I understand your post, there will be several users on this computer and they will likely use their own usb sticks (multiple) and you want all of them to have total access to any usb to write to and/or delete anything on the usb, is that correct? If you give users write permissions, you give them permission to delete. What filesystem type would you expect to be on them? Would this be expected to vary? If you expect windows filesystems, the method will be a bit different.
Hi,
Yes, that's right, I'd like them to have full access. In my case, it's in the /etc/currentuser directory. When I connect to another user, since the key was mounted in the first user's directory, I don't have access rights. With the number of USB keys that will be plugged into this computer, it's impossible to make a specific configuration per key. I think the file system will be NTFS, FAT32 or ext4.
"user" means that anyone can mount a device but only the same person can unmount it. "noauto" prevents the startup scripts from trying to automatically mount a plugin device that isn't there.
I don't know if you can allow for different partitioning models. When you buy a memory stick, it typically has a single partition formatted as vfat because it's designed for Windows users. They probably wouldn't repartition the drive but a Linux user might.
Note that for most usb devices there will be no partitioning done at the time purchased and they usually will be formatted as vfat. That means most devices would be seen as /dev/sdb and not /dev/sdb1 for mounting.
Also, if there is more than one device plugged in at a time they would get in sequence differing names such as sdb for the first one, sdc for the next, etc. Each would need its own mount point as well as accounting for the differing device names.
If you used the same mount point for all then only the last one mounted would be accessible as it would be mounted 'over' the previous one and the earlier one would no longer be accessible. That is a recipe for data disaster if files were open on one device then another is mounted and blocks access to the first.
I do have a few older flash drives that do not have a partition but I would say in general that most do.
Typically how they are formatted just depends on the manufacture and sometimes by size i.e. <32GB either FAT32 or exFAT and >32GB NTFS or maybe exFAT.
What distribution / version is running on this system?
Since how permissions work are different between Windows, flash drives are typically automatically mounted with read/write only for that user that is currently logged in. A custom udev rule might be necessary to mount a flash drive for access by all users.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.