29

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

user174879
  • 301
  • 2
  • 4
  • 5
  • The best is using onedriver (it has a GUI). It's perfect. https://github.com/jstaf/onedriver – Allexj May 03 '23 at 13:41

5 Answers5

33

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.

Nick S
  • 171
  • 8
abu_bua
  • 10,473
  • 10
  • 45
  • 62
  • 2020/04/28 22:56:44 Fatal error: unknown flag: --vfs-cache-mode – Tony Apr 29 '20 at 03:02
  • --vfs-cache-mode is a known flag according to the rclone manual! Please add your command line and the name of your drive in the post. In order to see if your rclone configuration is rigth type `rclone lsd : ` – abu_bua Apr 29 '20 at 13:23
  • @Tony is correct. That option is not valid and is not in the current man page. – Juan Jimenez Jul 02 '20 at 18:03
  • from man rclone(1) (version v1.50.2): **Limitations** Without the use of “–vfs-cache-mode” this can only write files sequentially, it can only seek when reading. This means that many applications won’t work with their files on an rclone mount without `–vfs-cache-mode writes` or `–vfs-cache-mode full`. See the File Caching section for more info. – abu_bua Jul 17 '20 at 10:59
  • This solution works for me, thanks in advance. The only problem is after reboot using the Startup Applications the onedrive does not mount, it has to be manually mounted. Perhaps i'm missing something. – White Horse Sep 27 '20 at 23:38
  • The best is using onedriver (it has a GUI). It's perfect. https://github.com/jstaf/onedriver – Allexj May 03 '23 at 13:40
  • Maybe I misunderstood something. Can I somehow see the data shared with me in OneDrive by other users, groups, etc.? Currently I only see my private data in the mounted directory. – Alfe May 08 '23 at 16:10
  • I don't use windows any more (3 years) and the post is very old (4 years). – abu_bua May 08 '23 at 16:28
1

For any WSL users, it is easy. Without doing anything at all, I could access OneDrive at

/mnt/c/Users/my_user_name/OneDrive/

which uses the standard Windows OneDrive and filesystem drivers.

0

extra

If you are on xfce4 (Manjaro)

create /home/$(USER)/.onedive.sh give excute permission

#!/bin/sh
sleep 3
rclone --vfs-cache-mode writes mount onedrive: ~/onedrive

add sh /home/$(USER)/.onedive.sh to start up application

0

Just use

onedrive --monitor

after proper installation: https://itslinuxfoss.com/how-to-install-and-use-onedrive-on-ubuntu-20-04/

You can put it in e.g. the Startup apps.

Mata Pata
  • 31
  • 1
  • The best is using onedriver (it has a GUI). It's perfect. https://github.com/jstaf/onedriver – Allexj May 03 '23 at 13:40
0

As far as I know there is no easy solution to mount OneDrive in any gnu/linux distribution.

You can use Storage Made Easy (SMEStorage) to mount several providers in one folder. It is free up to 3 providers, but it is not opensource.

You can also use the app provided or mount it via webdav (Nautilus - Connect to server) and use the instructions provided in: CloudDAV

Danilo
  • 127
  • 1
  • 8