Sometimes you need to resize your partition of your VPS system when you for example requested additional diskspace. In the below tutorial I resized my VPS hard-disk. Keep in mind that having a LVM file system is required for this tutorial.
With the below commands you can checking your current partition table.
root@ahv-id-10973:~# parted GNU Parted 3.2 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Model: Msft Virtual Disk (scsi) Disk /dev/sda: 270GB Sector size (logical/physical): 512B/4096B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 400GB 400GB primary boot, lvm (parted)
Now we know our partitions let’s resize the partition from 300GB to 400GB
root@ahv-id-10973:~# parted GNU Parted 3.2 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) resizepart 1 End? [300GB]? 400GB (parted) quit Information: You may need to update /etc/fstab.
With pvresize and lvextend we extend our partition to the new size.
root@ahv-id-10973:~# pvresize /dev/sda1 Physical volume "/dev/sda1" changed 1 physical volume(s) resized / 0 physical volume(s) not resized root@ahv-id-10973:~# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-root Size of logical volume ubuntu-vg/root changed from 277.49 GiB (71037 extents) to 370.62 GiB (94878 extents). Logical volume root successfully resized.
Now resize our filesystem with resize2fs
root@ahv-id-10973:~# resize2fs /dev/mapper/ubuntu--vg-root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/ubuntu--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 18, new_desc_blocks = 24
The filesystem on /dev/mapper/ubuntu--vg-root is now 97155072 (4k) blocks long.
And there we have new diskspace.
root@ahv-id-10973:~# df -kh
Filesystem Size Used Avail Use% Mounted on
udev 7.9G 0 7.9G 0% /dev
tmpfs 1.6G 8.6M 1.6G 1% /run
/dev/mapper/ubuntu--vg-root 365G 2.2G 348G 1% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0