Expand VM disks

You can increase the size of your virtual machine (VM) disk partition when your VM instance requires additional storage space or increased performance limits.

You can only increase, and not decrease, the size of a disk. To decrease the disk size, you must create a new disk with a smaller size. Until you delete the original, larger disk, you are charged for both disks.

This page provides instructions to increase the size of both boot and non-boot disks.

Before you begin

To get the permissions you need to perform disk expansion, ask your Project IAM Admin to grant you the Project VirtualMachine Admin (project-vm-admin) role in the namespace where the VM resides. Follow the steps to verify that you have the required permissions.

Disk expansion

Follow the gdcloud or API steps to expand the disk size.

gdcloud

Expand the VM disk:

 gdcloud compute disks resize DISK_NAME --project=PROJECT --size=NEW_SIZE
  • Replace DISK_NAME with the name of the disk.

  • Replace PROJECT with the name of the GDC project in which the VM lives.

  • Replace NEW_SIZE with the new size of the disk.

API

  1. Expand the VirtualMachineDisk by updating the .spec.size field:

    kubectl --kubeconfig MANAGEMENT_API_SERVER \
        apply -n PROJECT -f - <<EOF
    apiVersion: virtualmachine.gdc.goog/v1
    kind: VirtualMachineDisk
    metadata:
      name: VM_BOOT_DISK_NAME
    spec:
      source:
        image:
          name: BOOT_DISK_IMAGE_NAME
          namespace: vm-system
      size: BOOT_DISK_SIZE
    EOF
    

    Replace the following variables:

    VariableDefinition
    MANAGEMENT_API_SERVER The Management API server kubeconfig file.
    PROJECT The GDC project to create the VM.
    VM_BOOT_DISK_NAME The name of the new VM boot disk.
    BOOT_DISK_IMAGE_NAME The name of the image to use for the new VM boot disk.
    BOOT_DISK_SIZE The size of the boot disk, such as 20Gi.
    This value must always be greater than or equal to the minimumDiskSize of the boot disk image.
  2. Wait until the .spec.size field updates to the new size.

Expand the file systems and partitions

After expanding the block device, you must expand the guest's partition and file system so that applications can consume the additional space. Some OS's do this automatically using cloud-init.