resizevm

Quick notes on how to resize a Ubuntu VM using ext4 and LVM.

FIRST MAKE A SNAPSHOT

SECOND BACKUP ALL PARTION/META DATA (

$ DOS: sudo sfdisk -d /dev/sda > sda_partitions
$ GPT: sudo sgdisk -b sda_gpt_backup /dev/sda
$ LVM: sudo lvm vgcfgbackup -f lvm_backup_vg my_vg_name

)

THE IDEA IS TO DELETE THE PARTITION TABLE AND RECREATE IT AT THE EXACT SAME PLACE WITHOUT TOUCHING AT THE DATA ON THE DISK.

USE IT AT YOUR OWN RISKS!

  1. Use fdisk /dev/sda to check the partition with p
    1. Use "d" to delete the partition
    2. Use "n" to create a new partition
    3. Check again with "p"
    4. If the Type / System is not the same that the previous check, use "t" to set it (e.g. "8e" for Linux LVM)
    5. If the boot flag is gone, use the "a" to replace it.
    6. Check again with "p" and,
    7. if you are really really really sure of your backups, press "w"
    8. reboot
  2. Now you should be able to see some free space with "lsblk" (sda1 is extendend but not the LVM)
    1. pvresize /dev/sda1
    2. lvresize -l +100%FREE /dev/ielgesrv4-vg/root
    3. resize2fs /dev/ielgesrv4-vg/root  (PROBABLY NOT NEEDED)
    4. check with pvdisplay, vgdisplay, lvdisplay
  3. You are done