Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
Well, the easy way would've been to just pvcreate the NTFS partition and use vgextend, instead of removing the partition entirely. If you grow the existing PV partition instead you probably have to reboot, as Linux refuses to re-read the partition table while the disk is in use. Working around this online is awkward. -- Please show your current partition table. –  frostschutz Oct 31 '13 at 18:05
    
I can reboot if necessary. –  klingt.net Oct 31 '13 at 18:15

2 Answers 2

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 -l +100%FREE /dev/VGNAME/LVNAME.
    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.
  5. Resize the filesystem. With ext2/3/4 you can just run resize2fs /mount/point. With other filesystems you'll need to use the appropriate utility for that filesystem.
share|improve this answer
    
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 '13 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. –  Patrick Dec 17 at 16:00
    
@Patrick, I did not add the idea for it; I "improved" the edit by putting the command in backticks (the war for code escapes wages on!). –  HalosGhost Dec 17 at 16:02
    
Oh, sorry, read the name off the wrong history event. @Qetesh that applies to you then :-) –  Patrick Dec 17 at 16:03
    
@Patrick, no worries :) –  HalosGhost Dec 17 at 16:17
up vote 1 down vote accepted

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 whereever your pv is (use pvs to determine if you dont know)
  • now resize yout 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 :)
share|improve this answer
    
Actually you can cut out about half those steps and do it with only 1 reboot. –  Patrick Oct 31 '13 at 23:04
    
GParted refused to resize the partition, because it was locked (this key symbol). –  klingt.net Nov 1 '13 at 9:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.