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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
- 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 asfdisk. 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. - Reboot. Since the partition table was modified on the running system, it won’t take effect until a reboot.
- Run
pvresize /dev/sdXYto have LVM pick up the new space. - Resize the logical volume with
lvextend. If you want to use the whole thing,lvextend -r -l +100%FREE /dev/VGNAME/LVNAME. The-rwill 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.
Method 2
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
homelogical volume insidelinuxvgvolume 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
homewith 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
Method 3
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 oldfdisk - 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 -sto refresh the partition table without a reboot - resize your physical volume with
pvresize /dev/sdb1or wherever your pv is (usepvsto determine if you don’t know) - now resize your logical volume with
lvextend -l +100%FREE /dev/file/of/your/lv, in my casesudo 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 🙂
Method 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.
Method 5
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:
-
I ran
lsblkto understand where/varwas sitting- disk
sda - partition
sda2 - lvm
rhel-var
so
/var was a logical volume in a partitionsda2on disksda. - disk
-
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.
-
Run
partedto get device partition to claim the spaceparted
-
Run the parted
printcommand to get the number of the partition. -
Run the parted
resizepartcommand to set the new partition size. -
Run the parted
printcommand to confirm the partition has increased in size. -
Run parted
quitto exit the program. -
Run
pvresizeto get the OS to understand that the partitionsda2is now larger.pvresize /dev/sda2
-
Run
lvextendto get/varto claim the mew space on the partition.lvextend -l +100%FREE '/dev/mapper/rhel-var'
I got
/dev/mapper/rhel-varfilesystem name from runningdf -h. -
Use good old
resize2fsto 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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0