Mounting Google Cloud buckets in CentOS (GCP)

Power off the machine in question, and add full storage permissions.
Boot machine.

install gcsfuse repo:

sudo tee /etc/yum.repos.d/gcsfuse.repo > /dev/null <<EOF
[gcsfuse]
name=gcsfuse (packages.cloud.google.com)
baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

And install gcsfuse:

yum -y install gcsfuse

Make a directory to mount bucket in:

sudo mkdir -p /mnt/images

Change ownership:

sudo chown user:group /mnt/images
sudo chown -R user:group /mnt/images

edit /etc/fstab for automount:

my-google-bucket /mnt/images/ gcsfuse rw,allow_other,uid=<uid>,gid=<gid>

You can also do it insecure so all users can read/write on the server but I would not recommend.

my-google-bucket /mnt/images gcsfuse rw,allow_other,file_mode=777,dir_mode=777 

Once you modify the fstab, lets see if it mounts without issue, mount -a will mount all filesystems in /etc/fstab

mount -a

You should see the following output if successful.

Calling gcsfuse with arguments: -o rw -o allow_other --uid 1002 --gid 1003 my-
google-bucket /mnt/images
Using mount point: /mnt/images
Opening GCS connection...
Opening bucket...
Mounting file system...
File system has been successfully mounted.

now see if your user can write to the mount:

cd /mnt/images
mkdir test

if you do not get an I/O error, you should be good… Now lets see if we can create a file:

cd /mnt/images
touch testfile

If you DO get an IO error at this point, power off the machine and make sure it has the needed permissions. Also double check you used the right user and group ID’s from /etc/password.

Leave a Reply

Your email address will not be published. Required fields are marked *