amtoaer

晓风残月

叹息似的渺茫,你仍要保存着那真!
github
x
telegram
steam
nintendo switch
email

Configure the Century Internet version of OneDrive to enable network shared folders

Background#

I have wanted a network shared folder for a long time, which can be used as a regular folder locally and accessed via the internet.

I roughly compared the services that could potentially achieve this functionality:

ServiceAdvantagesDisadvantages
Domestic cloud storage represented by Baidu CloudLarge storage spacePoor support for linux, slow access speed
Foreign cloud storage like google drive/megalinux client supportSmaller storage space, slow or even unreachable in China
Various oss services (e.g., Alibaba Cloud oss)Official mount support, unlimited speedAccumulated storage, traffic, and request costs, expensive
Idle storage space on serversAccessible via sftpLimited by server bandwidth, not ideal usage

As we can see, each service has its pros and cons. Recently, I discovered another product: Century Internet Version of OneDrive. It is operated by Microsoft through Century Internet in China. Compared to the international version of OneDrive, its data centers are located in Beijing/Shanghai, greatly optimizing access speed for domestic users. Additionally, there are many low-priced accounts available on Taobao, where you can buy "permanent" 5T storage space for fifty or sixty yuan (this is questionable). After searching online, I found that this Century Internet Version of OneDrive can be mounted locally using modified rclone, and accessed in the cloud using open-source projects like modified oneindex, zfile, etc. (without using server traffic, unlimited speed), perfectly meeting my needs, so I got one and prepared to get started.

Requirements#

  1. A personal computer
  2. A server
  3. An open API Century Internet Version of OneDrive account (must be open API!)

Cloud Side#

First, let's talk about the simple cloud access. I am using zfile (because it is easy to configure and natively supports Century Internet OneDrive).

The following operations are based on ubuntu, for centos please refer to the official documentation.

SSH into the server and first install the dependencies:

sudo apt install -y openjdk-8-jre-headless unzip

Download the project, unzip it, and give it executable permissions:

cd ~
wget https://c.jun6.net/ZFILE/zfile-release.war
mkdir zfile && unzip zfile-release.war -d zfile && rm -rf zfile-release.war
chmod +x zfile/bin/*.sh

Start the project:

~/zfile/bin/start.sh

Next, access http://your_public_ip:8080/#/install for configuration. The access token and refresh token need to be obtained by logging in at this URL. After filling in successfully, click confirm to complete the configuration, and you can access your OneDrive cloud drive on the web!

Local#

Next, let's configure the slightly more complex local mount.

The following content is reproduced from znov's blog, as he mounted it on the server, while I am doing it on my local machine, so I made a few minor modifications. (Windows only needs to perform the first three steps, not tested).

  1. Obtain CLIENT_ID and CLIENT_SECRET for Century Internet OneDrive

    1. Open this webpage and log in.
    2. Find Azure Active Directory on the left and click it.
      Find App registrations on the left and click it.
      Find New registration at the top and click it.
      Name: onedrive
      Supported account types: Any organizational directory (the second option)
      Redirect URL: http://localhost:53682
      Click register.
      Find Application (client) ID and copy it for later use.
      Find Certificates & secrets on the left and click it.
      Below, Client secrets - New client secret
      Description: onedrive
      Expiration: default in one year
      Click Add, copy the Value for later use.
      Find API permissions on the left and click it.
      Add permissions: Microsoft Graph - Delegated permissions: check all (through my testing, checking only the File section is sufficient).
  2. Install and configure rclone

    1. Download here the rclone Century Internet version.

      This file comes from the global hosting forum, thanks to the great contributor. The original blog's download link is very slow, so I saved a copy. I hope everyone can also take a moment to comment and support the original blog!

    2. Open terminal in the current directory on linux and execute

      sudo mv ./rclone_filename /usr/bin/rclone
      sudo chmod +x /usr/bin/rclone
      

      For windows, please refer to how to add files to the environment variable.

      Note: This step is not mandatory. If not executed, change rclone in the following commands to the path form of rclone.

    3. Enter rclone config to configure as follows

      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
      name>onedrive
      Type of storage to configure.
      Enter a string value. Press Enter for the default ("").
      Choose a number from below, or type in your own value
       1 / 1Fichier
         \ "fichier"
       2 / Alias for an existing remote
         \ "alias"
       3 / Amazon Drive
         \ "amazon cloud drive"
       4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
         \ "s3"
       5 / Backblaze B2
         \ "b2"
       6 / Box
         \ "box"
       7 / Cache a remote
         \ "cache"
       8 / Citrix Sharefile
         \ "sharefile"
       9 / Dropbox
         \ "dropbox"
      10 / Encrypt/Decrypt a remote
         \ "crypt"
      11 / FTP Connection
         \ "ftp"
      12 / Google Cloud Storage (this is not Google Drive)
         \ "google cloud storage"
      13 / Google Drive
         \ "drive"
      14 / Google Photos
         \ "google photos"
      15 / Hubic
         \ "hubic"
      16 / JottaCloud
         \ "jottacloud"
      17 / Koofr
         \ "koofr"
      18 / Local Disk
         \ "local"
      19 / Mail.ru Cloud
         \ "mailru"
      20 / Mega
         \ "mega"
      21 / Microsoft Azure Blob Storage
         \ "azureblob"
      22 / Microsoft OneDrive
         \ "onedrive"
      23 / OpenDrive
         \ "opendrive"
      24 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
         \ "swift"
      25 / Pcloud
         \ "pcloud"
      26 / Put.io
         \ "putio"
      27 / QingCloud Object Storage
         \ "qingstor"
      28 / SSH/SFTP Connection
         \ "sftp"
      29 / Transparently chunk/split large files
         \ "chunker"
      30 / Union merges the contents of several remotes
         \ "union"
      31 / Webdav
         \ "webdav"
      32 / Yandex Disk
         \ "yandex"
      33 / http Connection
         \ "http"
      34 / premiumize.me
         \ "premiumizeme"
      Storage>22
      ** See help for onedrive backend at: https://rclone.org/onedrive/ **
      
      Microsoft App Client Id
      Leave blank normally.
      Enter a string value. Press Enter for the default ("").
      client_id>Enter the "Application (client) ID" from above
      Microsoft App Client Secret
      Leave blank normally.
      Enter a string value. Press Enter for the default ("").
      client_secret>Enter the "Value" obtained above
      OneDrive operated by 21Vianet (Century Internet).
      Enter a boolean value (true or false). Press Enter for the default ("false").
      is_21vianet_version>true
      Edit advanced config? (y/n)
      y) Yes
      n) No
      y/n>n
      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
      A webpage will automatically open for login, then continue...
      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
      Found 1 drives, please select the one you want to use:
      0: OneDrive (business) id=******
      Chose drive to use:>0
      Found drive 'root' of type 'business', URL: https://alphaone-my.sharepoint.cn/personal/***
      Is that okay?
      y) Yes
      n) No
      y/n>y
      y
      q
      
  3. Mounting

    linux needs to install fuse, which varies by distribution, so I won't elaborate. My manjaro comes with it.

    The command is as follows: (where / represents the path to mount onedrive locally, and /mnt/ represents the local mount path, which can be modified accordingly)

    Mount command: rclone mount onedrive:/ /mnt/ --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
    
    Background mount command: nohup rclone mount onedrive:/ /mnt --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 >/dev/null 2>&1 &
    
    Unmount command: fusermount -qzu LocalFolder onedrive
    
  4. Using the mount script

    This mount script can achieve basic mounting, unmounting, and remounting functions, so you won't need to enter such long commands afterward. The script is as follows:

    #!/bin/bash
    # ------------------------------------------
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
    export PATH
    
    ### BEGIN INIT INFO
    # Provides:          rclone
    # Required-Start:    $all
    # Required-Stop:     $all
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start rclone at boot time
    # Description:       Enable rclone by daemon.
    ### END INIT INFO
    # ------------------------------------------
    # The content between the two lines above can be removed if you don't want it to start automatically (I personally think it won't affect if removed).
    
    NAME_BIN="rclone"
    NAME="onedrive"
    REMOTE='/' # The path to mount to the local onedrive, can be modified
    LOCAL='/mnt/' # Which local folder to mount to, can be modified
    
    Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
    Info="${Green_font_prefix}[Info]${Font_color_suffix}"
    Error="${Red_font_prefix}[Error]${Font_color_suffix}"
    RETVAL=0
    
    check_running(){
        PID="$(ps -C $NAME_BIN -o pid= |head -n1 |grep -o '[0-9]\{1,\}')"
        if [[ ! -z ${PID} ]]; then
            return 0
        else
            return 1
        fi
    }
    do_start(){
        check_running
        if [[ $? -eq 0 ]]; then
            echo -e "${Info} $NAME_BIN (PID ${PID}) is running..." && exit 0
        else
            fusermount -zuq $LOCAL >/dev/null 2>&1
            mkdir -p $LOCAL
            /usr/bin/rclone mount $NAME:$REMOTE $LOCAL --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 >/dev/null 2>&1 &
            check_running
            if [[ $? -eq 0 ]]; then
                echo -e "${Info} $NAME_BIN started successfully!"
            else
                echo -e "${Error} $NAME_BIN failed to start!"
            fi
        fi
    }
    do_stop(){
        check_running
        if [[ $? -eq 0 ]]; then
            kill -9 ${PID}
            RETVAL=$?
            if [[ $RETVAL -eq 0 ]]; then
                echo -e "${Info} $NAME_BIN stopped successfully!"
            else
                echo -e "${Error} $NAME_BIN failed to stop!"
            fi
        else
            echo -e "${Info} $NAME_BIN is not running"
            RETVAL=1
        fi
        fusermount -zuq $LOCAL >/dev/null 2>&1
        fusermount -zuq $LOCAL1 >/dev/null 2>&1
    }
    do_status(){
        check_running
        if [[ $? -eq 0 ]]; then
            echo -e "${Info} $NAME_BIN (PID $(echo ${PID})) is running..."
        else
            echo -e "${Info} $NAME_BIN is not running!"
            RETVAL=1
        fi
    }
    do_restart(){
        do_stop
        do_start
    }
    case "$1" in
        start|stop|restart|status)
        do_$1
        ;;
        *)
        echo "Usage: $0 { start | stop | restart | status }"
        RETVAL=1
        ;;
    esac
    exit $RETVAL
    

    Assuming this script is saved as rcloned, first give it executable permissions:

    chmod +x path_to_rcloned
    

    You can then choose to move it to the environment variable, manually execute rcloned start when using:

    sudo mv path_to_rcloned /usr/bin/rcloned
    # Each time you use it
    rcloned start
    

    You can also choose to set it to run automatically at boot like the original text (may not be supported by all distributions):

    sudo mv path_to_rcloned /etc/init.d/rcloned
    sudo /etc/init.d/rcloned start
    

Screenshot#

image

Thoughts#

I originally planned to write a short article, but unexpectedly ended up writing so much...

Some steps in between are overly detailed, I hope you don't find me verbose while reading orz

References#

  1. zfile Official Documentation

  2. znov's Blog

  3. Zephyr Grocery Store (where I purchased the account)

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.