OneDrive on Ubuntu Linux(7 min read)

UPDATE: Thanks to a comment from @abraunegg about the OneDrive Client for Linux (https://abraunegg.github.io/), I installed and have been using that instead. It features full 2-way sync and just runs in the background. I have set it up to sync both my personal OneDrive, and my work account OneDrive, and it has been working great. If you mostly want OneDrive (and not the other features of rclone), then I would recommend OneDrive Client for Linux, https://abraunegg.github.io/

Verdict (so far): Not fully stable, but somewhat usable.

So, I decided to try and use Linux (Ubuntu, now 19.10, although I started with 18.04 LTS) as my host operating system for my new laptop, a HP ZBook Studio x360 G5, as most of my client work is done in virtual machines anyway, that don't really care what the host is.

On my previous Windows machines, I have used OneDrive for cloud storage for a long time now, and it is really good to start up a brand new computer, sign in, and all my files just appear over the next day or two.

Normally, OneDrive is the first thing (it is easy), but this time I did a few others, like setting up virtual machines for work, before looking for a solution for OneDrive.

The solution I have so far is using rclone, and I thought I would document my setup.

rclone

After looking through several options for syncing OneDrive, some commercial, it looked like rclone was the most widely used.

There was a version available in the Ubuntu store, but it was a bit old, so I downloaded the latest (1.51 at the time) and installed.

Setting up a remote to connect to my personal OneDrive was pretty straight forward with 'rclone config' following the wizard.

Syncing and copying

Basic operations for rclone are syncing (one way, mirrors deletes as well as new or edit), and copying (one way, additive).

Neither is really the solution I wanted, so looking further I found mounting, and then also the cache backend.

Mounting

'rclone mount' allows you to mount a remote as a local drive. It includes a bunch of virtual file system caching options designed to improve compatibility with programs. This allows programs to directly load files from the remote without having to worry so much about the lag.

One drawback of mounting, however, is that the documentation says it only works while online.

The documentation did, however, mention a cache backend that could be used separately, or in conjuction with, VFS caching, and that allowed offline upload.

To automatically mount, you can set up a systemd configuration service; I tried the global service first (on machine start up), but then changed to a user configuration.

This means it connects to OneDrive when I sign in, and then disconnects on sign out; I only use it while signed in.

Cache backend

The cache backend is set up as a cache remote that points to a cloud remote.

From the features, it appears to be designed mostly for video caching solutions, as it has integration options for a Plex (video streaming) server.

I am not using it for that, but it did have an advanced option for offline uploading, something that seemed what I wanted.

Verdict (so far)

It does work, but is no where near as stable as OneDrive on Windows, plus has no real offline/two-way sync (yet).

  • OneDrive can only be accessed while online. If offline, you see nothing; it is simply a view to the remote file system.
  • File operations (copy to/from the mount) are fine, but some applications have trouble opening or creating files.
  • I have now increase VFS cache to full, and still get problems. e.g. saving a new file from LibreOffice will display errors and take a long time to appear.
  • I had trouble even opening files in LibreOffice until I increased the mount VFS caching from the default (none) to at least writes.
  • Applications, e.g. LibreOffice, will lock up on saving too often to be comfortable; the UI freezes, and you can't even save elsewhere. This seems to happen more often using backend cache, although it still occurs without it.
  • The "offline upload" of the cache backend is for uploading large files, e.g. movies, where you copy the file in while online, it inserts into the cache, and does the upload in the background. The documentation says it will continue across restarts, etc, although I haven't tested this. You still need to be online for the initial copy though.

My work around so far for new files has been to create new documents in a local folder, close them, copy them across to OneDrive, and then open the file.

For crash-on-save, I just have to save more often and hope I don't lose too much.

When it freezes, the LibreOffice (or other) process becomes unresponsive, and in System Monitor sometimes shows as "Uninterruptible". Using the file explorer, the rest of OneDrive is okay, but the folder I am working in doesn't load.

To fix, I have been stopping the rclone service, check the status and if there was an error (usually if it is frozen) manually cleaning up the mount point, and then restarting:

 systemctl --user stop rclonemount-OneDrive.service systemctl --user status rclonemount-OneDrive.service fusermount -u /home/(user)/OneDrive systemctl --user start rclonemount-OneDrive.service 

Sometimes this will unfreeze apps, but sometimes they will crash. I've also had them crash and then the files recovered by LibreOffice, although I wouldn't rely on this.


Set up instructions

Set up a OneDrive remote, a caching remote, and then mount the cache.

1) Use 'rclone config' to set up a onedrive remote; I called mine 'OneDrive'

2) Test it works, e.g. 'rclone lsd OneDrive:'

3) Use 'rclone config' to set up a cache remote. I called mine 'OneDrive-cache', and just pointed it at the root 'OneDrive:/' (although the documentation recommends a subfolder, I just use the root in Windows before and I wanted it similar).

During config, select the advanced options and set up tmp_upload_path, in my case to point to '/home/(user)/.tmp-upload/OneDrive'

Note: Replace (user) with your actual user name, in the examples.

4) Test it works, e.g. 'rclone lsd OneDrive-cache:'

5) Create a mount point, I used '/home/(user)/OneDrive', but you could also use a more traditional /mnt if you wanted.

mkdir ~/OneDrive

6) Test mounting the cache works (this will run in the console; CTRL+C to end when you have tested it works):

rclone mount OneDrive-cache: /home/(user)/OneDrive -vv

Note that to get files to open properly I needed to tweak the VFS cache options (details below); the above is just to test it is working.

Also, the cache didn't add any features I needed and seemed to make the system less stable, so I have been trying both it and mounting OneDrive: directly.

7) Set up a systemd service to automatically mount the cache. I am familiar with using vi as my editor, but you can use something different if you want.

You need to create a user service entry for systemd:

vi /home/<user>/.config/systemd/user/rclonemount-OneDrive.service

 [Unit] Description=rclone mount for OneDrive: [Service] Type=simple ExecStart=/usr/bin/rclone mount OneDrive: /home/&amp;amp;amp;lt;user&amp;amp;amp;gt;/OneDrive -vv --config /home/&amp;amp;amp;lt;user&amp;amp;amp;gt;/.config/rclone/rclone.conf --vfs-cache-mode full ExecStop=/bin/fusermount -u /home/&amp;amp;amp;lt;user&amp;amp;amp;gt;/OneDrive Restart=on-abort [Install] WantedBy=default.target 

You can use 'mount OneDrive-cache:' instead of 'mount OneDrive:', if you want to try the backend cache.

Note that you need full paths for commands and the config file.

8) Enable

systemctl --user enable rclonemount-OneDrive.service

9) Test that it starts

systemctl --user start rclonemount-OneDrive.service


Troubleshooting the systemd job

If the problem is with the job, you can check the output of the attempt to start from, e.g. if there is a typo or issue with the command:

systemctl --user status rclonemount-OneDrive.service


Using a systemd mount

To keep things simple, I ran rclone directly as a systemd service, but there is also a helper script available to set it up as a mount dependency instead, i.e. rclone-OneDrive.mount


Backup sync for offline access

For situations where I might want to access files while offline, I also have a script that uses rclone to do a regular one-way sync of some key folders (those I would need for reference offline).


Future

Continue testing the stability and whether using the backend cache is better or worse, or there are any other parameters I can tweak.

The rclone website also mentions two-way sync is planned for some time in the future, so that would be good to have.

2 thoughts on “OneDrive on Ubuntu Linux(7 min read)

    1. Hey thanks, that looks great, and what I had been looking for.

      I had found some paid products that did OneDrive sync, but no open source ones, only a lot of references to rclone.

      Will definitely be installing and checking it out!

Leave a Reply

Your email address will not be published. Required fields are marked *