Unmount or refuse unwanted USB drives

This is a bit of a tricky one, as evidenced by the lack of replies.

There are many ways to skin this particular cat, but I think the simplest and most practical method for you is to disable the udisks-glue service and create specific fstab entries for each of your “authorised” USB devices.

First, to find the identifier (UUID) of devices you wish to authorise, type blkid. Here’s an example:

osmc@osmc:~$ blkid
/dev/mmcblk0p1: UUID="7A51-069A" TYPE="vfat" PARTUUID="6244dd12-01"
/dev/mmcblk0p2: UUID="5f623acd-7038-4bbd-9c7b-acf4705bc07d" TYPE="ext4" PARTUUID="6244dd12-02"
/dev/sda1: UUID="2C36-5545" TYPE="vfat"
/dev/sdb1: LABEL="29GB" UUID="270039e3-b846-4e38-aeda-544e23c1090b" TYPE="ext4" PARTUUID="01217391-01"
/dev/mmcblk0: PTUUID="6244dd12" PTTYPE="dos"

In this case, I have two external USB devices: /dev/sda1 and /dev/sdb1, with UUIDs of 2C36-5545 and 270039e3-b846-4e38-aeda-544e23c1090b, respectively. Also make note of the TYPEs, since you’ll need these later.

To disable the udisks-glue service, type:

sudo systemctl disable udisks-glue.service

You’ll now need to create a separate mount point for each authorised device. The names are for you to choose but they should ideally be created under /mnt and be meaningful in some way. In this example, UUID 2C36-5545 will go to /mnt/videos and UUID 270039e3-b846-4e38-aeda-544e23c1090b to /mnt/music. So:

sudo mkdir /mnt/videos
sudo mkdir /mnt/music

Now edit /etc/fstab and add two lines:

UUID=2C36-5545 /mnt/videos vfat defaults,noatime,nofail 0 0
UUID=270039e3-b846-4e38-aeda-544e23c1090b /mnt/music ext4 defaults,noatime,nofail 0 0

You’ll see that I’ve used the TYPEs from the blkid command here (vfat and ext4).

If you now reboot OSMC, any “authorised” device that’s plugged in should be automatically mounted. If you later plug in a drive while OSMC is running, you can mount it with:

sudo mount /mnt/music or sudo mount /mnt/video

As long as nobody else has access to the osmc userid, other USB drives shouldn’t be usable on the box. Of course, there might be some unforeseen complications with this method that I haven’t thought of. :wink: Good luck!

Edit: Updated, after @grahamh’s suggestions.

2 Likes