This is howto extend a virtual machine drive running Debian / Ubuntu
1. First you need to make sure that there are no snapshot of the VM. If there are snapshot, you can extend the drive in either vmWare or Hyper-V.
2. If the server is running Hyper-v, you can’t extend an IDE drive. If it are an IDE device, you need to turn of the computer first.
3. Make sure that the partition is not an extended partition. If it are you can still extend it, but then this guide won’t work for you. Run fdisk -l /dev/sdX
4. Make sure that the drive is not an LVM storage. Then you can’t used this guide.
The above image, showes that there are an extend partition.
After you have checked, that there are no snapshot, the drive is not an IDE and it the last partition on the drive that needed to extend. Then goes to yours hypervisor and extend the drive, with the amount of storage you will like to have the drive extend with.
Then back on the linux server, install the package cloud-guest-utils, with this command
apt install cloud-guest-utils
Then run these commands:
ls /sys/class/scsi_host/ | while read host ; do echo "- - -" > /sys/class/scsi_host/$host/scan ; done
ls /sys/class/scsi_device/ | while read host ; do echo 1 > /sys/class/scsi_device/$host/device/rescan ; done
This will rescan the SCSI bus for new drive and drive extension.
After you have run the rescan you should extend the partition you want to extend
growpart /dev/sda 2
This commands will extend partition 2 on /dev/sda with the amount of free space on the drive, after partition 2.
After the partition have been extended, you need to extend the filesystem. This can be done by resize2fs