How To Mount OneDrive In Linux Using Rclone (Supports Business And Personal Accounts)

Microsoft OneDrive doesn't have an official client application for Linux, but you can access your OneDrive files from a file manager on Linux thanks to a third-party tool called Rclone. This article explains how to mount OneDrive in Linux using Rclone.

OneDrive mounted Linux

Microsoft OneDrive (previously SkyDive) is a cloud storage / file synchronization service, part of the Office Online suite. It offers 5 GB of storage free of charge, with additional storage available with a paid subscription.

Rclone is "rsync for cloud storage". It can synchronize files not only from your filesystem to the cloud (and the other way around), but also from one cloud storage service to another. The tool supports a wide variety of cloud storage services, from Google Drive to Amazon Drive and S3, ownCloud, Yandex Disk, and many others.

Besides on demand file synchronization, Rclone supports mounting any supported cloud storage systems as a file system with FUSE. While this feature exists for some time, it's still considered experimental, so use it with care.

After mounting Microsoft OneDrive, you'll be able to access it from your file manager, be it Nautilus (Files), Nemo, Caja, etc. The behavior is similar to the one explained on our article about Google Drive: Mounting Google Drive On Xfce Or MATE Desktops (Ubuntu, Linux Mint). As a side note, you can also use Rclone to mount Google Drive in Linux.

Rclone supports OneDrive for Business / Office 365. However, if the organization is in an unmanaged state (not verified by the domain owner), you won't be able to mount OneDrive using Rclone with FUSE. Such accounts can be used with Sharepoint though. See this page for more information.

OneDrive Rclone mount limitations:

  • Any files deleted with Rclone are moved to the trash because Microsoft doesn't provide an API to permanently delete files or empty the trash
  • OneDrive is case insensitive, so you can't have two files with the same names but different cases in the same folder (example: MyFile.txt and myfile.txt can't be in the same folder).
  • OneDrive doesn't support some characters that are not allowed in filenames on Windows operating systems. Rclone maps these characters to identical looking Unicode equivalents, like ? to

Also, renaming folders doesn't seem to work, at least on my system. I'm not sure if this is a Rclone issue or limitation, since Rclone is supposed to support renaming folders in general.

These instructions should work not only on any Linux distribution (from Ubuntu, Linux Mint, or Debian, to Arch Linux, Fedora, openSUSE, and so on), but also on FreeBSD and macOS. It even works on Windows but you'll need WinFsp.

Related: Cryptomator Secures Your Cloud Storage Data (Open Source, Multi-Platform Client-Side Encryption Tool)

Mount OneDrive as a file system in Linux using Rclone


1. Install Rclone.

You can download Rclone binaries from here. For Linux you'll find generic binaries, as well as DEB and RPM binaries.

I don't recommend installing the Rclone Snap package (even if you use Ubuntu), because it fails to find the fusermount executable, even if it's installed with --classic. When using the Snap package, you'll get an error similar to the one below when trying to mount a cloud storage service supported by Rclone:

failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH

This was apparently fixed a while back but it looks like the issue occurs again.

2. Add a new OneDrive remote to Rclone. The instructions below may seem long but it only takes a few seconds to set it up.

To start adding the OneDrive remote to Rclone, use this command to enter the Rclone configuration mode:

rclone config

Rclone will display a list of options from which you need to select the New remote option by entering n and pressing the Enter key:

$ rclone config
Current remotes:

Name                 Type
====                 ====
mega                 mega

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> n

Next, it will prompt you to enter a name for the new remote. Enter the name you want to use (I'm using onedrive as the name in these instructions):

name> onedrive

After pressing the Enter key, a list of supported cloud storage services is displayed. You need to select the Microsoft OneDrive option by entering its corresponding number (18 right now but it may change in the future):

Type of storage to configure.
Choose a number from below, or type in your own value
 1 / A stackable unification remote, which can appear to merge the contents of several remotes
   \ "union"
 2 / Alias for a existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Dropbox
   \ "dropbox"
 9 / Encrypt/Decrypt a remote
   \ "crypt"
10 / FTP Connection
   \ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
12 / Google Drive
   \ "drive"
13 / Hubic
   \ "hubic"
14 / JottaCloud
   \ "jottacloud"
15 / Local Disk
   \ "local"
16 / Mega
   \ "mega"
17 / Microsoft Azure Blob Storage
   \ "azureblob"
18 / Microsoft OneDrive
   \ "onedrive"
19 / OpenDrive
   \ "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
21 / Pcloud
   \ "pcloud"
22 / QingCloud Object Storage
   \ "qingstor"
23 / SSH/SFTP Connection
   \ "sftp"
24 / Webdav
   \ "webdav"
25 / Yandex Disk
   \ "yandex"
26 / http Connection
   \ "http"
Storage> 18

For the next two steps, press Enter without entering any information since there's no need to enter the Microsoft App Client ID or Secret:

Microsoft App Client Id - leave blank normally.
client_id> 
Microsoft App Client Secret - leave blank normally.
client_secret>

Next, you'll be asked if you want to edit advanced config. Enter "n" unless you have some advanced settings in mind:

Edit advanced config? (y/n)
y) Yes
n) No
y/n> n

Depending on your setup, you'll have to enter auto configuration or manual for the next step. For most users, type y to use the auto configuration:

Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> y

A new tab should open in your default web browser, asking you to give Rclone access to your OneDrive account. Allow it and you can close the tab.

Rclone runs a webserver on your local machine (on port 53682) to retrieve the authentication token. You may need to unblock it temporarily if you use a firewall.

Now you'll have to enter your account type. For most users, enter 1, which corresponds to a OneDrive Personal or Business account:

Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Type in driveID
   \ "driveid"
 4 / Type in SiteID
   \ "siteid"
 5 / Search a Sharepoint site
   \ "search"
Your choice> 1

You'll see an account (multiple in some special cases) listed, like this:

Found 1 drives, please select the one you want to use:
0:  (personal) id=f119f51f0a00000
Chose drive to use:> 0

Enter 0 and press Enter.

You should now reach this screen - enter y to continue.

Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=0f119f51f000000
Is that okay?
y) Yes
n) No
y/n> y

Now you'll need to check if everything is correct and save the settings by typing y:


[onedrive]
type = onedrive
token = {"access_token":"GoKSt5YMioiuCWX1KOuo8QT0Fwy+Y6ZeX7M","token_type":"bearer","refresh_token":"7OMvoEAO3l*8BbhS2AMxpTbJW0Y6np9cdql!bwEdYAhJ6XBG0tnR0UK","expiry":"2018-07-26T15:15:13.696368366+03:00"}
drive_id = f119f51f0a00000
drive_type = personal
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

And finally, quit the Rclone configuration by typing q:

Current remotes:

Name                 Type
====                 ====
onedrive             onedrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

3. Create a new folder on your system that will be used to mount Microsoft OneDrive.

I suggest creating a folder called OneDrive in your home directory. The instructions below will be using this as the mount point (~/OneDrive).

4. Mount OneDrive (with Rclone using FUSE) as a file system.

To mount Microsoft OneDrive using Rclone, use this command:

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

Where onedrive is the name of the Rclone remote, followed by : (we've used exactly onedrive in the instructions above so you can use precisely that for the command), and ~/OneDrive is the folder where you want to mount OneDrive on your system.

The mount command uses --vfs-cache-mode writes because according to the Rclone documentation, "many applications won't work with their files on an Rclone mount" without this or --vfs-cache-mode full. The Rclone file caching section explains this in detail.

You can stop and unmount it by pressing Ctrl + C to close Rclone.

5. (Optional) Mount OneDrive on system startup

To mount OneDrive on startup, open Startup Applications. This depends on the desktop environment you're using so I'll list some of them below and how to access startup applications to add a new entry:

  • Gnome / Unity: search for Startup Applications in the Dash / applications thingy, and in Startup Applications click Add
  • Xfce: launch Session and Startup from the menu, go to the Application Autostart tab and click Add
  • MATE: launch Startup Applications from the menu, and click Add

After clicking Add, use the following:

  • Name: Rclone OneDrive Mount
  • Command: sh -c "rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive"

There are other ways of mounting OneDrive automatically, like adding a line in your /etc/fstab file, using systemd, etc. As a starting point you can use the examples from google-drive-ocamlfuse, as they should also work for Rclone.

16 comments:

  1. This was incredibly helpful. Thank you!

    ReplyDelete
  2. So the mounting part works... how to have it auto-mount via CLI ? can this be added to fstab? (my server is headless )

    ReplyDelete
    Replies
    1. The easiest way to mount it would be to add this to ~/.profile:

      mount | grep "${HOME}/OneDrive" >/dev/null || rclone --vfs-cache-mode writes mount onedrive: "${HOME}/OneDrive"

      Delete
  3. Excellent! And simple to do. Odlično!

    ReplyDelete
  4. отличная статья! это действительно работает с onedrive

    ReplyDelete
  5. Thanks very much for this tutorial. Very straightforward and easy to follow, even though the rclone configuration was slightly different (October 2018, version 1.44)

    ReplyDelete
    Replies
    1. I updated the config steps to reflect the changes in the latest Rclone, thanks.

      Delete
  6. this was awesome and worked until getting to the part where I am tring to add it to start up. I am using manjaro gnome and I found a startup applications in gnome tweaks but it doesnt have anyway to add that command.

    ReplyDelete
    Replies
    1. Another way of adding it to startup is to create a file called onedrive-rclone.desktop in ~/.config/autostart/ with the following contents:

      [Desktop Entry]
      Type=Application
      Exec=sh -c "rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive"
      Hidden=false
      NoDisplay=false
      X-GNOME-Autostart-enabled=true
      Name=OneDrive Rclone mount

      Delete
  7. This was very helpful, however I am having problems with mounting Onedrive automatically on system start. I used the code from the example, and it works if you restart shortly afterwards, but there appears to be a problem with the app's access to OneDrive expiring, so that it no longer works later on. When I try to mount onedrive manually I receive the following error:
    "Failed to create file system for "onedrive:": failed to get root: Get https://redhalldudley-my.sharepoint.com/_api/v2.0/drives/me/root:/: oauth2: token expired and refresh token is not set"

    ReplyDelete
  8. Error in Deepin: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
    2018/11/06 10:34:39 Failed to create file system for "onedrive:": didn't find section in config file

    ReplyDelete
    Replies
    1. It looks like you're trying to use Rclone as root. That's not recommended and why this doesn't work for you. Try using it as a regular user and it should work.

      Delete
  9. This is very well done, I've been looking for this for some time, worked first time. Kudos!

    ReplyDelete
  10. Thank you. You don't know how much this means to me. I can now cast off my Windows VM and blow a great raspberry at the vile OS. I feel rather emotional now.

    ReplyDelete
  11. "OneDrive doesn't support some characters that are not allowed in filenames on Windows operating systems. Rclone maps these characters to identical looking Unicode equivalents, like ? to ?" That sounds pretty much like a disaster to me. If you can't do it right, don't do it at all, not something that will create problems down the line!

    ReplyDelete