# Create a Filestore instance using the gcloud CLI

This quickstart shows you how to get up and running quickly with Filestore
using the Google Cloud CLI. In this quickstart, you learn how to:

- Create a Filestore instance.
- Mount the file share from that instance on a Compute Engine client VM.
- Create a file on the mounted file share.
- Delete the Filestore instance.

## Before you begin

<br />

### Required roles


To get the permissions that
you need to complete this quickstart,

ask your administrator to grant you the
following IAM roles on your project:

- Create and manage Filestore instances: [Cloud Filestore Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/file.md.txt#file.editor) (`roles/file.editor`)
- Create and manage Compute Engine instances: [Compute Instance Admin (v1)](https://docs.cloud.google.com/iam/docs/roles-permissions/compute.md.txt#compute.instanceAdmin.v1) (`roles/compute.instanceAdmin.v1`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

When you finish the tasks that are described in this document, you can avoid
continued billing by deleting the resources that you created. For more information, see
[Clean up](https://docs.cloud.google.com/filestore/docs/create-instance-gcloud.md.txt#clean-up).

## Create a Compute Engine VM

### Linux


1. Create a Compute Engine instance. Configure the instance as follows:
   - Name the instance `nfs-client`.
   - Set the `--zone` flag to `us-central1-c`.
   - Set the `--image-project` flag to `debian-cloud`.
   - Set the `--image-family` flag to `debian-11`.
   - Set the `--tags` flag to `http-server`.

   ```bash
   gcloud compute instances create nfs-client --zone=us-central1-c --image-project=debian-cloud --image-family=debian-11 --tags=http-server
   ```

<br />

### Windows


1. Create a Compute Engine instance. Configure the instance as follows:
   - Name the instance `nfs-client`.
   - Set the `--zone` flag to `us-central1-c`.
   - Set the `--image-project` flag to `windows-cloud`.
   - Set the `--image-family` flag to `windows-2012-r2`.
   - Set the `--tags` flag to `http-server`.

   ```bash
   gcloud compute instances create nfs-client --zone=us-central1-c --image-project=windows-cloud --image-family=windows-2012-r2 --tags=http-server
   ```

<br />

## Create a Filestore instance

This quickstart shows how to create an instance in the regional service tier with custom performance enabled. For details on creating instances, see [create an instance](https://docs.cloud.google.com/filestore/docs/creating-instances.md.txt).

1. Create a Filestore instance. Configure the instance as follows:

   - Name the instance `nfs-server`.
   - Set the `--region` flag to `us-central1`.
   - Set the `--tier` flag to `REGIONAL`.
   - Set the `--performance` flag to `max-iops-per-tb=17000`.

     > [!NOTE]
     > **Note:** After activating custom performance for an instance you can't deactivate it for that instance. Instances with activated custom performance are billed according to purchased IOPS. For details, see [configure custom performance](https://docs.cloud.google.com/filestore/docs/custom-performance.md.txt#enable-custom-performance) and [Filestore pricing](https://docs.cloud.google.com/filestore/pricing).

   - Set the `--file-share` flag to `name="vol1",capacity=1TB`.

   - Set the `--network` flag to `name="default"`.

     ```bash
     gcloud filestore instances create nfs-server --region=us-central1 --tier=REGIONAL --performance=max-iops-per-tb=17000 --file-share=name="vol1",capacity=1TB --network=name="default"
     ```
2. Get information about the Filestore instance you created:

   ```bash
     gcloud filestore instances describe nfs-server --region=us-central1 
   ```

   The command returns something like:

   ```bash
       createTime: '2025-02-12T09:15:08.163246004Z'
       customPerformanceSupported: true
       fileShares:
        -capacityGb: '1024'
           name: vol1
       name: projects/yourproject/locations/us-central1/instances/nfs-server
       networks:
       -connectMode: DIRECT_PEERING
         ipAddresses:
          - 10.0.0.2
         network: default
         reservedIpRange: 10.0.0.2/26
       performanceConfig:
         iopsPerTb:
           maxIopsPerTb: '17000'
       performanceLimits:
         maxIops: '17000'
         maxReadIops: '17000'
         maxReadThroughputBps: '417792000'
         maxWriteIops: '5100'
         maxWriteThroughputBps: '139264000'
       protocol: NFS_V3
       state: READY
       tier: REGIONAL
   ```

Copy down the IP address of the instance for use when mounting the
file share. For this quickstart, we use the IP address `10.0.0.2`.

## Mount the Filestore file share on the `nfs-client` instance

### Linux


1. Establish an SSH connection to the `nfs-client` instance:

   ```bash
   gcloud compute ssh nfs-client
   ```

<br />

1. Install NFS by running the following commands on the terminal window of
   `nfs-client`:

       sudo apt-get -y update &&
       sudo apt-get -y install nfs-common

2. Create a mount directory on the `nfs-client` instance for the
   Filestore file share:

       sudo mkdir /mnt/test

3. Mount the file share to the `nfs-client` instance with the [`mount`](https://linux.die.net/man/8/mount)
   command by specifying the IP address of the Filestore
   instance, the name of the file share, and the mount directory to mount to:

       sudo mount MOUNT-POINT-DIRECTORY /mnt/test

   where:

   <var translate="no">MOUNT-POINT-DIRECTORY</var> is the path to the directory where the Filestore file share is mounted. For example: `10.0.0.2:/vol1`

   > [!NOTE]
   > **Note:** For NFS mount option recommendations, see [Mounting file shares](https://docs.cloud.google.com/filestore/docs/mounting-fileshares.md.txt#mounting-fileshare-on-vm).

4. **Optional**: Confirm that the Filestore file share is
   mounted:

   df -h --type=nfs
5. Make the file share accessible by changing its permissions:

       sudo chmod go+rw /mnt/test

> [!IMPORTANT]
> **Important:** We recommend setting more specific permissions in a production environment. For more information, see [Configuring access on a file share](https://docs.cloud.google.com/filestore/docs/access-control.md.txt#fileshare-access).

### Windows

### Sign in to the `nfs-client` instance and open a Command Prompt as an administrator

1. Create an account and set an initial password for the `nfs-client` instance:

       gcloud compute reset-windows-password nfs-client

2. Configure your instance to enable connecting to serial ports:

       gcloud compute instances add-metadata nfs-client --metadata=serial-port-enable=1

3. Enter an interactive session:

       gcloud compute connect-to-serial-port nfs-client --port=2

4. At the `SAC>` prompt, create a new channel:

       cmd

   A channel with the name `Cmd0001` is created.
5. Connect to the channel:

       ch -sn Cmd0001

6. Enter the username and password of the `nfs-client` instance and leave the
   `Domain` field blank. You are connected to the `Command Prompt` interface
   of the `nfs-client` instance.

### Install NFS client

1. In the `Command Prompt` of `nfs-client`, switch to `Windows PowerShell`:

       powershell

2. Install the `NFS` client:

       Install-WindowsFeature -Name NFS-Client

3. Restart the `nfs-client` instance when prompted:

       restart-computer

4. At the `SAC>` prompt, wait for the following notification to appear:

   ```bash
   EVENT: The CMD command is now available.
   ```

   Then, run the `cmd` and `ch -sn` commands as previously instructed to sign
   in and reconnect to the `nfs-client` instance.

### Configure the user ID used by the NFS client

1. In the Command Prompt, run `powershell` to switch to Windows PowerShell.
2. In `PowerShell`, run the following commands to create two new registry entries, `AnonymousUid` and `AnonymousGid`:

       New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default" `
           -Name "AnonymousUid" -Value "0" -PropertyType DWORD

       New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default" `
           -Name "AnonymousGid" -Value "0" -PropertyType DWORD

3. Restart the NFS client service:

       nfsadmin client stop

       nfsadmin client start

### Map the `vol1` file share to the `nfs-client` instance

1. Exit `PowerShell`:

       exit

2. From `Command Prompt`, mount the file share to the `nfs-client` instance
   with the [`mount`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/mount) command by
   specifying the IP address of the Filestore instance, the
   name of the file share, and the drive letter to mount to:

       mount -o mtype=hard 10.0.0.2:/vol1 z:

## Create a file on the mounted file share

### Linux

1. In the `nfs-client` terminal window, create a file named `testfile` by
   running the following command:

       echo 'This is a test' > /mnt/test/testfile

2. Confirm the file was created by running the following command and verifying
   that `testfile` is in the directory contents returned:

       ls /mnt/test

### Windows

1. In the Command Prompt window of the `nfs-client` instance, create a file
   named `testfile`:

       echo 'This is a test' > Z:\testfile

2. Confirm the file was created by running the following command:

       dir Z:

   and verifying that `testfile` is in the directory contents returned.

## Clean up


To avoid incurring charges to your Google Cloud account for
the resources used on this page, delete the Google Cloud project with the
resources.

### Delete the Google Cloud project

> [!CAUTION]
> **Caution** : Deleting a project has the following effects:
>
> - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
> - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.
>
>
> If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects
> can help you avoid exceeding project quota limits.

1. Delete a Google Cloud project:

```
gcloud projects delete PROJECT_ID
```

<br />

### Delete the Filestore instance

Delete the `nfs-server` instance:

    gcloud filestore instances delete nfs-server --zone=us-central1-c

### Delete the Compute Engine instance

Delete the instance:

```bash
gcloud compute instances delete nfs-client
```

## What's next

- Read the [Filestore Overview](https://docs.cloud.google.com/filestore) to learn more about the basics of Filestore.
- Set up a Filestore instance on your own by following the instructions at [Creating Instances](https://docs.cloud.google.com/filestore/docs/creating-instances.md.txt).
- Read [Access Control](https://docs.cloud.google.com/filestore/docs/access-control.md.txt) to learn how to control access to Filestore operations and the resources on an instance.
- See how to [copy data to or from a Filestore instance](https://docs.cloud.google.com/filestore/docs/copying-data.md.txt).
- See how to [transfer large datasets from Cloud Storage to Filestore](https://docs.cloud.google.com/filestore/docs/transfer-data-from-gcs.md.txt).