Exposing symlinks to other drives via samba (using two external drives in one library).

  • Due to space restrictions, my tv shows are distributed to two ext4 USB drives. Exemplary directory structure is like this:

    Code
    /media/drive1/tvshows/show1
    /media/drive1/tvshows/show3
    
    /media/drive2/tvshows/show2
    /media/drive2/tvshows/show4

    As I might want to later replace drive1 with a bigger drive and get all shows back together on one USB device, I want Kodi to use both drives in a single library. This can easily be achieved with symlinks:

    The Kodi tvshow library points to /media/drive1/tvshows/. Directory structure looks like this:

    Code
    /media/drive1/tvshows/show1
    /media/drive1/tvshows/show2 -> /media/drive2/tvshows/show2
    /media/drive1/tvshows/show3
    /media/drive1/tvshows/show4 -> /media/drive2/tvshows/show4

    This works fine for Kodi, all links in the tv show database will point to drive1 only.


    Now I want to expose this whole directory structure via samba. I can of course have shares for both drives separately, but it would be nicer to have one share for both. Seemingly there is two ways to achieve this:

    1. Via follow symlinks in samba.conf

    The problem is that follow symlinks does not allow links across file system borders. So the additional option wide links = yes must be set per share. It seems though that the necessary module is not part of LibreELEC, log.smbd reports the following:

    Code
    [2022/06/20 13:36:33.446886,  0] ../../lib/util/modules.c:49(load_module)
    Error loading module '/usr/lib/vfs/widelinks.so': /usr/lib/vfs/widelinks.so: cannot open shared object file: No such file or directory
    [2022/06/20 13:36:33.447224,  0] ../../source3/smbd/vfs.c:185(vfs_init_custom)
    error probing vfs module 'widelinks': NT_STATUS_UNSUCCESSFUL
    [2022/06/20 13:36:33.447399,  0] ../../source3/smbd/vfs.c:379(smbd_vfs_init)
    smbd_vfs_init: widelinks enabled and vfs_init_custom failed for vfs_widelinks module
    [2022/06/20 13:36:33.447515,  0] ../../source3/smbd/service.c:636(make_connection_snum)
    make_connection_snum: vfs_init failed for service drive1

    This whole approach is also not recommended (not even by the samba team), as it poses a security risk.

    2. Via bind mounts

    Using bind mounts instead of symlinks is supposed to achieve the same thing:

    mount --bind /media/drive2/tvshows/show2 /media/drive1/tvshows/show2 works as expected. But how can I make these mounts being executed at boot time? As /etc/fstab is not being used by LibreELEC, I am not sure which other way I have to approach - do I use udev rules or systemd .mount files? And either way, does somebody have an example on how to do that? Because I am familiar with neither and from initial search it looked somewhat complicated (do I need to use systemd-mount with udev?).

    3. Insert your proposal here

    Maybe there is a third or completely different approach that I missed. I am happy for every other suggestion. Thanks!

  • 3. Kodi stores all references to sources and file-paths in an sqlite database (or MySQL for shared DB) so you can always move the content to a new drive and then search/update links in the DB to point to new locations. This might require a bit of experimentation (learn to backup the DB files before you start to permit easy stop/copy/restart of files to revert mistakes) but it's probably not that hard and someone somewhere has probably documented it in the Kodi forums already.

  • Yeah, I did that last time. After that I wanted to find a method that does not need tinkering with the database. ;) But maybe you are right and this is all overkill for a problem which is easily solvable.

    Still, do you have any insight in option 2: udev rules vs systemd mount files?

  • maybe for 3.:

    have on drive1 .../tvshow2 and 4 as empty directories and mount the second disks directories there

    dir's on disk 1:

    |--- tvshow1

    |--- tvshow2 (empty dir.; mountpoint for disk2)

    |--- tvshow3

    |--- tvshow4 (empty dir.; mountpoint for disk2)

    maybe needs on disk2 two partitions, one for tvshow2 and one for tvshow4.

    normal mount tvshow2 should work [1]

    but I'm unsure for tvshow4 (same disk gets mounted twice): maybe via bind mount, but I guess: cleaner is with two partition [2]

    [1]

    - remove all mount scripts you're maybe currently using

    - leave the systemd-mount service for disk1 as is and plug the disk in (what in any case would create such systemd-mount service file if none exists)

    - wait

    - plug disk2 in

    - wait

    - find out the sytemd-mount-service file for disk2

    - adjust that sytemd-mount-service file for the above mount points (and notice that in an howto for new installs of LE)

    * maybe the systemd-mount service file for disk1 needs adjustment for the mount point too, cause it usually mount to /var/media (IIRC)


    shouldn't that be doable ???

    I'm also unsure how to reliable manage that the 2. disk always gets mounted after disk1 (otherwise no mount points for disk2 available)

    think of: both disks plugged and the box gets booted

    if doable, this should fullfill:

    - automatic mounts without user intervention, cause systemd does the job

    - it should creates/keep entries in the DB which would/should survive the exchange to one disk only (DB reads the same directory structure)

    - no/minimized samba security risks (NO idea if sharing a directories which contains mounted drives introduces some)

    [2]

    - needs temp. disk space for (some or all of) the content of disk2 what will become partition2 on that disk

    Edited 6 times, last by GDPR-7 (June 21, 2022 at 9:43 PM).