How to Mount Google Drive on a cloud instance for extra storage!
WHY ?!?!?
Why do this? Well, easy access to up to 2TB of storage for $10/mo with a google drive subscription. Not to mention a free 15GB with ANY google account and you can sync up as many as you want…This is nice as unlike standard cloud options you won't have to pay rates and it's just there easy to use.
First — Install a GUI environment and install VNC
This will depend on your system but first, we will install a desktop env. If you are a system with the apt package managed use as follows:
sudo apt update
sudo apt install ubuntu-desktop
sudo apt install tightvncserver
sudo apt install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
If you are on a yum / dnf system:
*note* on rhel and centos systems the gnome desktop package come with the gnome-terminal panel etc so no need to install those as well
sudo yum update
- for yum:
sudo yum groupinstall “GNOME Desktop”
- for dnf:
sudo dnf groupinstall “Server with GUI”
sudo yum -y install tigervnc-server
Second — Configure VNC
Start VNC
vncserver :1
Create VNC config (copy and paste as one fat command):
cat << EOF > ~/.vnc/xstartup
export XKL_XMODMAP_DISABLE=1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &
EOF
*note* this command will cat into your VNC config file, if you are not comfortable doing that go to your ~/.vnc/xstartup file and paste the config into the folder.
Restart VNC by killing and starting it:
Kill: vncserver -kill :1
Start: vncserver :1
Third — Install and configure OCAML and OPAM package manager
This is where things start to really split off for rehl and centos users vs apt systems. On apt, you can just run sudo apt install opam
and it will take you through :) If you like you can also follow along using the installer as it will work just fine as well!
First, install OCAML:
yum install ocaml ocamldoc ocaml-camlp4-devel
next, wget the OPAM installer:
wget https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh
mod the file to be executable:
chmod +x install.sh
Run the installer but we will want to get an older version. The reason for this is that depext has installation restrictions that won't let us get it on new versions (there is a GitHub bug report on this already as of August 2021).
./install.sh --version 2.0.10
Copy and paste this configuration into your /tmp/profile file:
test -r ~/.opam/opam-init/init.sh && . ~/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true
echo 'PATH="$PATH:$HOME/.opam/default/bin"' >> /tmp/profileeval $(opam env)
Copy the OPAM config into the bashrc and profile environments:
cat /tmp/profile >> ~/.profile
cat /tmp/profile >> ~/.bashrc
rm /tmp/profile
source ~/.bashrc
If you did this correctly the next terminal you open should yell about OPAM not running.
Fourth — Install depext and google-drive-ocamlfuse
Start opam:
opam init
Install depext:
opam install depext
Install google-drive-ocamlfuse:
*note* If you are using a newer version of Sqlite3 you will need to use a minor older version of this as there are errors currently (very generic ones, is a reported but on GitHub as well hopefully should be patched)
opam depext google-drive-ocamlfuse
opam install google-drive-ocamlfuse
Run this instead if you are using newer Sqlite3 versions:
opam install google-drive-ocamlfuse.0.7.20
Fifth — Configure Ocaml Google Drive Fuse (OGDF) and MOUNT IT!!!
So, time for the actual portion of mounting the google drive. Ocaml Google drive fuse uses the Google app engine to connect your google drive account to Ocaml (duh). The reason we need a GUI is 1 for the cloud instance but mainly because OGDF uses browsers to authenticate. (which makes things simple for us tbh).
Start OGDF and send it to the background as a task:
google-drive-ocamlfuse &
This should start a browser on your local machine for you to authenticate into your google account (if not maybe reliant on what you are using to connect to the box, I use MobaXTerm it's free). Just follow along with the prompts and you will reach a success page, when you do close the browser and return to the terminal. The process should be automatically completed.
To verify check that this file has data populated:
cat ~/.gdfuse/default/state
Make a directory and mount Google Drive to it:
mkdir ~/.gdrive_one
google-drive-ocamlfuse ~/.gdrive_one
Verify the mount went through:
df -h | grep google
You can unmount using the following:
fusermount -u ~/.gdrive_one
Six and Final step — Set up a service to automount Google Drive
This will create a service daemon that systemd will identity and use :)
cat << EOF >> /etc/systemd/system/google-drive.service
[Unit]
Description=FUSE filesystem over Google Drive
After=network.target
[Service]
User=$USER
Group=$USER
ExecStart=/home/$USER/.opam/default/bin/google-drive-ocamlfuse -label default /home/$USER/.gdrive_one
ExecStop=fusermount -u /home/$USER/.gdrive_one
Restart=always
Type=forking
[Install]
WantedBy=multi-user.target
Alias=google-drive.service
EOF
*note* if you are doing these as the root user you will want to remove the /home/
portions from the google-drive.service file
Restart and test the service:
sudo systemctl daemon-reload
sudo systemctl start google-drive
sudo systemctl status google-drive
Note for adding a second drive:
google-drive-ocamlfuse -lable gdrive_numba2 ~/.gdrive_two
That is pretty much it! Kinda a fun nifty thing to have and play around with! You can test the read and write speed using something like this as well:
[Sasdf@asdf]# sync; dd if=/dev/zero of=/root/.gdrive_one/testfile bs=1M count=1024; sync
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 21.0641 s, 51.0 MB/s
Hope yall enjoyed this, I know I did when I stumbled upon it, hope this also helps any RHEL and CentOS users get it done headache-free.