π§© 1. Overview of Options
Method | Description | Sync / Mount | API Access |
---|---|---|---|
rclone | Universal cloud storage sync tool supporting OneDrive, Google Drive, etc. | β Sync | β Uses Microsoft Graph API |
onedrive (abraunegg) | Native Linux OneDrive client written in D | β Sync | β Uses Microsoft Graph API |
mount via rclone | Mount OneDrive as a local folder using FUSE | β Mount | β Uses Graph API |
Graph API (manual) | Access OneDrive directly via HTTPS REST API | β | β Full programmable control |
βοΈ 2. Option 1 β Using rclone
(Recommended)
π§ Installation
sudo apt install rclone -y
or from source:
curl https://rclone.org/install.sh | sudo bash
π Configure for OneDrive
Run the configuration wizard:
rclone config
Then:
n) New remote
name> onedrive
storage> onedrive
client_id> (leave empty unless using your own Azure app)
client_secret> (leave empty unless using your own)
region> global
edit advanced config? n
use auto config? y
This will open your browser β log in to your Microsoft account β authorize rclone
.
When finished, you can test:
rclone lsd onedrive:
ποΈ Sync or Mount Commands
Sync local folder β OneDrive:
rclone sync ~/Documents onedrive:Documents --progress
Mount OneDrive as local folder (via FUSE):
mkdir ~/OneDrive
rclone mount onedrive: ~/OneDrive --vfs-cache-mode full &
Unmount:
fusermount -u ~/OneDrive
βοΈ 3. Option 2 β Using Native Linux Client (onedrive
by abraunegg)
This client is written in D language and supports:
- Background sync (systemd)
- Differential uploads
- Multiple account support
π§ Install
sudo apt install onedrive
# Or latest release:
sudo add-apt-repository ppa:yann1ck/onedrive
sudo apt update
sudo apt install onedrive
π Authenticate
onedrive
Youβll get a link β open it in your browser β login β paste the response URL.
π Sync Files
onedrive --synchronize
βοΈ Continuous Sync (Daemon)
onedrive --monitor
π§ 4. Option 3 β Direct API Access (Microsoft Graph)
If you want low-level control (like building tools or integrating into a script), you can directly call the Microsoft Graph API.
Authentication
- Register an app in Azure Portal β βApp registrationsβ.
-
Add API permissions:
Files.ReadWrite
,offline_access
,User.Read
- Get
client_id
,client_secret
,tenant_id
.
Obtain OAuth2 Token
curl -X POST https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token \
-d "client_id=<client_id>" \
-d "scope=https://graph.microsoft.com/.default offline_access" \
-d "client_secret=<client_secret>" \
-d "grant_type=client_credentials"
List OneDrive Files
curl -H "Authorization: Bearer <access_token>" \
https://graph.microsoft.com/v1.0/me/drive/root/children
Upload a File
curl -X PUT -H "Authorization: Bearer <access_token>" \
-H "Content-Type: text/plain" \
--data-binary @localfile.txt \
https://graph.microsoft.com/v1.0/me/drive/root:/Documents/localfile.txt:/content
π§© 5. Under the Hood β Protocol & Code Path
rclone and onedrive (abraunegg) both use Microsoft Graph REST API underneath:
- Auth flow: OAuth2 Authorization Code β Refresh token β Access token
- Endpoints:
https://graph.microsoft.com/v1.0/me/drive/*
- Transport: HTTPS + JSON over HTTP 1.1
- Files transmitted as multipart or PUT binary streams.
Example (from rclone/backend/onedrive/onedrive.go
):
// upload small file
url := fmt.Sprintf("%s/root:/%s:/content", apiURL, path)
resp, err := httpClient.Put(url, body)
From onedrive/src/onedrive.d
:
auto request = new HTTPRequest("PUT", endpoint ~ "/content");
request.setRequestHeader("Authorization", "Bearer " ~ accessToken);
request.send(fileData);
So fundamentally both tools are just wrappers over Microsoft Graph, automating token refresh, delta queries (/delta
endpoint for change tracking), and FUSE mounting.
π§© 6. Verify Connectivity
To verify your OneDrive mount or sync:
rclone about onedrive:
rclone ls onedrive:
Check network logs:
sudo lsof -i | grep rclone
If mounted via FUSE:
mount | grep OneDrive
π§ Summary
Goal | Recommended Method |
---|---|
Mount OneDrive like a local disk | rclone mount |
Auto-sync in background | onedrive --monitor |
Programmatic access | Microsoft Graph API |
Lightweight CLI access | rclone |