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
- If you want to use the command-line examples in this guide, do the following:
- Install or update to the latest version of the Google Cloud CLI.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
- Review the local SSD limitations before using local SSDs.
- Read about the difference between Persistent Disks and local SSDs.
- If you are adding local SSDs to virtual machines (VM) instances that have attached GPUs, see local SSD availability by GPU regions and zones.
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
Go to the Create an instance page.
Specify the VM details.
In the Machine configuration section, select a first-generation series from the Series list.
Expand the Networking, disks, security, management, sole tenancy section.
Expand Disks, click Add local SSD, and do the following:
- On the Configure local SSD page, select the number of disks you want from the Number of local SSDs list.
- Click Save.
Continue with the VM creation process.
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. Specifynvme
if your boot disk image has optimized NVMe drivers, orscsi
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 SSDautoDelete
: Set to truetype
: Set toSCRATCH
The following properties cannot be set for local SSD instances:
diskName
sourceImage
propertydiskSizeGb
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.
Go to the VM instances page.
Click the SSH button next to the instance that has the new attached local SSD. The browser opens a terminal connection to the instance.
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 likenvme0n1
, 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
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, specifynvme0n1
to format the first NVMe local SSD on the instance.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.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.
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.
Create the
/etc/fstab
entry. Use theblkid
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.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.
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.
Right-click the Windows Start button and select Disk Management.
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.
After the local SSD initializes, right click the unallocated disk space and select New Simple Volume.
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.After you complete the wizard and the volume finishes formatting, check the new local SSD to ensure it 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.
Go to the VM instances page.
Click the SSH button next to the instance that has the new attached local SSD. The browser opens a terminal connection to the instance.
In the terminal, install the
mdadm
tool. The install process formdadm
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
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 likenvme0n1
.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 thelsblk
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.
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
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.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.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.
Create the
/etc/fstab
entry. Use theblkid
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 thenofail
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.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.
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.
Right click the Windows Start button and select Disk Management.
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.
After the local SSD initializes, right click the unallocated disk space and select New Striped Volume.
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.
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.After you complete the wizard and the volume finishes formatting, check the new local SSD to ensure it has a
Healthy
status.
You can now write files to the local SSD.