0

I have a server running on ubuntu 20.04 and I am using usbmount to mount external drives on following mountpoints:

/home/bric/usb0
/home/bric/usb1 
/home/bric/usb2 
/home/bric/usb3       
/home/bric/usb4
...

Sometimes, when I reboot, drives are monted on a different point than before and I was just wondering if it was possible to setup a rule so that each drive could only be mounted on a single point for instance following disk:

$ sudo fdisk -l

Disk /dev/sdb: 465,78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: 2115            
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd31fd8de

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdb1        2048 976773119 976771072 465,8G  c W95 FAT32 (LBA)

always mounted on the following point:

$ df -h
/dev/sdb1       466G  337G  129G  73% /home/bric/usb0

I have not found post or documentation about this topic.

/etc/usbmount/usbmount.conf

MOUNTPOINTS="/home/bric/usb0 /home/bric/usb1 /home/bric/usb2 /home/bric/usb3
             /home/bric/usb4 /home/bric/usb5 /home/bric/usb6 /home/bric/usb7"
FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus ntfs"
MOUNTOPTIONS="sync,noexec,nodev,noatime,nodiratime,umask=0"
FS_MOUNTOPTIONS=""
VERBOSE=yes

1 Answer 1

0

So I found a solution avoiding using usbmount, the idea is to identify each drive by drive label and then mounting it to the desired mounting point:

#!/bin/bash

# mount disk 0 on usb0
volume_label="DISK"
mounting_point="usb0"
volume=$(lsblk -lo NAME,LABEL | grep "$volume_label" | tr -d "  $volume_label")
echo **** | sudo -S mount -t vfat /dev/$volume /home/bric/$mounting_point -o uid=1000

This script is triggered at startup with a systemctl .service

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .