How to automount to a generic path (usb0, usb1 etc)

Main question
I am managing RPI2 and Cubox’s for family and friends and try to keep every setup as generic as possible.
I used XBian but I am switching over to OSMC. With Xbian, a USB harddrive will be available via /media/usb0 regardless of the label of the drive. This is perfect because every house has all of its media for Kodi and SyncThing in the same path (/media/usb0) regardless of the drive label.

I know I can edit fstab and mount drives by their UUID, but the whole purpose is not to have to do that for every setup in every house, while still having the same path to all media for everyone.

Is there a way to simply add a symlink or mountpoint automatically for each mounted drive? usb0, usb1 (if a second drive is attached) etc.
I found /etc/udisks-glue.conf contains the configuration of automounting drives, but I am afraid to edit it and not sure what to edit.

2nd question
I am wondering how OSMC mounts NTFS drives. I used to use fstab to have better performance by mounting it like this: UUID=643C03443C0310AA /media/usb0 ntfs-3g defaults,noatime,nodiratime,async,big_writes 0 0

Especially async helps a lot. Before I remove a drive, I simply unmount it via Kodi>Files context menu.
Does OSMC mount NTFS drives like this as well? There are no arguments in the /etc/udisks-glue.conf file.

3rd question
Where in OSMC can I set idle time for connected harddrives? I want to make them go sleep after 3min of inactivity.

My own research has made me more confused. I found all options for udisk:

And changed this line in /etc/udisks-glue.conf:

match ntfs-partitions {
        automount = true
        automount_options = { 'fmask=0111','dmask=0000','uid=1000','gid=1000' }

to this:

match ntfs-partitions {
        automount = true
        automount_options = { 'fmask=0111','dmask=0000','uid=1000','gid=1000','async','noatime','nodiratime' }

And my drive is not mounted anymore after reboot (so I changed it back). I do not understand why though.
I also read “big_writes” is not supported, you need ntfs-3g for that, and it should increase write speed. If that is the case, should OSMC use ntfs-3g by default? And add the three options (async, noatime, nodiratime) and big_writes by default for NTFS drives?

I still have not figured out how to mount drives always to /media/usb0, media/usb1…
Also, I do not understand how to add a spindown timeout, I also would expect OSMC to do this by default (20 or 30min to keep the SMART ATA start-stop counter healthy).

I hope someone can shed some light on this. I am still learning about linux.

You should be able to set usb0 usb1 or whatever as the mount point by changing the drive label. If its a linux drive, use e2label /dev/whatever usb0
Alternatively you could set a symlink to point to the drive under its real label, ssh into your pi and
ln -s /media/real_drive_name /media/usb0

I know I can do those things, but I would like udisk do it automatically for all RPIs Im installing. I still want to have separate labels for all hdds.

It has to be that udisks-glue.conf file, also for setting mount options to increase NTFS performance and for spindown. But there is a lack of documentation on udisks-glue file. I still do not know which mount options are supported, why big_writes is missing and why ntfs-3g is not used if it has better performance.

edit: it seems Debian -- Error can do this, perhaps udisk cannot do this. OSMC does not use usbmount so perhaps what I want is impossible if I want to stick to what OSMC is using.

As far as I know we do use ntfs-3g already - on what are you basing that we don’t ? ntfs-3g is required for write support of ntfs, and we do have full write support.

As for udisks-glue.conf - as the poor schlub who had to write 90% of that monstrosity I feel your pain and sense of confusion. udisks-glue’s configuration file is very poorly documented (one man page basically) and has a very limited syntax that doesn’t allow for multiple matches or fall through of matches.

This is why there is a massive amount of duplication in the file - we need the script to add samba shares for all variations of file systems etc, but a match entry, staggeringly, cannot match multiple filters! :frowning: Which kind of makes it pointless having separate filter and match clauses in the conf file’s syntax IMHO, but it is what it is and we have to work with it…

There’s two issues that you’re probably running into - one is that if you add even one “invalid” option in the automount_options, then the partition just won’t mount at all. That’s why we have separate matches for optical-udf and optical-other for example - because for a UDF formatted disk we need to specify umask=0000 for optimal file permissions for the mount point, yet umask is an invalid mount option for an iso9660 disk causing the mount to fail…sigh.

The other thing you may be running into is that udisks-glue itself rejects a number of valid mount options for some file system types based on a list that is hard coded in the source code. :frowning:

For an example of that issue, see this kludgey but expedient workaround for EXFAT:

From memory, fmask and dmask are valid options for an exfat file system, that we need to use, but are explicitly blacklisted for exfat file systems in the udisks-glue source code so any attempt to use them as automount_options results in the partition failing to mount at all.

Yeah, we could fork udisks-glue, patch the source code to remove these restrictions and supply our only custom version of udisks-glue, but in the end we decided it wasn’t worth the effort when a small script and a dpkg diversion could solve the problem for now. (Every extra package you fork means more work to maintain your own version - we already fork connman, lircd, and eventlircd among others, for example)

So yeah, customising the automount options is a right PITA at the moment. Eventually we will replace udisks-glue for something else more flexible, but that won’t be until well into the future, partly because Kodi has good support for udisks.

One final comment I would make is that are you certain the the mount options you’re trying to apply aren’t already defaults ? Check with the mount command after the drive is mounted what options are listed, also just because you don’t see an option doesn’t mean it isn’t there, for example I see that you have noatime in your list - noatime has been the default in Linux for many years now.

If you try to manually specify noatime in mount options and then check with the mount command after the drive is mounted, you will not see noatime listed - because noatime IS the default already. But if you were to specify atime (the opposite of noatime) you would see it listed when you check with mount.

I’m pretty certain that async and nodiratime are also defaults in linux for a long time now. (Running in sync mode is really slow) The only one I’m not sure about is big_writes.

Edit: Just realised that noatime and nodiratime are probably invalid for an ntfs file system in the first place, as ntfs doesn’t support the concept of an “access time” - that’s purely a unix file system concept, eg ufs,ext4 etc. So you shouldn’t be trying to use these options on ntfs in the first place.

1 Like

Thanks A LOT! I started to wonder why udisk was being used, and must say I have much respect for you writing that glue file. I checked mount and you are right (this is an NTFS filesystem):

/dev/sda1 on /media/devina type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096,uhelper=udisks)

So noatime is a default, perhaps async is as well because it is also not shown. I will do some more tests.
I always thought ‘sync’ was the default, but thats because I’m used to XBian, you can disable ‘sync’ in the XBian config (the first thing I used to do).

I decided to ditch the relative paths and just use a unique label.

Only thing left now: spinning down HDDs (reason: noise during quiet moments in a movie)
A RaspBMC developer (s7mx1) shared useful code for the udisks-glue.conf:

udisks --set-spindown %device_file --spindown-timeout 600

I am not a programmer but I believe I will need to add this before or after the first IF statement, but I am not sure :pensive: I know this might traumatize you but if you are able to have a look at it, I will be very grateful!

match ntfs-partitions {
        automount = true
        automount_options = { 'fmask=0111','dmask=0000','uid=1000','gid=1000' }
        post_mount_command = '
                if [ -f /usr/bin/net ] && /bin/systemctl is-enabled samba > /dev/null; then
                        while [ $count -gt 0 ]; do
                                if sudo /usr/bin/net usershare add "$(basename "%mount_point")" "%mount_point" "Auto-mount Volume" "$(hostname)\osmc:f"
                                        then break
                        sleep 5; let count-=5

        post_unmount_command = '
                if [ -f /usr/bin/net ]; then
                        sudo /usr/bin/net usershare delete "$(basename "%mount_point")"

We already use hdparm to spin down disks:

match fixed-disks {
	post_insertion_command = '
		if [ "$(/bin/findmnt -n -o SOURCE / | sed "s/p\?[0-9]\+$//")" != "%device_file" ]; then
			sudo /sbin/hdparm -S 240 %device_file

If you want to try the udisks spin down command replace hdparm in the match fixed-disks section - bear in mind that an update to the diskmount-osmc package will overwrite your change.

Many (most?) external USB hard drives cannot have their spindown timer set - of the external drives that I have none of them will spin down either with our existing hdparm command or with udisks --set-spindown, so don’t be surprised if the udisks command doesn’t work either.

Ah I should have seen that! sorry.
It works for me. I have had 3 broken HDDs in my life so I carefully select my HDD by always choosing an internal drive. And as enclosure, I use DeLock which are extremely reliable cases and provide eSATA, eSATAp (power via USB) and USB3.0 in one port:

HDparm also works with WD Elements portable drive and an ADATA portable USB3 drive.