Learn how to mount a Cloud Storage bucket as a local filesystem using Cloud Storage FUSE, so you can interact with your objects using standard file system semantics.
In this quickstart, you'll complete the following tasks:
Install Cloud Storage FUSE on Debian or Ubuntu
Mount the bucket as a folder on the machine
Upload an object to the bucket
You'll use the Google Cloud CLI to create and manage the object in your storage bucket, and you'll use the gcsfuse CLI to mount your bucket to your machine.
Before you begin
To set up a project, complete the following steps:
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
- Have a Cloud Storage bucket that you want to mount. If you don't already have one, create a new bucket.
Install Cloud Storage FUSE
To install Cloud Storage FUSE, complete the following instructions using your local shell on Debian or Ubuntu:
Add the Cloud Storage FUSE distribution URL as a package source:
export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb https://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
Import the Google Cloud APT repository public key:
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Update the list of available packages:
sudo apt-get update
Install Cloud Storage FUSE and its dependency FUSE:
sudo apt-get install fuse gcsfuse
When prompted, press Enter to confirm.
Confirm that Cloud Storage FUSE has been installed:
gcsfuse -v
If successful, the command returns output similar to the following:
gcsfuse version 0.41.12 (Go version go1.18.4)
Mount the bucket
To mount the bucket to your local file system, complete the following steps:
Generate Application Default Credentials using the
gcloud auth application-default login
command:gcloud auth application-default login
Cloud Storage FUSE automatically loads the credentials.
Create a directory to mount the storage bucket to:
mkdir "$HOME/mount-folder"
Mount your storage bucket using the
gcsfuse
command:gcsfuse BUCKET_NAME "$HOME/mount-folder"
Replace BUCKET_NAME with the name of the bucket you want to mount.
If successful, the command returns output which contains text similar to the following:
File system has been successfully mounted.
Upload an object into the bucket
To download an example object and upload it to the mounted bucket, complete the following steps:
Right-click the image above and save it somewhere on your computer, such as on the desktop.
You can also download the image using the cURL command
curl -O https://cloud.google.com/storage/images/kitten.png
.Copy the image from its saved location to the folder where your bucket is mounted, using the
cp
command:cp kitten.png "$HOME/mount-folder/kitten.png"
Verify that the image was copied to your local file system and uploaded to the bucket successfully by following the steps below:
To check that
kitten.png
was copied to your local file system, runls
on the folder where your bucket is mounted:ls "$HOME/mount-folder"
If the copy operation was successful,
kitten.png
is returned in the output.To list the contents of your bucket, use the
gcloud storage ls
command:gcloud storage ls gs://BUCKET_NAME
Replace BUCKET_NAME with the name of your bucket.
If the image was successfully uploaded to your bucket,
kitten.png
is returned in the output.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, delete the resources by completing the following steps:
Unmount the storage bucket from your Linux machine by using the
fusermount
tool:fusermount -u "$HOME/mount-folder"
To delete the bucket and everything inside of it, use the
gcloud storage rm
command with the--recursive
flag:gcloud storage rm gs://BUCKET_NAME --recursive
Replace BUCKET_NAME with the name of your bucket.
If successful, the command returns output similar to the following:
Removing gs://my-bucket/kitten.png#1676488739323620... Removing gs://my-bucket/...
What's next
Read about ways to mount buckets for different use cases.
- Learn how Vertex AI uses Cloud Storage FUSE to mount Cloud Storage buckets for custom training jobs.