Skip to main content

Part 5 - Mounting the drive(s)

You made it up to here, you finished Part 4 - Setting up Rclone and/or Plexdrive and are still with it, congratulations! The hardest parts are done, it'll be downhill from now on. Promise!

We now need to mount our drive so that Plex can access it as if it is just one giant external drive.


Douglas Adams would have loved it!

Mounting the Google drive (Rclone)


You are probably still logged in with your plexuser account, which is exactly what we want.

Let's create the required folders first:

mkdir -p /home/plexuser/logs
mkdir -p /home/plexuser/uploads

Creating the mount script:

sudo nano /etc/systemd/system/rclone.service

Then paste (right click):

[Unit]
Description=Mount and cache Google drive to /media/Plex
After=syslog.target local-fs.target network.target
[Service]
Environment=RCLONEHOME=/home/plexuser/.config/rclone
Environment=MOUNTTO=/media/Plex
Environment=LOGS=/home/plexuser/logs
Environment=UPLOADS=/home/plexuser/uploads
Type=simple
User=root
ExecStartPre=/bin/mkdir -p ${MOUNTTO}
ExecStartPre=/bin/mkdir -p ${LOGS}
ExecStartPre=/bin/mkdir -p ${UPLOADS}
ExecStart=/usr/bin/rclone mount \
  --rc \
  --log-file ${LOGS}/rclone.log \
  --log-level INFO \
  --umask 022 \
  --allow-non-empty \
  --allow-other \
  --fuse-flag sync_read \
  --tpslimit 10 \
  --tpslimit-burst 10 \
  --dir-cache-time=160h \
  --buffer-size=64M \
  --attr-timeout=1s \
  --vfs-read-chunk-size=2M \
  --vfs-read-chunk-size-limit=2G \
  --vfs-cache-max-age=5m \
  --vfs-cache-mode=writes \
  --cache-dir ${UPLOADS} \
  --config ${RCLONEHOME}/rclone.conf \
  Gdrive: ${MOUNTTO}
ExecStop=/bin/fusermount -u -z ${MOUNTTO}
ExecStop=/bin/rmdir ${MOUNTTO}
Restart=always
[Install]
WantedBy=multi-user.target

Of course you will need to replace all instances of plexuser with your own username.

When you are done, save the file by typing Ctrl-O, Enter to save, then Ctrl-X to exit.

You will need to enable the service. Type

sudo systemctl enable rclone.service

Reload the service so it'll work:

sudo systemctl daemon-reload

If you don't plan on installing Plexdrive, then you will need to reboot your server now. Type

sudo reboot

You may need to wait a few seconds for the server to be back online again... just enough time to grab another cup of coffee. You deserve a break.

If you only wish to use Rclone and if you rebooted, just click away the PuTTY session (it has become unresponsive anyway). You are done now and you can proceed to Part 6 - Making it all come together.

If however you are planning to add Plexdrive, read on.

Mounting Plexdrive


Only follow these instructions if you are installing Plexdrive - which is now a legacy feature (Rclone is just as good now).

Make sure you are logged into PuTTY with your own username. First, let's create the mount directory:

sudo mkdir /media/Plexdrive

To speed up the installation a bit, create a screen session so that we can proceed while Plexdrive is creating the cache. Type

screen -S plexdrive

This will open a new session which we can place in the background later to continue setting things up. Type

sudo plexdrive mount -c /root/.plexdrive -o allow_other -v 2 /media/Plexdrive

You will be asked to provide your generated client ID. This is the Google client ID you created in part 4. Remember how I asked you to keep the browser open? The codes are probably still sitting on your screen. Paste it using right click, then hit Enter.

Do the same with the generated client secret, again this is the client secret you created in part 4 and that is still on your browser screen. If you had closed your browser after all, head back to https://console.developers.google.com, click "Credentials", and click "Edit" behind the API you created. This will show you the OAuth information again.

You will now be asked to paste a link in your browser. Use your mouse to select the entire link (see screenshot below). DO NOT TYPE CTRL-C!!! Just selecting it will copy the link.


Paste this link in your PC browser. You are asked to authorize Google drive and will be given an authorization code. Paste the code in PuTTY (right click!).

If all goes well, Plexdrive will start generating the cache. This will take a long time, but thanks to the separate screen we do not have to wait till it is completely finished. I do suggest waiting a few minutes until it mentions that it finished the initial scanning.

Once the cache creating process slows down to 1 or 2 items at the time, you can safely detach the screen to proceed with the following steps. To detach from the screen press Ctrl-A, then the letter D.

Once you are back on your main screen (placing the cache process in the background), type

sudo nano /etc/systemd/system/plexdrive.service

In the nano text editor paste the following lines:

[Unit]
Description=Mount Plexdrive to /media/Plexdrive
After=syslog.target local-fs.target network.target
[Service]
Type=simple
User=root
ExecStartPre=-/bin/mkdir -p /media/Plexdrive
ExecStart=/usr/local/bin/plexdrive mount \
  -c /root/.plexdrive \
  -o allow_other \
  /media/Plexdrive
ExecStop=/bin/fusermount -u -z /media/Plexdrive
ExecStop=/bin/rmdir /media/Plexdrive
Restart=always
[Install]
WantedBy=default.target

Save with Ctrl-O, Enter, then Ctrl-X. You will need to enable the service. Type

sudo systemctl enable plexdrive.service

Reload the service so it'll work:

sudo systemctl daemon-reload

Time to check our caching process! Go back to the screen you placed in the background:

screen -r plexdrive

I did not find it necessary to wait till the entire scanning process was done. Once mine slowed down to one or two items at the time, I found I could reboot safely and let the service take over. First detach your screen (Ctrl-A, D), then reboot.

sudo reboot

Click away the PuTTY session, it has become unresponsive.

We're almost there! All that needs to be done now is Part 6 - Making it all come together.


Comments