Add a local SSD to your VM

Local SSDs are designed for temporary storage use cases such as caches or scratch processing space. When you add a local SSD to your VM, the local SSD is physically attached to the server that hosts your VM.

Before you begin

Create a VM with a local SSD

Because local SSDs are located on the physical machine where your VM is running, they can be created only during the VM creation process. Local SSDs cannot be used as boot devices.

After creating a local SSD, you must format and mount the device before you can use it.

You can create a VM with a local SSD using the Google Cloud console, the gcloud CLI, or the Compute Engine API.

Console

  1. Go to the Create an instance page.

    Go to Create an instance

  2. Specify the VM details.

  3. In the Machine configuration section, select a first-generation series from the Series list.

  4. Expand the Networking, disks, security, management, sole tenancy section.

  5. Expand Disks, click Add local SSD, and do the following:

    1. On the Configure local SSD page, select the number of disks you want from the Number of local SSDs list.
    2. Click Save.
  6. Continue with the VM creation process.

  7. After creating a local SSD, you must format and mount the device before you can use it.

gcloud

To create a VM instance with an attached local SSD, follow the instructions to create an instance, using the --local-ssd flag to create and attach local SSD partitions. To create multiple local SSD partitions, add more --local-ssd flags. Optionally, you can also set values for the interface and the device name for each --local-ssd flag.

Similarly, you can create an instance with two local SSDs that each use a SCSI interface as follows:

gcloud compute instances create example-instance \
    --machine-type n2-standard-8 \
    --local-ssd interface=[INTERFACE_TYPE] \
    --local-ssd interface=[INTERFACE_TYPE] \
    --image-project [IMAGE_PROJECT] \
    --image-family [IMAGE_FAMILY]

where:

  • [INTERFACE_TYPE] is the local SSD interface that you want to use for this device. Specify nvme if your boot disk image has optimized NVMe drivers, or scsi for other images.
  • [INSTANCE_NAME] is the name for the new instance.
  • [IMAGE_FAMILY] is one of the available image families.
  • [IMAGE_PROJECT] is the image project that the image family belongs to.

If necessary, you can attach local SSD partitions a single instance using a combination of nvme and scsi for different partitions. Performance for the nvme device depends on the boot disk image for your instance.

After creating a local SSD, you must format and mount the device before you can use it.

API

In the API, you can create a local SSD device when creating a virtual machine instance by using the initializeParams property. You must also provide the following properties:

  • diskType: Set to local SSD
  • autoDelete: Set to true
  • type: Set to SCRATCH

The following properties cannot be set for local SSD instances:

  • diskName
  • sourceImage property
  • diskSizeGb

Here is a sample request payload that creates an instance with a boot disk and a local SSD device:

{
   "machineType":"zones/us-central1-f/machineTypes/n2-standard-8",
   "name":"local-ssd-instance",
   "disks":[
      {
         "type":"PERSISTENT",
         "initializeParams":{
            "sourceImage":"projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts"
         },
         "boot":true
      },
      {
         "type":"SCRATCH",
         "initializeParams":{
            "diskType":"zones/us-central1-f/diskTypes/local-ssd"
         },
         "autoDelete":true,
         "interface": "NVME"
      }
   ],
   "networkInterfaces":[
      {
         "network":"global/networks/default"
      }
   ]
 }

After creating a local SSD, you must format and mount the device before you can use it.

For more information on creating an instance in the API, see the Compute Engine API.

Format and mounting a local SSD device

Format and mount individual local SSD partitions

The easiest way to connect local SSDs to your instance is to format and mount each device with a single partition. Alternatively, you can combine multiple partitions into a single logical volume.

Linux instances

Format and mount the new local SSD on your Linux instance. You can use any partition format and configuration that you need. For this example, create a single ext4 partition.

  1. Go to the VM instances page.

    Go to VM instances

  2. Click the SSH button next to the instance that has the new attached local SSD. The browser opens a terminal connection to the instance.

  3. In the terminal, use the lsblk command to identify the local SSD that you want to mount.

    $ lsblk
    

    Local SSDs in SCSI mode have standard names like sdb. Local SSDs in NVMe mode have names like nvme0n1, as shown in the NAME column of the following output:

    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda       8:0    0   10G  0 disk
    └─sda1    8:1    0   10G  0 part /
    nvme0n1 259:0    0  375G  0 disk
    
  4. Format the local SSD with an ext4 file system. This command deletes all existing data from the local SSD.

    $ sudo mkfs.ext4 -F /dev/[SSD_NAME]
    

    Replace [SSD_NAME] with the ID of the local SSD that you want to format. For example, specify nvme0n1 to format the first NVMe local SSD on the instance.

  5. Use the mkdir command to create a directory where you can mount the device.

    $ sudo mkdir -p /mnt/disks/[MNT_DIR]
    

    where: [MNT_DIR] is the directory where you want to mount your local SSD.

  6. Mount the local SSD to the instance. Optionally, you can disable write cache flushing to improve write performance while risking reduced durability for up to two seconds of cached data writes.

    $ sudo mount /dev/[SSD_NAME] /mnt/disks/[MNT_DIR]
    

    where:

    • [SSD_NAME] is the ID of the local SSD that you want to mount.
    • [MNT_DIR] is the directory where you want to mount your local SSD.
  7. Configure read and write access to the device. For this example, grant write access to the device for all users.

    $ sudo chmod a+w /mnt/disks/[MNT_DIR]
    

    where: [MNT_DIR] is the directory where you mounted your local SSD.

Optionally, you can add the local SSD to the /etc/fstab file so that the device automatically mounts again when the instance restarts. This entry does not preserve data on your local SSD if the instance stops. See Local SSD data persistence for complete details about local SSD data persistence.

When you specify the entry /etc/fstab file, be sure to include the nofail option so that the instance can continue to boot even if the local SSD is not present. For example, if you take a snapshot of the boot disk and create a new instance without any local SSDs attached, the instance can continue through the startup process and not pause indefinitely.

  1. Create the /etc/fstab entry. Use the blkid command to find the UUID for the file system on the device and edit the /etc/fstab file to include that UUID with the mount options. You can complete this step with a single command.

    For example, for a local SSD in NVMe mode, use the following command:

    $ echo UUID=`sudo blkid -s UUID -o value /dev/disk/by-id/google-local-nvme-ssd-0` /mnt/disks/[MNT_DIR] ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab
    

    For a local SSD in a non-NVMe mode such as SCSI, use the following command:

    $ echo UUID=`sudo blkid -s UUID -o value /dev/disk/by-id/google-local-ssd-0` /mnt/disks/[MNT_DIR] ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab
    

    where [MNT_DIR] is the directory where you mounted your local SSD.

  2. Use the cat command to verify that your /etc/fstab entries are correct:

    $ cat /etc/fstab
    

If you create a snapshot from the boot disk of this instance and use it to create a separate instance that does not have local SSDs, edit the /etc/fstab file and remove the entry for this local SSD. Even with the nofail option in place, keep the /etc/fstab file in sync with the partitions that are attached to your instance and remove these entries before you create your boot disk snapshot.

Windows instances

Use the Windows Disk Management tool to format and mount a local SSD on a Windows instance.

  1. Connect to the instance through RDP. For this example, go to the VM instances page and click the RDP button next the instance that has the local SSDs attached. After you enter your username and password, a window opens with the desktop interface for your server.

  2. Right-click the Windows Start button and select Disk Management.

    Selecting the Windows Disk Manager tool from the right-click menu on the Windows Start button.

  3. If you have not initialized the local SSD before, the tool prompts you to select a partitioning scheme for the new partitions. Select GPT and click OK.

    Selecting a partition scheme in the disk initialization window.

  4. After the local SSD initializes, right click the unallocated disk space and select New Simple Volume.

    Creating a new simple volume from the attached disk.

  5. Follow the instructions in the New Simple Volume Wizard to configure the new volume. You can use any partition format that you like, but for this example select NTFS. Also, check Perform a quick format to speed up the formatting process.

    Selecting the partition format type in the New Simple Volume Wizard.

  6. After you complete the wizard and the volume finishes formatting, check the new local SSD to ensure it has a Healthy status.

    Viewing the list of disks that are recognized by Windows, verify that the local SSD has a Healthy status.

That's it! You can now write files to the local SSD.

Format and mount multiple local SSD partitions into a single logical volume

Unlike persistent SSDs, local SSDs have a fixed 375 GB capacity for each device that you attach to the instance. If you want to combine multiple local SSD partitions into a single logical volume, you must define volume management across these partitions yourself.

Linux instances

Use mdadm to create a RAID 0 array. This example formats the array with a single ext4 file system, but you can apply any file system that you prefer.

  1. Go to the VM instances page.

    Go to VM instances

  2. Click the SSH button next to the instance that has the new attached local SSD. The browser opens a terminal connection to the instance.

  3. In the terminal, install the mdadm tool. The install process for mdadm includes a user prompt that halts scripts, so run this process manually.

    Debian and Ubuntu:

    $ sudo apt update && sudo apt install mdadm --no-install-recommends
    

    CentOS and RHEL:

    $ sudo yum install mdadm -y
    

    SLES and openSUSE:

    $ sudo zypper install -y mdadm
    

  4. Use the lsblk command to identify all of the local SSDs that you want to mount together. For this example, the instance has eight local SSD partitions in NVMe mode:

    $ lsblk
    
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda       8:0    0   10G  0 disk
    └─sda1    8:1    0   10G  0 part /
    nvme0n1 259:0    0  375G  0 disk
    nvme0n2 259:1    0  375G  0 disk
    nvme0n3 259:2    0  375G  0 disk
    nvme0n4 259:3    0  375G  0 disk
    nvme0n5 259:4    0  375G  0 disk
    nvme0n6 259:5    0  375G  0 disk
    nvme0n7 259:6    0  375G  0 disk
    nvme0n8 259:7    0  375G  0 disk
    
    

    Local SSDs in SCSI mode have standard names like sdb. Local SSDs in NVMe mode have names like nvme0n1.

  5. Use mdadm to combine multiple local SSD devices into a single array named /dev/md0. This example merges eight local SSD devices in NVMe mode. For local SSD devices in SCSI mode, specify the names that you obtained from the lsblk command:

    $ sudo mdadm --create /dev/md0 --level=0 --raid-devices=8 \
    /dev/nvme0n1 /dev/nvme0n2 /dev/nvme0n3 /dev/nvme0n4 \
    /dev/nvme0n5 /dev/nvme0n6 /dev/nvme0n7 /dev/nvme0n8
    
    mdadm: Defaulting to version 1.2 metadata
    mdadm: array /dev/md0 started.
    
    
  6. Format the full /dev/md0 array with an ext4 file system. This command deletes all existing data from the local SSDs.

    $ sudo mkfs.ext4 -F /dev/md0
    
  7. Create a directory to where you can mount /dev/md0. For this example, create the /mnt/disks/ssd-array directory:

    $ sudo mkdir -p /mnt/disks/[MNT_DIR]
    

    where: [MNT_DIR] is the directory where you want to mount your local SSD array.

  8. Mount the /dev/md0 array to the /mnt/disks/ssd-array directory. Optionally, you can disable write cache flushing to improve write performance while risking reduced durability for up to two seconds of cached data writes.

    $ sudo mount /dev/md0 /mnt/disks/[MNT_DIR]
    

    where: [MNT_DIR] is the directory where you want to mount your local SSD array.

  9. Configure read and write access to the device. For this example, grant write access to the device for all users.

    $ sudo chmod a+w /mnt/disks/[MNT_DIR]
    

    where: [MNT_DIR] is the directory where you mounted your local SSD array.

Optionally, you can add the local SSD to the /etc/fstab file so that the device automatically mounts again when the instance restarts. This entry does not preserve data on your local SSD if the instance stops. See Local SSD data persistence for complete details on local SSD data persistence.

When you specify the entry /etc/fstab file, be sure to include the nofail option so that the instance can continue to boot even if the local SSD is not present. For example, if you take a snapshot of the boot disk and create a new instance without any local SSDs attached, the instance can continue through the startup process and not pause indefinitely.

  1. Create the /etc/fstab entry. Use the blkid command to find the UUID for the file system on the device and edit the /etc/fstab file to include that UUID with the mount options. Specify the nofail option to allow the system to boot even if the local SSD is unavailable.You can complete this step with a single command. For example:

    $ echo UUID=`sudo blkid -s UUID -o value /dev/md0` /mnt/disks/[MNT_DIR] ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab
    

    where [MNT_DIR] is the directory where you mounted your local SSD array.

  2. Use the cat command to verify that your /etc/fstab entries are correct:

    $ cat /etc/fstab
    

If you create a snapshot from the boot disk of this instance and use it to create a separate instance that does not have local SSDs, edit the /etc/fstab file and remove the entry for this local SSD array. Even with the nofail option in place, keep the /etc/fstab file in sync with the partitions that are attached to your instance and remove these entries before you create your boot disk snapshot.

Windows instances

Use the Windows Disk Management tool to format and mount an array of local SSDs on a Windows instance.

  1. Connect to the instance through RDP. For this example, go to the VM instances page and click the RDP button next the instance that has the local SSDs attached. After you enter your username and password, a window opens with the desktop interface for your server.

  2. Right click the Windows Start button and select Disk Management.

    Selecting the Windows Disk Manager tool from the right-click menu on the Windows Start button.

  3. If you have not initialized the local SSDs before, the tool prompts you to select a partitioning scheme for the new partitions. Select GPT and click OK.

    Selecting a partition scheme in the disk initialization window.

  4. After the local SSD initializes, right click the unallocated disk space and select New Striped Volume.

    Creating a new striped volume from the attached disk.

  5. Select the local SSD partitions that you want to include in the striped array. For this example, select all of the partitions to combine them into a single local SSD device.

    Selecting the local SSD partitions to include in the array.

  6. Follow the instructions in the New Striped Volume Wizard to configure the new volume. You can use any partition format that you like, but for this example select NTFS. Also, check Perform a quick format to speed up the formatting process.

    Selecting the partition format type in the New Striped Volume Wizard.

  7. After you complete the wizard and the volume finishes formatting, check the new local SSD to ensure it has a Healthy status.

    Viewing the list of disks that are recognized by Windows, verify that the local SSD has a Healthy status.

You can now write files to the local SSD.