rclone挂载OneDrive 作者: morningp 时间: 2021-04-08 分类: 技术笔记 最近嫖了个OneDrive 5TB的免费空间,想着也不能浪费,于是就想用rclone挂到服务器上 ~~下片~~ 这边其实挂载步骤都差不多,不过OneDrive的挂载步骤据说是要比Google drive要多一步,而我以前没用过rclone,所以还是记录一下。 1. ##下载rclone 服务器上基本就是一条命令`wget https://www.moerats.com/usr/shell/rclone_debian.sh && bash rclone_debian.sh` ~~别的系统推荐把系统换成debian~~,然后你还需要在本机上下载一个rclone,这边注意一定要和服务器上的版本一样,可以在服务器上使用`rclone -V`查看版本(一般来说debian这样安装的就是最新的版本),然后到[这里][1]找对应版本下载。 2. ##获取token 在个人电脑上下载的rclone解压后用命令行打开,然后输入`rclone authorize "onedrive"`,然后应该会打开一个浏览器,让你登录你的Microsoft账户,登录之后会跳出一个授权页面,选择是就可以了。然后命令行会跳出来一堆东西,是一个json格式的`{"access_token":"xxx","token_type":"xxx","refresh_token":"xxx","expiry":"xxx"} `,大概形如这样,把这一段复制下来之后要用用到。 3. ##服务器配置rclone 服务器上运行`rclone config`根据提示进行一系列配置: ``` n) New remote s) Set configuration password q) Quit config n/s/q> n name> onedirve #随便填,后面要用到 Type of storage to configure. Choose a number from below, or type in your own value 1 / Amazon Drive \ "amazon cloud drive" 2 / Amazon S3 (also Dreamhost, Ceph, Minio) \ "s3" 3 / Backblaze B2 \ "b2" 4 / Box \ "box" 5 / Cache a remote \ "cache" 6 / Dropbox \ "dropbox" 7 / Encrypt/Decrypt a remote \ "crypt" 8 / FTP Connection \ "ftp" 9 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage" 10 / Google Drive \ "drive" 11 / Hubic \ "hubic" 12 / Local Disk \ "local" 13 / Microsoft Azure Blob Storage \ "azureblob" 14 / Microsoft OneDrive \ "onedrive" 15 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift" 16 / Pcloud \ "pcloud" 17 / QingCloud Object Storage \ "qingstor" 18 / SSH/SFTP Connection \ "sftp" 19 / Webdav \ "webdav" 20 / Yandex Disk \ "yandex" 21 / http Connection \ "http" Storage> 14 #选择14,Microsoft OneDrive,,注意该序列号会随时变化,看清楚再填 Microsoft App Client Id - leave blank normally. client_id> #留空 Microsoft App Client Secret - leave blank normally. client_secret> #留空 Choose national cloud region for OneDrive. Enter a string value. Press Enter for the default ("global"). Choose a number from below, or type in your own value 1 / Microsoft Cloud Global \ "global" 2 / Microsoft Cloud for US Government \ "us" 3 / Microsoft Cloud Germany \ "de" 4 / Azure and Office 365 operated by 21Vianet in China \ "cn" region> 1 #这里根据实际情况选择区域版本 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> n #选择n For this to work, you will need rclone available on a machine that has a web browser available. Execute the following on your machine: rclone authorize "onedrive" Then paste the result below: result{"access_token":"xxx","token_type":"xxx","refresh_token":"xxx","expiry":"xxx"} #输入之前在客户端授权的内容 Choose a number from below, or type in an existing value 1 / OneDrive Personal or Business \ "onedrive" 2 / Root Sharepoint site \ "sharepoint" 3 / Type in driveID \ "driveid" 4 / Type in SiteID \ "siteid" 5 / Search a Sharepoint site \ "search" Your choice> 1 # 输入1 Found 1 drives, please select the one you want to use: 0: OneDrive (business) id=xxx Chose drive to use:> 0 #输入id前面的数字,不是id=后面的这一段 Found drive 'root' of type 'business', URL: https://shadoworld-my.sharepoint.com/personal/yushui_gfw_today/Documents Is that okay? y) Yes n) No ``` 到这里就算配置完成了,后面会出现一些配置信息。 4. ##挂载到服务器 首先在服务器上创建一个要挂载的目录。比如我这边是`/opt`,然后执行 `rclone mount onedirve: /opt --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode full --daemon` 然后`df -h` 就可以看到5TB的空间已经挂载上了。卸载的话命令是 `fusermount -qzu /opt` 5. ##创建服务开机自启(optional) 每次手动命令挂载确实太蠢,可以将这个命令写到service文件里创建一个服务,开机自启就方便多了。 在`/lib/systemd/system/`下创建rclone.service文件,在文件中写入如下内容: ``` [Unit] Description=rclone After=network-online.target [Service] Type=simple ExecStart=rclone mount onedirve: /opt --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode full Restart=on-abort User=root [Install] WantedBy=default.target ``` 保存好后执行 `systemctl daemon-reload`,重新加载systemctl服务列表,然后执行 `systemctl enable rclone.service` 允许开机自启。 到此位置就挂载好了OneDrive的超大空间。 [1]: https://rclone.org/downloads/ 标签: none