How can I extend a hard disk in Ubuntu logical volume

40,904

Suppose there is one LVM partition (except from /boot and maybe EFI), depending on the configuration of your virtual disk. As you choose LVM, you may proceed as follows:

Start gparted in the virtual machine, select the system disk, and create a new partition in the free space with type 'LVM'. You could also do this from the commandline with fdiskor gdisk, ifyou are used to. Remember the name of the newly created partition. For now say it's /dev/sda4.

Next, from commandline execute:

sudo pvcreate /dev/sda4  # to make the partition available for LVM

Now find out the name of your LVM volume group:

sudo vgdisplay

Remember the name of the volume group (say it is vg0). Then execute

sudo vgextend vg0 /dev/sda4

Again, find out the name of your logical volume

sudo lvdisplay

Say the volume's name is vg0-root. Then

sudo lvresize -r -l 100%VG vg0-root

should increase the logical volume vg0-rootto the possible maximum (option -l 100%VG) and resize the filesystem as well (option -r). The online resize of the (mounted) filesystem depends on your kernel; current kernels with ext2/3/4 filesystem support expansion of mounted filesystems.

An other solution would be to extend the partition itself with gparted, then use pvresize (see here, but for that you would have to boot Live Ubuntu from a CD or ISO, as you cannot increase a mounted partition through gparted.

If you could post some more information to your question (output of df, fdisk -l, pvdisplay, vgdisplay and lvdisplay), I could give you additional hints and correct my answer to fit your configuration.

Share:
40,904

Related videos on Youtube

user3214546
Author by

user3214546

Updated on September 18, 2022

Comments

  • user3214546
    user3214546 over 1 year

    When I installed Ubuntu 16.04 I selected logical volume management. I created a virtual machine with 40GB Hard disk.

    The I cloned that to a new machine with Hard disk 100. but when I check df -h it still shows 40GB.

    Is there any way to increase it?

    • Admin
      Admin about 7 years
      When searching the web for tutorials you may find something useful/helpful if you use "resize partition" and "grow filesystem" each in combination with "Ubuntu"
    • Admin
      Admin about 7 years
      What's the output of sudo lsblk -f?
    • Admin
      Admin over 3 years
      How to resize partitions? is related, but I don't think anything there actually answers this question about resizing LVM.
  • Andrius Štikonas
    Andrius Štikonas about 7 years
    Note: mounted partitions can be increased. And often decreased too (e.g. btrfs although not ext4).