Mounting OneDrive on Ubuntu Linux command line

For some requirement, I need to mount OneDrive instead of Syncing files through onedrive-d. Also, I need need a command line solution to automate something in my scripts. Can anyone help on this ?

I tried to mount it from usual mount command, but failed. Please note, I am not an expert of Linux command line, so please help.

Thanks in advance.

-- Ninad


Solution 1:

Mount OneDrive on Ubuntu

This instruction follows RCLONE - Microsoft OneDrive

  1. Download and install Rclone

sudo apt install rclone

or download the latest one

wget https://downloads.rclone.org/v1.42/rclone-v1.42-linux-amd64.deb
sudo apt install ./rclone-v1.42-linux-amd64.deb

2. Add a new OneDrive remote to Rclone

rclone config
  • 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
    
  • Enter a name for the new remote, here onedrive is used:

      name> onedrive
    
  • After pressing the Enter, 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
      [snip]
      ... 
      ...
      xx / Microsoft OneDrive
         \ "onedrive"
      ...
      ...
      [snip]
      Storage> onedrive
    
  • 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>
    
  • 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. If you are setting up on a remote or headless machine type n (you will need to run rclone config on a machine with browser access and copy/paste an authentication token later:

      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
    
  • If you are mounting on a local machine: 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.
    .
    If setting up a remote or headless machine: rclone will provide a terminal command that you will need to execute on a machine with a web browser. This command will provide you with an authentication key that you should paste into this session. See these instructions for more details.

  • 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
    
  • 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
    
  1. Create a new folder

mkdir ~/OneDrive 
  1. Mount OneDrive

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

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

  1. (Optional) Mount OneDrive on system startup

To mount OneDrive on startup, open Startup Applications, and in Startup Applications 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.