47

On my 240 GB SSD I had at first two partitions, one containing the Logical Volume with Linux Mint and the other had contained a NTFS partition to share with Windows.

Now I removed the NTFS partition and want to extend my logical volume group to use the released disk space.

How do I extend the volume group, my logical volume containing /home and the filesystem (ext4) on /home? Is this possible to do online?

PS: Yes, I know that I have to backup my data :)

/dev/sdb/  (240GB)
    linuxvg  (160GB) should use 100% of the disk space
        swap
        root
        home (ext4, 128GB) should be extended to use the remaining space

output of sudo vgdisplay:

  --- Volume group ---
  VG Name               linuxvg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               160,00 GiB
  PE Size               4,00 MiB
  Total PE              40959
  Alloc PE / Size       40959 / 160,00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               ...
   
  --- Logical volume ---
  LV Path                /dev/linuxvg/swap
  LV Name                swap
  VG Name                linuxvg
  LV UUID                ...
  LV Write Access        read/write
  LV Creation host, time mint, 2013-08-06 22:48:32 +0200
  LV Status              available
  # open                 2
  LV Size                8,00 GiB
  Current LE             2048
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
  --- Logical volume ---
  LV Path                /dev/linuxvg/root
  LV Name                root
  VG Name                linuxvg
  LV UUID                ...
  LV Write Access        read/write
  LV Creation host, time mint, 2013-08-06 22:48:43 +0200
  LV Status              available
  # open                 1
  LV Size                24,00 GiB
  Current LE             6144
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1
   
  --- Logical volume ---
  LV Path                /dev/linuxvg/home
  LV Name                home
  VG Name                linuxvg
  LV UUID                ...
  LV Write Access        read/write
  LV Creation host, time mint, 2013-08-06 22:48:57 +0200
  LV Status              available
  # open                 1
  LV Size                128,00 GiB
  Current LE             32767
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2
   
  --- Physical volumes ---
  PV Name               /dev/sdb1     
  PV UUID               ...
  PV Status             allocatable
  Total PE / Free PE    40959 / 0

output of sudo fdisk -l:

Disk /dev/sdb: 240.1 GB, 240057409536 bytes
255 heads, 63 sectors/track, 29185 cylinders, total 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1   468862127   234431063+  ee  GPT

Disk /dev/mapper/linuxvg-swap: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/linuxvg-root: 25.8 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders, total 50331648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/linuxvg-home: 137.4 GB, 137434759168 bytes
255 heads, 63 sectors/track, 16708 cylinders, total 268427264 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
0

5 Answers 5

75

You can do this fairly simply. Kinda surprised there wasn't an answer for this here already.

You can do this entire process while running on the filesystem you want to resize (yes, it's safe and fully supported). There is no need for rescue CDs or alternate operating systems.

  1. Resize the partition (again, you can do this with the system running). GParted is easy to use and supports resizing.
    You can also use a lower level tool such as fdisk. But you'll have to delete the partition and recreate it. Just make sure when doing so that the new partition starts at the exact same location.
  2. Reboot. Since the partition table was modified on the running system, it won't take effect until a reboot.
  3. Run pvresize /dev/sdXY to have LVM pick up the new space.
  4. Resize the logical volume with lvextend. If you want to use the whole thing, lvextend -r -l +100%FREE /dev/VGNAME/LVNAME. The -r will resize the filesystem as well.
    Though I always recommend against using the entire volume group. You never know what you'll need in the future. You can always expand later, you can't shrink.
9
  • 3
    I would like to accept your answer, but i didn't worked as you suggested, because GParted can't resize the root partition on a running system (at least in my case).
    – klingt.net
    Nov 3, 2013 at 10:29
  • @HalosGhost I reverted your edit. partprobe -s does not do what you think it does. The kernel will not pick up a resize of a partition which is in use. partprobe -s only works if the partition was in use during the resize (so when fdisk notified the kernel it failed), but it is no longer.
    – phemmer
    Dec 17, 2014 at 16:00
  • 2
    It's possible to not reboot at all using "partx -u" for step 2, to tell the kernel to update the partition's size: works even on active partitions and can be verified by checking /sys/.../sdXY/size before and after.
    – A.B
    Jun 1, 2019 at 2:01
  • 1
    @A.B Or partprobe.
    – Pryftan
    Oct 15, 2019 at 16:30
  • 3
    or just use growpart instead of GParted/Fdisk... Growpart does it all by itself and does not need reboot. Then you can pvresize and lvextend Jan 22, 2021 at 9:16
22

None of the answers make justice to the power of LVM.

(This is based on @frostchutz comment to the question above.)

Let's get the facts:

  • OP has two partitions, sdb1 and sdb2 is a physical volume for LVM.
  • sdb1 is ntfs right now, we need to give that space to home logical volume inside linuxvg volume group.

LVM steps using the "pragmatic way":

  • create physical volume on sdb1: pvcreate /dev/sdb1
  • add sdb1 to linuxvg: vgextend linuxvg /dev/sdb1
  • extend logical volume home with all free space (and resize filesystem): lvextend -r -l +100%FREE /dev/linuxvg/home

LVM allows great level of indirection. A logical volume is inside a volume group, which could be using several disks.

home --> linuxvg --> (sdb1, sdb2, sdc1)

http://tldp.org/HOWTO/LVM-HOWTO/createvgs.html

0
12

The question was solved, after reading this blog post. I will write the solution in short form:

  • boot from a live cd with
  • use gdisk (if you use GPT) otherwise you could go with good old fdisk
  • note your partition settings, in my case gdisk -l /dev/sdb
  • delete your partition with
  • create a new partition with the exact same alignment as the previous one (in my example starting at block 2048)
  • write your new partition table
  • run partprobe -s to refresh the partition table without a reboot
  • resize your physical volume with pvresize /dev/sdb1 or wherever your pv is (use pvs to determine if you don't know)
  • now resize your logical volume with lvextend -l +100%FREE /dev/file/of/your/lv, in my case sudo lvextend -l +100%FREE /dev/linuxvg/home
  • resize the filesystem sudo resize2fs /dev/linuxvg/home
  • first check the consistency sudo e2fsck -f /dev/linuxvg/home
  • enjoy :)
2
  • Actually you can cut out about half those steps and do it with only 1 reboot.
    – phemmer
    Oct 31, 2013 at 23:04
  • GParted refused to resize the partition, because it was locked (this key symbol).
    – klingt.net
    Nov 1, 2013 at 9:30
4

Some great answers already.

If you're using xfs, then you use the command

xfs_growfs /mountpoint

rather than resize2fs. You can do that whilst that mountpoint is active, such as if you've grown the root partition, and you don't need to reboot after.

3

I'm using RHEL7 and needed to extend /var. I'm no expert, but any time I tried to umount /var to resize2fs it failed because unsurprisingly it was in use. After a couple of days of trial and error I got this to work for me.

First, add Space to the disk in VMWare vSphere (or whatever hypervisor you're using I suppose.)

Then on the RHEL7 VM as root I followed these steps to get the additional disk space to trickle all the way down to /var:

  1. I ran lsblk to understand where /var was sitting

    • disk sda
    • partition sda2
    • lvm rhel-var

    so /var was a logical volume in a partition sda2 on disk sda.

  2. Get the disk to claim the new space

    echo 1 > /sys/class/block/**sda**/device/rescan
    

    the bit in bold should be the disk you've established that your logical volume is sitting on.

  3. Run parted to get device partition to claim the space

    parted
    
  4. Run the parted print command to get the number of the partition.

  5. Run the parted resizepart command to set the new partition size.

  6. Run the parted print command to confirm the partition has increased in size.

  7. Run parted quit to exit the program.

  8. Run pvresize to get the OS to understand that the partition sda2 is now larger.

    pvresize /dev/sda2
    
  9. Run lvextend to get /var to claim the mew space on the partition.

    lvextend -l +100%FREE '/dev/mapper/rhel-var'
    

    I got /dev/mapper/rhel-var filesystem name from running df -h.

  10. Use good old resize2fs to get the OS to claim that additional space that you just added to the logical volume in the previous step.

    resize2fs '/dev/mapper/rhel-var'
    

Job done. Confirm your success by running df -h

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .