Frequently Asked Questions Menu

Configuring OneDrive access on *NIX machines

Swinburne University uses Microsoft Office365 for Business. As well as being allowed to install and run Office applications on your local Windows Desktop, you are also able to access web-based versions of the Office applicaitons via https://login.microsoftonline.com. This is useful if you need to edit Word/Excel/Powerpoint from your *NIX desktop

Another included feature with Microsoft Office365 for Business is that all University staff get 1TB of storage on the Microsoft OneDrive storage platform. While you may have misgiving about storing files on external servers, these documents can be shared with other Swinburne users and may be convenient for some people. This feature can be particularly useful for any paperwork/documentation you need to prepare for our administrative staff

This page has instructions on how to access your OneDrive files natively from your *NIX machine without having to download/upload via the OneDrive web interface

The tool we will be installing to access OneDrive is Rclone. After configuring Rclone for your OneDrive account, you then have the choice of uploading/downloading individual files, maintaining a local sync of the remote OneDrive (sub-)folder(s), and/or mouting remote OneDrive (sub-)folder(s) to save local disk space

Installing and Configuring RClone

In this section there will be a list of instructions on how to to install Rclone and configure it to connect to your OneDrive account. Other sections of this page will show you how to mount and access the files stores on OneDrive

Select your *NIX distribution for a customised set of instructions:

Installation

At the time of writing, the latest version of Rclone is v1.53.3.

BSD - Installing Rclone

a href="https://rclone.org">Rclone can only be installed via ports on BSD. To install Rclone execute (as root)


cd /usr/ports/net/rclone

make && make install clean

Gentoo Linux - Installing Rclone

Rclone is installed via the Gentoo portage system. The following command needs to be executed (as root)

emerge rclone

Connecting to OneDrive

OneDrive is configured using your user account. Post-installation, there is no further need to do anything logged in as root. Rclone is used in configuration mode to create and manage your account with OneDrive (and other remote filesystems) and then in a second mode to access those connections. Here we will describe the process to create/manage your OneDrive account within Rclone

From the command line, as your regular user, execute:

 

rclone config

The Rclone application will tell you that there is no config file and create a default one for you (~/.config/rclone/rclone.conf). You will then be presented with a menu:

 

No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config

Select n to create a new remote, then use the following options:

Option Purpose Enter Value
name What the remote storage will be called by Rclone. Using the example here will result in a remote storage called OneDrive: OneDrive
Storage The type of remote storage to configure 13 - Microsoft OneDrive
client_id Unknown purpose Leave blank for OneDrive
client_secret Unknown purpose Leave blank for OneDrive
OneDrive account type Swinburne uses OneDrive for Business. You can repeat this process with a personal OneDrive account if you have one b
Use auto config Auto config works, so lets use it y

Rclone will create a local browser window asking you to login to OneDrive. Your login is required for OneDrive to provide Rclone with an access token for future connections. Once you login via the browser, the Rclone program will continue by informing you of the newly downloaded token. You then need to accept the token. Finally you will be back at the configuration menu from which you can exit the program

 

Got code
2018/02/09 08:03:18 NOTICE: Found API v2.0 endpoint https://liveswinburneeduau-my.sharepoint.com/_api/v2.0/me
--------------------
[OneDrive]
client_id = 
client_secret = 
token = {"access_token":"XXXXXXX"}
resource_url = https://liveswinburneeduau-my.sharepoint.com/
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
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

If you have reached this far, you have successfully configured your OneDrive account with Rclone. To test whether it works you can get a file listing of your OneDrive folder by issuing:

 

rclone ls OneDrive:

and a directory listing of your OneDrive folder by issuing:

 

rclone lsd OneDrive:

The rest of this page assumes you have called your OneDrive remote OneDrive. If you have chosen a different name, you will need to adjust the instructions appropriately

Copying files to/from OneDrive

This section is useful if you wish to copy or clone files or directories from your local file system to your OneDrive share or copy/clone files/directories from OneDrive to your local file system

"rclone copy" Command

As per the RClone documentation (rclone copy), the rclone copy command performs the following tasks:

  • Copy the source to the destination
  • Doesn't transfer unchanged files, testing by size and modification time or MD5SUM
  • Doesn't delete files from the destination

Consider a sub-folder in your OneDrive account called I4T. In order to make a complete copy of this sub-folder to ~/OneDrive_subfoldertest, issue the command (as a regular user):

 

rclone copy OneDrive:I4T ~/OneDrive_subfoldertest

When you have edited local files and/or created new ones, they can be copied back to OneDrive by issuing the command (as a regular user):

 

rclone copy ~/OneDrive_subfoldertest OneDrive:I4T

You can also specify deeper folder names on OneDrive and to the local directory

"rclone sync" Command

As per the RClone documentation (rclone sync), the rclone sync command performs the following tasks:

  • Sync the source to the destination, changing the destination only
  • Doesn't transfer unchanged files, testing by size and modification time or MD5SUM
  • Destination is updated to match source, including deleting files if necessary

Note the difference in that destination files may be deleted

The corresponding commands to sync the files in either direction are:
 

rclone sync OneDrive:I4T ~/OneDrive_subfoldertest

rclone sync ~/OneDrive_subfoldertest OneDrive:I4T

This version of the rclone command behaves similarly to the rsync command except with configured remote/cloud based services. Note that you must either manually sync directories and/or schedule a regular cron job to do so. If you would like to automatically keep the folders in sync, you might be more interested in Mounting a remote OneDrive directory

Mounting a remote OneDrive directory

Using this mounts the remote OneDrive folder (or sub-folder) to a local mount point. This is useful in that files from OneDrive are not taking up any local storage space, often useful for laptop deployments. As files are opened, they are downloaded to a local temporary cache and later deleted (from cache) when not accessed for some time

Ideally to use this feature you want Rclone v1.39 which supports random read/write access to a locally mounted OneDrive folder. That means you can open and edit non-simple files (such as Word documents) successfully. Older versions are limited to simple text-based editors and/or copying files to and from OneDrive using drag/drop functionality in your window manager

Mounting a folder

Before mounting your OneDrive folder, you need to create an empty directory to serve as a mountpoint. For this example we will use the folder ~/OneDrive_test. Before continuing, lets create this folder

 

mkdir ~/OneDrive_test

In order to mount your entire OneDrive folder to ~/OneDrive_test, issue the command (as a regular user):

 

rclone mount OneDrive: ~/OneDrive_test

Note that the rclone program will not terminate until you unmount the folder. Alternatively, killing the program will force an unmount. This is a good way to test your mounts prior to automating the process

You may now copy files to and from the ~/OneDrive directory and its sub-directories. If you login to OneDrive via a browser, you can see the files being added and removed from OneDrive

Mounting a sub-folder

For this example, we will create an alternate mountpoint to mount our OneDrive sub-folder. Lets call this directory ~/OneDrive_subfoldertest

 

mkdir ~/OneDrive_subfoldertest

Consider a sub-folder in your OneDrive account called I4T. In order to mount this sub-folder ~/OneDrive_subfoldertest, issue the command (as a regular user):

 

rclone mount OneDrive:I4T ~/OneDrive_subfoldertest

You can also specify deeper folder names on OneDrive and to the local mountpoint. As for mounting the entire OneDrive folder, the rclone program will not terminate until you unmount the folder, killing rclone will force an unmount

Parameters to rclone

To maximise performance, you might want to use the following command line parameters when mounting a OneDrive (sub-)folder:
Parameter Comment
--no-modtime Will maximise network performance by not modifying times on OneDrive. The current API will result in backup copies being made on every edit/save if you do not use this option
--vfs-cache-mode full Only functions on v1.39 or higher of Rclone. If used, will allow random read/write access to the mounted drive, allowing you to edit files live to the OneDrive folder

For further parameters which might be useful, see the rclone online documentation

Automating mounts

As the rclone mount command is run as a regular user rather than as root, you cannot apply the usual techniques to automatically mount your OneDrive folders. Below is a simple technique that works in the KDE environment, if you are using a different Window Manager, there will be a similar option available

  • Create the following file as ~/bin/rclone_mount.sh
  •  
    
    #!/bin/bash
    
    RCLONE=`which rclone`
    RCLONE_PARAMS="--no-modtime"
    ### Use this RCLONE_PARAMS for rclone >=v1.39
    #RCLONE_PARAMS="--vfs-cache-mode full --no-modtime"
    
    ${RCLONE} mount ${RLCONE_PARAMS} OneDrive: ~/OneDrive &
    
    
  • Change permissions on the script to make it executable
  •  
    
    chmod +x ~/bin/rclone_mount.sh
    
    
  • Within KDE System Settings --> Startup and Shutdown --> Autostart
    • Click Add Script...
    • Browse for your new script and select it
    • Click OK
  • The script will run (and mount your OneDrive folder upon login
  • If you wish to add more mount-points for OneDrive sub-folders, add extra ${RCLONE} lines to the script above

    Other Useful Information

    OneDrive and/or rclone provide a number of other useful features you might wish to explore

    Sharing with other OneDrive users

    You can share your files/folders with other OneDrive users. The sharing cannot be done via rclone and instead has to be done via the Microsoft web interface

    Files shared with you are not available via rclone at this stage

    Other cool things

    rclone provides a number of other sub-commands outside of copy, sync and mount. To see these commands and their usage see the online documentation

    Note that the documentation also lists other options that are outside the scope of this document that you might find useful

    Other data sources

    rclone supports a number of other data sources aside from OneDrive including Amazon, DropBox, Google Drive, WebDAV and other remote/cloud sources. Once the source is set up using the rclone config command, you can access/copy/sync/mount the remote files in the same manner

    For information on configuring rclone to support these alternate sources, see the online documentation

    Last Updated: Thursday 11-Mar-2021 17:18:45 AEDT | Maintained by: Jason But (jbut@swin.edu.au) | Authorised by: Grenville Armitage ( garmitage@swin.edu.au)