SmartOS – Expanding disks of a VM

Recently I had to quickly resize a disk of one of my KVM virtual machines due to an incident that required me to upload a very large file to our supplier from that VM.

As this was the first time I had to perform this exercise on SmartOS I decided to write up the steps.

1) Find the disk in the guest operating system

Find the SCSI-id of the disk in the guest operating system. In Windows you can go to Disk Management or Device Manager to find the SCSI-id of the drive.

2) Find the volume in Smart Os representing the disk

First find the uid of the VM owning the disk you wish to expand. Perform a vmadm list and take note of the UID of the VM owning the disk.

# vmadm list

UID                                  TYPE  RAM      STATE             ALIAS
ec949393-2d5b-433f-9bca-06274f568f63  KVM   1024     running           srv0

Now perform a vmadm get of the VM and take note of the zfs_filesystem lines in the disks section of the output.

 # vmadm get ec949393-2d5b-433f-9bca-06274f568f63

<lines removed for brevity>

  "disks": [
      "path": "/dev/zvol/rdsk/zones/ec949393-2d5b-433f-9bca-06274f568f63-disk0",
      "boot": true,
      "model": "virtio",
      "media": "disk",
      "size": 38912,
      "zfs_filesystem": "zones/ec949393-2d5b-433f-9bca-06274f568f63-disk0",
      "zpool": "zones",
      "compression": "off",
      "refreservation": 25600,
      "block_size": 8192

By comparing the SCSI-id and size of the disk to listed disks you should be able to locate the correct zfs filesystem to expand. The VM in the example only has one disk which is mapped to zones/ec949393-2d5b-433f-9bca-06274f568f63-disk0.

3) Expand the volume in SmartOS

Modern Windows and Linux versions should be able to handle a live resize but if you wish to minimize risks you should shutdown the guest OS.

Expanding the volume in SmartOS is pretty easily performed with the zfs set volsize command. In the example below we expand the size to 50 gigabytes.

zfs set volsize=50g zones/ec949393-2d5b-433f-9bca-06274f568f63-disk0

Check the result with the zfs get volsize command.

# zfs get volsize zones/ec949393-2d5b-433f-9bca-06274f568f63-disk0
NAME                                              PROPERTY  VALUE    SOURCE
zones/ec949393-2d5b-433f-9bca-06274f568f63-disk0  volsize   50G      local

4 Last step: Expand the volume/partition in the Guest OS.

Rescan the disk(s) and expand the volume/partition with the tools available in the OS.
In Windows you can use Disk Management or diskpart to rescan the disk and expand your existing volume or partition. If you use LVM and extfs in Linux you can use tools like lvextend and resize2fs.