> ## Documentation Index
> Fetch the complete documentation index at: https://docs.idocs.fyi/llms.txt
> Use this file to discover all available pages before exploring further.

# Mount Google GCS Buckets

> Mount Google Cloud Storage buckets on Linux using gcsfuse.

To mount a Google Cloud Storage (GCS) bucket on a Linux machine as a file system, the standard tool is Cloud Storage FUSE (gcsfuse).

This tool allows you to access your bucket via standard file system commands (like `ls`, `cp`, `cat`), though it acts differently than a standard hard drive (higher latency, different consistency model).

### Step 1: Install `gcsfuse`

First, you need to configure the Google Cloud package repository and install the tool.

**For Ubuntu/Debian:**

```
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
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

sudo apt-get update
sudo apt-get install gcsfuse
```

**For CentOS/RHEL:**

```
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=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
EOF

sudo yum install gcsfuse
```

### Step 2: Authenticate

You need to provide credentials so the Linux machine can access your bucket.

```
gcloud auth application-default login
```

### Step 3: Mount the Bucket

Create a directory to serve as the mount point and run the mount command

```
# 1. Create a directory
mkdir ~/cloud-drive

# 2. Mount the bucket (replace 'cloud-drive' with your actual bucket name)
gcsfuse cloud-drive ~/cloud-drive
```

### Common Issues & Options

**Empty Directories:** GCS is an object store, not a true filesystem. It doesn't really have "folders." If you don't see your folders, add the `--implicit-dirs` flag:

```
gcsfuse --implicit-dirs cloud-drive ~/cloud-drive
```

**Permissions:** By default, only the user who mounted the bucket can access it. To allow other users (like a web server) to access it, use `allow_other`

```
gcsfuse -o allow_other cloud-drive ~/cloud-drive
```

### Step 4: Permanent Mount (Optional)

To have the bucket mount automatically when the server restarts, you must edit the `/etc/fstab` file.

1. Open the file: `sudo nano /etc/fstab`
2. Add a line at the bottom:

```

cloud-drive /path/to/mountpoint gcsfuse rw,user,key_file=/path/to/key.json,implicit_dirs 0 0
```

1. *Note: Ensure the user running the mount has read access to the key file.*

### Important Limitations

* **Latency:** It is much slower than a local disk. Do not run a database (like MySQL or Postgres) on a mounted bucket.
* **Cost:** Listing files (`ls`) and reading files counts as operations and can incur costs (Class A/B operations).
* **Consistency:** It offers "close-to-open" consistency. You might not see a file immediately after writing it if you are checking from a different machine.
