0% found this document useful (0 votes)
131 views

Extending An LVM Volume

This document provides an overview of how to extend a logical volume (LV) in LVM when the underlying volume group (VG) does not have enough free space. It explains that to extend the LV, the VG must first be extended by adding a new physical volume (PV) using tools like pvcreate and vgextend. After extending the VG, the LV can then be resized with lvextend followed by resizing the filesystem with resize2fs.

Uploaded by

Fahmi Anhar C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

Extending An LVM Volume

This document provides an overview of how to extend a logical volume (LV) in LVM when the underlying volume group (VG) does not have enough free space. It explains that to extend the LV, the VG must first be extended by adding a new physical volume (PV) using tools like pvcreate and vgextend. After extending the VG, the LV can then be resized with lvextend followed by resizing the filesystem with resize2fs.

Uploaded by

Fahmi Anhar C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Extending an LVM volume: Physical

volumes (partitions) -> Volume groups ->


Logical volume -> Filesystem
Logical Volume Management (AKA LVM) is a powerful, robust mechanism for managing
storage space.

In TurnKey 11, instead of installing the root filesystem directly to a fixed size partition, we
setup LVM by default, and install the root filesystem to a Logical Volume, which may later
be expanded, even across multiple physical devices.

Unfortunately, as with anything powerful, to get the most out of LVM you first have to
negotiate a learning curve. From the feedback we've been getting it seems that confusion
regarding LVM is common with new users, so here's a quick "crash course"...

How LVM works


In LVM, there are several layers, each builds on top of the other:

PV[s] (Physical Volumes) -> VG[s] (Volume Groups) -> LV[s] (Logical Volumes) ->
Filesystems.

Logical Volumes are allocated/extended within the boundaries of their underlying storage
pool which is called a Volume Group in LVM terminology.

For example, in TurnKey the filesystem is installed by default to the /dev/turnkey/root


Logical Volume, which is allocated within the turnkey Volume Group:

--- Logical volume ---


LV Name /dev/turnkey/root
VG Name turnkey
LV UUID OzX3fe-aRQa-81XM-0vCV-8aJo-eUL4-6J90XJ
LV Write Access read/write
LV Status available
# open 1
LV Size 17.0 GiB
Current LE 4502
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:0

Out of the box the turnkey Volume Group doesn't have too much free space:

# vgdisplay
--- Volume group ---
VG Name turnkey
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 18.14 GiB
PE Size 4.00 MiB
Total PE 4645
Alloc PE / Size 4480 / 17.50 GiB
Free PE / Size 165 / 660.00 MiB
VG UUID IwaFL0-QCi8-iIUE-TWjQ-R906-PYpH-gMPaH9

We can only extend a Logical Volume within the free space of the underlying Volume Group.
How much free space we currently have within the Volume Group can be seen in this part of
the output:

Free PE / Size 165 / 660.00 MiB

In the above example we only have 660 MB to allocate to LVMs within the turnkey Volume
Group. So if we want to extend the root LV we'll have to first extend the VG backs it up.

Volume Groups group together Physical Volumes. That's why they're called Volume Groups.
This command will show us which Physical Volumes have been registered into LVM, and to
which volume groups they have been assigned:

# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name turnkey
PV Size 18.15 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4645
Free PE 165
Allocated PE 4480
PV UUID H1Prpv-0VXR-7moE-zsbt-eyVt-m0fQ-GkAT6w

In this example we only have one Physical Volume (the /dev/sda2 partition) in the turnkey
Volume Group.

Extending a Logical Volume


Bottom line: if the underlying Volume Group doesn't have enough free space, to extend the
Logical Volume you'll first have to extend the underlying Volume Group by adding another
Physical Volume to it.

In VMWare you could either create a new virtual hard disk device to add to the volume
group, or extend an existing virtual hard disk device, create a new partition with cfdisk, and
add the new partition to the Volume Group:
# example #1: you've added to VMWare a new virtual hard disk called
/dev/sdb
pvcreate /dev/sdb
vgextend turnkey /dev/sdb

# example #2: you've expanded the existing sda hard disk


cfdisk /dev/sda # creating /dev/sda3 (you may need to reboot before you
can see this)
pvcreate /dev/sda3
vgextend turnkey /dev/sda3

After you've extended the Volume Group, you are free to extend the underlying Logical
Volume:

# lvextend -L+10G /dev/turnkey/root


Extending logical volume root to 27.0 GiB
Logical volume root successfully resized

Finally, you'll have to resize the filesystem within /dev/turnkey/root so it can see that the
underlying block device just got 10G bigger:

# resize2fs /dev/turnkey/root
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/turnkey/root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/turnkey/root to 7077888 (4k) blocks.
The filesystem on /dev/turnkey/root is now 7077888 blocks long.

You might also like