Mount a Cloud Storage bucket using Cloud Storage FUSE

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:

  1. 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.
  2. In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Install the Google Cloud CLI.
  5. To initialize the gcloud CLI, run the following command:

    gcloud init
  6. In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.

    Go to project selector

  7. Make sure that billing is enabled for your Google Cloud project.

  8. Install the Google Cloud CLI.
  9. To initialize the gcloud CLI, run the following command:

    gcloud init
  10. 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:

  1. 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
  2. Import the Google Cloud APT repository public key:

    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
  3. Update the list of available packages:

    sudo apt-get update
  4. Install Cloud Storage FUSE and its dependency FUSE:

    sudo apt-get install fuse gcsfuse
  5. When prompted, press Enter to confirm.

  6. 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:

  1. Generate Application Default Credentials using the gcloud auth application-default login command:

    gcloud auth application-default login

    Cloud Storage FUSE automatically loads the credentials.

  2. Create a directory to mount the storage bucket to:

    mkdir "$HOME/mount-folder"
  3. 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:

The image of a kitten to upload into the bucket.

  1. 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.

  2. 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"
  3. Verify that the image was copied to your local file system and uploaded to the bucket successfully by following the steps below:

    1. To check that kitten.png was copied to your local file system, run ls 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.

    2. 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:

  1. Unmount the storage bucket from your Linux machine by using the fusermount tool:

    fusermount -u "$HOME/mount-folder"
  2. 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