суббота, 28 ноября 2015 г.

How to mount Google Drive on Linux

As I speak, more than 22,000 people signed up for a petition, desperately wanting to have an official native Linux client for Google Drive, and yet their voice is still being ignored by Google. Perhaps when it comes to boosting their bottom line, Linux desktop market is not a priority for Google.
They can ignore Linux desktop market all they want, but they cannot ignore the power of FOSS. Faced with the frustration, the open-source community responded, producing unofficial Google Drive clients such as Grive or SyncDrive. These clients are file synchronization tools which sync files and folders between local file system and remote Google Drive. As such, you cannot mount Google Drive using these tools.
If you want to mount Google Drive on Linux, you can try google-drive-ocamlfuse, which is a FUSE-based file system backed by Google Drive. Using this user-space file system, you can mount your Google Drive account on Linux, and have full read/write access to files/folders in Google Drive as if they were local files/folders.
In this tutorial, I will describe how to mount Google Drive on Linux with google-drive-ocamlfuse.

Install google-drive-ocamlfuse on Linux

google-drive-ocamlfuse is written in OCaml, and you can use OPAM (OCaml package manager) to build and install google-drive-ocamlfuse from its source. In this case, you need to install prerequisites such as FUSE. The following are distro-specific such instructions.
To install google-drive-ocamlfuse on Debian:
$ sudo apt-get install ocaml camlp4-extra
$ git clone https://github.com/OCamlPro/opam.git
$ cd opam
$ ./configure
$ make
$ sudo make install
$ sudo apt-get install m4 libcurl4-gnutls-dev libfuse-dev libsqlite3-dev
$ opam init
$ opam update
$ opam install google-drive-ocamlfuse
After successful build, the google-drive-ocamlfuse binary will be found in ~/.opam/system/bin. Add this path to your PATH environment variable as follows.
$ vi ~/.bashrc
PATH= $PATH:$HOME/.opam/system/bin
export PATH 
$ source ~/.bashrc
To install google-drive-ocamlfuse on Ubuntu or Linux Mint, you can use its official PPA as follows.
$ sudo add-apt-repository ppa:alessandro-strada/ppa
$ sudo apt-get update
$ sudo apt-get install google-drive-ocamlfuse
To install google-drive-ocamlfuse on Fedora:
$ sudo yum install ocaml ocaml-camlp4-devel ocaml-ocamldoc
$ git clone https://github.com/OCamlPro/opam.git
$ cd opam
$ ./configure
$ make
$ sudo make install
$ sudo yum install m4 fuse fuse-devel libcurl-devel libsqlite3x-devel zlib-devel
$ opam init
$ opam update
$ opam install google-drive-ocamlfuse
After successful build, the google-drive-ocamlfuse binary will be found in ~/.opam/system/bin. Add this path to your PATH environment variable as follows.
$ vi ~/.bashrc
PATH=$PATH:$HOME/.opam/system/bin
export PATH 
$ source ~/.bashrc
To install google-drive-ocamlfuse on CentOS or RHEL, you can follow the above Fedora instructions. However, the default version of OCaml installed on CentOS/RHEL does not meet the minimum version requirement (3.12.1) for building OPAM. Therefore you need to upgrade OCaml by installing it from source.

Mount Google Drive with google-drive-ocamlfuse

The first step is to add your user name to Linux group named fuse as follows, so that Google Drive can be mounted by you (i.e., a non-root user).
$ sudo usermod -a -G fuse <user_name>
$ exec su -l $USER
Next, configure google-drive-ocamlfuse by running it without any argument:
$ google-drive-ocamlfuse
This will open up a web browser window, asking you to log in to your Google account. After logging in, you will see the following screen, requesting for permission. Click on "Accept".
Next you have to grant "gdfuse OAuth2 Endpoint" access to your Google account. For that, log in to your Google account again.
Click on "Allow" button.
Then you should see a message saying that google-drive-ocamlfuse was successfully granted access. Close the browser tab / window to finalize.
At this point, the initial configuration is completed. You should see a new directory named ~/.gdfuse/default created, which contains the configuration file "config", application state and file cache.
Now proceed to create a mount point, and mount Google Drive as follows.
$ mkdir ~/googledrive
$ google-drive-ocamlfuse ~/googledrive
Use mount command to check if Google Drive is mounted successfully.
$ mount
google-drive-ocamlfuse on /home/dev/googledrive type fuse.google-drive-ocamlfuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
You can also check how much space is left on your Google Drive account by using df command.
$ df
google-drive-ocamlfuse  15728640     304  15728336   1% /home/dev/googledrive
To unmount the Google Drive file system, simply run:
$ fusermount -u ~/googledrive

Mount Multiple Google Drive Accounts Simultaneously

If you have more than one Google Drive account, you can mount them simultaneously. In this case, use "-label" option to distinguish between them as follows.
$ google-drive-ocamlfuse -label [label] [mountpoint]
The first time you run google-drive-ocamlfuse with a given label, you will need to go through the same Google authentication procedure as before, but for a different Google account. After that, ~/.gdfuse/[label] will be created to store configuration data for the different Google account.

Auto-mount Google Drive upon Boot

If you want to have Google Drive mounted automatically upon boot, you can follow the steps below. The credit goes to Alessandro Strada, the original author of google-drive-ocamlfuse.
Create a shell script named "gdfuse" in /usr/bin (as root) with this content:
$ sudo vi /usr/bin/gdfuse
#!/bin/bash

google-drive-ocamlfuse -label $1 $*
exit 0
Give it exec permissions:
$ sudo chmod +x /usr/bin/gdfuse
Copy your directory ~/.gdfuse in root home (that's because mount is executed by root)
$ sudo cp -r /home/[user]/.gdfuse /root/
Edit /etc/fstab adding a line like this:
gdfuse#default  /mnt/gdrive     fuse    allow_other     0       0
And then you can use mount command to run google-drive-ocamlfuse:
$ sudo mount /mnt/gdrive
If you want, you can change the owner of the filesystem by adding a line to /etc/fstab (if the user id is 1000):
gdfuse#default  /mnt/gdrive     fuse    allow_other,uid=1000,gid=1000   0       0
If you have more than one Google drive accounts, you can also mount them by adding their corresponding label after the # (in /etc/fstab):
gdfuse#label  /mnt/gdrive     fuse    allow_other     0       0

Комментариев нет: