User Tools

Site Tools


Resize partition to grow the filesystem (useful on Virtual Environment Disks)

There is some cases when you need to grow/enlarge a partition on a virtual disk (usually represented as /dev/vdX), here is how to do it rebooting once (yes, i would be better sysadmin if no reboot was needed :-( )

We use this /dev/vda setup in the example:

--/dev/vda1 20GB ext4
--/dev/vda2 2GB  swap
# in my case, i had a non-used swap partition at the end of /dev/vda,
# so i swap it off and delete it using fdisk
swapoff -a
fdisk /dev/vda
> d
> 2
> w
# i announce the changes to the OS
partprobe /dev/vda
# i grow the first partition (defaults to the max size of the physical disk)
growpart /dev/vda 1
# it MIGHT need reboot, but maybe not
shutdown -r now
# if you HAVE AN LVM ext4 you must
pvs  # PFree must show new space
pvresize /dev/vda1
vgs  # same as pvs
lvs  # you must see new available space here too
lvextend -l +100%FREE /dev/thelvm-vg/mapper-lv
# resize2fs on the partition if NOT LVM
resize2fs /dev/vda1
docu/csheet/sysadm/disks/grow_partition.txt · Last modified: 2021/05/05 07:12 by admin