Mounting OneDrive in Linux using Rclone

Miko Nunez

--

☁️ OneDrive and the Cloud

OneDrive is a popular cloud-based file storage service provided by Microsoft and it is included in Microsoft’s Office365 subscription. The system works seamlessly in Windows, as you might expect. Microsoft also provides a macOS client to cater to Apple users. However, there’s no official Linux client for OneDrive or any of Microsoft’s Office365 applications. The Office365 applications can be emulated using Wine or similar software but it’s not a particularly graceful solution for cloud-based file storage.

Fortunately, Rclone exists! This article will guide you on what Rclone is and how to use it to mount OneDrive in a Linux system.

🧑‍💻 Rclone

Rclone is a command-line program used for managing and synchronizing files between various cloud storage providers and local filesystems. It stands for “rsync for cloud storage,” and it offers a versatile and efficient way to interact with cloud storage services through a command-line interface.

Installation

The command below curls and runs the installation script of rclone:

sudo -v ; curl https://rclone.org/install.sh | sudo bash

Config

With rclone installed, it’s time to configure OneDrive as a remote. This can be done using the `rclone config` command. Detailed instructions are available from the official documentation: https://rclone.org/onedrive/.

Mounting the OneDrive Remote

After the OneDrive remote is configured, we can mount it to directory in the local filesystem. This allows you to access your OneDrive files from your Linux system:

rclone mount [remote]: [mount path] --vfs-cache-mode writes

Replace [remote] with the name you set for your OneDrive remote. Additionally, the mount path should be an existing, empty, directory

By running this command, you will have successfully mounted your OneDrive in your local filesystem!

Un-mounting

Terminating the process from the command in the above section *should* automatically unmount the remote. However, there are some instances when that doesn’t happen. When you encounter such instances, you can manually unmount the remote using the command below:


fusermount -u [mount path]

⚙️ Automate the process!

It would be inconvenient to have to manually run the command every time you want to access your files on the OneDrive remote. But it is easy to automatically mount the remote on startup using a systemd service.

Use nano, vim, or your text editor of choice to create and edit a new “rclone-mount.service” file in the systemd directory:


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

Paste the following to the newly-created file:


[Unit]
Description=RClone Mount OneDrive
AssertPathIsDirectory=[mount path]
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount --vfs-cache-mode writes [remote]: [mount path]
ExecStop=/bin/fusermount -u [mount path]
User=[user]
Restart=on-failure
RestartSec=10

[Install]
WantedBy=default.target

Make sure you change the mount path and user fields to match your’s!

Before enabling the service, we need to give the user permission to use fusermount without having to put a password. This may be a security risk for some users. Proceed with caution.

Use visudo to change user permissions:


sudo visudo

Paste this at the bottom:


[user] ALL=(ALL) NOPASSWD: /bin/fusermount -u

Now, we can enable the service!

Reload systemd:

sudo systemctl daemon-reload

Enable the service:

sudo systemctl enable rclone-mount.service

Start the service:

 systemctl start rclone-mount.service

That should do it! You should now have access to your OneDrive!

--

--

Miko Nunez
Miko Nunez

Written by Miko Nunez

Threat Intelligence and all things cyber

Responses (2)