How to config udevil to auto-mount usb drive and create a Samba share for it?

  • Hello,

    I'm curious to understand how udevil and devmon are configured in LibreELEC to auto mount an attached usb drive at boot up and create a samba share for it.

    Can someone give me the config steps? I would like to replicate that functionality elsewhere. Basically my other machine (OSMC on Pi) uses udisks and udisks-glue. I disabled those systemd services and installed udevil/devmon. The usb drives get mounted but then immediately get un-mounted again so they end up not mounted at all.

    Also how does LibreELEC make a samba share with the name being the label of the usb drive?

    Cheers,

    Flex

  • See the configs and scripts in our repository.

    Basically we have a udev rule LibreELEC.tv/95-udevil-mount.rules at master · LibreELEC/LibreELEC.tv · GitHub that determines which devices should be auto-mounted and then starts the udevil-mount@ systemd service LibreELEC.tv/[email protected] at master · LibreELEC/LibreELEC.tv · GitHub

    This service calls the samba-autoshare wrapper script LibreELEC.tv/samba-autoshare at master · LibreELEC/LibreELEC.tv · GitHub which in turn calls the samba-config script LibreELEC.tv/smbd-config at master · LibreELEC/LibreELEC.tv · GitHub to (re-)generate the samba config file and then sends a HUP signal to smbd so samba re-reads the config file.

    The share name is identical to the mount-directory in /media which is handled by udevil (using the filesystem label, if present).

    so long,

    Hias

  • Iridium

    Well I know you can add more Samba share definitions in samba.conf but what I am asking about is how the LibreELEC team designed this to happen automatically regardless of what usb key you attach.

    HiassofT

    Thanks so much for this really helpful information. I started using Kodi with LibreELEC on a Pi 1 Model B. But recently I have been trying out OSMC because it is easier to install more stuff onto. However OSMC just haven't (yet?) got auto-mounting down like LibreELEC do. In LE my usb drives are always auto-mounted on boot but running OSMC on the exact same hardware this hardly ever works. The explanation given to me is that it is a "power issue" and to buy a powered USB hub. The USB drives seem to take a bit longer to spin up on boot so when udisks-glue runs at boot up the drives are not ready to mount. A workaround is to add a sleep 10 to the udisks-glue service.

    I am trying to investigate if the LE method with udevil can be ported into OSMC and make my drives always mount on boot. Maybe there is something about OSMC that it draws more power at boot up and that stops the drives from spinning up fast enough and this will always stop even udevil working too? I don't know but I'll give it some more investigation anyway.

    Thank you!

    Flex

  • If you have a power issue then you need to fix that.

    Self-powered hard drives have always been problematic, especially on RPi1. Either use a powered USB hub or a drive with it's own power supply.

    Keep in mind that if you don't fix the power issue the data on the drive could get corrupted - so interpret these mount issues as a strong warning sign that you have an urgent problem to fix and that you have been quite lucky so far that the data on your drive survived without damage.

    so long,

    Hias