Automatically Mounting acd_cli, EncFS, and UnionFS Mounts at Boot

UPDATED – 26 January, 2017

This script has been updated to work with the changes made in the last guide using rClone rather than acd_cli for the ACD mount.

People have been asking how to mount all those different directories we set up in Using Amazon Cloud Drive with Plex Media Server on Ubuntu… And Encrypting It! at boot automatically. So here’s a quick guide on getting that set up. As usual, we’ll be assuming you’re using a user called “plex” for all this, and the directory structure from the guide as well.

I’ve played around with using fstab to mount all these directories, but there are just too many hurdles and things that tend to go wrong, between acd_cli needing the “_netdev” option to wait for a network device, and the EncFS mounts trying to run before acd_cli is fully mounted. Not only all that, but anything mounted automatically in fstab is mounted as root, which can cause another set of issues with accessing the directories as another user. I’ve found that a simple crontab entry is the easiest and most straightforward method.

Step 1 – Create a Password File for EncFS

To fully automate the mounting of our EncFS directories, we’ll have to have the password readily available to pass into our script. I like to keep a “scripts” directory right inside my plex home folder with another directory for logs, so let’s create that first and then move into that scripts directory:

cd ~
mkdir scripts
mkdir scripts/logs
cd scripts

And now we can create a password file. Just run:

nano encfspass

And type only your EncFS password. When you’re finished, press “CTRL+X” and “Y” to save the file. Make that file executable with the following command:

chmod +x encfspass

Step 2 – Write a Script

We’ll need a script that will automatically clear out any mount points (if any) and then mount all our different shares. Go ahead and start off with opening Nano with a filename of “mount.sh” like so:

nano mount.sh

And then copy and paste the following:

#!/bin/sh

#Unmount any directories already mounted
/bin/fusermount -uz /home/plex/acd
/bin/fusermount -uz /home/plex/.acd
/bin/fusermount -uz /home/plex/.local
/bin/fusermount -uz /home/plex/media

#Mount ACD using rClone
/usr/sbin/rclone mount acd:Plex /home/plex/.acd &

#Mount encryption over these folders
ENCFS6_CONFIG='/home/plex/encfs.xml' encfs --extpass="cat /home/plex/scripts/encfspass" /home/plex/.acd /home/plex/acd
ENCFS6_CONFIG='/home/plex/encfs.xml' encfs --extpass="cat /home/plex/scripts/encfspass" /home/plex/.local /home/plex/local

#Use union-fs to merge our remote and local directories
unionfs-fuse -o cow /home/plex/local=RW:/home/plex/acd=RO /home/plex/media

exit

The first section in this script is to unmount the directories we’re using just in case something breaks, so you can simply just execute this script to easily “start fresh.” If you receive any errors from fusermount, you can usually ignore them.

And to allow the script to be executed, we have to add the “execute” permission to the file:

chmod +x mount.sh

Now that you’ve got your script written, we can add it to our cron list!

Step 3 – Add Mount Script to Crontab

Start by editing your crontab jobs:

crontab -e

If this is your first time editing crontab, you’ll be asked to choose a text editor. If you haven’t noticed, I prefer Nano. Press “2” and “enter” to continue. Now, use your arrow keys to scroll down to the last blank line in the file, and enter the following line:

@reboot /home/plex/scripts/mount.sh > /home/plex/scripts/logs/mount.log 2>&1

“@reboot” obviously means this script will be run on a system reboot. The 2>&1 bit at the end will append to the specified log file, just in case something goes wrong with our script.

Wrap-Up

So that’s about it. The nice thing about this method is, if anything happens to your mounts or directories, you can just hop over to your scripts directory and run that mount.sh script. It should clear up most issues. Not having to worry about manually mounting anything during reboots is definitely a plus! As always, leave a comment if you have any issues with the guide, or drop me a message on Reddit. Thanks for reading!

Advertisements

45 thoughts on “Automatically Mounting acd_cli, EncFS, and UnionFS Mounts at Boot

  1. Pingback: Using Amazon Cloud Drive with Plex Media Server on Ubuntu… And Encrypting It! | enzTV

  2. Pingback: The (Almost) Complete Guide to Creating the Ultimate Plex Server | enzTV

  3. This is what I get after running the script:
    plex@xxxxxxxx:~/scripts$ sudo ./mount.sh
    [sudo] password for plex:
    /bin/fusermount: invalid option — ‘x’
    /bin/fusermount: invalid option — ‘x’
    /bin/fusermount: invalid option — ‘x’
    /bin/fusermount: invalid option — ‘x’
    /bin/fusermount: invalid option — ‘x’
    Getting changes..
    Inserting nodes.
    The directory “/home/plex/local” does not exist. Should it be created? (y,n) y
    Unable to create directory: : File exists
    12:58:23 (main.cpp:466) Unable to locate mount point, aborting.
    Build: encfs version 1.8.1

    Usage: encfs [options] rootDir mountPoint [– [FUSE Mount Options]]

    Common Options:
    -H show optional FUSE Mount Options
    -s disable multithreaded operation
    -f run in foreground (don’t spawn daemon).
    Error messages will be sent to stderr
    instead of syslog.
    -v, –verbose verbose: output encfs debug messages
    -i, –idle=MINUTES Auto unmount after period of inactivity
    –anykey Do not verify correct key is being used
    –forcedecode decode data even if an error is detected
    (for filesystems using MAC block headers)
    –public act as a typical multi-user filesystem
    (encfs must be run as root)
    –reverse reverse encryption
    –extpass=program Use external program for password prompt

    Example, to mount at ~/crypt with raw storage in ~/.crypt :
    encfs ~/.crypt ~/crypt

    For more information, see the man page encfs(1)

    Failed to open /home/plex/local/: Permission denied. Aborting!

    Liked by 1 person

    • Wow, I’m just off my game lately. The script has been updated in this guide. The options for fusermount are -uz not -ux. Update your script and try running it again. If that doesn’t work, check the ownership of your directories and make sure plex is the owner (or whichever user you’re running the script as).

      Like

      • It seems that the directories: acd, local, and media are not owned by my plex user. When I try ls -l those 3 directories have a bunch of ?s. When I log in to root I can access all these directories. I’ve been trying to change ownership/permissions on these directories and it won’t add my plex user as an owner. Any ideas?

        Like

  4. So after uploading new media to acd from another computer and then doing acdcli sync on the server vps I notice that no new media is being added to plex. Running the mount.sh script again I get the following output at start up:

    /bin/fusermount: entry for /home/plex/acd not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/.acd not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/local not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/.local not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/media not found in /etc/mtab
    /home/plex/scripts/mount.sh: 9: /home/plex/scripts/mount.sh: acdcli: not found
    /home/plex/scripts/mount.sh: 11: /home/plex/scripts/mount.sh: acdcli: not found
    The directory “/home/plex/.acd/Plex/” does not exist. Should it be created? (y,$
    19:45:54 (main.cpp:460) Unable to locate root directory, aborting.
    Build: encfs version 1.8.1

    Usage: encfs [options] rootDir mountPoint [– [FUSE Mount Options]]

    Common Options:
    -H show optional FUSE Mount Options
    -s disable multithreaded operation
    -f run in foreground (don’t spawn daemon).
    Error messages will be sent to stderr
    instead of syslog.
    -v, –verbose verbose: output encfs debug messages
    -i, –idle=MINUTES Auto unmount after period of inactivity
    –anykey Do not verify correct key is being used
    –forcedecode decode data even if an error is detected
    (for filesystems using MAC block headers)
    –public act as a typical multi-user filesystem
    (encfs must be run as root)
    –reverse reverse encryption
    –extpass=program Use external program for password prompt

    Example, to mount at ~/crypt with raw storage in ~/.crypt :
    encfs ~/.crypt ~/crypt

    For more information, see the man page encfs(1)

    Apparently the media I already had on there was being saved to the local folder after syncing with acd. I deleted the media there, making sure it was still also in /home/plex/media/. Now plex won’t play the few files I had on the server before all this happened.

    Like

      • I ran into the same problem as Michael so I added the location of acdcli, and it works! Except… the acdcli unmounts randomly – negating me access to all the media. If I go into the console and mount it again it’s fine, but why is it unmounting? Is there a way to prevent this?

        Thanks!

        Like

  5. Thank you for the effort in your write up and this script, it’s definitely the most concise I believe. I had everything working after following your initial write up but, up reboot, after running this script (customized a bit for me) I get a similar error as the user above me. I’ve verified my directories are owned by my user (plex) but I get this:

    /bin/fusermount -uz /var/lib/plexmediaserver/media
    /bin/fusermount: entry for /var/lib/plexmediaserver/media not found in /etc/mtab

    Am I missing the step of actually mounting these directories first? If I understand correctly, -u is unmount ? Thanks for any help, much appreciated!

    Like

  6. /bin/fusermount: entry for /home/plex/acd not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/.acd not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/local not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/.local not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/media not found in /etc/mtab

    Howcome?

    Like

    • If this is the first time you run the script, those messages are just telling you those mounts don’t exist. They can be ignored, basically it’s just telling you you’re trying to unmount something that isn’t mounted to begin with. Once the script runs, those mounts are then created.

      Like

  7. First off thanks for this guide. Its wonderfully explained! So .local and local are behaving as they ought for me. I add a folder and file in local and it comes out encrypted in .local. But i suspect something is up w/ acd and .acd. I see my amazon folders in .acd, but nothing in acd. Its blank.. Shouldn’t one or the other come out encrypted? I’ve disected the code and it appears to be right.. am i missing something? thanks!

    Like

  8. Nevermind. Its working. I had to run acdcli sync. Now i see the encrypted files in .acd and the decrypted in acd. My question now is after i delete my local files, the files sitting in acd, are those a decrypted copy of whats sitting in amazon? In other words when playing a media file from that folder (i.e. acd), am i streaming a decrypted copy from amazon’s servers or a local copy? if a local copy, wont i be doubling up data (both in amazon and locally?)

    thanks!

    Like

  9. hahaha… so near and yet so far : ) : (
    feel like i’m losing my mind 🙂

    followed the instructions to a T fixed a few nagging problems (places where i missed a ‘plex’ putting in my username etc..

    everything worked perfectly with no errors.. except for the unionfs-fuse -o cow,allow_other command
    it gives me a “mountpoint is not empty” error….

    i CAN SEE the files in my .acd acd .local and local folders fine in file manager… (i had to name my local folders ‘local2’ btw if yer looking below and wondering…. ) but nothing shows up in media.

    but oddly nothing shows up in .acd acd local and media folders in Plex

    i did that edit to fuse.conf and uncommented out the allow other thing… but to no avail.. r4booted many times…

    i’m at the end of my rope (and linux abilities) : )

    if this helps.. here is the error i get at the terminal trying to run the unionfs line.

    tried the nonempty -ne on the acdcli mount command… with got rid of the nonempty errror on that… but still got the error in the unionfs line..

    (btw i dont really care if its all nice and easy/both places in a ‘media’ directory… i just want it to work period : ) : (

    ————-
    jaquestati@Ubuntu-1604-xenial-64-minimal:~/scripts/logs$ acdcli sync
    Getting changes..
    Inserting nodes.
    jaquestati@Ubuntu-1604-xenial-64-minimal:~/scripts/logs$ acdcli mount -ro /home/jaquestati/.acd
    fuse: mountpoint is not empty
    fuse: if you are sure this is safe, use the ‘nonempty’ mount option
    Traceback (most recent call last):
    File “/usr/local/bin/acdcli”, line 9, in
    load_entry_point(‘acdcli==0.3.2’, ‘console_scripts’, ‘acdcli’)()
    File “/usr/local/bin/acd_cli.py”, line 1680, in main
    ret = args.func(args)
    File “/usr/local/bin/acd_cli.py”, line 1155, in mount_action
    volname=args.volname)
    File “/usr/local/lib/python3.5/dist-packages/acdcli/acd_fuse.py”, line 719, in mount
    FUSE(ACDFuse(**args), path, subtype=ACDFuse.__name__, **kwargs)
    File “/usr/local/lib/python3.5/dist-packages/fuse.py”, line 480, in __init__
    raise RuntimeError(err)
    RuntimeError: 1
    jaquestati@Ubuntu-1604-xenial-64-minimal:~/scripts/logs$ acdcli mount -ro -ne /home/jaquestati/.acd
    jaquestati@Ubuntu-1604-xenial-64-minimal:~/scripts/logs$ unionfs-fuse -o cow,allow_other /home/jaquestati/local2=RW:/home/jaquestati/acd=RO /home/jaquestati/media/
    fuse: mountpoint is not empty
    fuse: if you are sure this is safe, use the ‘nonempty’ mount option

    ———

    also if this is any help this is the mount.sh script error log-

    ———

    /bin/fusermount: entry for /home/jaquestati/acd not found in /etc/mtab
    /bin/fusermount: entry for /home/jaquestati/.acd not found in /etc/mtab
    /bin/fusermount: entry for /home/jaquestati/local2 not found in /etc/mtab
    /bin/fusermount: entry for /home/jaquestati/.local2 not found in /etc/mtab
    /bin/fusermount: entry for /home/jaquestati/media not found in /etc/mtab
    /home/jaquestati/scripts/mount.sh: 9: /home/jaquestati/scripts/mount.sh: acdcli: not found
    /home/jaquestati/scripts/mount.sh: 11: /home/jaquestati/scripts/mount.sh: acdcli: not found

    ————

    which is to do with this nonempty thing i’m sure..

    any help would be greatly appreciated… been at this for like 10 hours and having to give up… : (

    Like

  10. an update on my attempt.

    i finally got everything working (don’t ask me how… because i’m really not sure) : ) : (

    it all works perfectly.. except every time i rclone a batch to the ACD… the acd mount disappears (still there… just gone… poof… can’t remount it as it says its still there…) i can unmount remou8nt and sync and everything is back to normal/working.. but literally EVERY single time i rclone stuff to the drive it unmounts when done… ??

    has anyone else run into this?

    Like

  11. The nonempty message was happening to me. Turned out, encfs mount (.local) was unmounting randomly (not with any consistency) and then what happened was I was writing to another non encfs local directory. The encfs mount can mount over an existing directory with no empty but then data integrity comes to question. Be sure when you write local, you’re see the change happen encrypted to .local. If not, then u have to unmount (everything) then move the unencrypted data you thought was going to encfs mount, leaving an empty directory, then remount using encfs and move data back through the encrypted directory, being sure it’s actually ending up in .local encrypted. This is what’s happened to me, twice :-). Good luck.

    Like

  12. new rclone setup working great (i was worried about performance… after reading a bunch of threads saying it was way slower than acd_cli) but so far it seems fine : )

    i can run the commands in terminal and it all works perfectly.. but i am getting this error in the mount.sh

    “/home/jaquestati/scripts/mount.sh: 10: /home/jaquestati/scripts/mount.sh: rclone: not found”

    any ideas?

    the line works fine with no errors in a terminal.

    Like

      • woohoo!
        that worked : )
        i finally have everything working perfectly!
        and now with the rclone mount the mount isn’t even unmounting every time i upload : )

        thank you thank you : )

        ps- .. if we want to delete move or rename something on the acd… is that possible? will it mess anything up if we do? and if not…. do we do it in the media folder or the acd folder?

        Like

  13. I’m trying to upgrade to rclone, but I’m getting the whole “not folder found” problem. I already checked that mount.sh points to /usr/sbin/rclone but it asks me to create the folders again and again. I even checked encfspass to make sure the password is correct and everything. Anything else that I might be missing?

    Thanks!

    Like

      • it says

        ls cannot access ‘acd’: No such file or directory
        total 24
        d????????? ? ? ? ? ? acd
        and it shows the other directories and files just fine (I don’t know how to copy from the console in DigitalOcean, sorry).

        I tried to use mkdir acd in the console and it says mkdir: cannot create directory ‘acd’ File exists

        Using FileZilla I can’t see the acd directory, but I can see .acd, so I guess something is not letting me update the acd directory or something.

        Like

      • So I did the most basic thing: I rebooted my VPS. Now I have the folders listed, yay! But they don’t see any data at all – they show empty. If I run sh mount.sh I see that /home/plex/acd and /home/plex/.local not found, and that home/plex/.acd/Plex does not exist. So, kind of a redundant problem?

        The files are there on amazon cloud, perfectly encrypted, so I haven’t lost them (yet). Any ideas why this may be happening?

        Thanks!

        Like

      • Same for me. I removed the cronjob and just ran the commands and got the media folder going but I’ve lost permission for the local and acd folders. Even tho this my username

        Like

  14. Doesn’t this require a change in the encfs part of the script too?

    ENCFS6_CONFIG=’/home/plex/encfs.xml’ encfs –extpass=”cat /home/plex/scripts/encfspass” /home/plex/.acd/Plex /home/plex/acd
    ->
    ENCFS6_CONFIG=’/home/plex/encfs.xml’ encfs –extpass=”cat /home/plex/scripts/encfspass” /home/plex/.acd/ /home/plex/acd

    Like

  15. so we can- “use the “rm” command from the media directory and it will delete from ACD too.”

    but will editing or moving files in the media directory in a file manager mess anything up?

    ps- i think i jinxed it/spoke too soon… everything was working great with the rclone setup… did 3 or for uploads and the mount didnt break… rebooting 3 or 4 times and everything was perfect…
    but then i uploaded a big chunk last night and woke up to find i could not enter the folders inside media or acd… it just hung forever… i rebooted several times and had the same problem : (
    panicked that i’d lost terabytes of stuff… i removed the mount script and rebooted… and mounted with acdcli and everything was fine : )

    i’ll uncomment the mount script and try rclone again later (cant today) but has anyone run into this with the rclone mount? i could see the movies/tv folders in acd and media… but clicking on them i could never get in… (what is the command to unmount an rclone mount exactly?)

    Like

  16. Couple things.
    1. I am still using the initial script with acd_cli successfully, it worked from day1/try1. Obviously the issue with acd_cli is that the mount broke after an rclone upload fairly often.
    2. my directory at amazon uses a lower case “p” in plex. That’s virtually the only difference between my script and yours, so I’ve used the identical structure to convert, however I’m seeing this now:
    Results of rclone to show that it does indeed have a mount.
    plex@host:~/scripts$ rclone listremotes
    acd:
    plex@host:~/scripts$

    plex@host:~/scripts$ ./mountvol2rclone.sh
    /bin/fusermount: entry for /home/plex/acd not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/.acd not found in /etc/mtab
    /bin/fusermount: entry for /mnt/vol02/local not found in /etc/mtab
    /bin/fusermount: entry for /mnt/vol02/.local not found in /etc/mtab
    /bin/fusermount: entry for /home/plex/media1 not found in /etc/mtab
    The directory “/home/plex/.acd/plex/” does not exist. Should it be created? ( y,n)

    1. Is this an ok thing? I’ve stopped it from moving forward because i don’t want to screw this up. I’m guessing that this is simply because we did the fusermount -uz..
    2. Is it going to ask this every single time (think reboot etc)
    3. What version of rclone are you running (stable ? beta?)

    Like

      • I did it, and it seems to work! Filezilla can see the files.

        Plex can’t, but I’ll see if it’s because suddenly I have three files for the same episode. Weird.

        Thanks!

        Like

      • Hi! Me again, I think I completely screwed up.

        So, my VPS got saturated (someone forgot to limit downloads to wait until uploads were done) so I erased a bunch of files. I thought I hadn’t erased anything from the set up files (as I only erased stuff from the Downloads folder) but alas, rclone stopped working. It said “rclone failed to create file system for acd:Plex”, so I listed the remotes with rclone listremotes and it listed none. So I redid the whole remote set up from the other guide and I have the acd remote again, but now when I run the mount script I get the whole “not found in /etc/mtab” followed by fusermount: failed to access mountpoint Permission denied. I ran a sudo sh mount.sh and I got invalid argument.

        So… How badly did I screw up?

        I can’t see the files on the vps. They are safe and sound in ACD, so at least they are there.

        Thanks!

        Like

  17. So in my prior script for uploading, I would always run an acd_cli sync prior to doing an upload (followed your guide)
    Obviously now after moving to rclone for the mount things are different. Is a “sync” needed at all? Does the concept of “sync” exist within rclone or is it always happening automatically in the background?

    Like

  18. I reverted to acdcli for my mount. I’m seeing a bunch of these errors after switching over to rclone. (I’d still like to understand how rclone works as far as needing to be synced or not needing to be synced as I previously posted)
    Here’s the error I’m seeing and it happens about every 3-5 minutes when clients are streaming from plex rclone mount
    2017/02/14 14:38:11 be9w3Kt8SXWzVB4jjuzEg3qy/-VoMG6iIiM9dGx4bYbjbbjJnKHpo8A9UpZ9qSQJ6MT-T9us22iJ0t54yl6YWWW22Nq,/NGzHdZuT4g4KyLiWPVmM7ySSXguCbp0yoUZ6JiCjgWcFvb4x4vdWn3PjcuQfZBNQjh0: ReadFileHandle.Read error: low level retry 1/10: unexpected EOF

    Like

  19. I tried to add the rclone arguments to mount.sh script but it failed to pass the command and didn’t mount anything. Can you paste a working mount.sh file?

    Like

    • You should be directing all downloads to: /home/plex/media (if you are following the guide exactly) . So for sonarr it would PROBABLY be /home/plex/media/tv/Top Gear (for instance), and radarr would be /home/plex/media/movies/Star Wars (1977)

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s