Skip to content

Instantly share code, notes, and snippets.

@naamancampbell
Last active September 1, 2021 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naamancampbell/adae77f944611b1e0139f2763eacef1c to your computer and use it in GitHub Desktop.
Save naamancampbell/adae77f944611b1e0139f2763eacef1c to your computer and use it in GitHub Desktop.
rclone OneDrive User Mount - Ubuntu 21.04 Hirsuite Hippo

rclone OneDrive User Mount

Ubuntu 21.04 Hirsuite Hippo

OneDrive rclone remote setup

  • Install rclone and run wizard to setup new "OneDrive" remote:
sudo apt install -y rclone
rclone config
# Enter n for new remote
# Select Microsoft OneDrive
  • Accept all defaults for OneDrive personal accounts
  • Enter q to quit config wizard
  • Test OneDrive remote:
rclone lsd OneDrive:
          -1 2021-07-21 18:29:23        38 Documents
          -1 2015-05-25 20:09:58         1 Music
          -1 2021-04-08 08:24:38        14 Pictures
          -1 2015-09-05 16:43:49         1 Videos
  • Test OneDrive mount (CTRL+C to stop):
cd ~
mkdir OneDrive
rclone --vfs-cache-mode writes mount OneDrive:/ OneDrive

User-mode mount on startup

mkdir -p ~/.config/systemd/user
wget -O ~/.config/systemd/user/rclone@.service https://gist.githubusercontent.com/naamancampbell/adae77f944611b1e0139f2763eacef1c/raw/e227556c7b701692b98d9468963cb771afc93346/rclone@.service
wget -O ~/.config/rclone/OneDrive.env https://gist.githubusercontent.com/naamancampbell/adae77f944611b1e0139f2763eacef1c/raw/e227556c7b701692b98d9468963cb771afc93346/OneDrive.env
sed -i -e "s/USERNAME/$USERNAME/" ~/.config/rclone/OneDrive.env
# test mount config
systemctl --user start rclone@OneDrive
ls -l ~/OneDrive
# enable mount on startup
systemctl --user enable rclone@OneDrive
REMOTE_NAME=OneDrive
MOUNT_DIR=/home/USERNAME/OneDrive
RCLONE_MOUNT_VFS_CACHE_MODE=writes
[Unit]
Description=RClone mount of users remote %i using filesystem permissions
Documentation=http://rclone.org/docs/
After=network-online.target
[Service]
Type=notify
#Set up environment
Environment=REMOTE_NAME="%i"
Environment=REMOTE_PATH="/"
Environment=MOUNT_DIR="%h/%i"
Environment=POST_MOUNT_SCRIPT=""
Environment=RCLONE_CONF="%h/.config/rclone/rclone.conf"
Environment=RCLONE_TEMP_DIR="/tmp/rclone/%u/%i"
Environment=RCLONE_RC_ON="false"
#Default arguments for rclone mount. Can be overridden in the environment file
Environment=RCLONE_MOUNT_ATTR_TIMEOUT="1s"
#TODO: figure out default for the following parameter
Environment=RCLONE_MOUNT_DAEMON_TIMEOUT="UNKNOWN_DEFAULT"
Environment=RCLONE_MOUNT_DIR_CACHE_TIME="60m"
Environment=RCLONE_MOUNT_DIR_PERMS="0777"
Environment=RCLONE_MOUNT_FILE_PERMS="0666"
Environment=RCLONE_MOUNT_GID="%G"
Environment=RCLONE_MOUNT_MAX_READ_AHEAD="128k"
Environment=RCLONE_MOUNT_POLL_INTERVAL="1m0s"
Environment=RCLONE_MOUNT_UID="%U"
Environment=RCLONE_MOUNT_UMASK="022"
Environment=RCLONE_MOUNT_VFS_CACHE_MAX_AGE="1h0m0s"
Environment=RCLONE_MOUNT_VFS_CACHE_MAX_SIZE="off"
Environment=RCLONE_MOUNT_VFS_CACHE_MODE="off"
Environment=RCLONE_MOUNT_VFS_CACHE_POLL_INTERVAL="1m0s"
Environment=RCLONE_MOUNT_VFS_READ_CHUNK_SIZE="128M"
Environment=RCLONE_MOUNT_VFS_READ_CHUNK_SIZE_LIMIT="off"
#TODO: figure out default for the following parameter
Environment=RCLONE_MOUNT_VOLNAME="UNKNOWN_DEFAULT"
#Overwrite default environment settings with settings from the file if present
EnvironmentFile=-%h/.config/rclone/%i.env
#Check that rclone is installed
ExecStartPre=/usr/bin/test -x /usr/bin/rclone
#Check the mount directory
ExecStartPre=/usr/bin/test -d "${MOUNT_DIR}"
ExecStartPre=/usr/bin/test -w "${MOUNT_DIR}"
#TODO: Add test for MOUNT_DIR being empty -> ExecStartPre=/usr/bin/test -z "$(ls -A "${MOUNT_DIR}")"
#Check the rclone configuration file
ExecStartPre=/usr/bin/test -f "${RCLONE_CONF}"
ExecStartPre=/usr/bin/test -r "${RCLONE_CONF}"
#TODO: add test that the remote is configured for the rclone configuration
#Mount rclone fs
ExecStart=/usr/bin/rclone mount \
--config="${RCLONE_CONF}" \
#See additional items for access control below for information about the following 2 flags
# --allow-other \
# --default-permissions \
--rc="${RCLONE_RC_ON}" \
--cache-tmp-upload-path="${RCLONE_TEMP_DIR}/upload" \
--cache-chunk-path="${RCLONE_TEMP_DIR}/chunks" \
--cache-workers=8 \
--cache-writes \
--cache-dir="${RCLONE_TEMP_DIR}/vfs" \
--cache-db-path="${RCLONE_TEMP_DIR}/db" \
--no-modtime \
--drive-use-trash \
--stats=0 \
--checkers=16 \
--bwlimit=40M \
--cache-info-age=60m \
--attr-timeout="${RCLONE_MOUNT_ATTR_TIMEOUT}" \
#TODO: Include this once a proper default value is determined
# --daemon-timeout="${RCLONE_MOUNT_DAEMON_TIMEOUT}" \
--dir-cache-time="${RCLONE_MOUNT_DIR_CACHE_TIME}" \
--dir-perms="${RCLONE_MOUNT_DIR_PERMS}" \
--file-perms="${RCLONE_MOUNT_FILE_PERMS}" \
--gid="${RCLONE_MOUNT_GID}" \
--max-read-ahead="${RCLONE_MOUNT_MAX_READ_AHEAD}" \
--poll-interval="${RCLONE_MOUNT_POLL_INTERVAL}" \
--uid="${RCLONE_MOUNT_UID}" \
--umask="${RCLONE_MOUNT_UMASK}" \
--vfs-cache-max-age="${RCLONE_MOUNT_VFS_CACHE_MAX_AGE}" \
--vfs-cache-max-size="${RCLONE_MOUNT_VFS_CACHE_MAX_SIZE}" \
--vfs-cache-mode="${RCLONE_MOUNT_VFS_CACHE_MODE}" \
--vfs-cache-poll-interval="${RCLONE_MOUNT_VFS_CACHE_POLL_INTERVAL}" \
--vfs-read-chunk-size="${RCLONE_MOUNT_VFS_READ_CHUNK_SIZE}" \
--vfs-read-chunk-size-limit="${RCLONE_MOUNT_VFS_READ_CHUNK_SIZE_LIMIT}" \
#TODO: Include this once a proper default value is determined
# --volname="${RCLONE_MOUNT_VOLNAME}"
"${REMOTE_NAME}:${REMOTE_PATH}" "${MOUNT_DIR}"
#Execute Post Mount Script if specified
ExecStartPost=/bin/sh -c "${POST_MOUNT_SCRIPT}"
#Unmount rclone fs
ExecStop=/bin/fusermount -u "${MOUNT_DIR}"
#Restart info
Restart=on-success
RestartSec=10
[Install]
WantedBy=default.target
# COPIED from https://github.com/rclone/rclone/wiki/Systemd-rclone-mount
# 2021-07-24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment