Andi Ashari

Tech Voyager & Digital Visionary

Turn Your Google Cloud Storage Bucket into a VM Disk - Easy Guide!

Turn Your Google Cloud Storage Bucket into a VM Disk - Easy Guide!

Ever thought about leveraging Google Cloud Storage beyond its conventional use? Imagine turning it into a virtual disk for your VM. Surprisingly, it’s not as daunting as it seems. Let’s dive into how you can achieve this with Cloud Storage FUSE.

Getting Started with Cloud Storage FUSE

Cloud Storage FUSE is a fantastic tool that allows you to mount Google Cloud Storage buckets as regular file systems on Linux or macOS. Follow these steps to set it up:

Step 1: Add Cloud Storage FUSE to Your System

Initiate by integrating Cloud Storage FUSE into your package sources. Execute these commands in your terminal:

export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list

Step 2: Import the Google Cloud Key

Securely import the Google Cloud public key for APT repositories:

curl | sudo apt-key add -

Step 3: Refresh Your Package List

Ensure your package list is up to date:

sudo apt-get update

Step 4: Install Cloud Storage FUSE

Proceed to install Cloud Storage FUSE alongside FUSE:

sudo apt-get install fuse gcsfuse

Step 5: Verify the Installation

Check that Cloud Storage FUSE installed correctly:

gcsfuse -v

A version number confirmation indicates a successful installation.

Mounting Your Bucket

Now, let’s get to the exciting part – mounting your storage bucket.

Step 1: Authenticate with Google Cloud

Begin by authenticating yourself to Google Cloud:

gcloud auth application-default login

Step 2: Create a Mount Point

Set up a directory for your bucket mount:

mkdir "$HOME/my-gcs-bucket-mount"

Step 3: Mount Your Bucket

Execute the mount command:

gcsfuse [your-bucket-name] "$HOME/my-gcs-bucket-mount"

Replace [your-bucket-name] with the name of your actual bucket.

Uploading Files to Your Bucket

To demonstrate, let’s upload a simple text file to your bucket.

Step 1: Create a Text File

Generate a file named example.txt.

Step 2: Transfer the File

Move the file to your bucket mount:

cp example.txt "$HOME/my-gcs-bucket-mount/example.txt"

Step 3: Confirm the Upload

Ensure the file exists both locally and in your bucket:

ls "$HOME/my-gcs-bucket-mount"
gcloud storage ls gs://[your-bucket-name]

If you see example.txt in both directories, your setup is correct.

Your Google Cloud Storage bucket now functions as a virtual disk on your VM, streamlining tasks like web hosting or data backup. The convenience of accessing Google Cloud Storage like a local file system is indeed a game-changer.

Considerations When Using Cloud Storage FUSE with Your VM:

  1. Storage Space: Data in your mounted directory resides in your GCS bucket, not your VM’s disk.
  2. Local Disk Usage: Minimal local disk usage occurs for caching and metadata.
  3. Network Use: Data transfer between your VM and GCS consumes VM network bandwidth.
  4. Performance: Access times may vary from local disk usage due to network conditions.
  5. Billing: Usage fees for GCS apply, along with potential network usage charges.
  6. Ideal Uses: Suited for extensive storage needs without increasing VM disk size or for sharing data across VMs.

While it appears as if the data is locally stored on your VM, it’s actually securely housed in GCS, adhering to its storage and billing protocols.