Mounting Fileshares on Compute Engine Clients

This page shows you how to mount a Cloud Filestore fileshare on a Compute Engine virtual machine (VM) instance.

Client VMs must be in the same Google Cloud Platform project and VPC network as the Cloud Filestore instance.

Mounting a fileshare on a VM instance

Use one of the following procedures to mount a Cloud Filestore fileshare on a Compute Engine VM:

Linux: mount

To manually mount a fileshare to a Linux client VM:

  1. Go to the VM instances page
  2. Locate the Linux VM you want to use as a client, then click SSH to open a terminal on that VM.
  3. Install NFS by running the following commands:

    Debian/Ubuntu

    Use the following commands to install NFS on Debian or Ubuntu.

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

    RHEL/CentOS

    Use the following commands to install NFS on Red Hat Enterprise Linux or CentOS.

    sudo yum update
    sudo yum install nfs-utils

    SUSE

    Use the following commands to install NFS on SUSE.

    sudo zypper update
    sudo zypper -n install nfs-client
  4. Make a local directory to map to the Cloud Filestore fileshare by running the following command:

    sudo mkdir -p [MOUNT_POINT_DIRECTORY]
    

    where [MOUNT_POINT_DIRECTORY] is the directory to create (for example /mnt/filedir).

  5. Mount the fileshare from the Cloud Filestore instance by running the mount command. You can use any NFS mount options. For the best performance, we recommend using the default NFS mount options, especially using a hard mount and having the rsize and wsize options set to 1 MB.

    Run the mount command, replacing [VALUES_IN_BRACKETS] with the appropriate values:

    sudo mount [IP_ADDRESS]:/[FILESHARE]/[FILESHARE_SUB_DIR] [MOUNT_POINT_DIRECTORY]
    

    where:

    • [IP_ADDRESS] is the IP address for the Cloud Filestore instance.
    • [FILESHARE] is the name of the fileshare on the instance.
    • [FILESHARE_SUB_DIR] is the path of the subdirectory in the fileshare to mount. To mount the entire fileshare, leave this blank.
    • [MOUNT_POINT_DIRECTORY] is the path where you want to map the Cloud Filestore fileshare to.

    You can get the IP address and fileshare name of an instance from any of following sources:

    For example, given a Cloud Filestore instance with an IP address 10.0.1.2 and a fileshare named share1, the following command mounts the fileshare to the local mount point directory /mnt/render:

    sudo mount 10.0.1.2:/share1 /mnt/render
    
  6. Optionally, run chmod to set permissions on the mount directory so that it is writable by other than the root user. Run the following command to set directory permissions, replacing [VALUES_IN_BRACKETS] with the appropriate values:

    sudo chmod [PERMISSIONS] [MOUNT_POINT_DIRECTORY]
    

    where:

    • [PERMISSIONS] is the set of permissions to grant. For example, chmod go+rw makes the directory readable and writeable by users in the group that owns the directory and all other users. For more information about setting permissions, see Configuring access on a fileshare.
    • [MOUNT_POINT_DIRECTORY] is the path to the directory where the Cloud Filestore fileshare is mounted.
  7. Optional: Confirm that the Cloud Filestore fileshare is mounted by running the following command:

    df -h --type=nfs
    

    The output should contain an entry similar to the following:

     Filesystem        Size    Used  Avail  Use%  Mounted on
     10.0.1.2:/share1  1018G   76M   966G   1%    /mnt/render
     10.0.2.2:/vol3    1018G   76M   966G   1%    /mnt/filestore3
  8. If the applications you plan to use with the mounted Cloud Filestore fileshare require NFS file locking, and this client VM instance is using something other than the default VPC network with unchanged settings, you might need to set two ports on the instance in order to make firewall configuration easier. For more information on determining if you need to configure a firewall rule for the VPC network, see Configuring Firewall Rules. For more information on setting ports, see Setting NFS Ports.

Linux: /etc/fstab

You can make fileshares automatically mount to client VMs during boot up by modifying the client's /etc/fstab file:

  1. Go to the VM instances page
  2. Locate the Linux VM you want to use as a client, then click SSH to open a terminal on that VM.
  3. Install NFS by running the following commands:

    Debian/Ubuntu

    Use the following commands to install NFS on Debian or Ubuntu.

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

    RHEL/CentOS

    Use the following commands to install NFS on Red Hat Enterprise Linux or CentOS.

    sudo yum update
    sudo yum install nfs-utils

    SUSE

    Use the following commands to install NFS on SUSE.

    sudo zypper update
    sudo zypper -n install nfs-client
  4. Make a local directory to map to the Cloud Filestore fileshare by running the following command:

    sudo mkdir -p [MOUNT_POINT_DIRECTORY]
    

    where [MOUNT_POINT_DIRECTORY] is the directory to create (for example /mnt/filedir).

  5. Open the /etc/fstab file by running the following command:

    sudo vim /etc/fstab
    
  6. Add the following line in the /etc/fstab file:

    [IP_ADDRESS]:/[FILESHARE]/[FILESHARE_SUB_DIR] [MOUNT_POINT_DIRCTORY] nfs defaults 0 0
    

    where:

    • [IP_ADDRESS] is the IP address for the Cloud Filestore instance.
    • [FILESHARE] is the name of the fileshare on the instance.
    • [FILESHARE_SUB_DIR] is the path of the subdirectory in the fileshare to mount. To mount the entire fileshare, leave this blank.
    • [MOUNT_POINT_DIRECTORY] is the path you want to map the Cloud Filestore fileshare to.

    Example: The following line in /etc/fstab mounts fileshare vol1 of the Cloud Filestore instance with IP address 10.0.0.2 in the mount point directory /mnt with the default mount options:

    10.0.0.2:/vol1 /mnt nfs defaults 0 0
    
  7. Run the following command to mount everything in /etc/fstab:

    sudo mount -a
    

    The fileshare is now automatically mounted each time the client VM boots up.

Linux: autofs

You can configure autofs to automatically mount a fileshare only when it is accessed and keep it unmounted when it is not used. Compared to having a fileshare statically mounted in /etc/fstab, this method helps conserve client VM resources in situations where the client needs to map to many mount points.

  1. Go to the VM instances page
  2. Locate the Linux VM you want to use as a client, then click SSH to open a terminal on that VM.
  3. Install NFS by running the following commands:

    Debian/Ubuntu

    Use the following commands to install NFS on Debian or Ubuntu.

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

    RHEL/CentOS

    Use the following commands to install NFS on Red Hat Enterprise Linux or CentOS.

    sudo yum update
    sudo yum install nfs-utils

    SUSE

    Use the following commands to install NFS on SUSE.

    sudo zypper update
    sudo zypper -n install nfs-client
  4. From the terminal window of the client VM, install autofs by running the following command:

    Debian/Ubuntu

    sudo apt-get install autofs
    

    RHEL/CentOS

    sudo yum install autofs
    

    SUSE

    sudo zypper -n install autofs
    
  5. Enable autofs by running the following command:

    sudo systemctl enable --now autofs
    
  6. Open the /etc/auto.master file by running the following command:

    sudo vim /etc/auto.master
    
  7. Make a local directory to map to the Cloud Filestore fileshare by running the following command:

    sudo mkdir -p [MOUNT_POINT_DIRECTORY]
    

    where [MOUNT_POINT_DIRECTORY] is the directory to create. It must not contain any subdirectories. For the purpose of this guide, we use /nfs as the mount point directory.

  8. Add the following line in the /etc/auto.master file:

    /nfs /etc/auto.nfs --timeout [SECONDS]
    

    where [SECONDS] is the duration in seconds before the mount timeout. The default value is 300. Setting this value to 0 disables unmounting by autofs.

  9. Create the /etc/auto.nfs file by running the following command:

    sudo vim /etc/auto.nfs
    
  10. Add the following line in the /etc/auto.nfs file:

    [MOUNT_POINT_SUBDIR] [OPTIONS] [IP_ADDRESS]:/[FILESHARE]/[FILESHARE_SUB_DIR]
    

    where:

    • [MOUNT_POINT_SUBDIR] is the subdirectory in /nfs you want to map the Cloud Filestore fileshare to. This subdirectory is dynamically generated and should not exist in the client VM.
    • [OPTIONS] are the NFS mount options. If you want use the default options, just leave this field blank.
    • [IP_ADDRESS] is the IP address for the Cloud Filestore instance.
    • [FILESHARE] is the name of the fileshare on the instance.
    • [FILESHARE_SUB_DIR] is the path of the subdirectory in the fileshare to mount. To mount the entire fileshare, leave this blank.

    Example: The following line in /etc/auto.nfs mounts fileshare vol1 of the Cloud Filestore instance with IP address 10.0.0.2 in the dynamically generated subdirectory fileshares with read/write access granted:

    fileshares -rw 10.0.0.2:/vol1
    
  11. If the fileshare is currently mounted, you need to unmount it by running the following command:

    sudo umount [MOUNT_POINT_DIRECTORY]
    

    where [MOUNT_POINT_DIRECTORY] is the path where the Cloud Filestore fileshare is mapped to.

    If there is an /etc/fstab entry that mounts the fileshare at system boot, make sure to remove it.

  12. Reload autofs by running the following command:

    sudo service autofs reload
    
  13. Confirm that your configuration works by running the following command:

    ls [MOUNT_POINT_DIRECTORY]/[MOUNT_POINT_SUBDIR]
    

    where:

    • [MOUNT_POINT_DIRECTORY] is the mount point directory indicated in the /etc/auto.master file.
    • [MOUNT_POINT_SUBDIR] is the mount point subdirectory indicated in the /etc/auto.nfs file.

    From our example, the command would be:

    ls /nfs/fileshares
    

    If the automount is configured correctly, the system will first mount the fileshare and then return the results of the ls command.

Windows

  1. Go to the VM instances page
  2. Locate the Windows VM you want to use as a client, then click RDP to open a remote desktop connection to that VM.
  3. Open PowerShell as an administrator.
  4. In PowerShell, install the NFS client by running the following command:

      Install-WindowsFeature -Name NFS-Client
    
  5. Restart the Windows VM instance as prompted, then open a new remote desktop connection.

  6. Click the Windows Start button to open the Start page.

  7. On the Start page, search for regedit and then open the Registry Editor.

  8. Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default.

  9. Right-click on the Default folder, choose New, and then choose DWORD (32-bit) Value.

  10. Type AnonymousUid as the name for the new entry.

  11. Repeat step 9 and create another entry named AnonymousGid.

  12. Open PowerShell as an administrator.

  13. In PowerShell, restart the NFS client service by running the following commands:

    nfsadmin client stop
    nfsadmin client start
    
  14. Open Windows Explorer and click the Map network drive menu item.

  15. For Drive, select an unused drive letter to map to.

  16. For Folder, type the connection information for the Cloud Filestore fileshare, in the format \\[IP_ADDRESS]\[FILESHARE],

    where:

    • [IP_ADDRESS] is the IP address for the Cloud Filestore instance.
    • [FILESHARE] is the name of the fileshare on the instance.

    You can get the IP address and fileshare name of an instance from any of following sources:

    For example, given a Cloud Filestore instance with an IP address of 10.0.1.2 and a fileshare named share1, the Folder value should be as follows:

    \\10.0.1.2\share1
    
  17. Click Finish.

  18. In the left-hand pane of Windows Explorer, right-click the mounted fileshare and choose Properties.

  19. On the NFS Attributes tab, adjust the permissions in the File permissions (mode) section to reflect who is allowed to read, write, and execute files on this share.

What's next

Copy data to the mounted fileshare.

Kunde den här sidan hjälpa dig? Berätta:

Skicka feedback om ...

Cloud Filestore Documentation