Expanding disk on Ubuntu 20.04

on

Not using Ubuntu often, I found recently that the way of expanding disks has changed or I forgot how it was.

After adding storage to your disk, open the terminal as root:

 

This will rescan the disk

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
echo 1 > /sys/block/sda/device/rescan
echo 1 > /sys/block/sda/device/rescan
echo 1 > /sys/block/sda/device/rescan

(note sda as main disk)

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cfdisk
cfdisk
cfdisk

 If cfdisk doesn’t show the new added storage, use this guide.

This will list the partitions.

Highlighted, the partition we want to expand.

Hit right and select Resize.

Accept the new disk value.  Then select Write, and accept the changes.

Type

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fdisk -l
fdisk -l
fdisk -l

 

to check if the disk has its new size:

 

Execute parted

Resize the partition:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pvresize /dev/sda3
pvresize /dev/sda3
pvresize /dev/sda3

Extend the partition:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

Resize to finish the expansion:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Now, doing a df -h will show the new extra space:

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *