Directories (mount points in this case) being deleted from /media/

I created two folders in my /media/ directory on which I mount my NFS shares to my content. After every reboot, the folders are missing, and the mount obviously fails for this reason. Does anyone know why the folders would be getting deleted?

how are you mounting them?

debug logs?

I am mounting them with fstab.

x.x.x.x:/media/1.5TB/Shows /media/shows nfs _netdev,defaults,user,auto,noatime,intr,rw 0 0
x.x.x.x:/media/2TB/movies /media/movies nfs _netdev,defaults,user,auto,noatime,intr,rw

I am not sure where I could see any logs which would show the folders getting deleted, but I am happy to check if you could point me in the right direction.

Is there a reason why you are mounting them in fstab?

Join me, and others, in IRC
http://webchat.freenode.net/?channels=osmc

/media gets wiped at shutdown/reboot to avoid problems with automount which creates directorys at every mount. If you’re mounting from fstab then mount them in the /mnt directory or anywhere other than /media

1 Like

I plan on changing how I am doing my mounts now anyway after chatting about it, but it seems that deleting everything from this location is non-standard, and not a good idea as others way want to use it. Why not just have osmc delete the folders that it auto-creates when it mounts attached media? There are many reasons someone would put a directory here to mount network locations for other purposes.

With automount the drive will be mounted in a folder in /media with the drive name or uuid as its name for instance a drive named usb1 will mount in /media/usb1 or /media/uuid********* if the drive is unnamed.
The folder is created by the automount process and deleted by it when shutdown properly. The problem is unclean shutdowns/crashes/plug pull will leave the folder so automount appends a 1 to the new mountpoint it creates /media/usb11 then usb12, usb 13, usb14… Of course this plays tricks on the Kodi library. The fix is to clear the folder before automount takes over.

Any suggestions to improve this are welcome

1 Like

What Dilligaf said.

It was a deliberate design decision to avoid the common problem on Raspbmc where an unclean shutdown causes automounted drives (typically USB drives) to be mounted to a slightly different location - thus breaking the link between a library entry and the file, requiring manual intervention via the command line to resolve.

It may be non-standard for a Linux distribution but keep in mind that OSMC is optimised solely for the purpose of running a Kodi mediacenter - and while OSMC is compatible with Debian in most ways we have customised the OS in many ways to enhance the functionality as a mediacenter, and this is just one of those ways.

For the record, it doesn’t actually delete everything under /media on boot, it only removes empty directories. See the following code:

So if you’re really adamant about placing your /etc/fstab mounts under /media, manually unmount your mount, create any file within the mount folder (for example using touch) then remount your mount.

This file will only be visible when the mount is not active - it will cause the rmdir to fail to delete the directory because it is not empty, and when the drive is mounted it mounts over top of that directory and the file you created is “hidden”.

The recommended location for manual mounts is still /mnt though - that’s why the folder is there.

As a followup in the next release there will be a file /media/README that explains the purge on reboot situation.

Maybe it would be better to detect mountpoints that have been automatically created under /media with a regex, rather than just attempting to nuke all mountpoints within the folder.

a patch that does this is very welcome

S

1 Like

OK, I’ll try to contribute something this evening. It think this is within my limited abilities… And obviously allows you try concentrate on issues that require greater knowledge.

1 Like

I’ve just come against this. +1 for a patch here. If you can point me to where this sits in the source I may be able to contribute a patch. Being that I only heard of OSMC about 2 days ago I’m a wee bit green.

1 Like

A PR would be great

S

So I’ve tried to dive in here but I’m missing something important. Looking at /lib/systemd/system/udisks-glue.service on my system I see this:

[Unit]
Description = mount disks automatically with standby
After = remote-fs.target

[Service]
User = osmc
Group = osmc
Type = simple
ExecStartPre = /bin/sh -c "for dir in $(ls -l /media | egrep '^d' | awk '{print $NF'}); do rmdir $dir >/dev/null 2>&1; done"
ExecStart = /usr/bin/udisks-glue --foreground

[Install]
WantedBy = multi-user.target

However in Github it’s as you have pasted. Checking the commit you seem to bump the version of discmount-osmc to 1.2.0 from 1.1.9 but dpkg reports that I have 1.0.17.

It also seems that I’m not falling in the same bug as even if I mount to say /mnt/foo my mount won’t come up on boot. So I tested with a bind mount and it works. It seems that nfs isn’t available to fstab. I also tried pushing this into rc.local but that doesn’t seem to mount them either. Both fstab and rc.local work fine once I’ve logged in.

Any help/tips/pointers?

I have discmount-osmc installed. For some reason it was being held back on updates. Still the same outcome except now the mount points in /media/ are actually being removed. So at least I think I’m on the right starting page. :smile:

Now any hints on why nfs isn’t available at boot?

Hint:
systemd is in the way. traditional fstab syntax doesn’t work.

I had to revise my entries to look like this:

XXX.XXX.XXX.XXX:/media/mediasync /mnt/fake nfs noatime,async,rsize=8192,wsize=8192,nolock,local_lock=all,x-systemd.automount,noauto 0 2

So I’m back on the trail of fixing this blind delete… :smile:

Package versioning got changed which is why you aren’t seeing updates. If you can make the change and test locally and PR it that will be great.

S

I’ve got this script but it doesn’t work (shell scripting is a personal weakness). Can anyone help clean it up?

FSTAB =`awk '{print $2}' /etc/fstab|grep -i /media/`; 
for f in /media/*; 
    do 
    if [[ -d $f ]]; then 
        if ! [[ $FSTAB =~ $f ]]; then 
            rmdir $f; 
        fi
    fi 
done

Basically I’m making the assumption that the only mounts that should persist are the ones defined in fstab. Anything else can be removed.

One more. I got the above working in a stand alone script. So I tried to embed it but no dice and I’m out of time for today:

[Unit]
Description = mount disks automatically with standby
After = remote-fs.target

[Service]
User = osmc
Group = osmc
Type = simple
ExecStartPre = /bin/bash -c "FSTAB=`awk '{print $2}' /etc/fstab|grep -i /media/`; for f in /media/*; do if [[ -d $f ]]; then if [[ ! $FSTAB =~ $f ]]; then rmdir $f; fi fi done; exit 0"
ExecStart = /usr/bin/udisks-glue --foreground

[Install]
WantedBy = multi-user.target