Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active June 20, 2024 15:14
Show Gist options
  • Save plembo/c07187fb63c1369b7320a6985113241a to your computer and use it in GitHub Desktop.
Save plembo/c07187fb63c1369b7320a6985113241a to your computer and use it in GitHub Desktop.
Rclone mount onedrive

Using rclone to mount OneDrive on Linux

Introduction

Yes. Use rclone to mount OneDrive to a folder in your home directory on Linux. "How to Mount OneDrive In Linux Using Rclone (Supports Business and Personal Accounts". Linux Uprising, 17 March 2020, https://www.linuxuprising.com/2018/07/how-to-mount-onedrive-in-linux-using.html.

I really like this solution. The availability of 1 Gb/s bandwidth (thank you, Google Fiber!) at home has made the difference for me. Although I currently have this set up on both my personal desktop and laptop, it obviously doesn't work as well outside the high bandwidth envelope of my home network.

Rclone is my weapon of choice because it has proven itself both stable and performant over the years. It also has many options to improve both, and the doc for rclone mount is excellent.

Procedure

The procedure (used on Ubuntu Desktop 22.04 LTS with the latest rclone project deb package):

  1. Create "OneDrive" folder at root of $HOME.

  2. Set up a "onedrive" remote using rclone config.

  3. Test mounting:

$ rclone mount --vfs-cache-mode writes onedrive: ~/OneDrive

I have also created a pair of shell scripts under ~/bin (in my $PATH) to make mounting and unmounting easier:

onedrive-mount

#!/bin/bash
# Mount onedrive remote at ~/OneDrive in background
/usr/bin/rclone \
--vfs-cache-mode writes \
mount onedrive: ${HOME}/OneDrive --daemon

onedrive-umount

#!/bin/bash
# Unmount the rclone mounted onedrive at ~/OneDrive
/bin/fusermount -uz ${HOME}/OneDrive

Mounts continue to exist even after logging out, so you have to explicitly unmount. This is especially important if you do regular backups of your home directory (you do, don't you?).

Optional mounting automatically on login (not recommended)

I got this working, but eventually removed it because I was unable to trigger an unmount on session exit.

Create a "onedrive-mount.desktop" file under ~/.config/autostart to automatically mount on login with the following contents:

[Desktop Entry]
Type=Application
Exec=/home/philip/bin/onedrive-mount
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=OneDrive Mount
Name=OneDrive Mount
Comment[en_US]=Mounts personal OneDrive
Comment=Mounts personal OneDrive                                     

Change "X-GNOME-Autostart-enabled" to "false if you don't want it to run on every login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment