Linux – Mount point for specific USB port

linuxmountusb

I have a USB hub connected to my laptop, always through the same port – my question is how can I make my linux installation always mount whatever is plugged into one of the specific ports on this hub be mounted to (e.g) /mount/left and likewise for the other port.

I know how I can do this for specific drives with the UUID of the drive, but I want it to be that case that /mount/left always refer to whatever is in the left port, whichever order different USB devices are plugged in.

Best Answer

I know this is an old thread, but I came across it while looking to do the same thing, and found a solution using fstab, see below:

First, plug in a drive to the port you want to map a mountpoint to. Use sudo blkid to get the /dev/sd** path to the drive & note this down/remember it. I'll be using '/dev/sda1'

Second, use udevadm info --name=/dev/sda1 | grep disk/by-path, which should give you a readout something like:

S: disk/by-path/platform-20980000.usb-usb-0:1.3:1.0-scsi-0:0:0:0-part1
E: DEVLINKS=/dev/disk/by-id/usb-SanDisk_Cruzer_Switch_4C530001110415101044-0:0-part1 /dev/disk/by-label/BACKUP_1 /dev/disk/by-path/platform-20980000.usb-usb-0:1.3:1.0-scsi-0:0:0:0-part1 /dev/disk/by-uuid/5936-F7EA

It's the platform-20980000.usb-usb-0:1.3:1.0-scsi-0:0:0:0-part1 that we want. It might look fairly different depending on your device & hub. Copy it/note it down then open up fstab config sudo nano /etc/fstab and on a new line:

/dev/disk/by-path/platform-20980000.usb-usb-0:1.4:1.0-scsi-0:0:0:0-part1 /media/card exfat auto,nofail,noatime,users,rw,uid=pi,gid=pi 0 0

replace /media/card with the mountpoint you desire, and make sure the bit following /dev/disk/by-path/ matches what you copied earlier. The other options are variable depending on what you want.

Ctrl-X, Y, enter, to save fstab, then reboot and you should now have an auto-mounting usb port! You can repeat the previous steps for each port :)

Related Question