Академический Документы
Профессиональный Документы
Культура Документы
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
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
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.
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
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.
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.
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
# 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:
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"
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
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:
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
# 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
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.