Adding or Resizing Persistent Disks

This page explains how to resize both persistent boot disks and secondary (non-boot) persistent disks. The page also explains how to add and format new persistent disks on your instances. You can only resize a persistent disk to increase its size. You cannot reduce the size of a persistent disk.

Persistent disks are available as either standard hard disk drives (HDD) or solid-state drives (SSD). For more general information about persistent disks and the types of persistent disks that are available, read the persistent disks overview.

Compute Engine manages the hardware behind persistent disks so you can add and resize your disks without handling striping or redundancy. Either attach one large secondary disk and resize it as you require additional space, or attach multiple smaller disks to separate your data into multiple volumes.

Unless you create a disk from an image, your new persistent disks start with no data or file systems. You must format those disks yourself after you attach them to your instances.

If either standard persistent disks or SSD persistent disks do not meet all of your performance or flexibility requirements, you can add additional storage options to your instances.

Before you begin

Adding a persistent disk to your instance

Create a standard persistent disk or an SSD persistent disk and attach it to an existing instance. If you do not have any instances, you must first create and start a new instance. During instance creation you can attach up to 15 secondary non-boot persistent disks to store your applications, data files, databases, and logs on separate volumes.

Create and attach a persistent disk through the Google Cloud Platform Console, the gcloud tool, or the API.

Permissions required for this task

Console

gcloud

API

Create and attach a persistent disk in the Google Cloud Platform Console:

  1. Go to the VM instances page. Go to the VM instances page
  2. Click the name of the instance where you want to add a disk.
  3. At the top of the instance details page, click Edit.
  4. Under Additional disks, click Add item.
  5. In the Name drop-down menu, click Create disk.
  6. Specify a name for the disk, configure the disk’s properties and select the Blank disk option.
  7. Click Create to create the disk.
  8. At the bottom of the instance details page, click Save to apply your changes to the instance and attach the new disk.
  9. After you create and attach a new disk to an instance, you must format and mount the disk so that the operating system can use the available storage space.

Formatting and mounting a persistent disk

New persistent disks start with no data or file systems. You must format those disks yourself after you attach them to your instances. The formatting process is different on Linux instances and Windows instances.

Permissions required for this task

Linux instances

Windows instances

Format and mount the new disk on your Linux instance. You can use any partition format and configuration that you need, but it is easiest to create a single ext4 file system without a partition table. This makes it simple to resize your disk later if you need more storage space.

  1. Go to the VM instances page. Go to the VM instances page
  2. Click the SSH button next to the instance that has the new attached disk. The browser opens a terminal connection to the instance.
  3. In the terminal, use the lsblk command to list the disks that are attached to your instance and find the disk that you want to format and mount.
sudo lsblk

In this example, sdb is the device ID for the new persistent disk.

Format the disk. You can use any file format that you need, but the most simple method is to format the entire disk with a single ext4 file system and no partition table. If you resize the persistent disk later, you can resize the file system without having to modify disk partitions.

Format the disk using the mkfs tool. This command deletes all data from the specified disk, so make sure that you specify the disk device correctly. To maximize disk performance, use the recommended formatting options in the -E flag. It is not necessary to reserve space for root on this secondary disk, so specify -m 0 to use all of the available disk space.





sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/[DEVICE_ID]

where [DEVICE_ID] is the device ID of the persistent disk that you are formatting. For this example, specify sdb to format the entire disk with no partition table.Note: RHEL 6 and CentOS 6 do not accept the lazy_journal_init=0 argument. Remove this parameter when formatting persistent disks on instances with these images.

Create a directory that serves as the mount point for the new disk. You can use any directory that you like, but this example creates a new directory under /mnt/disks/.





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

where: [MNT_DIR] is the directory where you will mount your persistent disk.

Use the mount tool to mount the disk to the instance with the discard option enabled:





sudo mount -o discard,defaults /dev/[DEVICE_ID] /mnt/disks/[MNT_DIR]

where:

  • [DEVICE_ID] is the device ID of the persistent disk that you are mounting.
  • [MNT_DIR] is the directory where you will mount your persistent disk.

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





  1. sudo chmod a+w /mnt/disks/[MNT_DIR] where: [MNT_DIR] is the directory where you mounted your persistent disk.

Optionally, you can add the persistent disk to the /etc/fstab file so that the device automatically mounts again when the instance restarts.

  1. Create a backup of your current /etc/fstab file.
sudo cp /etc/fstab /etc/fstab.backup

Use the blkid command to find the UUID for the persistent disk. The system generates this UUID when you format the disk. Use UUIDs to mount persistent disks because UUIDs do not change when you move disks between systems.





sudo blkid /dev/[DEVICE_ID]

where:

  • [DEVICE_ID] is the device ID of the persistent disk that you want to automatically mount. If you created a partition table on the disk, specify the partition that you want to mount.
  • [UUID_VALUE] is the UUID of the persistent disk that you must include in the /etc/fstab file.

Open the /etc/fstab file in a text editor and create an entry that includes the UUID. For example:

UUID=[UUID_VALUE] /mnt/disks/[MNT_DIR] ext4 discard,defaults,[NOFAIL_OPTION] 0 2

where:

  • [UUID_VALUE] is the UUID of the persistent disk that you must include in the /etc/fstab file.
  • [MNT_DIR] is the directory where you mounted your persistent disk.
  • [NOFAIL_OPTION] is a variable that specifies what the operating system should do if it cannot mount the persistent disk at boot time. To allow the system to continue booting even when it cannot mount the persistent disk, specify this option. For most distributions, specify the nofail option. For Ubuntu 12.04 or Ubuntu 14.04, specify the nobootwait option.

Optionally, you can complete this step with a single command. For example, the following command creates an entry in /etc/fstab to mount the /dev/sdb persistent disk at /mnt/disks/disk-1 using its UUID.





echo UUID=`sudo blkid -s UUID -o value /dev/sdb` /mnt/disks/disk-1 ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab

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





cat /etc/fstab

If you detach this persistent disk or create a snapshot from the boot disk for this instance, edit the /etc/fstab file and remove the entry for this persistent disk. Even with the nofail or nobootwait options in place, keep the /etc/fstab file in sync with the devices that are attached to your instance and remove these entries before you create your boot disk snapshot or when you detach persistent disks.