An existing disk can be expanded or moved to another storage without deleting it and without recreating the machine.

Changing the disk size

You can grow a disk even while it’s attached to a running virtual machine (VM). You can’t shrink a disk.

  • Using the CLI
  • Using the web interface
  1. Check the current disk size:

    d8 k get vd linux-vm-root
    

    Example output:

    NAME            PHASE   CAPACITY   VIRTUALMACHINE   AGE
    linux-vm-root   Ready   10Gi       linux-vm         10m
    
  2. Set the new size in the .spec.persistentVolumeClaim.size parameter:

    d8 k patch vd linux-vm-root --type merge -p '{"spec":{"persistentVolumeClaim":{"size":"11Gi"}}}'
    
    # You can achieve the same result by editing the resource.
    d8 k edit vd linux-vm-root
    
  3. Verify that the size has changed:

    d8 k get vd linux-vm-root
    

    Example output:

    NAME            PHASE   CAPACITY   VIRTUALMACHINE   AGE
    linux-vm-root   Ready   11Gi       linux-vm         12m
    

You can change the size from the virtual machine page:

  1. Go to the Projects tab and select the project you need.
  2. Go to VirtualizationVirtual machines.
  3. Select the VM the disk is attached to from the list and click its name.
  4. On the Configuration tab, in the Disks section, click the pencil icon next to the disk size.
  5. In the window that opens, specify a larger size.
  6. Click Apply.

Or from the disk page itself:

  1. Go to VirtualizationDisks.
  2. Select the disk you need and click its name.
  3. On the Configuration tab, specify a larger size in the Size field.
  4. Click the Save button that appears.
  5. Check the disk status on its page.

Migrating disks to other storage

In commercial Deckhouse Platform (DP) editions, you can move a disk to another storage by changing its storage class. The move works both for disks defined in the VM specification and for disks attached as a separate resource.

The virtual machine must be in the Running phase, and the source and target storage must be of the same type. You can’t move a disk from a file system volume to a block device or the other way around.

To move a disk, specify the new storage class in the .spec.persistentVolumeClaim.storageClassName parameter:

d8 k patch vd disk --type=merge --patch '{"spec":{"persistentVolumeClaim":{"storageClassName":"new-storage-class-name"}}}'

# You can achieve the same result by editing the resource.
d8 k edit vd disk

After that, a live migration of the VM starts, during which the disk moves to the new storage.

If you need to move several disks of the same machine, change the storage class one disk at a time:

d8 k patch vd disk1 --type=merge --patch '{"spec":{"persistentVolumeClaim":{"storageClassName":"new-storage-class-name"}}}'
d8 k patch vd disk2 --type=merge --patch '{"spec":{"persistentVolumeClaim":{"storageClassName":"new-storage-class-name"}}}'

DP retries a failed migration with a growing delay. The first attempt runs immediately, the next ones after 5 and 10 seconds, then the delay doubles and from the seventh attempt stays at 300 seconds. To cancel the migration, restore the previous storage class in the specification.

Additional resources