Monday, July 30, 2018

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

https://www.linuxuprising.com/2018/07/how-to-mount-onedrive-in-linux-using.html

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 (16 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 / Alias for a existing remote
   \ "alias"
 2 / Amazon Drive
   \ "amazon cloud drive"
 3 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
   \ "s3"
 4 / Backblaze B2
   \ "b2"
 5 / Box
   \ "box"
 6 / Cache a remote
   \ "cache"
 7 / Dropbox
   \ "dropbox"
 8 / Encrypt/Decrypt a remote
   \ "crypt"
 9 / FTP Connection
   \ "ftp"
10 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
11 / Google Drive
   \ "drive"
12 / Hubic
   \ "hubic"
13 / Local Disk
   \ "local"
14 / Mega
   \ "mega"
15 / Microsoft Azure Blob Storage
   \ "azureblob"
16 / Microsoft OneDrive
   \ "onedrive"
17 / OpenDrive
   \ "opendrive"
18 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
19 / Pcloud
   \ "pcloud"
20 / QingCloud Object Storage
   \ "qingstor"
21 / SSH/SFTP Connection
   \ "sftp"
22 / Webdav
   \ "webdav"
23 / Yandex Disk
   \ "yandex"
24 / http Connection
   \ "http"
Storage> 16

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>

Now you can choose the OneDrive account type (enter b for Business or p for Personal OneDrive accounts):

Remote config
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p

Depending on your setup, you'll have to enter auto configuration or manual for the next step. For desktop 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 need to check if everything is correct and save the settings by typing y:


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

And finally, exit 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.

No comments:

Post a Comment