How to Expand an LVM Disk in Ubuntu Linux

Share This:

Expand LVM Partition Ubuntu

After installing Ubuntu as a Hyper-V virtual Machine and using LVM (Logical Volume Manager), you may run into a situation where there’s only 3.9GB available on the root volume regardless of the size you made the disk in Hyper-V. In my situation, the root volume’s name is /dev/mapper/ubuntu–vg-ubuntu–lv which is what I’ll refer to in the steps below. I’ll point out where your’s might be different. Since you’re using LVM, all of these changes can be made online so you don’t need a live CD/USB or reboots.

How to Expand an LVM Volume in Ubuntu Linux

First, let’s get some information from your disk:

sudo df -h

This should show the breakdown of your partitions and you should see something similar to this for your root partition:

/dev/mapper/ubuntu–vg-ubuntu–lv 3.9G 3.2G 489M 87% /

The left column is the name of your root volume. Replace it to match your’s in the steps below.

Now we’ll list your partitions to verify there is more space available:

sudo fdisk -l

In my case, you can see that /dev/sda3 was larger and also see the space allotted to the root volume:

Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 52426751 50325504 24G Linux filesystem
Disk /dev/mapper/ubuntu–vg-ubuntu–lv: 4 GiB

Next, let’s run parted and resize a partition if needed (the commands you type are in bold below:

user@tecklyfe:~# 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: 26.8GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 1076MB 1074MB ext4
3 1076MB 26.8GB 25.8GB
(parted) resizepart
Partition number? 3
End? [26.8GB]?
(parted) quit
Information: You may need to update /etc/fstab.

Next we’ll resize the physical volume:

pvresize /dev/sda3

And the output should be similar to:

Physical volume “/dev/sda3” changed
1 physical volume(s) resized / 0 physical volume(s) not resized

Now we’ll need to extend the logical volume:

lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

Finally, we’ll need to run resize2fs to apply the changes:

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Now you can verify the changes:

df -h

Troubleshooting

One issue I ran into was at the pvresize command and I was getting an error that it couldn’t be resized because there wasn’t enough space. My root volume was actually at 100% used.

Since I had no free space, I couldn’t run sudo apt autoremove to remove unused packages.

I get enough free space, I ran sudo uname -r to get my current kernel, then I ran sudo rm -rf /usr/src/linux-headers-#### where the #### represents different kernel header versions that are installed that aren’t used anymore.


Share This:

 

2 Comments

  1. David April 29, 2021
  2. David April 29, 2021

Leave a Comment