Вы находитесь на странице: 1из 7

How to Increase the Size of an LVM2 Logical Volume

Author Name: John Ruemker and Allison Pranger


Editor: Chris Negus
09/08/11

OVERVIEW
Logical Volume Manager 2 (LVM2) allows you to aggregate physical storage devices into volume groups.
You can then divide that aggregated space into one or more logical volumes.
Once created, logical volumes can be extended to utilize unused space within the volume group, allowing
the file system residing on the logical volume to be extended as well. However, if all of the physical storage
in a volume group is already occupied by logical volumes, then more storage partitions must be added
before the logical volume can be extended.

NOTE: Red Hat recommends that all critical data be backed up and verified before making any changes to the
underlying storage as an unforeseen problem might occur.

This document outlines a scenario in which unpartitioned disk space is added to an existing volume group in
order to extend a logical volume and the corresponding file system while they are active.

EXAMPLE SCENARIO
The example scenario in this document uses a Red Hat Enterprise Linux server with two hard drives or
storage-array LUNs for storing application data. When this system was first set up, the first of these hard
drives, /dev/sdb, had a single partition created: /dev/sdb1. This partition was initialized as an LVM
physical volume and was subsequently added to a volume group named appvg. This volume group has one
logical volume, datalv, which occupies all of the physical extents (PE) provided by /dev/sdb1.
As shown using the vgdisplay command, this volume group has no remaining PE:

# vgdisplay -v appvg

Using volume group(s) on command line


Finding volume group "appvg"

--- Volume group ---


VG Name appvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 10.00 GiB

How to Increase the Size of an LVM2 Logical Volume | John Ruemker and Allison Pranger 1
PE Size 4.00 MiB
Total PE 2559
Alloc PE / Size 2559 / 10.00 GiB
Free PE / Size 0 / 0
VG UUID P8qQO1-qOj2-Yby3-achI-AHd2-ItU8-S3EdNc

--- Logical volume ---


LV Name /dev/appvg/datalv
VG Name appvg
LV UUID N11gEq-IMts-7P9d-ofzR-ZW8c-UmmB-1qMQfK
LV Write Access read/write
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2559
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3

--- Physical volumes ---


PV Name /dev/sdb1
PV UUID LgqiAX-toIS-Kpp1-aC1v-53Eq-kdrZ-JxQQJo
PV Status allocatable
Total PE / Free PE 2559 / 0

The file system that resides on the logical volume is nearly full:

# df -h /dev/mapper/appvg-datalv
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/appvg-datalv 9.9G 9.0G 897M 91% /app

Procedure Overview
The procedure described in this document first creates a new partition using the entire unpartitioned disk
space on the unused hard drive on a single partition (/dev/sdc1) and initializes it as a physical volume.

NOTE: Physical volumes can also be created directly on a disk device, such as /dev/sdc, without first
creating a partition.

Next, the appvg volume group and datalv logical volume are extended to use the newly added space from
/dev/sdc1. Finally, the file system on the extended datalv logical volume is increased, and the integrity
of the file system is checked.
In this test procedure, the mount, mkfs.ext3, df, e2fsck, and resize2fs commands, as well as the
LVM and fdisk programs, are used. If you are not already familiar with these commands and programs,
consult their man pages before continuing.

Step 1: Create a New Partition for the New Physical Volume


Using fdisk, you can display the details about the new device that you will initialize as a physical volume.

How to Increase the Size of an LVM2 Logical Volume | John Ruemker and Allison Pranger 2
NOTE: Alternatively, the parted utility can be used to manage disk partitions.

# fdisk -l /dev/sdc

Disk /dev/sdc: 10.7 GB, 10737418240 bytes


64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table

Since there is not yet a disk label on this device, you need to create one.

WARNING: The following command might overwrite existing data on the disk. Before proceeding, ensure you
have backed up all critical data.

# fdisk -cu /dev/sdc

Command (m for help):

Here, you can create a new partition. Because you want it to occupy the entire disk, you can accept the
default start and end cylinders by pressing Enter.

Command (m for help): n


command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10240, default 1): <Enter>
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10240, default
10240): <Enter>
Using default value 10240

Print to make sure the changes are correct:

Command (m for help): p


Disk /dev/sdc: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x58bbc73f

Device Boot Start End Blocks Id System


/dev/sdc1 1 10240 10485744 83 Linux

Finally, write the changes to disk and exit:

Command (m for help): w


The partition table has been altered!

How to Increase the Size of an LVM2 Logical Volume | John Ruemker and Allison Pranger 3
Calling ioctl() to re-read partition table.
Syncing disks.

To tell the kernel to re-read the partition table, either reboot the system or use the partprobe command:

# partprobe /dev/sdc

If successful, this command will not display any output.

Step 2: Initialize the New Device as an LVM Physical Volume


The LVM program is used to manipulate LVM2 volume groups, logical volumes, and physical volumes. To
initialize the new device as a physical volume, begin by using the LVM program’s pvs command to list the
physical volumes already present. Next, use pvcreate to create the new physical volume using the new
partition, and then run pvs again to verify that the new physical volume was created:

# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 appvg lvm2 a- 10.00g 0

# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created

# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 appvg lvm2 a- 10.00g 0
/dev/sdc1 lvm2 a- 10.00g 10.00g

Step 3: Extend the Volume Group Onto the New Physical Volume
Extending a volume group is simple using the LVM program's vgextend command:

# vgextend appvg /dev/sdc1


Volume group "appvg" successfully extended

You should confirm that the physical volume is listed as part of the volume group and that appvg now has
free PE available:

# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 appvg lvm2 a- 10.00g 0
/dev/sdc1 appvg lvm2 a- 10.00g 10.00g

# vgdisplay -v appvg
Using volume group(s) on command line
Finding volume group "appvg"

--- Volume group ---


VG Name appvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3

How to Increase the Size of an LVM2 Logical Volume | John Ruemker and Allison Pranger 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 19.99 GiB
PE Size 4.00 MiB
Total PE 5118
Alloc PE / Size 2559 / 10.00 GiB
Free PE / Size 2559 / 10.00 GiB <- Shows 10GiB now free
VG UUID P8qQO1-qOj2-Yby3-achI-AHd2-ItU8-S3EdNc

--- Logical volume ---


LV Name /dev/appvg/datalv
VG Name appvg
LV UUID N11gEq-IMts-7P9d-ofzR-ZW8c-UmmB-1qMQfK
LV Write Access read/write
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2559
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3

--- Physical volumes ---


PV Name /dev/sdb1
PV UUID LgqiAX-toIS-Kpp1-aC1v-53Eq-kdrZ-JxQQJo
PV Status allocatable
Total PE / Free PE 2559 / 0

PV Name /dev/sdc1 <- Shows new PV available


PV UUID kf50UY-2JfN-Xd1q-eNqL-CeOs-xydU-qlrRR1
PV Status allocatable
Total PE / Free PE 2559 / 2559

Step 4: Extend the Logical Volume in the Volume Group


As shown in Step 3, you know that you have 2,559 free PE (10 GiB). That is the maximum amount by which
you can grow the logical volume. You could choose to grow it by less and reserve the remainder for a new
logical volume. However, this example extends the logical volume to use all available free space:

# lvextend -l+100%FREE appvg/datalv


Extending logical volume datalv to 19.99 GiB
Logical volume datalv successfully resized

Note that the number of PE to use for the extend are specified as +100%FREE. The + sign indicates that the
extend should add the value specified to the existing number of extents in the logical volume. Alternatively,
you could have specified the exact number of PE to use:

How to Increase the Size of an LVM2 Logical Volume | John Ruemker and Allison Pranger 5
# lvextend -l+2559 appvg/datalv
Extending logical volume datalv to 19.99 GiB
Logical volume datalv successfully resized

It is also possible to specify a size in K, M, G, or other units using the -L option. However, in some cases,
rounding might cause this to fail:

# lvextend -L+10G appvg/datalv


Extending logical volume datalv to 20.00 GiB
Insufficient free space: 2560 extents needed, but only 2559
available

For that reason, Red Hat recommends either using %FREE or -l with an exact number of PE.
At this point, you have grown the logical volume to take up all available space in the volume group, as you
can see using vgdisplay:

# vgdisplay appvg

--- Volume group ---


VG Name appvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 19.99 GiB
PE Size 4.00 MiB
Total PE 5118
Alloc PE / Size 5118 / 19.99 GiB
Free PE / Size 0 / 0 <- All free extents are consumed
VG UUID P8qQO1-qOj2-Yby3-achI-AHd2-ItU8-S3EdNc

Step 5: Increase the Size of the File System


After extending the volume group and the logical volume, you can now increase the size of the file system.
In Red Hat Enterprise Linux 5 and later and Red Hat Enterprise 6 and later, this is done for ext3 file systems
using the resize2fs command. This procedure can be performed while the file system is live and
mounted.
Verify the file system size, perform the resize, and then verify that the change has been made:

# df -h /dev/mapper/appvg-datalv
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/appvg-datalv 9.9G 9.0G 897M 91% /app

# resize2fs /dev/appvg/datalv

How to Increase the Size of an LVM2 Logical Volume | John Ruemker and Allison Pranger 6
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/appvg/datalv is mounted on /app; on-line
resizing required.
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/appvg/datalv to 5240832 (4k)
blocks.
The filesystem on /dev/appvg/datalv is now 5240832 blocks long.

# df -h /dev/mapper/appvg-datalv
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/appvg-datalv 20G 9.0G 11.0G 45% /app

Step 6: Check File-System Integrity after the Resize Procedure


While not absolutely necessary, it is useful to run a file-system check after resizing.

NOTE: This must be done while the file system is unmounted, so downtime might be required to stop any
applications from using it.

Once the file system is unmounted, you can check it using e2fsck (-f forces the check):

# e2fsck -f /dev/appvg/datalv
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/appvg/datalv: 11/1310720 files (0.0% non-contiguous),
122098/5240832 blocks

How to Increase the Size of an LVM2 Logical Volume | John Ruemker and Allison Pranger 7

Copyright © 2011 Red Hat, Inc. “Red Hat,” Red Hat Linux, the Red Hat “Shadowman” logo, and the products www.redhat.com
listed are trademarks of Red Hat, Inc., registered in the U.S. and other countries. Linux® is the registered
trademark of Linus Torvalds in the U.S. and other countries.

Вам также может понравиться