I’m extremely new to GCP, but I explicitly joined it because I wanted a storage solution where I could mount directly to my machine and just work normally without having to manually drag and drop things to ensure they are backed up. Not only is it easy, it’s really cheap. To ensure my day-to-day is smooth, I ensure that, upon booting up my machine, my GCP bucket is mounted automatically. In order to do this, there are a few things I had to tinker with in order to make it happen.
The configuration file /etc/fstab contains the necessary information to automate the process of mounting partitions. For mounting GCP storage in this case, I will be using fstab. Since the fstab configuration is read by the root user, this is the part where I ran into a few issues because root is not the local user when signing into to the machine, it’s me.
- Before we begin, please have a look at https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/docs/installing.md for installing the gcsfuse application installed.
- Secondly, look at the main article for configuring gcsfuse https://cloud.google.com/storage/docs/gcs-fuse. You will need to go through all of the steps, including 2a. A service account will be needed for the root user to mount under your Google account.
- Installation of the Google SDK: https://cloud.google.com/sdk/docs/
- After installing the gcsfuse application, create a service account as noted in https://cloud.google.com/storage/docs/gcs-fuse in 2a. When doing this, ensure that the project you select is the same project as the bucket. If you do not select the same project, the json file generated will NOT work. Download the json file.
- There may be a workaround for this step, but this way worked for me. Change to the root user
sudo suand then run
gcloud auth application-default login. When doing this, it will provide a URL. Copy the URL and paste into the web browser. Select the Google account that the bucket is associated with.
- Credentials will be written to
/root/.config/gcloud/application_default_credentials.json, but those are YOUR credentials. Really, we want to use the service account credentials here for security reasons. Replace the contents of
application_default_credentials.jsonwith the contents of the json file downloaded in #1.
- Switch back to your user account by running
- Make a directory on your machine that the bucket will be mounting to. In this example, let’s use /media/bucket:
sudo mkdir /media/bucket && sudo chown $WHOAMI:$WHOAMI /media/bucket. This will ensure that the directory created will be owner by your user account.
/etc/fstaband add the following line, replacing attributes to match your own:
BUCKETNAME /media/bucket gcsfuse rw,gid=1000,uid=1000,noauto,user,allow_other,_netdev. Replace
BUCKETNAMEwith your bucket name and replace
1000with your uid and gid. You can determine this by running
/etc/fuse.confand uncomment the line
- Finally, test to ensure that the bucket mounts correctly:
sudo mount /media/bucket(Replacing /media/bucket with the directory you created in #5).