Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 6070  / 2 Years ago, tue, october 25, 2022, 3:16:29

Here is my issue:



My computer has 4 USB ports and is running Ubuntu 12.10. I receive different USBs every day, plug to my computer, read/write data to them, and then send them away.



What I want is to automatically mount any USB I plug into my computer. The first detected USB will go to /media/HDD1, the second will go to /media/HDD2 and so on.
Or it would be great if USB plugged to port1 will go to /media/HDD1, USB plugged to port2 will go to /media/HDD2, and so on.



The path /media is not important but I would like the HDD1-4 directories in one place so that I can easily access them.



The USBs are normally ext2 but sometimes I get FAT32, NTFS USBs as well.



I also want USB to be mounted without logging in to Ubuntu as I often access /media/HDD.. from another Windows computer.



How can I do that? What change in udev rules, fstab should I make? Any suggestion is highly appreciated.


More From » mount

 Answers
3

Well, here we can use the same trick that fstab uses for Optical media (aka CD's and DVD's):



/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0


The first column indicates the file system, I'm sure your USB's will have fixed values, so lets presume that everything after sda is a USB, and since you can only have 4 USB's at the same time, the list goes from sdb, sdc, sdd and sde.



$ ls /dev/sd*
/dev/sda /dev/sdb /dev/sdb3 /dev/sdb6 /dev/sdc /dev/sdf
/dev/sda1 /dev/sdb1 /dev/sdb4 /dev/sdb7 /dev/sdd
/dev/sda2 /dev/sdb2 /dev/sdb5 /dev/sdb8 /dev/sde


(In my case I use a memory reader, so my USB drivers start from sdg but lets continue.)



Now, we assume each USB have one and only one partition, so the lines we need, for our fstab, are:



/dev/sdb1
/dev/sdc1
/dev/sdd1
/dev/sde1


Then you said your mount points has to be fixed, so after you have created your directories, lets add them:



/dev/sdb1 /media/HDD1
/dev/sdc1 /media/HDD2
/dev/sdd1 /media/HDD3
/dev/sde1 /media/HDD4


Since you can have almost all type of file systems, lets use the auto so fstab guess the file type to use:



/dev/sdb1 /media/HDD1 auto
/dev/sdc1 /media/HDD2 auto
/dev/sdd1 /media/HDD3 auto
/dev/sde1 /media/HDD4 auto


Ok, now lets boil down to the options, which will be the very same for CD's with the plus of read/write permissions:



/dev/sdb1 /media/HDD1 auto rw,users,noauto,allow_other,umask=0
/dev/sdc1 /media/HDD2 auto rw,users,noauto,allow_other,umask=0
/dev/sde1 /media/HDD3 auto rw,users,noauto,allow_other,umask=0
/dev/sde1 /media/HDD4 auto rw,users,noauto,allow_other,umask=0


rw tells that we want read and write permission, users allows any user to mount a device, noauto prevents that the driver gets mounted automatically when mount -a is called, like it does at boot, preventing boot ERRORS and WARNINGS, allow_other allows other but the user that mounted the driver to have the same permissions, and umask=0 prevents the defaults umask from being applied.



Now the only 2 left fields are pretty much just about the dump order and fsck order, which could be in 0 both, leaving us with the final result:



/dev/sdb1 /media/HDD1 auto rw,user,noauto,allow_other 0 0
/dev/sdc1 /media/HDD2 auto rw,user,noauto,allow_other 0 0
/dev/sdd1 /media/HDD3 auto rw,user,noauto,allow_other 0 0
/dev/sde1 /media/HDD4 auto rw,user,noauto,allow_other 0 0


With this, each time that you plug a USB device it will being automagically mounted in the mount point without the intervention of the user. You should modify according to your necessities.


[#32308] Tuesday, October 25, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lowstonnequ

Total Points: 279
Total Questions: 125
Total Answers: 123

Location: Finland
Member since Sun, Dec 5, 2021
2 Years ago
lowstonnequ questions
Wed, Oct 26, 22, 14:40, 2 Years ago
Tue, Feb 28, 23, 01:39, 1 Year ago
Wed, Dec 1, 21, 23:44, 2 Years ago
Thu, Apr 21, 22, 13:13, 2 Years ago
;