Tutorial
Mounting OneDrive Remotely with Rclone to Expand Server Storage
When purchasing instances from cloud providers, we often choose relatively conservative disk sizes for cost-performance reasons. As more and more services are deployed on an instance, the impact of insufficient space becomes increasingly obvious. This article shares how to use Rclone to expand disk space for free.
On this page
Prerequisites
You already have a cloud computing instance, and the server operating system is Ubuntu
You already have a Microsoft Developer E5 account; this setup uses a non-admin account
- Go to Azure Portal and click
新注册 - Enter a name, choose
任何组织目录(任何 Azure AD 目录 - 多租户)中的帐户和个人 Microsoft 帐户(例如,Skype、Xbox)as the account type, choose重定向 URI (可选)asWeb, enterhttp://localhost:53682/as the address (manual input is recommended to avoid mistakes), and click Register. Copy and save theApplication (client) ID 应用程序(客户端) IDbelow the display name for later use:b2...ef - In the left
管理menu, select证书和密码, click新客户端密码, enter a description, choose730天(24个月)for the expiration date, click Add, then obtain and save the client secret值for later use (visible only once):.m28...ocqx - In the left
管理menu, selectAPI权限, click添加权限, selectMicrosoft Graph, choose委托的权限, then search for and select these permissions:Files.Read,Files.ReadWrite,Files.Read.All,Files.ReadWrite.All,offline_access,User.ReadandSites.Read.All(if you have customized the access scope, select the corresponding permissions as well). After making your selections, click添加权限
- Go to Azure Portal and click
If using a business account
- Repeat steps 1-4, and add the extra steps below. Note that when choosing the account type in step 2, select Accounts in this organizational directory only (*** - Single tenant)
- Go to Azure Portal to obtain the
租户ID:e9...56 - During rclone config, set
auth_urlto: https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/authorize - During rclone config, set
token_urlto: https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/token
Download Rclone in advance from the official website
https://rclone.org/downloads/and extract it locally for later use
Server-Side Configuration
1. Install Rclone
Enter the official installation script (here it is run with a non-root account; in practice, I feel that running it as root would make the following steps smoother):
sudo -v ; curl https://rclone.org/install.sh | sudo bashExample output:
$ sudo -v ; curl https://rclone.org/install.sh | sudo bash
# 输出:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4707 100 4707 0 0 4085 0 0:00:01 0:00:01 --:--:-- 4089
Archive: rclone-current-linux-arm64.zip
creating: tmp_unzip_dir_for_rclone/rclone-v1.63.0-linux-arm64/
inflating: tmp_unzip_dir_for_rclone/rclone-v1.63.0-linux-arm64/rclone [binary]
inflating: tmp_unzip_dir_for_rclone/rclone-v1.63.0-linux-arm64/README.txt [text]
inflating: tmp_unzip_dir_for_rclone/rclone-v1.63.0-linux-arm64/git-log.txt [text]
inflating: tmp_unzip_dir_for_rclone/rclone-v1.63.0-linux-arm64/rclone.1 [text]
inflating: tmp_unzip_dir_for_rclone/rclone-v1.63.0-linux-arm64/README.html [text]
Purging old database entries in /usr/share/man...
Processing manual pages under /usr/share/man...
Purging old database entries in /usr/share/man/zh_CN...
Processing manual pages under /usr/share/man/zh_CN...
Purging old database entries in /usr/share/man/fr...
Processing manual pages under /usr/share/man/fr...
Processing manual pages under /usr/local/man...
mandb: can't update index cache /var/cache/man/oldlocal/267107: No such file or directory
Updating index cache for path `/usr/local/man/man1'. Wait...done.
Checking for stray cats under /usr/local/man...
Checking for stray cats under /var/cache/man/oldlocal...
1 man subdirectory contained newer manual pages.
1 manual page was added.
0 stray cats were added.
0 old database entries were purged.
rclone v1.63.0 has successfully installed.
Now run "rclone config" for setup. Check https://rclone.org/docs/ for more details.2. Configure Rclone:
rclone configUse the interactive prompts and choose according to your actual situation:
$ rclone config
# 输出:
2023/07/04 15:59:21 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
Enter name for new remote.
name> onedrive
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
1 / 1Fichier
\ (fichier)
2 / Akamai NetStorage
\ (netstorage)
3 / Alias for an existing remote
\ (alias)
4 / Amazon Drive
\ (amazon cloud drive)
5 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, ArvanCloud, Ceph, China Mobile, Cloudflare, GCS, DigitalOcean, Dreamhost, Huawei OBS, IBM COS, IDrive e2, IONOS Cloud, Liara, Lyve Cloud, Minio, Netease, Petabox, RackCorp, Scaleway, SeaweedFS, StackPath, Storj, Tencent COS, Qiniu and Wasabi
\ (s3)
6 / Backblaze B2
\ (b2)
7 / Better checksums for other remotes
\ (hasher)
8 / Box
\ (box)
9 / Cache a remote
\ (cache)
10 / Citrix Sharefile
\ (sharefile)
11 / Combine several remotes into one
\ (combine)
12 / Compress a remote
\ (compress)
13 / Dropbox
\ (dropbox)
14 / Encrypt/Decrypt a remote
\ (crypt)
15 / Enterprise File Fabric
\ (filefabric)
16 / FTP
\ (ftp)
17 / Google Cloud Storage (this is not Google Drive)
\ (google cloud storage)
18 / Google Drive
\ (drive)
19 / Google Photos
\ (google photos)
20 / HTTP
\ (http)
21 / Hadoop distributed file system
\ (hdfs)
22 / HiDrive
\ (hidrive)
23 / In memory object storage system.
\ (memory)
24 / Internet Archive
\ (internetarchive)
25 / Jottacloud
\ (jottacloud)
26 / Koofr, Digi Storage and other Koofr-compatible storage providers
\ (koofr)
27 / Local Disk
\ (local)
28 / Mail.ru Cloud
\ (mailru)
29 / Mega
\ (mega)
30 / Microsoft Azure Blob Storage
\ (azureblob)
31 / Microsoft OneDrive
\ (onedrive)
32 / OpenDrive
\ (opendrive)
33 / OpenStack Swift (Rackspace Cloud Files, Blomp Cloud Storage, Memset Memstore, OVH)
\ (swift)
34 / Oracle Cloud Infrastructure Object Storage
\ (oracleobjectstorage)
35 / Pcloud
\ (pcloud)
36 / PikPak
\ (pikpak)
37 / Put.io
\ (putio)
38 / QingCloud Object Storage
\ (qingstor)
39 / SMB / CIFS
\ (smb)
40 / SSH/SFTP
\ (sftp)
41 / Sia Decentralized Cloud
\ (sia)
42 / Storj Decentralized Cloud Storage
\ (storj)
43 / Sugarsync
\ (sugarsync)
44 / Transparently chunk/split large files
\ (chunker)
45 / Union merges the contents of several upstream fs
\ (union)
46 / Uptobox
\ (uptobox)
47 / WebDAV
\ (webdav)
48 / Yandex Disk
\ (yandex)
49 / Zoho
\ (zoho)
50 / premiumize.me
\ (premiumizeme)
51 / seafile
\ (seafile)
Storage> 31
Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id> b2...ef
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret> .m28...cqx
Option region.
Choose national cloud region for OneDrive.
Choose a number from below, or type in your own string value.
Press Enter for the default (global).
1 / Microsoft Cloud Global
\ (global)
2 / Microsoft Cloud for US Government
\ (us)
3 / Microsoft Cloud Germany
\ (de)
4 / Azure and Office 365 operated by Vnet Group in China
\ (cn)
region> 1
Edit advanced config?
y) Yes
n) No (default)
y/n> n
Use web browser to automatically authenticate rclone with remote?
* Say Y if the machine running rclone has a web browser you can use
* Say N if running rclone on a (remote) machine without web browser access
If not sure try Y. If Y failed, try N.
y) Yes (default)
n) No
y/n> n
Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
rclone authorize "onedrive" "eyJjbGl...b2NxeCJ9"
Then paste the result.
Enter a value.
config_token>Next, go to the local machine to perform authorization. After entering the local Rclone directory, run:
./rclone authorize "onedrive" "eyJjbGl...b2NxeCJ9"Note: After executing this, a browser will be opened for authorization. Once successful, you can obtain the config_token in the terminal. However, note that due to a bug in Rclone itself, the token displayed on the local machine may be incomplete, for example:
2023/07/04 23:19:39 NOTICE: Got code
Paste the following into your remote machine --->
eyJ0b2tlbi...In0ifQ
<---End pasteIf you copy this content directly from the terminal and paste it on the server side, an error will occur. You will need to use the rclone config reconnect onedrive: command to re-enter it, but even after several attempts it may still fail. The official workaround is actually simple: complete the entire rclone config process locally, then replace the remote configuration file with the local configuration file (use rclone config file to find the file location). Here, we only need to obtain the complete token information:
- token: {"access_token":"eyJ0eX...chVKv-FC","expiry":"2023-07-05T00:29:16.923549+08:00"}Paste the token information into the remote terminal to complete the remaining interactive steps successfully:
Option config_type.
Type of connection
Choose a number from below, or type in an existing string value.
Press Enter for the default (onedrive).
1 / OneDrive Personal or Business
\ (onedrive)
2 / Root Sharepoint site
\ (sharepoint)
/ Sharepoint site name or URL
3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite
\ (url)
4 / Search for a Sharepoint site
\ (search)
5 / Type in driveID (advanced)
\ (driveid)
6 / Type in SiteID (advanced)
\ (siteid)
/ Sharepoint server-relative path (advanced)
7 | E.g. /teams/hr
\ (path)
config_type> 1
Option config_driveid.
Select drive you want to use
Choose a number from below, or type in your own string value.
Press Enter for the default (b!a_9W...50kT).
1 / OneDrive (business)
\ (b!a_9W...50kT)
config_driveid> 1
Drive OK?
Found drive "root" of type "business"
URL: https://xxxx-my.sharepoint.com/personal/xxx_xxx_com/Documents
y) Yes (default)
n) No
y/n> y
Configuration complete.
Options:
- type: onedrive
- client_id: b2...ef
- client_secret: .m28...ocqx
- token: {"access_token":"eyJ0eX...chVKv-FC","expiry":"2023-07-05T00:29:16.923549+08:00"}
- drive_id: b!a_9W...50kT
- drive_type: business
Keep this "onedrive" remote?
y) Yes this is OK (default)
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> qAt this point, the Rclone configuration is basically complete. Next, we finish the mount.
3. Mount the remote cloud drive:
Create the /onedrive folder on the server as the local folder mapped to the remote cloud drive. Use the command below for a temporary mount:
rclone mount onedrive:/ /onedrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writesIf an error like the following appears:
2023/07/04 23:41:40 Fatal error: failed to mount FUSE fs: mount stopped before calling Init: mount failed: cgofuse: cannot find FUSEOr an error like this:
2023/07/04 16:31:23 Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount3": executable file not found in $PATHYou can solve it by installing the corresponding software version:
apt install fuse3After the required software is installed, mount it again. Once the mount command is running, you can open a new terminal to access the server and use df -h to verify whether the mount succeeded. If the mount succeeds, you can proceed to configure the boot-time startup service.
4. Configure the boot-time startup service
First, create the Rclone service:
command="mount onedrive:/ /onedrive --default-permissions --transfers 4 --buffer-size 32M --low-level-retries 200 --dir-cache-time 6h --vfs-read-chunk-size 64M --vfs-read-chunk-size-limit 1G --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes"Add the command to the service configuration:
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target
[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root
[Install]
WantedBy=default.target
EOFOr directly:
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/rclone mount onedrive:/ /data/onedrive \
--umask 0000 \
--default-permissions \
--allow-non-empty \
--allow-other \
--transfers 4 \
--buffer-size 32M \
--low-level-retries 200 \
--dir-cache-time 6h \
--vfs-read-chunk-size 64M \
--vfs-read-chunk-size-limit 1G \
--vfs-cache-mode writes
Restart=on-abort
User=root
[Install]
WantedBy=default.target
EOFThen reload the daemon so the service file takes effect:
systemctl daemon-reloadsystemctl start rclonesystemctl enable rcloneOutput:
Created symlink /etc/systemd/system/default.target.wants/rclone.service → /etc/systemd/system/rclone.service.Other Rclone service-related commands for reference:
# 重启:
systemctl restart rclone
# 停止:
systemctl stop rclone
# 状态:
systemctl status rcloneFinally, use df -h to check whether the disk has been mounted successfully. The result looks great:
$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 2.4G 2.3M 2.4G 1% /run
/dev/sda1 146G 7.3G 138G 6% /
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda15 98M 6.3M 92M 7% /boot/efi
tmpfs 2.4G 4.0K 2.4G 1% /run/user/1001
onedrive: 5.0T 1.7M 5.0T 1% /onedriveSummary
Rclone is simply a fantastic tool. It supports not only OneDrive, but also common cloud drive services and object storage services. I have to say, this software is incredibly powerful. More importantly, after mounting a cloud drive, it can be combined with other open-source programs for many more practical uses, such as automatic backups, image hosting support, and more. The main problem encountered during this setup was the bug when configuring the server-side config_token, which is very easy to trip over during the first deployment.