How can I resize a VM’s volume?

Once in a while you may have the need for more storage space in an existing VM. How to accomplish this depends on the type of volume you need to enlarge.

Additional Volumes

If you are dealing with a volume that you attached additionally to you VM, then enlarging is rather straightforward.

  1. Connect to your virtual machine via SSH, and unmount the volume.
  2. Now login to the web interface, navigate to the volume page and detach the volume via ‚Manage Attachments‘ in the drop down menu on the right. (Or use the CLI Client)
  3. Then click on ‚Extend Volume‘ in the same drop down, and choose a new bigger size for it.
  4. After that you can attach the volume again via ‚Manage Attachments‘
  5. Adjust the partition layout of the volume if necessary from the virtual machine and mount the volume again.
  6. Finally enlarge the filesystem of the volume. For example in case of an xfs or ext4 filesystem use the xfs_growfs /mount/point or resize2fs /mount/point commands.

Root Volumes

Root volumes need special treatment, because you cannot detach them from an instance. There are two options:

Deleting the virtual machine

If you didn’t choose ‚Delete volume on instance‘ delete when creating the virtual machine, you can do the following:

  1. Delete the virtual machine.
  2. Go to the volume page, and extend the volume via the drop down ‚Manage Attachments‚.
  3. Then create a new virtual machine from this volume.
  4. Finally adjust the partition layout if necessary.

Using the Cinder CLI Client

First of all you have to install the OpenStack and Cinder command line tools on your local (Linux) computer. To install the Cinder CLI on Ubuntu do ‚apt install python3-cinderclient‚.

  1. Shut down the instance using the OpenStack CLI command ‚openstack server stop <INSTANCE-UUID>‘ or by using the OpenStack Web UI selecting ‚Shut Off Instance‚ in the pull down menu.
  2. When the instance state has changed to shutoff, call ‚ openstack server volume list‚ and get the VOLUME_ID of the /dev/vda volume, i.e. the root volume.
  3. Call ‚cinder --os-volume-api-version 3.42 extend <VOLUME_ID> <NEW_SIZE>‚ .
  4. Restart the instance using Web UI or by calling ‚openstack server start <INSTANCE-UUID>‘ .
  5. Finally adjust the partition layout if necessary and enlarge the filesystem, see above.