Extend Disk
Step 1: Increase Disk Size
The first step is to increase the size of the disk that your Linux OS uses. This can be done by expanding the virtual disk in virtualization platforms like VMWare, KVM or Hyper-V , or also on you cloud platform.we’ll extend a 2Gb on our example
Step 2: Rescan the Disk
After resizing check that you can see the free space by doing sudo cfdisk. Use "q" to exit when done.
If there's no free space listed, initiate a rescan for /dev/sda with the command:
echo 1 > /sys/class/block/sda/device/rescan
Step 3: Resize the Partition
Select your /dev/sda3 partition from the list and choose " Resize" from the menu. Hit ENTER and confirm the new size. Then select "Write," type "yes" to confirm, and hit ENTER. Finally, use "q" or select quit to exit the program. Your /dev/sda3 partition should now reflect the new, larger size.
Step 4: Extend the Physical Volume (PV)
With the LVM partition backing up the /dev/sda3 PV extended, it's time to extend the PV itself.
Run
sudo pvresize /dev/sda3
exmaple output :
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
Step 5: Extend Logical Volume (LV)
For extending the LV to use all available VG free space with the below command
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Step 7: Resize the File System
Use the below command to resize it
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
to check the new size please do:
df -h
example output :
Filesystem Size Used Avail Use% Mounted on
tmpfs 588M 6.0M 582M 2% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 84G 62G 17G 79% /
tmpfs 2.9G 0 2.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 2.0G 251M 1.6G 14% /boot
tmpfs 588M 4.0K 588M 1% /run/user/1000
Updated 9 months ago