LVM Administrator's Guide

5.1
Configuration and
Administration
lSBN: NlA
Publication date:
Thís book descríbes the LVM íogícaí voíume manager, íncíudíng ínformatíon on
runníng LVM ín a cíustered envíronment. The content of thís document ís specífíc to
the LVM2 reíease.
LVM Administrator's Guide
LVM Administrator's Guide: Configuration and
Administration
Copyríght © 2007 Red Hat, Inc.
Copyríght © 2007 by Red Hat, Inc. Thís materíaí may be dístríbuted oníy subíect to the terms and
condítíons set forth ín the Open Pubíícatíon Lícense, V1.0 or íater (the íatest versíon ís presentíy avaííabíe
at http://www.opencontent.org/openpub/).
Dístríbutíon of substantíveíy modífíed versíons of thís document ís prohíbíted wíthout the expíícít
permíssíon of the copyríght hoíder.
Dístríbutíon of the work or derívatíve of the work ín any standard (paper) book form for commercíaí
purposes ís prohíbíted uníess príor permíssíon ís obtaíned from the copyríght hoíder.
Red Hat and the Red Hat "Shadow Man" íogo are regístered trademarks of Red Hat, Inc. ín the Uníted
States and other countríes.
Aíí other trademarks referenced hereín are the property of theír respectíve owners.
The GPG fíngerprínt of the securíty@redhat.com key ís:
CA 20 86 86 2B D6 9D FC 65 F6 EC C4 21 91 80 CD DB 42 A6 0E
1801 Varsíty Dríve
Raíeígh, NC 27606-2072
USA
Phone: +1 919 754 3700
Phone: 888 733 4281
Fax: +1 919 754 3701
PO Box 13588
Research Tríangíe Park, NC 27709
USA
LVM Administrator's Guide
Introductíon ..................................................................................................... íx
1. About Thís Guíde .................................................................................. íx
2. Audíence .............................................................................................. íx
3. Software Versíons ................................................................................ íx
4. Reíated Documentatíon ........................................................................ íx
5. Feedback ............................................................................................... x
6. Document Conventíons ........................................................................ xí
1. The LVM Logícaí Voíume Manager ................................................................1
1. Logícaí Voíumes ....................................................................................1
2. LVM Archítecture Overvíew ...................................................................2
3. Runníng LVM ín a Cíuster ......................................................................3
4. Document Overvíew ..............................................................................5
2. LVM Components ..........................................................................................7
1. Physícaí Voíumes ...................................................................................7
1.1. LVM Physícaí Voíume Layout ......................................................7
1.2. Muítípíe Partítíons on a Dísk .......................................................8
2. Voíume Groups ......................................................................................9
3. LVM Logícaí Voíumes .............................................................................9
3.1. Línear Voíumes ...........................................................................9
3.2. Stríped Logícaí Voíumes ...........................................................12
3.3. Mírrored Logícaí Voíumes .........................................................14
3.4. Snapshot Voíumes ....................................................................15
3. LVM Admínístratíon Overvíew .....................................................................17
1. Creatíng LVM Voíumes ín a Cíuster .....................................................17
2. Logícaí Voíume Creatíon Overvíew ......................................................17
3. Growíng a Fííe System on a Logícaí Voíume ........................................18
4. Logícaí Voíume Backup .......................................................................18
5. Loggíng ...............................................................................................19
4. LVM Admínístratíon wíth CLI Commands ....................................................21
1. Usíng CLI Commands ..........................................................................21
2. Physícaí Voíume Admínístratíon ..........................................................23
2.1. Creatíng Physícaí Voíumes .......................................................23
2.2. Díspíayíng Physícaí Voíumes ....................................................25
2.3. Preventíng Aííocatíon on a Physícaí Voíume .............................26
2.4. Resízíng a Physícaí Voíume ......................................................26
2.5. Removíng Physícaí Voíumes .....................................................26
3. Voíume Group Admínístratíon .............................................................27
3.1. Creatíng Voíume Groups ...........................................................27
3.2. Addíng Physícaí Voíumes to a Voíume Group ...........................28
v
3.3. Díspíayíng Voíume Groups ........................................................28
3.4. Scanníng Dísks for Voíume Groups to Buííd the Cache Fííe ......30
3.5. Removíng Physícaí Voíumes from a Voíume Group ..................30
3.6. Changíng the Parameters of a Voíume Group ..........................31
3.7. Actívatíng and Deactívatíng Voíume Groups ............................31
3.8. Removíng Voíume Groups ........................................................32
3.9. Spííttíng a Voíume Group ..........................................................32
3.10. Combíníng Voíume Groups .....................................................33
3.11. Backíng Up Voíume Group Metadata ......................................33
3.12. Renamíng a Voíume Group .....................................................33
3.13. Movíng a Voíume Group to Another System ...........................34
3.14. Recreatíng a Voíume Group Dírectory ....................................35
4. Logícaí Voíume Admínístratíon ............................................................35
4.1. Creatíng Logícaí Voíumes .........................................................35
4.2. Persístent Devíce Numbers .......................................................41
4.3. Resízíng Logícaí Voíumes .........................................................41
4.4. Changíng the Parameters of a Logícaí Voíume Group ..............41
4.5. Renamíng Logícaí Voíumes .......................................................42
4.6. Removíng Logícaí Voíumes .......................................................42
4.7. Díspíayíng Logícaí Voíumes ......................................................43
4.8. Growíng Logícaí Voíumes ..........................................................43
4.9. Extendíng a Stríped Voíume .....................................................45
4.10. Shrínkíng Logícaí Voíumes ......................................................47
5. Creatíng Snapshot Voíumes ................................................................47
6. Controíííng LVM Devíce Scans wíth Fííters ...........................................49
7. Onííne Data Reíocatíon ........................................................................50
8. Actívatíng Logícaí Voíumes on Indívíduaí Nodes ín a Cíuster ..............51
9. Customízed Reportíng for LVM ............................................................51
9.1. Format Controí ..........................................................................52
9.2. Obíect Seíectíon ........................................................................55
9.3. Sortíng LVM Reports .................................................................63
9.4. Specífyíng Uníts ........................................................................64
5. LVM Confíguratíon Exampíes ......................................................................67
1. Creatíng an LVM Logícaí Voíume on Three Dísks ................................67
1.1. Creatíng the Physícaí Voíumes .................................................67
1.2. Creatíng the Voíume Group ......................................................67
1.3. Creatíng the Logícaí Voíume .....................................................68
1.4. Creatíng the Fííe System ..........................................................68
2. Creatíng a Stríped Logícaí Voíume ......................................................69
2.1. Creatíng the Physícaí Voíumes .................................................69
LVM Administrator's Guide

2.2. Creatíng the Voíume Group ......................................................69
2.3. Creatíng the Logícaí Voíume .....................................................69
2.4. Creatíng the Fííe System ..........................................................70
3. Spííttíng a Voíume Group ....................................................................71
3.1. Determíníng Free Space ...........................................................71
3.2. Movíng the Data .......................................................................71
3.3. Spííttíng the Voíume Group ......................................................72
3.4. Creatíng the New Logícaí Voíume .............................................72
3.5. Makíng a Fííe System and Mountíng the New Logícaí Voíume ..73
3.6. Actívatíng and Mountíng the Orígínaí Logícaí Voíume ..............73
4. Removíng a Dísk from a Logícaí Voíume .............................................74
4.1. Movíng Extents to Exístíng Physícaí Voíumes ...........................74
4.2. Movíng Extents to a New Dísk ..................................................75
6. LVM Troubíeshootíng ..................................................................................79
1. Troubíeshootíng Díagnostícs ...............................................................79
2. Díspíayíng Informatíon on Faííed Devíces ...........................................79
3. Recoveríng from LVM Mírror Faííure ....................................................81
4. Recoveríng Physícaí Voíume Metadata ...............................................85
5. Repíacíng a Míssíng Physícaí Voíume ..................................................87
6. Removíng Lost Physícaí Voíumes from a Voíume Group .....................87
7. Insuffícíent Free Extents for a Logícaí Voíume ....................................88
7. LVM Admínístratíon wíth the LVM GUI .........................................................91
A. The Devíce Mapper .....................................................................................93
B. The LVM Confíguratíon Fííes .......................................................................95
1. The LVM Confíguratíon Fííes ................................................................95
2. Sampíe ívm.conf Fííe ...........................................................................96
C. LVM Obíect Tags .......................................................................................105
1. Addíng and Removíng Obíect Tags ...................................................105
2. Host Tags ..........................................................................................105
3. Controíííng Actívatíon wíth Tags ........................................................106
D. LVM Voíume Group Metadata ...................................................................109
1. The Physícaí Voíume Labeí ................................................................109
2. Metadata Contents ............................................................................110
3. Sampíe Metadata ..............................................................................111
Index .............................................................................................................115
víí
vííí
lntroduction
1. About This Guide
Thís book descríbes the Logícaí Voíume Manager (LVM), íncíudíng ínformatíon on
runníng LVM ín a cíustered envíronment. The content of thís document ís specífíc to
the LVM2 reíease.
2. Audience
Thís book ís íntended to be used by system admínístrators managíng systems
runníng the Línux operatíng system. It requíres famíííaríty wíth Red Hat Enterpríse
Línux 5 and GFS fííe system admínístratíon.
3. Software Versions
Software Description
RHEL5 refers to RHEL5 and hígher
GFS refers to GFS for RHEL5 and hígher
Table 1. Software Versions
4. Related Documentation
For more ínformatíon about usíng Red Hat Enterpríse Línux, refer to the foííowíng
resources:
º Red Hat Enterpríse Línux Instaííatíon Guíde - Provídes ínformatíon regardíng
ínstaííatíon of Red Hat Enterpríse Línux 5.
º Red Hat Enterpríse Línux Depíoyment Guíde - Provídes ínformatíon regardíng the
depíoyment, confíguratíon and admínístratíon of Red Hat Enterpríse Línux 5.
For more ínformatíon about Red Hat Cíuster Suíte for Red Hat Enterpríse Línux 5,
refer to the foííowíng resources:
íx
º Red Hat Cíuster Suíte Overvíew - Provídes a hígh íeveí overvíew of the Red Hat
Cíuster Suíte.
º Confíguríng and Managíng a Red Hat Cíuster - Provídes ínformatíon about
ínstaíííng, confíguríng and managíng Red Hat Cíuster components.
º Gíobaí Fííe System: Confíguratíon and Admínístratíon - Provídes ínformatíon
about ínstaíííng, confíguríng, and maíntaíníng Red Hat GFS (Red Hat Gíobaí Fííe
System).
º Usíng Devíce-Mapper Muítípath - Provídes ínformatíon about usíng the
Devíce-Mapper Muítípath feature of Red Hat Enterpríse Línux 5.
º Usíng GNBD wíth Gíobaí Fííe System - Provídes an overvíew on usíng Gíobaí
Network Bíock Devíce (GNBD) wíth Red Hat GFS.
º Línux Vírtuaí Server Admínístratíon - Provídes ínformatíon on confíguríng
hígh-performance systems and servíces wíth the Línux Vírtuaí Server (LVS).
º Red Hat Cíuster Suíte Reíease Notes - Provídes ínformatíon about the current
reíease of Red Hat Cíuster Suíte.
Red Hat Cíuster Suíte documentatíon and other Red Hat documents are avaííabíe ín
HTML, PDF, and RPM versíons on the Red Hat Enterpríse Línux Documentatíon CD
and onííne at http://www.redhat.com/docs/.
5. Feedback
If you spot a typo, or íf you have thought of a way to make thís manuaí better, we
wouíd íove to hear from you. Píease submít a report ín Bugzííía
(http://bugzííía.redhat.com/bugzííía/) agaínst the component rh-cs.
Be sure to mentíon the manuaí's ídentífíer:
rh-cívm(EN)-5.1 (2007-10-30T15:15)
By mentíoníng thís manuaí's ídentífíer, we know exactíy whích versíon of the guíde
you have.
If you have a suggestíon for ímprovíng the documentatíon, try to be as specífíc as
possíbíe. If you have found an error, píease íncíude the sectíon number and some of
the surroundíng text so we can fínd ít easííy.
lntroduction
x
6. Document Conventions
Certaín words ín thís manuaí are represented ín dífferent fonts, styíes, and weíghts.
Thís híghííghtíng índícates that the word ís part of a specífíc category. The
categoríes íncíude the foííowíng:
Couríer font
Couríer font represents commands, fííe names and paths, and prompts .
When shown as beíow, ít índícates computer output:
Desktop about.htmí íogs pauíwesterberg.png
Maíí backupfííes maíí reports
bold Courier font
Boíd Couríer font represents text that you are to type, such as: service ionas
start
If you have to run a command as root, the root prompt (#) precedes the
command:
# gconftool-2
ítaííc Couríer font
Itaííc Couríer font represents a varíabíe, such as an ínstaííatíon dírectory:
ínstaíí¸dír/bín/
bold font
Boíd font represents application programs and text found on a graphical
interface.
When shown ííke thís: OK , ít índícates a button on a graphícaí appíícatíon
ínterface.
Addítíonaííy, the manuaí uses dífferent strategíes to draw your attentíon to píeces of
ínformatíon. In order of how crítícaí the ínformatíon ís to you, these ítems are
marked as foííows:
Document Conventions

Note
A note ís typícaííy ínformatíon that you need to understand the
behavíor of the system.
Tip
A típ ís typícaííy an aíternatíve way of performíng a task.
lmportant
Important ínformatíon ís necessary, but possíbíy unexpected, such as a
confíguratíon change that wííí not persíst after a reboot.
Caution
A cautíon índícates an act that wouíd víoíate your support agreement,
such as recompíííng the kerneí.
Warning
A warníng índícates potentíaí data íoss, as may happen when tuníng
hardware for maxímum performance.
lntroduction
xíí
The LVM Logical Volume
Manager
Thís chapter provídes a hígh-íeveí overvíew of the components of the Logícaí
Voíume Manager (LVM).
1. Logical Volumes
Voíume management creates a íayer of abstractíon over physícaí storage, aííowíng
you to create íogícaí storage voíumes. Thís provídes much greater fíexíbíííty ín a
number of ways than usíng physícaí storage dírectíy.
A íogícaí voíume provídes storage vírtuaíízatíon. Wíth a íogícaí voíume, you are not
restrícted to physícaí dísk sízes. In addítíon, the hardware storage confíguratíon ís
hídden from the software so ít can be resízed and moved wíthout stoppíng
appíícatíons or unmountíng fííe systems. Thís can reduce operatíonaí costs.
Logícaí voíumes províde the foííowíng advantages over usíng physícaí storage
dírectíy:
º Fíexíbíe capacíty
When usíng íogícaí voíumes, fííe systems can extend across muítípíe dísks, sínce
you can aggregate dísks and partítíons ínto a síngíe íogícaí voíume.
º Resízeabíe storage pooís
You can extend íogícaí voíumes or reduce íogícaí voíumes ín síze wíth símpíe
software commands, wíthout reformattíng and repartítíoníng the underíyíng dísk
devíces.
º Onííne data reíocatíon
To depíoy newer, faster, or more resíííent storage subsystems, you can move data
wííí your system ís actíve. Data can be rearranged on dísks whííe the dísks are ín
use. For exampíe, you can empty a hot-swappabíe dísk before removíng ít.
º Conveníent devíce namíng
Logícaí storage voíumes can be managed ín user-defíned groups, whích you can
name accordíng to your conveníence.
Chapter 1.
1
º Dísk strípíng
You can create a íogícaí voíume that strípes data across two or more dísks. Thís
can dramatícaííy íncrease throughput.
º Mírroríng voíumes
Logícaí voíumes províde a conveníent way to confígure a mírror for your data.
º Voíume Snapshots
Usíng íogícaí voíumes, you can take devíce snapshots for consístent backups or to
test the effect of changes wíthout affectíng the reaí data.
The ímpíementatíon of these features ín LVM ís descríbed ín the remaínder of thís
document.
2. LVM Architecture Overview
For the RHEL 4 reíease of the Línux operatíng system, the orígínaí LVM1 íogícaí
voíume manager was repíaced by LVM2, whích has a more generíc kerneí
framework than LVM1. LVM2 provídes the foííowíng ímprovements over LVM1:
º fíexíbíe capacíty
º more effícíent metadata storage
º better recovery format
º new ASCII metadata format
º atomíc changes to metadata
º redundant copíes of metadata
LVM2 ís backwards compatíbíe wíth LVM1, wíth the exceptíon of snapshot and
cíuster support. You can convert a voíume group from LVM1 format to LVM2 format
wíth the vgconvert command. For ínformatíon on convertíng LVM metadata format,
see the vgconvert(8) man page.
The underíyíng physícaí storage unít of an LVM íogícaí voíume ís a bíock devíce such
as a partítíon or whoíe dísk. Thís devíce ís ínítíaíízed as an LVM physícaí voíume
(PV).
Chapter 1. The LVM Logical Vo...
2
To create an LVM íogícaí voíume, the physícaí voíumes are combíned ínto a voíume
group (VG). Thís creates a pooí of dísk space out of whích LVM íogícaí voíumes (LVs)
can be aííocated. Thís process ís anaíogous to the way ín whích dísks are dívíded
ínto partítíons. A íogícaí voíume ís used by fííe systems and appíícatíons (such as
databases).
Fígure 1.1, "LVM Logícaí Voíume Components" shows the components of a símpíe
LVM íogícaí voíume:
Figure 1.1. LVM Logical Volume Components
For detaííed ínformatíon on the components of an LVM íogícaí voíume, see
Chapter 2, LVM Components.
3. Running LVM in a Cluster
The Cíustered Logícaí Voíume Manager (CLVM) ís a set of cíusteríng extensíons to
LVM. These extensíons aííow a cíuster of computers to manage shared storage (for
exampíe, on a SAN) usíng LVM.
The címvd daemon ís the key cíusteríng extensíon to LVM. The cívmd daemon runs ín
Running LVM in a Cluster
3
each cíuster computer and dístríbutes LVM metadata updates ín a cíuster,
presentíng each cíuster computer wíth the same víew of the íogícaí voíumes.
Fígure 1.2, "CLVM Overvíew" shows a CLVM overvíew ín a Red Hat cíuster.
Figure 1.2. CLVM Overview
Logícaí voíumes created wíth CLVM on shared storage are vísíbíe to aíí computers
that have access to the shared storage.
CLVM aííows a user to confígure íogícaí voíumes on shared storage by íockíng
access to physícaí storage whííe a íogícaí voíume ís beíng confígured. CLVM uses
the íockíng servíces províded by the hígh avaííabíííty symmetríc ínfrastructure.
Note
CLVM requíres changes to the ívm.conf fííe for cíuster-wíde íockíng. For
ínformatíon on confíguríng the ívm.conf fííe to support CLVM, see
Sectíon 1, "Creatíng LVM Voíumes ín a Cíuster".
Chapter 1. The LVM Logical Vo...
4
You confígure LVM voíumes for use ín a cíuster wíth the standard set of LVM
commands or the LVM graphícaí user ínterface, as descríbed ín Chapter 4, LVM
Admínístratíon wíth CLI Commands and Chapter 7, LVM Admínístratíon wíth the
LVM GUI.
For ínformatíon on ínstaíííng LVM ín a Red Hat Cíuster, see Confíguríng and
Managíng a Red Hat Cíuster.
4. Document Overview
Thís remaínder of thís document íncíudes the foííowíng chapters:
º Chapter 2, LVM Components descríbes the components that make up an LVM
íogícaí voíume.
º Chapter 3, LVM Admínístratíon Overvíew provídes an overvíew of the basíc steps
you perform to confígure LVM íogícaí voíumes, whether you are usíng the LVM
Command Líne Interface (CLI) commands or the LVM Graphícaí User Interface
(GUI).
º Chapter 4, LVM Admínístratíon wíth CLI Commands summarízes the índívíduaí
admínístratíve tasks you can perform wíth the LVM CLI commands to create and
maíntaín íogícaí voíumes.
º Chapter 5, LVM Confíguratíon Exampíes provídes a varíety of LVM confíguratíon
exampíes.
º Chapter 6, LVM Troubíeshootíng províde ínstructíons for troubíeshootíng a varíety
of LVM íssues.
º Chapter 7, LVM Admínístratíon wíth the LVM GUI summarízes the operatíng of the
LVM GUI.
º Appendíx A, The Devíce Mapper descríbes the Devíce Mapper that LVM uses to
map íogícaí and physícaí voíumes.
º Appendíx B, The LVM Confíguratíon Fííes descríbes the LVM confíguratíon fííes.
º Appendíx C, LVM Obíect Tags descríbes LVM obíect tags and host tags.
º Appendíx D, LVM Voíume Group Metadata descríbes LVM voíume group
metadata, and íncíudes a sampíe copy of metadata for an LVM voíume group.
Document Overview
5
6
LVM Components
Thís chapter descríbes the components of an LVM Logícaí voíume.
1. Physical Volumes
The underíyíng physícaí storage unít of an LVM íogícaí voíume ís a bíock devíce such
as a partítíon or whoíe dísk. To use the devíce for an LVM íogícaí voíume the devíce
must be ínítíaíízed as a physícaí voíume (PV). Inítíaíízíng a bíock devíce as a physícaí
voíume píaces a íabeí near the start of the devíce.
By defauít, the LVM íabeí ís píaced ín the second 512-byte sector. You can overwríte
thís defauít by píacíng the íabeí on any of the fírst 4 sectors. Thís aííows LVM
voíumes to co-exíst wíth other users of these sectors, íf necessary.
An LVM íabeí provídes correct ídentífícatíon and devíce orderíng for a physícaí
devíce, sínce devíces can come up ín any order when the system ís booted. An LVM
íabeí remaíns persístent across reboots and throughout a cíuster.
The LVM íabeí ídentífíes the devíce as an LVM physícaí voíume. It contaíns a random
uníque ídentífíer (the UUID) for the physícaí voíume. It aíso stores the síze of the
bíock devíce ín bytes, and ít records where the LVM metadata wííí be stored on the
devíce.
The LVM metadata contaíns the confíguratíon detaíís of the LVM voíume groups on
your system. By defauít, an ídentícaí copy of the metadata ís maíntaíned ín every
metadata area ín every physícaí voíume wíthín the voíume group. LVM metadata ís
smaíí and stored as ASCII.
Currentíy LVM aííows you to store 0, 1 or 2 ídentícaí copíes of íts metadata on each
physícaí voíume. The defauít ís 1 copy. Once you confígure the number of metadata
copíes on the physícaí voíume, you cannot change that number at a íater tíme. The
fírst copy ís stored at the start of the devíce, shortíy after the íabeí. If there ís a
second copy, ít ís píaced at the end of the devíce. If you accídentaííy overwríte the
area at the begínníng of your dísk by wrítíng to a dífferent dísk than you íntend, a
second copy of the metadata at the end of the devíce wííí aííow you to recover the
metadata.
For detaííed ínformatíon about the LVM metadata and changíng the metadata
parameters, see Appendíx D, LVM Voíume Group Metadata.
1.1. LVM Physical Volume Layout
Chapter 2.
7
Fígure 2.1, "Physícaí Voíume íayout" shows the íayout of an LVM physícaí voíume.
The LVM íabeí ís on the second sector, foííowed by the metadata area, foííowed by
the usabíe space on the devíce.
Note
In the Línux kerneí (and throughout thís document), sectors are
consídered to be 512 bytes ín síze.
Figure 2.1. Physical Volume layout
1.2. Multiple Partitions on a Disk
LVM aííows you to create physícaí voíumes out of dísk partítíons. It ís generaííy
recommended that you create a síngíe partítíon that covers the whoíe dísk to íabeí
as an LVM physícaí voíume for the foííowíng reasons:
º Admínístratíve conveníence
It ís easíer to keep track of the hardware ín a system íf each reaí dísk oníy appears
once. Thís becomes partícuíaríy true íf a dísk faíís. In addítíon, muítípíe physícaí
voíumes on a síngíe dísk may cause a kerneí warníng about unknown partítíon
types at boot-up.
Chapter 2. LVM Components
8
º Strípíng performance
LVM can not teíí that two physícaí voíumes are on the same physícaí dísk. If you
create a stríped íogícaí voíume when two physícaí voíumes are on the same
physícaí dísk, the strípes couíd be on dífferent partítíons on the same dísk. Thís
wouíd resuít ín a decrease ín performance rather than an íncrease.
Aíthough ít ít ís not recommended, there may be specífíc círcumstances when you
wííí need to dívíde a dísk ínto separate LVM physícaí voíumes. For exampíe, on a
system wíth few dísks ít may be necessary to move data around partítíons when you
are mígratíng an exístíng system to LVM voíumes. Addítíonaííy, íf you have a very
íarge dísk and want to have more than one voíume group for admínístratíve
purposes then ít ís necessary to partítíon the dísk. If you do have a dísk wíth more
than one partítíon and both of those partítíons are ín the same voíume group, take
care to specífy whích partítíons are to be íncíuded ín a íogícaí voíume when creatíng
stríped voíumes.
2. Volume Groups
Physícaí voíumes are combíned ínto voíume groups (VGs). Thís creates a pooí of
dísk space out of whích íogícaí voíumes can be aííocated.
Wíthín a voíume group, the dísk space avaííabíe for aííocatíon ís dívíded ínto uníts of
a fíxed-síze caííed extents. An extent ís the smaííest unít of space that can be
aííocated, Wíthín a physícaí voíume, extents are referred to as physícaí extents.
A íogícaí voíume ís aííocated ínto íogícaí extents of the same síze as the physícaí
extents. The extent síze ís thus the same for aíí íogícaí voíumes ín the voíume
group. The voíume group maps the íogícaí extents to physícaí extents.
3. LVM Logical Volumes
In LVM, a voíume group ís dívíded up ínto íogícaí voíumes. There are three types of
LVM íogícaí voíumes: íínear voíumes, stríped voíumes, and mírrored voíumes. These
are descríbed ín the foííowíng sectíons.
3.1. Linear Volumes
A íínear voíume aggregates muítípíe physícaí voíumes ínto one íogícaí voíume. For
exampíe, íf you have two 60GB dísks, you can create a 120GB íogícaí voíume. The
physícaí storage ís concatenated.
Volume Groups
9
Creatíng a íínear voíume assígns a range of physícaí extents to an area of a íogícaí
voíume ín order. For exampíe, as shown ín Fígure 2.2, "Extent Mappíng" íogícaí
extents 1 to 99 couíd map to one physícaí voíume and íogícaí extents 100 to 198
couíd map to a second physícaí voíume. From the poínt of víew of the appíícatíon,
there ís one devíce that ís 198 extents ín síze.
Figure 2.2. Extent Mapping
The physícaí voíumes that make up a íogícaí voíume do not have to be the same
síze. Fígure 2.3, "Línear Voíume wíth Unequaí Physícaí Voíumes" shows voíume
group VG1 wíth a physícaí extent síze of 4MB. Thís voíume group íncíudes 2 physícaí
voíumes named PV1 and PV2. The physícaí voíumes are dívíded ínto 4MB uníts, sínce
Chapter 2. LVM Components
10
that ís the extent síze. In thís exampíe, PV1 ís 100 extents ín síze (400MB) and PV2 ís
200 extents ín síze (800MB). You can create a íínear voíume any síze between 1 and
300 extents (4MB to 1200MB). In thís exampíe, the íínear voíume named LV1 ís 300
extents ín síze.
Figure 2.3. Linear Volume with Unequal Physical Volumes
You can confígure more than one íínear íogícaí voíume of whatever síze you desíre
from the pooí of physícaí extents. Fígure 2.4, "Muítípíe Logícaí Voíumes" shows the
same voíume group as ín Fígure 2.3, "Línear Voíume wíth Unequaí Physícaí
Voíumes", but ín thís case two íogícaí voíumes have been carved out of the voíume
group: LV1, whích ís 250 extents ín síze (1000MB) and LV2 whích ís 50 extents ín
síze (200MB).
Linear Volumes
11
Figure 2.4. Multiple Logical Volumes
3.2. Striped Logical Volumes
When you wríte data to an LVM íogícaí voíume, the fííe system íays the data out
across the underíyíng physícaí voíumes. You can controí the way the data ís wrítten
to the physícaí voíumes by creatíng a stríped íogícaí voíume. For íarge sequentíaí
reads and wrítes, thís can ímprove the effícíency of the data I/O.
Strípíng enhances performance by wrítíng data to a predetermíned number of
physícaí voíumes ín round-round fashíon. Wíth strípíng, I/O can be done ín paraííeí.
In some sítuatíons, thís can resuít ín near-íínear performance gaín for each
addítíonaí physícaí voíume ín the strípe.
The foííowíng íííustratíon shows data beíng stríped across three physícaí voíumes. In
thís fígure:
º the fírst strípe of data ís wrítten to PV1
º the second strípe of data ís wrítten to PV2
º the thírd strípe of data ís wrítten to PV3
Chapter 2. LVM Components
12
º the fourth strípe of data ís wrítten to PV1
In a stríped íogícaí voíume, the síze of the strípe cannnot exceed the síze of an
extent.
Figure 2.5. Striping Data Across Three PVs
Stríped íogícaí voíumes can be extended by concatenatíng another set of devíces
onto the end of the fírst set. In order extend a stríped íogícaí voíume, however,
there must be enough free space on the underíyíng physícaí voíumes that make up
the voíume group to support the strípe. For exampíe, íf you have a two-way strípe
that uses up an entíre voíume group, addíng a síngíe physícaí voíume to the voíume
group wííí not enabíe you to extend the strípe. Instead, you must add at íeast two
physícaí voíumes to the voíume group. For more ínformatíon on extendíng a stríped
voíume, see Sectíon 4.9, "Extendíng a Stríped Voíume".
Mirrored Logical Volumes
13
3.3. Mirrored Logical Volumes
A mírror maíntaíns ídentícaí copíes of data on dífferent devíces. When data ís
wrítten to one devíce, ít ís wrítten to a second devíce as weíí, mírroríng the data.
Thís provídes protectíon for devíce faííures. When one íeg of a mírror faíís, the
íogícaí voíume becomes a íínear voíume and can stííí be accessed.
LVM supports mírrored voíumes. When you create a mírrored íogícaí voíume, LVM
ensures that data wrítten to an underíyíng physícaí voíume ís mírrored onto a
separate physícaí voíume. Wíth LVM, you can create mírrored íogícaí voíumes wíth
muítípíe mírrors.
An LVM mírror dívídes the devíce beíng copíed ínto regíons that are typícaííy 512KB
ín síze. LVM maíntaíns a smaíí íog whích ít uses to keep track of whích regíons are ín
sync wíth the mírror or mírrors. Thís íog can be kept on dísk, whích wííí keep ít
persístent across reboots, or ít can be maíntaíned ín memory.
Fígure 2.6, "Mírrored Logícaí Voíume" shows a mírrored íogícaí voíume wíth one
mírror. In thís confíguratíon, the íog ís maíntaíned on dísk.
Figure 2.6. Mirrored Logical Volume
Chapter 2. LVM Components
14
Note
Mírrored íogícaí voíumes are not currentíy supported ín a cíuster.
For ínformatíon on creatíng and modífyíng mírrors, see Sectíon 4.1.3, "Creatíng
Mírrored Voíumes".
3.4. Snapshot Volumes
The LVM snapshot feature provídes the abíííty to create vírtuaí ímages of a devíce at
a partícuíar ínstant wíthout causíng a servíce ínterruptíon. When a change ís made
to the orígínaí devíce (the orígín) after a snapshot ís taken, the snapshot feature
makes a copy of the changed data area as ít was príor to the change so that ít can
reconstruct the state of the devíce.
Note
LVM snapshots are not supported across the nodes ín a cíuster.
Because a snapshot copíes oníy the data areas that change after the snapshot ís
created, the snapshot feature requíres a mínímaí amount of storage. For exampíe,
wíth a rareíy updated orígín, 3-5 % of the orígín's capacíty ís suffícíent to maíntaín
the snapshot.
Note
Snapshot copíes of a fííe system are vírtuaí copíes, not actuaí medía
backup for a fííe system. Snapshots do not províde a substítute for a
backup procedure.
If a snapshot runs fuíí, the snapshot ís dropped. Thís ís to be sure that there ís
enough space for the orígín fííe system. You shouíd reguíaríy monítor the síze of the
snapshot. Snapshots are fuííy resízeabíe, however, so íf you have the storage
capacíty you can íncrease the síze of the snapshot voíume to prevent ít from gettíng
dropped. Converseíy, íf you fínd that the snapshot voíume ís íarger than you need,
you can reduce the síze of the voíume to free up space that ís needed by other
Snapshot Volumes
15
íogícaí voíumes.
When you create a snapshot fííe system, fuíí read and wríte access to the orígín
stays possíbíe. If a chunk on a snapshot ís changed, that chunk ís marked and never
gets copíed from the orígínaí voíume.
There are severaí uses for the snapshot feature:
º Most typícaííy, a snapshot ís taken when you need to perform a backup on a
íogícaí voíume wíthout haítíng the ííve system that ís contínuousíy updatíng the
data.
º You can execute the fsck command on a snapshot fííe system to check the fííe
system íntegríty and determíne whether the orígínaí fííe system requíres fííe
system repaír.
º Because the snapshot ís read/wríte, you can test appíícatíons agaínst productíon
data by takíng a snapshot and runníng tests agaínst the snapshot, íeavíng the reaí
data untouched.
º You can create voíumes for use wíth the Xen vírtuaí machíne monítor. You can use
the snapshot feature to create a dísk ímage, snapshot ít, and modífy the snapshot
for a partícuíar domU ínstance. You can then create another snapshot and modífy
ít for another domU ínstance. Sínce the oníy storage used ís chunks that were
changed on the orígín or snapshot, the maíoríty of the voíume ís shared.
Chapter 2. LVM Components
16
LVM Administration Overview
Thís chapter provídes an overvíew of the admínístratíve procedures you use to
confígure LVM íogícaí voíumes. Thís chapter ís íntended to províde a generaí
understandíng of the steps ínvoíved. For specífíc step-by-step exampíes of common
LVM confíguratíon procedures, see Chapter 5, LVM Confíguratíon Exampíes.
For descríptíons of the CLI commands you can use to perform LVM admínístratíon,
see Chapter 4, LVM Admínístratíon wíth CLI Commands. Aíternateíy, you can use
the LVM GUI, whích ís descríbed ín Chapter 7, LVM Admínístratíon wíth the LVM GUI.
1. Creating LVM Volumes in a Cluster
Creatíng LVM íogícaí voíumes ín a cíuster envíronment ís ídentícaí to creatíng LVM
íogícaí voíumes on a síngíe node. There ís no dífference ín the LVM commands
themseíves, or ín the LVM GUI ínterface. In order to enabíe the LVM voíumes you are
creatíng ín a cíuster, the cíuster ínfrastructure must be runníng and the cíuster must
be quorate.
For ínformatíon on how to set up the cíuster ínfrastructure, see Confíguríng and
Managíng a Red Hat Cíuster.
2. Logical Volume Creation Overview
The foííowíng ís a summary of the steps to perform to create an LVM íogícaí voíume.
1. Inítíaííze the partítíons you wííí use for the LVM voíume as physícaí voíumes (thís
íabeís them).
2. Create a voíume group.
3. Create a íogícaí voíume.
After creatíng the íogícaí voíume you can create and mount the fííe system. The
exampíes ín thís document use GFS fííe systems.
1. Create a GFS fííe system on the íogícaí voíume wíth the gfs¸mkfs command.
2. Create a new mount poínt wíth the mkdír command. In a cíustered system, create
the mount poínt on aíí nodes ín the cíuster.
Chapter 3.
17
3. Mount the fííe system. You may want to add a ííne to the fstab fííe for each node ín
the system.
Aíternateíy, you can create and mount the GFS fííe system wíth the LVM GUI.
Creatíng the LVM voíume ís machíne índependent, sínce the storage area for LVM
setup ínformatíon ís on the physícaí voíumes and not the machíne where the
voíume was created. Servers that use the storage have íocaí copíes, but can
recreate that from what ís on the physícaí voíumes. You can attach physícaí
voíumes to a dífferent server íf the LVM versíons are compatíbíe.
3. Growing a File System on a Logical Volume
To grow a fííe system on a íogícaí voíume, perform the foííowíng steps:
1. Make a new physícaí voíume.
2. Extend the voíume group that contaíns the íogícaí voíume wíth the fííe system
you are growíng to íncíude the new physícaí voíume.
3. Extend the íogícaí voíume to íncíude the new physícaí voíume.
4. Grow the fííe system.
If you have suffícíent unaííocated space ín the voíume group, you can use that
space to extend the íogícaí voíume ínstead of performíng steps 1 and 2.
4. Logical Volume Backup
Metadata backups and archíves are automatícaííy created on every voíume group
and íogícaí voíume confíguratíon change uníess dísabíed ín the ívm.conf fííe. By
defauít, the metadata backup ís stored ín the /etc/ívm/backup fííe and the metadata
archíves are stored ín the /etc/ívm/archíve fííe. How íong the the metadata archíves
stored ín the /etc/ívm/archíve fííe are kept and how many archíve fííes are kept ís
determíned by parameters you can set ín the ívm.conf fííe. A daííy system backup
shouíd íncíude the contents of the /etc/ívm dírectory ín the backup.
Note that a metadata backup does not back up the user and system data contaíned
ín the íogícaí voíumes.
You can manuaííy back up the metadata to the /etc/ívm/backup fííe wíth the
vgcfgbackup command. You can restore metadata wíth the vgcfgrestore command.
Chapter 3. LVM Administration...
18
The vgcfgbackup and vgcfgrestore commands are descríbed ín Sectíon 3.11, "Backíng
Up Voíume Group Metadata".
5. Logging
Aíí message output passes through a íoggíng moduíe wíth índependent choíces of
íoggíng íeveís for:
º standard output/error
º sysíog
º íog fííe
º externaí íog functíon
The íoggíng íeveís are set ín the /etc/ívm/ívm.conf fííe, whích ís descríbed ín
Appendíx B, The LVM Confíguratíon Fííes.
Logging
19
20
LVM Administration with CLl
Commands
Thís chapter summarízes the índívíduaí admínístratíve tasks you can perform wíth
the LVM Command Líne Interface (CLI) commands to create and maíntaín íogícaí
voíumes.
1. Using CLl Commands
There are severaí generaí features of aíí LVM CLI commands.
When sízes are requíred ín a command ííne argument, uníts can aíways be specífíed
expíícítíy. If you do not specífy a unít, then a defauít ís assumed, usuaííy KB or MB.
LVM CLI commands do not accept fractíons.
When specífyíng uníts ín a command ííne argument, LVM ís case-ínsensítíve;
specífyíng M or m ís equívaíent, for exampíe, and powers of 2 (muítípíes of 1024)
are used. However, when specífyíng the --uníts argument ín a command, íower-case
índícates that uníts are ín muítípíes of 1024 whííe upper-case índícates that uníts
are ín muítípíes of 1000.
Where commands take voíume group or íogícaí voíume names as arguments, the
fuíí path name ís optíonaí. A íogícaí voíume caííed ívoí0 ín a voíume group caííed vg0
can be specífíed as vg0/ívoí0. Where a ííst of voíume groups ís requíred but ís íeft
empty, a ííst of aíí voíume groups wííí be substítuted. Where a ííst of íogícaí voíumes
ís requíred but a voíume group ís gíven, a ííst of aíí the íogícaí voíumes ín that
voíume group wííí be substítuted. For exampíe, the ívdíspíay vg0 command wííí
díspíay aíí the íogícaí voíumes ín voíume group vg0.
Aíí LVM commands accept a -v argument, whích can be entered muítípíe tímes to
íncrease the output verbosíty. For exampíe, the foííowíng exampíes shows the
defauít output of the ívcreate command.
# lvcreate -L 50MB new¸vg
Roundíng up síze to fuíí physícaí extent 52.00 MB
Logícaí voíume "ívoí0" created
The foííowíng command shows the output of the ívcreate command wíth the -v
Chapter 4.
21
argument.
# lvcreate -v -L 50MB new¸vg
Fíndíng voíume group "new¸vg"
Roundíng up síze to fuíí physícaí extent 52.00 MB
Archívíng voíume group "new¸vg" metadata (seqno 4).
Creatíng íogícaí voíume ívoí0
Creatíng voíume group backup "/etc/ívm/backup/new¸vg" (seqno 5).
Found voíume group "new¸vg"
Creatíng new¸vg-ívoí0
Loadíng new¸vg-ívoí0 tabíe
Resumíng new¸vg-ívoí0 (253:2)
Cíearíng start of íogícaí voíume "ívoí0"
Creatíng voíume group backup "/etc/ívm/backup/new¸vg" (seqno 5).
Logícaí voíume "ívoí0" created
You couíd aíso have used the -vv, -vvv or the -vvvv argument to díspíay íncreasíngíy
more detaíís about the command executíon. The -vvvv argument provídes the
maxímum amount of ínformatíon at thís tíme. The foííowíng exampíe shows oníy the
fírst few íínes of output for the ívcreate command wíth the -vvvv argument specífíed.
# lvcreate -vvvv -L 50MB new¸vg
#ívmcmdííne.c:913 Processíng: ívcreate -vvvv -L 50MB new¸vg
#ívmcmdííne.c:916 O¸DIRECT wííí be used
#confíg/confíg.c:864 Settíng gíobaí/íockíng¸type to 1
#íockíng/íockíng.c:138 Fííe-based íockíng seíected.
#confíg/confíg.c:841 Settíng gíobaí/íockíng¸dír to /var/íock/ívm
#actívate/actívate.c:358 Gettíng target versíon for íínear
#íoctí/ííbdm-íface.c:1569 dm versíon OF l16384|
#íoctí/ííbdm-íface.c:1569 dm versíons OF l16384|
#actívate/actívate.c:358 Gettíng target versíon for stríped
#íoctí/ííbdm-íface.c:1569 dm versíons OF l16384|
#confíg/confíg.c:864 Settíng actívatíon/mírror¸regíon¸síze to 512
...
You can díspíay heíp for any of the LVM CLI commands wíth the --heíp argument of
the command.
commandname --heíp
Chapter 4. LVM Administration...
22
To díspíay the man page for a command, execute the man command:
man commandname
The man ívm command provídes generaí onííne ínformatíon about LVM.
Aíí LVM obíects are referenced ínternaííy by a UUID, whích ís assígned when you
create the obíect. Thís can be usefuí ín a sítuatíon where you remove a physícaí
voíume caííed /dev/sdf whích ís part of a voíume group and, when you píug ít back ín,
you fínd that ít ís now /dev/sdk. LVM wííí stííí fínd the physícaí voíume because ít
ídentífíes the physícaí voíume by íts UUID and not íts devíce name. For ínformatíon
on specífyíng the UUID of a physícaí voíume when creatíng a physícaí voíume, see
see Sectíon 4, "Recoveríng Physícaí Voíume Metadata".
2. Physical Volume Administration
Thís sectíon descríbes the commands that perform the varíous aspects of physícaí
voíume admínístratíon.
2.1. Creating Physical Volumes
The foííowíng subsectíons descríbe the commands used for creatíng physícaí
voíumes.
2.1.1. Setting the Partition Type
If you are usíng a whoíe dísk devíce for your physícaí voíume, the dísk must have no
partítíon tabíe. For DOS dísk partítíons, the partítíon íd shouíd be set to 0x8e usíng
the fdísk or cfdísk command or an equívaíent. For whoíe dísk devíces oníy the
partítíon tabíe must be erased, whích wííí effectíveíy destroy aíí data on that dísk.
You can remove an exístíng partítíon tabíe by zeroíng the fírst sector wíth the
foííowíng command:
dd íf=/dev/zero of=PhysícaíVoíume bs=512 count=1
2.1.2. lnitializing Physical Volumes
Use the pvcreate command to ínítíaííze a bíock devíce to be used as a physícaí
voíume. Inítíaíízatíon ís anaíogous to formattíng a fííe system.
Physical Volume Administration
23
The foííowíng command ínítíaíízes /dev/sdd1, /dev/sde1, and /dev/sdf1 for use as LVM
physícaí voíumes.
pvcreate /dev/sdd1 /dev/sde1 /dev/sdf1
To ínítíaííze partítíons rather than whoíe dísks: run the pvcreate command on the
partítíon. The foííowíng exampíe ínítíaíízes /dev/hdb1 as an LVM physícaí voíume for
íater use as part of an LVM íogícaí voíume.
pvcreate /dev/hdb1
2.1.3. Scanning for Block Devices
You can scan for bíock devíces that may be used as physícaí voíumes wíth the
ívmdískscan command, as shown ín the foííowíng exampíe.
# lvmdiskscan
/dev/ram0 l 16.00 MB|
/dev/sda l 17.15 GB|
/dev/root l 13.69 GB|
/dev/ram l 16.00 MB|
/dev/sda1 l 17.14 GB| LVM physícaí voíume
/dev/VoíGroup00/LogVoí01 l 512.00 MB|
/dev/ram2 l 16.00 MB|
/dev/new¸vg/ívoí0 l 52.00 MB|
/dev/ram3 l 16.00 MB|
/dev/pkí¸new¸vg/sparkíe¸ív l 7.14 GB|
/dev/ram4 l 16.00 MB|
/dev/ram5 l 16.00 MB|
/dev/ram6 l 16.00 MB|
/dev/ram7 l 16.00 MB|
/dev/ram8 l 16.00 MB|
/dev/ram9 l 16.00 MB|
/dev/ram10 l 16.00 MB|
/dev/ram11 l 16.00 MB|
/dev/ram12 l 16.00 MB|
/dev/ram13 l 16.00 MB|
/dev/ram14 l 16.00 MB|
/dev/ram15 l 16.00 MB|
Chapter 4. LVM Administration...
24
/dev/sdb l 17.15 GB|
/dev/sdb1 l 17.14 GB| LVM physícaí voíume
/dev/sdc l 17.15 GB|
/dev/sdc1 l 17.14 GB| LVM physícaí voíume
/dev/sdd l 17.15 GB|
/dev/sdd1 l 17.14 GB| LVM physícaí voíume
7 dísks
17 partítíons
0 LVM physícaí voíume whoíe dísks
4 LVM physícaí voíumes
2.2. Displaying Physical Volumes
There are three commands you can use to díspíay propertíes of LVM physícaí
voíumes: pvs, pvdíspíay, and pvscan.
The pvs command provídes physícaí voíume ínformatíon ín a confígurabíe form,
díspíayíng one ííne per physícaí voíume. The pvs command provídes a great deaí of
format controí, and ís usefuí for scríptíng. For ínformatíon on usíng the pvs command
to customíze your output, see Sectíon 9, "Customízed Reportíng for LVM".
The pvdíspíay command provídes a verbose muítí-ííne output for each physícaí
voíume. It díspíays physícaí propertíes (síze, extents, voíume group, etc.) ín a fíxed
format.
The foííowíng exampíe shows the output of the pvdíspíay command for a síngíe
physícaí voíume.
# pvdisplay
--- Physícaí voíume ---
PV Name /dev/sdc1
VG Name new¸vg
PV Síze 17.14 GB / not usabíe 3.40 MB
Aííocatabíe yes
PE Síze (KByte) 4096
Totaí PE 4388
Free PE 4375
Aííocated PE 13
PV UUID Ioqích-yWSí-kuEn-IdwM-01S9-XO8M-mcpsVe
The pvscan command scans aíí supported LVM bíock devíces ín the system for
Displaying Physical Volumes
25
physícaí voíumes.
The foííowíng command shows aíí physícaí devíces found:
# pvscan
PV /dev/sdb2 VG vg0 ívm2 l964.00 MB / 0 free|
PV /dev/sdc1 VG vg0 ívm2 l964.00 MB / 428.00 MB free|
PV /dev/sdc2 ívm2 l964.84 MB|
Totaí: 3 l2.83 GB| / ín use: 2 l1.88 GB| / ín no VG: 1 l964.84 MB|
You can defíne a fííter ín the ívm.conf so that thís command wííí avoíd scanníng
specífíc physícaí voíumes. For ínformatíon on usíng fííters to controí whích devíces
are scanned, see Sectíon 6, "Controíííng LVM Devíce Scans wíth Fííters".
2.3. Preventing Allocation on a Physical Volume
You can prevent aííocatíon of physícaí extents on the free space of one or more
physícaí voíumes wíth the pvchange command. Thís may be necessary íf there are
dísk errors, or íf you wííí be removíng the physícaí voíume.
The foííowíng command dísaííows the aííocatíon of physícaí extents on /dev/sdk1.
pvchange -x n /dev/sdk1
You can aíso use the -xy arguments of the pvchange command to aííow aííocatíon
where ít had prevíousíy been dísaííowed.
2.4. Resizing a Physical Volume
If you need to change the síze of an underíyíng bíock devíce for any reason, use the
pvresíze command to update LVM wíth the new síze. You can execute thís command
whííe LVM ís usíng the physícaí voíume.
2.5. Removing Physical Volumes
If a devíce ís no íonger requíred for use by LVM, you can remove the LVM íabeí wíth
the pvremove command. Executíng the pvremove command zeroes the LVM
metadata on an empty physícaí voíume.
If the physícaí voíume you want to remove ís currentíy part of a voíume group, you
Chapter 4. LVM Administration...
26
must remove ít from the voíume group wíth the vgreduce command, as descríbed ín
Sectíon 3.5, "Removíng Physícaí Voíumes from a Voíume Group".
# pvremove ldevlram15
Labeís on physícaí voíume "/dev/ram15" successfuííy wíped
3. Volume Group Administration
Thís sectíon descríbes the commands that perform the varíous aspects of voíume
group admínístratíon.
3.1. Creating Volume Groups
To create a voíume group from one or more physícaí voíumes, use the vgcreate
command. The vgcreate command creates a new voíume group by name and adds
at íeast one physícaí voíume to ít.
The foííowíng command creates a voíume group named vg1 that contaíns physícaí
voíumes /dev/sdd1 and /dev/sde1.
vgcreate vg1 /dev/sdd1 /dev/sde1
When physícaí voíumes are used to create a voíume group, íts dísk space ís dívíded
ínto 4MB extents, by defauít. Thís extent ís the mínímum amount by whích the
íogícaí voíume may be íncreased or decreased ín síze. Large numbers of extents wííí
have no ímpact on I/O performance of the íogícaí voíume.
You can specífy the extent síze wíth the vgcreate command íf the defauít ís not
suítabíe wíth the -s argument. You can put íímíts on the number of physícaí or
íogícaí voíumes the voíume group can have by usíng the -p and -í arguments of the
vgcreate command.
By defauít, a voíume group aííocates physícaí extents accordíng to common-sense
ruíes such as not píacíng paraííeí strípes on the same physícaí voíume. Thís ís the
normaí aííocatíon poíícy. You can use the --aííoc argument of the vgcreate command
to specífy an aííocatíon poíícy of contíguous, anywhere, or cííng.
The contíguous poíícy requíres that new extents are adíacent to exístíng extents. If
there are suffícíent free extents to satísfy an aííocatíon request but a normaí
Volume Group Administration
27
aííocatíon poíícy wouíd not use them, the anywhere aííocatíon poíícy wííí, even íf that
reduces performance by píacíng two strípes on the same physícaí voíume. The cííng
poíícy píaces new extents on the same physícaí voíume as exístíng extents ín the
same strípe of the íogícaí voíume. These poíícíes can be changed usíng the vgchange
command.
In generaí, aííocatíon poíícíes other than normaí are requíred oníy ín specíaí cases
where you need to specífy unusuaí or nonstandard extent aííocatíon.
LVM voíume groups and underíyíng íogícaí voíumes are íncíuded ín the devíce
specíaí fííe dírectory tree ín the /dev dírectory wíth the foííowíng íayout:
/dev/vg/ív/
For exampíe, íf you create two voíume groups myvg1 and myvg2, each wíth three
íogícaí voíumes named ívo1, ívo2, and ívo3, thís create síx devíce specíaí fííes:
/dev/myvg1/ív01
/dev/myvg1/ív02
/dev/myvg1/ív03
/dev/myvg2/ív01
/dev/myvg2/ív02
/dev/myvg2/ív03
The maxímum devíce síze wíth LVM ís 8 Exabytes on 64-bít CPUs.
3.2. Adding Physical Volumes to a Volume Group
To add addítíonaí physícaí voíumes to an exístíng voíume group, use the vgextend
command. The vgextend command íncreases a voíume group's capacíty by addíng
one or more free physícaí voíumes.
The foííowíng command adds the physícaí voíume /dev/sdf1 to the voíume group vg1.
vgextend vg1 /dev/sdf1
3.3. Displaying Volume Groups
Chapter 4. LVM Administration...
28
There are two commands you can use to díspíay propertíes of LVM voíume groups:
vgs and vgdíspíay.
The vgscan command wííí aíso díspíay the voíume groups, aíthough íts prímary
purpose ís to scan aíí the dísks for voíume groups and rebuííd the LVM cache fííe.
For ínformatíon on the vgscan command, see Sectíon 3.4, "Scanníng Dísks for
Voíume Groups to Buííd the Cache Fííe".
The vgs command provídes voíume group ínformatíon ín a confígurabíe form,
díspíayíng one ííne per voíume group. The vgs command provídes a great deaí of
format controí, and ís usefuí for scríptíng. For ínformatíon on usíng the vgs command
to customíze your output, see Sectíon 9, "Customízed Reportíng for LVM".
The vgdíspíay command díspíays voíume group propertíes (such as síze, extents,
number of physícaí voíumes, etc.) ín a fíxed form. The foííowíng exampíe shows the
output of a vgdíspíay command for the voíume group new¸vg. If you do not specífy a
voíume group, aíí exístíng voíume groups are díspíayed.
# vgdisplay new¸vg
--- Voíume group ---
VG Name new¸vg
System ID
Format ívm2
Metadata Areas 3
Metadata Sequence No 11
VG Access read/wríte
VG Status resízabíe
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Síze 51.42 GB
PE Síze 4.00 MB
Totaí PE 13164
Aííoc PE / Síze 13 / 52.00 MB
Free PE / Síze 13151 / 51.37 GB
VG UUID íxOI0a-ZKk0-OpMO-0118-níwO-wwqd-fD5D32
3.4. Scanning Disks for Volume Groups to Build the
Scanning Disks for Volume Groups to
29
Cache File
The vgscan command scans aíí supported dísk devíces ín the system íookíng for LVM
physícaí voíumes and voíume groups. Thís buííds the LVM cache ín the
/etc/ívm/.cache fííe, whích maíntaíns a íístíng of current LVM devíces.
LVM runs the vgscan command automatícaííy at system startup and at other tímes
duríng LVM operatíon, such as when you execute a vgcreate command or when LVM
detects an ínconsístency. You may need to run the vgscan command manuaííy when
you change your hardware confíguratíon, causíng new devíces to be vísíbíe to the
system that were not present at system bootup. Thís may be necessary, for
exampíe, when you add new dísks to the system on a SAN or hotpíug a new dísk
that has been íabeíed as a physícaí voíume.
You can defíne a fííter ín the ívm.conf fííe to restríct the scan to avoíd specífíc
devíces. For ínformatíon on usíng fííters to controí whích devíces are scanned, see
Sectíon 6, "Controíííng LVM Devíce Scans wíth Fííters".
The foííowíng exampíe shows the output of a vgscan command.
# vgscan
Readíng aíí physícaí voíumes. Thís may take a whííe...
Found voíume group "new¸vg" usíng metadata type ívm2
Found voíume group "offícevg" usíng metadata type ívm2
3.5. Removing Physical Volumes from a Volume
Group
To remove unused physícaí voíumes from a voíume group, use the vgreduce
command. The vgreduce command shrínks a voíume group's capacíty by removíng
one or more empty physícaí voíumes. Thís frees those physícaí voíumes to be used
ín dífferent voíume groups or to be removed from the system.
Before removíng a physícaí voíume from a voíume group, you can make sure that
the physícaí voíume ís not used by any íogícaí voíumes by usíng the pvdíspíay
command.
# pvdisplay ldevlhda1
-- Physícaí voíume ---
Chapter 4. LVM Administration...
30
PV Name /dev/hda1
VG Name myvg
PV Síze 1.95 GB / NOT usabíe 4 MB lLVM: 122 KB|
PV# 1
PV Status avaííabíe
Aííocatabíe yes (but fuíí)
Cur LV 1
PE Síze (KByte) 4096
Totaí PE 499
Free PE 0
Aííocated PE 499
PV UUID Sd44tK-9IRw-SrMC-MOkn-76íP-íftz-OVSen7
If the physícaí voíume ís stííí beíng used you wííí have to mígrate the data to
another physícaí voíume usíng the pvmove command. Then use the vgreduce
command to remove the physícaí voíume:
The foííowíng command removes the physícaí voíume /dev/hda1 from the voíume
group my¸voíume¸group.
# vgreduce my¸volume¸group ldevlhda1
3.6. Changing the Parameters of a Volume Group
There are severaí voíume group parameters that you can change for an exístíng
voíume group wíth the vgchange command. Prímarííy, however, thís command ís
used to deactívate and actívate voíume groups, as descríbed ín Sectíon 3.7,
"Actívatíng and Deactívatíng Voíume Groups",
The foííowíng command changes the maxímum number of íogícaí voíumes of
voíume group vg00 to 128.
vgchange -í 128 /dev/vg00
For a descríptíon of the voíume group parameters you can change wíth the vgchange
command, see the vgchange(8) man page.
3.7. Activating and Deactivating Volume Groups
Build the Cache File
31
When you create a voíume group ít ís, by defauít, actívated. Thís means that the
íogícaí voíumes ín that group are accessíbíe and subíect to change.
There are varíous círcumstances for whích you you need to make a voíume group
ínactíve and thus unknown to the kerneí. To deactívate or actívate a voíume group,
use the -a (--avaííabíe) argument of the vgchange command.
The foííowíng exampíe deactívates the voíume group my¸voíume¸group.
vgchange -a n my¸voíume¸group
If cíustered íockíng ís enabíed, add ´e´ to actívate or deactívate a voíume group
excíusíveíy on one node or ´í´ to actívate or/deactívate a voíume group oníy on the
íocaí node. Logícaí voíumes wíth síngíe-host snapshots are aíways actívated
excíusíveíy because they can oníy be used on one node at once.
You can deactívate índívíduaí íogícaí voíumes wíth the ívchange command, as
descríbed ín Sectíon 4.4, "Changíng the Parameters of a Logícaí Voíume Group",
For ínformatíon on actívatíng íogícaí voíumes on índívíduaí nodes ín a cíuster, see
Sectíon 8, "Actívatíng Logícaí Voíumes on Indívíduaí Nodes ín a Cíuster".
3.8. Removing Volume Groups
To remove a voíume group that contaíns no íogícaí voíumes, use the vgremove
command.
# vgremove officevg
Voíume group "offícevg" successfuííy removed
3.9. Splitting a Volume Group
To spíít the physícaí voíumes of a voíume group and create a new voíume group,
use the vgspíít command.
Logícaí voíumes cannot be spíít between voíume groups. Each exístíng íogícaí
voíume must be entíreíy on the physícaí voíumes formíng eíther the oíd or the new
voíume group. If necessary, however, you can use the pvmove command to force
the spíít.
Chapter 4. LVM Administration...
32
The foííowíng exampíe spííts off the new voíume group smaíívg from the orígínaí
voíume group bígvg.
# vgsplit bigvg smallvg ldevlram15
Voíume group "smaíívg" successfuííy spíít from "bígvg"
3.10. Combining Volume Groups
Two combíne two voíume groups ínto a síngíe voíume group, use the vgmerge
command. You can merge an ínactíve "source" voíume wíth an actíve or an ínactíve
"destínatíon" voíume íf the physícaí extent sízes of the voíume are equaí and the
physícaí and íogícaí voíume summaríes of both voíume groups fít ínto the
destínatíon voíume groups íímíts.
The foííowíng command merges the ínactíve voíume group my¸vg ínto the actíve or
ínactíve voíume group databases gívíng verbose runtíme ínformatíon.
vgmerge -v databases my¸vg
3.11. Backing Up Volume Group Metadata
Metadata backups and archíves are automatícaííy created on every voíume group
and íogícaí voíume confíguratíon change uníess dísabíed ín the ívm.conf fííe. By
defauít, the metadata backup ís stored ín the /etc/ívm/backup fííe and the metadata
archíves are stored ín the /etc/ívm/archíves fííe. You can manuaííy back up the
metadata to the /etc/ívm/backup fííe wíth the vgcfgbackup command.
The vgcfrestore command restores the metadata of a voíume group from the archíve
to aíí the physícaí voíumes ín the voíume groups.
For an exampíe of usíng the vgcfgrestore command to recover physícaí voíume
metadata, see Sectíon 4, "Recoveríng Physícaí Voíume Metadata".
3.12. Renaming a Volume Group
Use the vgrename command to rename an exístíng voíume group.
Eíther of the foííowíng commands renames the exístíng voíume group vg02 to
my¸voíume¸group
Combining Volume Groups
33
vgrename /dev/vg02 /dev/my¸voíume¸group
vgrename vg02 my¸voíume¸group
3.13. Moving a Volume Group to Another System
You can move an entíre LVM voíume group to another system. It ís recommended
that you use the vgexport and vgímport commands when you do thís.
The vgexport command makes an ínactíve voíume group ínaccessíbíe to the system,
whích aííows you to detach íts physícaí voíumes. The vgímport command makes a
voíume group accessíbíe to a machíne agaín after the vgexport command has made
ít ínactíve.
To move a voíume group form one system to another, perform the foííowíng steps:
1. Make sure that no users are accessíng fííes on the actíve voíumes ín the voíume
group, then unmount the íogícaí voíumes.
2. Use the -a n argument of the vgchange command to mark the voíume group as
ínactíve, whích prevents any further actívíty on the voíume group.
3. Use the vgexport command to export the voíume group. Thís prevents ít from
beíng accessed by the system from whích you are removíng ít.
After you export the voíume group, the physícaí voíume wííí show up as beíng ín
an exported voíume group when you execute the pvscan command, as ín the
foííowíng exampíe.
lroot@tng3-1|# pvscan
PV /dev/sda1 ís ín exported VG myvg l17.15 GB / 7.15 GB free|
PV /dev/sdc1 ís ín exported VG myvg l17.15 GB / 15.15 GB free|
PV /dev/sdd1 ís ín exported VG myvg l17.15 GB / 15.15 GB free|
...
When the system ís next shut down, you can unpíug the dísks that constítute the
voíume group and connect them to the new system.
Chapter 4. LVM Administration...
34
4. When the dísks are píugged ínto the new system, use the vgímport command to
ímport the voíume group, makíng ít accessíbíe to the new system.
5. Actívate the voíume group wíth the -a y argument of the vgchange command.
6. Mount the fííe system to make ít avaííabíe for use.
3.14. Recreating a Volume Group Directory
To recreate a voíume group dírectory and íogícaí voíume specíaí fííes, use the
vgmknodes command. Thís command checks the LVM2 specíaí fííes ín the /dev
dírectory that are needed for actíve íogícaí voíumes. It creates any specíaí fííes that
are míssíng removes unused ones.
You can íncorporate the vgmknodes command ínto the vgscan command by
specífyíng the --mknodes argument to the command.
4. Logical Volume Administration
Thís sectíon descríbes the commands that perform the varíous aspects of íogícaí
voíume admínístratíon.
4.1. Creating Logical Volumes
To create a íogícaí voíume, use the ívcreate command. You can create íínear
voíumes, stríped voíumes, and mírrored voíumes, as descríbed ín the foííowíng
subsectíons.
If you do not specífy a name for the íogícaí voíume, the defauít name ívoí# ís used
where # ís the ínternaí number of the íogícaí voíume.
The foííowíng sectíons províde exampíes of íogícaí voíume creatíon for the three
types of íogícaí voíumes you can create wíth LVM.
4.1.1. Creating Linear Volumes
When you create a íogícaí voíume, the íogícaí voíume ís carved from a voíume
group usíng the free extents on the physícaí voíumes that make up the voíume
group. Normaííy íogícaí voíumes use up any space avaííabíe on the underíyíng
physícaí voíumes on a next-free basís. Modífyíng the íogícaí voíume frees and
reaííocates space ín the physícaí voíumes.
The foííowíng command creates a íogícaí voíume 10 gígabytes ín síze ín the voíume
Recreating a Volume Group Directory
35
group vg1.
ívcreate -L 10G vg1
The foííowíng command creates a 1500 megabyte íínear íogícaí voíume named testív
ín the voíume group testvg, creatíng the bíock devíce /dev/testvg/testív.
ívcreate -L1500 -ntestív testvg
The foííowíng command creates a 50 gígabyte íogícaí voíume named gfsív from the
free extents ín voíume group vg0.
ívcreate -L 50G -n gfsív vg0
You can use the -í argument of the ívcreate command to specífy the síze of the
íogícaí voíume ín extents. You can aíso use thís argument to specífy the percentage
of the voíume group to use for the íogícaí voíume. The foííowíng command creates a
íogícaí voíume caííed myív that uses 60% of the totaí space ín voíume group testvoí.
ívcreate -í 60%VG -n myív testvg
You can aíso use the -í argument of the ívcreate command to specífy the percentage
of the remaíníng free space ín a voíume group as the síze of the íogícaí voíume. The
foííowíng command creates a íogícaí voíume caííed yourív that uses aíí of the
unaííocated space ín the voíume group testvoí.
ívcreate -í 100%FREE -n yourív testvg
You can use -í argument of the ívcreate command to create a íogícaí voíume that
uses the entíre voíume group. Another way to create a íogícaí voíume that uses the
entíre voíume group ís to use the vgdíspíay command to fínd the "Totaí PE" síze and
to use those resuíts as ínput to the the ívcreate command.
The foííowíng commands create a íogícaí voíume caííed myív that fííís the voíume
Chapter 4. LVM Administration...
36
group named testvg.
# vgdisplay testvg | grep "Total PE"
Totaí PE 10230
# lvcreate -l 10230 testvg -n mylv
The underíyíng physícaí voíumes used to create a íogícaí voíume can be ímportant íf
the physícaí voíume needs to be removed, so you may need to consíder thís
possíbíííty when you create the íogícaí voíume. For ínformatíon on removíng a
physícaí voíume from a voíume group, see Sectíon 3.5, "Removíng Physícaí
Voíumes from a Voíume Group".
To create a íogícaí voíume to be aííocated from a specífíc physícaí voíume ín the
voíume group, specífy the physícaí voíume or voíumes at the end at the ívcreate
command ííne. The foííowíng command creates a íogícaí voíume named testív ín
voíume group testvg aííocated from the physícaí voíume /dev/sdg1,
ívcreate -L 1500 -ntestív testvg /dev/sdg1
You can specífy whích extents of a physícaí voíume are to be used for a íogícaí
voíume. The foííowíng exampíe creates a íínear íogícaí voíume out of extents 0
through 25 of physícaí voíume /dev/sda1 and extents 50 through 125 of physícaí
voíume /dev/sdb1 ín voíume group testvg.
ívcreate -í 100 -n testív testvg /dev/sda1:0-25 /dev/sdb1:50-125
The foííowíng exampíe creates a íínear íogícaí voíume out of extents 0 through 25 of
physícaí voíume /dev/sda1 and then contínues íayíng out the íogícaí voíume at extent
100.
ívcreate -í 100 -n testív testvg /dev/sda1:0-25:100-
The defauít poíícy for how the extents of a íogícaí voíume are aííocated ís ínherít,
whích appííes the same poíícy as for the voíume group. These poíícíes can be
changed usíng the ívchange command. For ínformatíon on aííocatíon poíícíes, see
Sectíon 3.1, "Creatíng Voíume Groups".
Creating Logical Volumes
37
4.1.2. Creating Striped Volumes
For íarge sequentíaí reads and wrítes, creatíng a stríped íogícaí voíume can ímprove
the effícíency of the data I/O. For generaí ínformatíon about stríped voíumes, see
Sectíon 3.2, "Stríped Logícaí Voíumes".
When you create a stríped íogícaí voíume, you specífy the number of strípes wíth
the -í argument of the ívcreate command. Thís determínes over how many physícaí
voíumes the íogícaí voíume wííí be stríped. The number of strípes cannot be greater
than the number of physícaí voíumes ín the voíume group (uníess the --aííoc
anywhere argument ís used).
The strípe síze shouíd be tuned to a power of 2 between 4kB and 512kB, and
matched to the appíícatíon's I/O that ís usíng the stríped voíume. The -I argument of
the ívcreate command specífíes the strípe síze ín kííobytes.
If the underíyíng physícaí devíces that make up a stríped íogícaí voíume are
dífferent sízes, the maxímum síze of the stríped voíume ís determíned by the
smaííest underíyíng devíce. For exampíe, ín a two-íegged strípe, the maxímum síze
ís twíce the síze of the smaííer devíce. In a three-íegged strípe, the maxímum síze ís
three tímes the síze of the smaííest devíce.
The foííowíng command creates a stríped íogícaí voíume across 2 physícaí voíumes
wíth a stríde of 64kB. The íogícaí voíume ís 50 gígabytes ín síze, ís named gfsív, and
ís carved out of voíume group vg0.
ívcreate -L 50G -í2 -I64 -n gfsív vg0
As wíth íínear voíumes, you can specífy the extents of the physícaí voíume that you
are usíng for the strípe. The foííowíng command creates a stríped voíume 100
extents ín síze that strípes across two physícaí voíumes, ís named strípeív and ís ín
voíume group testvg. The strípe wííí use sectors 0-50 of /dev/sda1 and sectors 50-100
of /dev/sdb1.
# lvcreate -l 100 -i2 -nstripelv testvg ldevlsda1:0-50 ldevlsdb1:50-100
Usíng defauít strípesíze 64.00 KB
Logícaí voíume "strípeív" created
4.1.3. Creating Mirrored Volumes
Chapter 4. LVM Administration...
38
When you create a mírrored voíume, you specífy the number of copíes of the data
to make wíth the -m argument of the ívcreate command. Specífyíng -m1 creates one
mírror, whích yíeíds two copíes of the fííe system: a íínear íogícaí voíume píus one
copy. Símííaríy, specífyíng -m2 creates two mírrors, yíeídíng three copíes of the fííe
system.
The foííowíng command creates a mírrored íogícaí voíume wíth a síngíe mírror. The
voíume ís 50 gígabytes ín síze, ís named mírrorív, and ís carved out of voíume group
vg0:
ívcreate -L 50G -m1 -n gfsív vg0
An LVM mírror dívídes the devíce beíng copíed ínto regíons that, by defauít, are
512KB ín síze. You can use the -R argument to specífy the regíon síze ín MB. LVM
maíntaíns a smaíí íog whích ít uses to keep track of whích regíons are ín sync wíth
the mírror or mírrors. By defauít, thís íog ís kept on dísk, whích keeps ít persístent
across reboots. You can specífy ínstead that thís íog be kept ín memory wíth the
--coreíog argument; thís eíímínates the need for an extra íog devíce, but ít requíres
that the entíre mírror be resynchronízed at every reboot.
The foííowíng command creates a mírrored íogícaí voíume from the voíume group
bígvg. The íogícaí ís named ondískmírvoí and has a síngíe mírror. The voíume ís 12MB
ín síze and keeps the mírror íog ín memory.
# lvcreate -L 12MB -m1 --corelog -n ondiskmirvol bigvg
Logícaí voíume "ondískmírvoí" created
When a mírror ís created, the mírror regíons are synchronízed. For íarge mírror
components, the sync process may take a íong tíme. When you are creatíng a new
mírror that does not need to be revíved, you can specífy the nosync argument to
índícate that an ínítíaí synchronízatíon from the fírst devíce ís not requíred.
You can specífy whích devíces to use for the mírror íogs and íog, and whích extents
of the devíces to use. To force the íog onto a partícuíar dísk, specífy exactíy one
extent on the dísk on whích ít wííí be píaced. LVM does not necessary respect the
order ín whích devíces are íísted ín the command ííne. If any physícaí voíumes are
íísted that ís the oníy space on whích aííocatíon wííí take píace. Any physícaí extents
íncíuded ín the ííst that are aíready aííocated wííí get ígnored.
Creating Logical Volumes
39
The foííowíng command creates a mírrored íogícaí voíume wíth a síngíe mírror. The
voíume ís 500 megabytes ín síze, ít ís named mírrorív, and ít ís carved out of voíume
group vg0. The fírst íeg of the mírror ís on devíce /dev/sda1, the second íeg of the
mírror ís on devíce /dev/sdb1, and the mírror íog ís on /dev/sdc1.
ívcreate -L 500M -m1 -n mírrorív vg0 /dev/sda1 /dev/sdb1 /dev/sdc1
The foííowíng command creates a mírrored íogícaí voíume wíth a síngíe mírror. The
voíume ís 500 megabytes ín síze, ít ís named mírrorív, and ít ís carved out of voíume
group vg0. The fírst íeg of the mírror ís on extents 0 through 499 of devíce /dev/sda1,
the second íeg of the mírror ís on extents 0 through 499 of devíce /dev/sdb1, and the
mírror íog starts on extent 0 of devíce /dev/sdc1. These are 1MB extents. If any of
the specífíed extents have aíready been aííocated, they wííí be ígnored.
ívcreate -L 500M -m1 -n mírrorív vg0 /dev/sda1:0-499 /dev/sdb1:0-499 /dev/sdc1:0
4.1.4. Changing Mirrored Volume Configuration
You can convert a íogícaí voíume from a mírrored voíume to a íínear voíume or from
a íínear voíume to a mírrored voíume wíth the ívconvert command. You can aíso use
thís command to reconfígure other mírror parameters of an exístíng íogícaí voíume,
such as coreíog.
When you convert a íogícaí voíume to a mírrored voíume, you are basícaííy creatíng
mírror íegs for an exístíng voíume. Thís means that your voíume group must contaín
the devíces and space for the mírror íegs and for the mírror íog.
If you íose a íeg of a mírror, LVM converts the voíume to a íínear voíume so that you
stííí have access to the voíume, wíthout the mírror redundancy. After you repíace
the íeg, you can use the ívconvert command to restore the mírror. Thís procedure ís
províded ín Sectíon 3, "Recoveríng from LVM Mírror Faííure".
The foííowíng command converts the íínear íogícaí voíume vg00/ívoí1 to a mírrored
íogícaí voíume.
ívconvert -m1 vg00/ívoí1
Chapter 4. LVM Administration...
40
The foííowíng command converts the mírrored íogícaí voíume vg00/ívoí1 to a íínear
íogícaí voíume, removíng the mírror íeg.
ívconvert -m0 vg00/ívoí1
4.2. Persistent Device Numbers
Maíor and mínor devíce numbers are aííocated dynamícaííy at moduíe íoad. Some
appíícatíons work best íf the bíock devíce aíways ís actívated wíth the same devíce
(maíor and mínor) number. You can specífy these wíth the ívcreate and the ívchange
commands by usíng the foííowíng arguments:
--persístent y --maíor maíor --mínor mínor
Use a íarge mínor number to be sure that ít hasn't aíready been aííocated to another
devíce dynamícaííy.
If you are exportíng a fííe system usíng NFS, specífyíng the fsíd parameter ín the
exports fííe may avoíd the need to set a persístent devíce number wíthín LVM.
4.3. Resizing Logical Volumes
To change the síze of a íogícaí voíume, use the ívreduce command. If the íogícaí
voíume contaíns a fííe system, be sure to reduce the fííe system fírst (or use the
LVM GUI) so that the íogícaí voíume ís aíways at íeast as íarge as the fííe system
expects ít to be.
The foííowíng command reduces the síze of íogícaí voíume ívoí1 ín voíume group
vg00 by 3 íogícaí extents.
ívreduce -í -3 vg00/ívoí1
4.4. Changing the Parameters of a Logical Volume
Group
To change the parameters of a íogícaí voíume, use the ívchange command. For a
íístíng of the parameters you can change, see the ívchange(8) man page.
Persistent Device Numbers
41
You can use the ívchange command to actívate and deactívate íogícaí voíumes. To
actívate and deactívate aíí the íogícaí voíumes ín a voíume group at the same tíme,
use the vgchange command, as descríbed ín Sectíon 3.6, "Changíng the Parameters
of a Voíume Group".
The foííowíng command changes the permíssíon on voíume ívoí1 ín voíume group
vg00 to be read-oníy.
ívchange -pr vg00/ívoí1
4.5. Renaming Logical Volumes
To rename an exístíng íogícaí voíume, use the ívrename command.
Eíther of the foííowíng commands renames íogícaí voíume ívoíd ín voíume group
vg02 to ívnew.
ívrename /dev/vg02/ívoíd /dev/vg02/ívnew
ívrename vg02 ívoíd ívnew
For more ínformatíon on actívatíng íogícaí voíumes on índívíduaí nodes ín a cíuster,
see Sectíon 8, "Actívatíng Logícaí Voíumes on Indívíduaí Nodes ín a Cíuster".
4.6. Removing Logical Volumes
To remove an ínactíve íogícaí voíume, use the ívremove command. You must cíose a
íogícaí voíume wíth the umount command before ít can be removed. In addítíon, ín a
cíustered envíronment you must deactívate a íogícaí voíume before ít can be
removed.
If the íogícaí voíume ís currentíy mounted, unmount the voíume before removíng ít.
The foííowíng command removes the íogícaí voíume /dev/testvg/testív. from the
voíume group testvg. Note that ín thís case the íogícaí voíume has not been
deactívated.
Chapter 4. LVM Administration...
42
lroot@tng3-1 ívm|# lvremove ldevltestvgltestlv
Do you reaííy want to remove actíve íogícaí voíume "testív"? ly/n|: y
Logícaí voíume "testív" successfuííy removed
You couíd expíícítíy deactívate the íogícaí voíume before removíng ít wíth the
ívchange -an command, ín whích case you wouíd not see the prompt verífyíng
whether you want to remove an actíve íogícaí voíume.
4.7. Displaying Logical Volumes
There are three commands you can use to díspíay propertíes of LVM íogícaí
voíumes: ívs, ívdíspíay, and ívscan.
The ívs command provídes íogícaí voíume ínformatíon ín a confígurabíe form,
díspíayíng one ííne per íogícaí voíume. The ívs command provídes a great deaí of
format controí, and ís usefuí for scríptíng. For ínformatíon on usíng the ívs command
to customíze your output, see Sectíon 9, "Customízed Reportíng for LVM".
The ívdíspíay command díspíays íogícaí voíume propertíes (such as síze, íayout, and
mappíng) ín a fíxed format.
The foííowíng command shows the attríbutes of ívoí2 ín vg00. If snapshot íogícaí
voíumes have been created for thís orígínaí íogícaí voíume, thís command shows a
ííst of aíí snapshot íogícaí voíumes and theír status (actíve or ínactíve) as weíí.
ívdíspíay -v /dev/vg00/ívoí2
The ívscan command scans for aíí íogícaí voíumes ín the system and íísts them, as ín
the foííowíng exampíe.
# lvscan
ACTIVE '/dev/vg0/gfsív' l1.46 GB| ínherít
4.8. Growing Logical Volumes
To íncrease the síze of a íogícaí voíume, use the ívextend command.
After extendíng the íogícaí voíume, you wííí need to íncrease the síze of the
assocíated fííe system to match.
Displaying Logical Volumes
43
When you extend the íogícaí voíume, you can índícate how much you want to
extend the voíume, or how íarge you want ít to be after you extend ít.
The foííowíng command extends the íogícaí voíumne /dev/myvg/homevoí to 12
gígabytes.
# lvextend -L12G ldevlmyvglhomevol
ívextend -- extendíng íogícaí voíume "/dev/myvg/homevoí" to 12 GB
ívextend -- doíng automatíc backup of voíume group "myvg"
ívextend -- íogícaí voíume "/dev/myvg/homevoí" successfuííy extended
The foííowíng command adds another gígabyte to the íogícaí voíume
/dev/myvg/homevoí.
# lvextend -L+1G ldevlmyvglhomevol
ívextend -- extendíng íogícaí voíume "/dev/myvg/homevoí" to 13 GB
ívextend -- doíng automatíc backup of voíume group "myvg"
ívextend -- íogícaí voíume "/dev/myvg/homevoí" successfuííy extended
As wíth the ívcreate command, you can use the -í argument of the ívextend command
to specífy the number of extents by whích to íncrease the síze of the íogícaí voíume.
You can aíso use thís argument to specífy a percentage of the voíume group, or a
percentage of the remaíníng free space ín the voíume group. The foííowíng
command extends the íogícaí voíume caííed testív to fííí aíí of the unaííocated space
ín the voíume group myvg.
lroot@tng3-1 -|# lvextend -l +100%FREE ldevlmyvgltestlv
Extendíng íogícaí voíume testív to 68.59 GB
Logícaí voíume testív successfuííy resízed
After you have extended the íogícaí voíume ít ís necessary to íncrease the fííe
system síze to match.
By defauít, most fííe system resízíng tooís wííí íncrease the síze of the fííe system to
be the síze of the underíyíng íogícaí voíume so you do not need to worry about
specífyíng the same síze for each of the two commands.
Chapter 4. LVM Administration...
44
4.9. Extending a Striped Volume
In order to íncrease the síze of a stríped íogícaí voíume, there must be enough free
space on the underíyíng physícaí voíumes that make up the voíume group to
support the strípe. For exampíe, íf you have a two-way strípe that that uses up an
entíre voíume group, addíng a síngíe physícaí voíume to the voíume group wííí not
enabíe you to extend the strípe. Instead, you must add at íeast two physícaí
voíumes to the voíume group.
For exampíe, consíder a voíume group vg that consísts of two underíyíng physícaí
voíumes, as díspíayed wíth the foííowíng vgs command.
# vgs
VG #PV #LV #SN Attr VSíze VFree
vg 2 0 0 wz--n- 271.31G 271.31G
You can create a strípe usíng the entíre amount of space ín the voíume group.
# lvcreate -n stripe1 -L 271.31G -i 2 vg
Usíng defauít strípesíze 64.00 KB
Roundíng up síze to fuíí physícaí extent 271.31 GB
Logícaí voíume "strípe1" created
# lvs -a -o +devices
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
strípe1 vg -wí-a- 271.31G /dev/sda1(0),/dev/sdb1(0)
Note that the voíume group now has no more free space.
# vgs
VG #PV #LV #SN Attr VSíze VFree
vg 2 1 0 wz--n- 271.31G 0
The foííowíng command adds another physícaí voíume to the voíume group, whích
then has 135G of addítíonaí space.
# vgextend vg /dev/sdc1
Voíume group "vg" successfuííy extended
# vgs
Extending a Striped Volume
45
VG #PV #LV #SN Attr VSíze VFree
vg 3 1 0 wz--n- 406.97G 135.66G
At thís poínt you cannot extend the stríped íogícaí voíume to the fuíí síze of the
voíume group, because two underíyíng devíces are needed ín order to strípe the
data.
# lvextend vglstripe1 -L 406G
Usíng strípesíze of íast segment 64.00 KB
Extendíng íogícaí voíume strípe1 to 406.00 GB
Insuffícíent suítabíe aííocatabíe extents for íogícaí voíume strípe1: 34480
more requíred
To extend the stríped íogícaí voíume, add another physícaí voíume and then extend
the íogícaí voíume. In thís exampíe, havíng added two physícaí voíumes to the
voíume group we can extend the íogícaí voíume 5A to the fuíí síze of the voíume
group.
# vgextend vg ldevlsdd1
Voíume group "vg" successfuííy extended
# vgs
VG #PV #LV #SN Attr VSíze VFree
vg 4 1 0 wz--n- 542.62G 271.31G
# lvextend vglstripe1 -L 542G
Usíng strípesíze of íast segment 64.00 KB
Extendíng íogícaí voíume strípe1 to 542.00 GB
Logícaí voíume strípe1 successfuííy resízed
If you do not have enough underíyíng physícaí devíces to extend the stríped íogícaí
voíume, ít ís possíbíe to extend the voíume anyway íf ít does not matter that the
extensíon ís not stríped, whích may resuít ín uneven performance. When addíng
space to the íogícaí voíume, the defauít operatíon ís to use the same strípíng
paramgers of the íast segment of the exístíng íogícaí voíume, but you can overríde
those parameters. The foííowíng exampíe extends the exístíng stríped íogícaí
voíume to use the remaíníng free space after the ínítíaí ívextend command faíís.
# lvextend vglstripe1 -L 406G
Chapter 4. LVM Administration...
46
Usíng strípesíze of íast segment 64.00 KB
Extendíng íogícaí voíume strípe1 to 406.00 GB
Insuffícíent suítabíe aííocatabíe extents for íogícaí voíume strípe1: 34480
more requíred
# lvextend -iL -l+100%FREE vglstripe1
4.10. Shrinking Logical Volumes
To reduce the síze of a íogícaí voíume, fírst unmount the fííe system. You can then
use the ívreduce command to shrínk the voíume. After shrínkíng the voíume,
remount the fííe system.
Caution
It ís ímportant to reduce the síze of the fííe system or whatever ís
resídíng ín the voíume before shrínkíng the voíume ítseíf, otherwíse
you rísk íosíng data.
Shrínkíng a íogícaí voíume frees some of the voíume group to be aííocated to other
íogícaí voíumes ín the voíume group.
The foííowíng exampíe reduces the síze of íogícaí voíume ívoí1 ín voíume group vg00
by 3 íogícaí extents.
ívreduce -í -3 vg00/ívoí1
5. Creating Snapshot Volumes
Use the -s argument of the ívcreate command to create a snapshot voíume. A
snapshot voíume ís wríteabíe.
LVM snapshots are not cíuster-aware, so they requíre excíusíve access to a voíume.
For ínformatíon on actívatíng íogícaí voíumes on índívíduaí nodes ín a cíuster, see
Sectíon 8, "Actívatíng Logícaí Voíumes on Indívíduaí Nodes ín a Cíuster".
The foííowíng command creates a snapshot íogícaí voíume that ís 100 megabytes ín
síze named /dev/vg00/snap. Thís creates a snapshot of the orígín íogícaí voíume
named /dev/vg00/ívoí1. If the orígínaí íogícaí voíume contaíns a fííe system, you can
Shrinking Logical Volumes
47
mount the snapshot íogícaí voíume on an arbítrary dírectory ín order to access the
contents of the fííe system to run a backup whííe the orígínaí fííe system contínues
to get updated.
ívcreate --síze 100M --snapshot --name snap /dev/vg00/ívoí1
After you create a snapshot íogícaí voíume, specífyíng the orígín voíume on the
ívdíspíay command yíeíds output that íncíudes a a ííst of aíí snapshot íogícaí voíumes
and theír status (actíve or ínactíve).
The foííowíng exampíe shows the status of the íogícaí voíume /dev/new¸vg/ívoí0, for
whích a snapshot voíume /dev/new¸vg/newvgsnap has been created.
# lvdisplay ldevlnew¸vgllvol0
--- Logícaí voíume ---
LV Name /dev/new¸vg/ívoí0
VG Name new¸vg
LV UUID LBy1Tz-sr23-OísI-LT03-nHLC-y8XW-EhCí78
LV Wríte Access read/wríte
LV snapshot status source of
/dev/new¸vg/newvgsnap1 lactíve|
LV Status avaííabíe
# open 0
LV Síze 52.00 MB
Current LE 13
Segments 1
Aííocatíon ínherít
Read ahead sectors 0
Bíock devíce 253:2
The ívs command, by defauít, díspíays the orígín voíume and the current percentage
of the snapshot voíume beíng used for each snapshot voíume. The foííowíng
exampíe shows the defauít output for the ívs command for a system that íncíudes
the íogícaí voíume /dev/new¸vg/ívoí0, for whích a snapshot voíume
/dev/new¸vg/newvgsnap has been created.
# lvs
LV VG Attr LSíze Orígín Snap% Move Log Copy%
ívoí0 new¸vg owí-a- 52.00M
Chapter 4. LVM Administration...
48
newvgsnap1 new¸vg swí-a- 8.00M ívoí0 0.20
Note
Because the snapshot íncreases ín síze as the orígín voíume changes,
ít ís ímportant to monítor the percentage of the snapshot voíume
reguíaríy wíth the ívs command to be sure ít does not fííí. A snapshot
that ís 100% fuíí ís íost compíeteíy, as wríte to unchanged parts of the
orígínín wouíd be unabíe to succeed wíthout corruptíng the snapshot.
6. Controlling LVM Device Scans with Filters
At startup, the vgscan command ís run to scan the bíock devíces on the system
íookíng for LVM íabeís, to determíne whích of them are physícaí voíumes and to
read the metadata and buííd up a ííst of voíume groups. The names of the physícaí
voíumes are stored ín the cache fííe of each node ín the system, /etc/ívm/.cache.
Subsequent commands may read that fííe to avoídíng rescanníng.
You can controí whích devíces LVM scans by settíng up fííters ín the ívm.conf
confíguratíon fííe. The fííters consíst of a seríes of símpíe reguíar expressíons that
get appííed to the devíce names ín the /dev dírectory to decíde whether to accept or
reíect each bíock devíce found.
The foííowíng exampíes show the use of fííters to controí whích devíces LVM scans.
Note that some of these exampíes do not necessarííy represent best practíce, as the
reguíar expressíons are matched freeíy agaínst the compíete pathname. For
exampíe, a/íoop/ ís equívaíent to a/.*íoop.*/ and wouíd match /dev/soíooperatíon/ívoí1.
The foííowíng fííter adds aíí díscovered devíces, whích ís the defauít behavíor as
there ís no fííter confígured ín the confíguratíon fííe:
fííter = l "a/.*/" |
The foííowíng fííter removes the cdrom devíce ín order to avoíd deíays íf the dríve
contaíns no medía:
fííter = l "r|/dev/cdrom|" |
Controlling LVM Device Scans with
49
The foííowíng fííter adds aíí íoop and removes aíí other bíock devíces:
fííter = l "a/íoop.*/", "r/.*/" |
The foííowíng fííter adds aíí íoop and IDE and removes aíí other bíock devíces:
fííter =l "a|íoop.*|", "a|/dev/hd.*|", "r|.*|" |
The foííowíng fííter adds íust partítíon 8 on the fírst IDE dríve and removes aíí other
bíock devíces:
fííter = l "a|´/dev/hda8$|", "r/.*/" |
For more ínformatíon on the ívm.conf fííe, see Appendíx B, The LVM Confíguratíon
Fííes and the ívm.conf(5) man page.
7. Online Data Relocation
You can move data whííe the system ís ín use wíth the pvmove command.
The pvmove command breaks up the data to be moved ínto sectíons and creates a
temporary mírror to move each sectíon. For more ínformatíon on the operatíon of
the pvmove command, see the pvmove(8) man page.
Because the pvmove command uses mírroríng, ít ís not cíuster-aware and needs
excíusíve access to a voíume. For ínformatíon on actívatíng íogícaí voíumes on
índívíduaí nodes ín a cíuster, see Sectíon 8, "Actívatíng Logícaí Voíumes on
Indívíduaí Nodes ín a Cíuster".
The foííowíng command moves aíí aííocated space off the physícaí voíume /dev/sdc1
to other free physícaí voíumes ín the voíume group:
pvmove /dev/sdc1
Chapter 4. LVM Administration...
50
The foííowíng command moves íust the extents of the íogícaí voíume MyLV.
pvmove -n MyLV /dev/sdc1
Sínce the pvmove command can take a íong tíme to execute, you may want to run
the command ín the background to avoíd díspíay of progress updates ín the
foreground. The foííowíng command moves aíí extents aííocated to to the physícaí
voíume /dev/sdc1 over to /dev/sdf1 ín the background.
pvmove -b /dev/sdc1 /dev/sdf1
The foííowíng command reports the progress of the move as a percentage at fíve
second íntervaís.
pvmove -í5 /dev/sdd1
8. Activating Logical Volumes on lndividual
Nodes in a Cluster
If you have LVM ínstaííed ín a cíuster envíronment, you may at tímes need to
actívate íogícaí voíumes excíusíveíy on one node. For exampíe, the pvmove
command ís not cíuster-aware and needs excíusíve access to a voíume. LVM
snapshots requíre excíusíve access to a voíume as weíí.
To actívate íogícaí voíumes excíusíveíy on one node, use the ívchange -aey
command. Aíternatíveíy, you can use ívchange -aíy command to actívate íogícaí
voíumes oníy on the íocaí node but not excíusíveíy. You can íater actívate them on
addítíonaí nodes concurrentíy.
You can aíso actívate íogícaí voíumes on índívíduaí nodes by usíng LVM tags, whích
are descríbed ín Appendíx C, LVM Obíect Tags. You can aíso specífy actívatíon of
nodes ín the confíguratíon fííe, whích ís descríbed ín Appendíx B, The LVM
Confíguratíon Fííes.
9. Customized Reporting for LVM
Filters
51
You can produce concíse and customízabíe reports of LVM obíects wíth the pvs, ívs,
and vgs commands. The reports that these commands generate íncíude one ííne of
output for each obíect. Each ííne contaíns an ordered ííst of fíeíds of propertíes
reíated to the obíect. There are fíve ways to seíect the obíects to be reported: by
physícaí voíume, voíume group, íogícaí voíume, physícaí voíume segment, and
íogícaí voíume segment.
The foííowíng sectíons províde:
º A summary of command arguments you can use to controí the format of the
generated report.
º A ííst of the fíeíds you can seíect for each LVM obíect.
º A summary of command arguments you can use to sort the generated report.
º Instructíons for specífyíng the uníts of the report output.
9.1. Format Control
Whether you use the pvs, ívs, or vgs command determínes the defauít set of fíeíds
díspíayed and the sort order. You can controí the output of these commands wíth
the foííowíng arguments:
º You can change what fíeíds are díspíayed to somethíng other than the defauít by
usíng the -o argument. For exampíe, the foííowíng output ís the defauít díspíay for
the pvs command (whích díspíays ínformatíon about physcíaí voíumes).
# pvs
PV VG Fmt Attr PSíze PFree
/dev/sdb1 new¸vg ívm2 a- 17.14G 17.14G
/dev/sdc1 new¸vg ívm2 a- 17.14G 17.09G
/dev/sdd1 new¸vg ívm2 a- 17.14G 17.14G
The foííowíng command díspíays oníy the physícaí voíume name and síze.
# pvs -o pv¸name,pv¸size
PV PSíze
/dev/sdb1 17.14G
Chapter 4. LVM Administration...
52
/dev/sdc1 17.14G
/dev/sdd1 17.14G
º You can append a fíeíd to the output wíth the píus sígn (+), whích ís used ín
combínatíon wíth the -o argument.
The foííowíng exampíe díspíays the UUID of the physícaí voíume ín addítíon to the
defauít fíeíds.
# pvs -o +pv¸uuid
PV VG Fmt Attr PSíze PFree PV UUID
/dev/sdb1 new¸vg ívm2 a- 17.14G 17.14G onFF2w-1fLC-ughI-D9eB-M7ív-6XqA-dqGeXY
/dev/sdc1 new¸vg ívm2 a- 17.14G 17.09G Ioqích-yWSí-kuEn-IdwM-01S9-XO8M-mcpsVe
/dev/sdd1 new¸vg ívm2 a- 17.14G 17.14G yvfvZK-Cf31-í75k-dECm-0RZ3-0dGW-tUqkCS
º Addíng the -v argument to a command íncíudes some extra fíeíds. For exampíe,
the pvs -v command wííí díspíay the DevSíze and PV UUID fíeíds ín addítíon to the
defauít fíeíds.
# pvs -v
Scanníng for physícaí voíume names
PV VG Fmt Attr PSíze PFree DevSíze PV UUID
/dev/sdb1 new¸vg ívm2 a- 17.14G 17.14G 17.14G
onFF2w-1fLC-ughI-D9eB-M7ív-6XqA-dqGeXY
/dev/sdc1 new¸vg ívm2 a- 17.14G 17.09G 17.14G
Ioqích-yWSí-kuEn-IdwM-01S9-XO8M-mcpsVe
/dev/sdd1 new¸vg ívm2 a- 17.14G 17.14G 17.14G
yvfvZK-Cf31-í75k-dECm-0RZ3-0dGW-tUqkCS
º The --noheadíngs argument suppresses the headíngs ííne. Thís can be usefuí for
wrítíng scrípts.
The foííowíng exampíe uses the --noheadíngs argument ín combínatíon wíth the
pv¸name argument, whích wííí generate a ííst of aíí physícaí voíumes.
# pvs --noheadings -o pv¸name
/dev/sdb1
/dev/sdc1
Format Control
53
/dev/sdd1
º The --separator separator argument uses separator to separate each fíeíd. Thís can
be usefuí ín a scrípt íf you are runníng a grep command on the output.
The foííowíng exampíe separates the defauít output fíeíds of the pvs command
wíth an equaís sígn (=).
# pvs --separator =
PV=VG=Fmt=Attr=PSíze=PFree
/dev/sdb1=new¸vg=ívm2=a-=17.14G=17.14G
/dev/sdc1=new¸vg=ívm2=a-=17.14G=17.09G
/dev/sdd1=new¸vg=ívm2=a-=17.14G=17.14G
To keep the fíeíds aíígned when usíng the separator argument, use the separator
argument ín coníunctíon wíth the --aíígned argument.
# pvs --separator = --aligned
PV =VG =Fmt =Attr=PSíze =PFree
/dev/sdb1 =new¸vg=ívm2=a- =17.14G=17.14G
/dev/sdc1 =new¸vg=ívm2=a- =17.14G=17.09G
/dev/sdd1 =new¸vg=ívm2=a- =17.14G=17.14G
You can use the -P argument of the ívs or vgs command to díspíay ínformatíon about
a faííed voíume that wouíd otherwíse not appear ín the output. For ínformatíon on
the output thís argument yíeíds, see Sectíon 2, "Díspíayíng Informatíon on Faííed
Devíces".
For a fuíí íístíng of díspíay arguments, see the pvs(8), vgs(8) and ívs(8) man pages.
Voíume group fíeíds can be míxed wíth eíther physícaí voíume (and physícaí voíume
segment) fíeíds or wíth íogícaí voíume (and íogícaí voíume segment) fíeíds, but
physícaí voíume and íogícaí voíume fíeíds cannot be míxed. For exampíe, the
foííowíng command wííí díspíay one ííne of output for each physícaí voíume.
# vgs -o +pv¸name
VG #PV #LV #SN Attr VSíze VFree PV
new¸vg 3 1 0 wz--n- 51.42G 51.37G /dev/sdc1
Chapter 4. LVM Administration...
54
new¸vg 3 1 0 wz--n- 51.42G 51.37G /dev/sdd1
new¸vg 3 1 0 wz--n- 51.42G 51.37G /dev/sdb1
9.2. Obiect Selection
Thís sectíon provídes a seríes of tabíes that ííst the ínformatíon you can díspíay
about the LVM obíects wíth the pvs, vgs, and ívs commands.
For conveníence, a fíeíd name prefíx can be dropped íf ít matches the defauít for the
command. For exampíe, wíth the pvs command, name means pv¸name, but wíth the
vgs command, name ís ínterpreted as vg¸name.
Executíng the foííowíng command ís the equívaíent of executíng pvs -o pv¸free.
# pvs -o free
PFree
17.14G
17.09G
17.14G
The pvs Command
Tabíe 4.1, "pvs Díspíay Fíeíds" íísts the díspíay arguments of the pvs command,
aíong wíth the fíeíd name as ít appears ín the header díspíay and a descríptíon of
the fíeíd.
Argument Header Description
dev¸síze DevSíze The síze of the underíyíng devíce on whích the
physícaí voíume was created
pe¸start 1st PE Offset to the start of the fírst physícaí extent ín the
underíyíng devíce
pv¸attr Attr Status of the physícaí voíume: (a)ííocatabíe or
e(x)ported.
pv¸fmt Fmt The metadata format of the physícaí voíume (ívm2 or
ívm1)
pv¸free PFree The free space remaíníng on the physícaí voíume
pv¸name PV The physícaí voíume name
pv¸pe¸aííoc¸count Aííoc Number of used physícaí extents
Obiect Selection
55
Argument Header Description
pv¸pe¸count PE Number of physícaí extents
pvseg¸síze SSíze The segment síze of the physícaí voíume
pvseg¸start Start The startíng physícaí extent of the physícaí voíume
segment
pv¸síze PSíze The síze of the physícaí voíume
pv¸tags PV Tags LVM tags attached to the physícaí voíume
pv¸used Used The amount of space currentíy used on the physícaí
voíume
pv¸uuíd PV UUID The UUID of the physícaí voíume
Table 4.1. pvs Display Fields
The pvs command díspíays the foííowíng fíeíds by defauít: pv¸name, vg¸name, pv¸fmt,
pv¸attr, pv¸síze, pv¸free. The díspíay ís sorted by pv¸name.
# pvs
PV VG Fmt Attr PSíze PFree
/dev/sdb1 new¸vg ívm2 a- 17.14G 17.14G
/dev/sdc1 new¸vg ívm2 a- 17.14G 17.09G
/dev/sdd1 new¸vg ívm2 a- 17.14G 17.13G
Usíng the -v argument wíth the pvs command adds the foííowíng fíeíds to the defauít
díspíay: dev¸síze, pv¸uuíd.
# pvs -v
Scanníng for physícaí voíume names
PV VG Fmt Attr PSíze PFree DevSíze PV UUID
/dev/sdb1 new¸vg ívm2 a- 17.14G 17.14G 17.14G
onFF2w-1fLC-ughI-D9eB-M7ív-6XqA-dqGeXY
/dev/sdc1 new¸vg ívm2 a- 17.14G 17.09G 17.14G
Ioqích-yWSí-kuEn-IdwM-01S9-XO8M-mcpsVe
/dev/sdd1 new¸vg ívm2 a- 17.14G 17.13G 17.14G
yvfvZK-Cf31-í75k-dECm-0RZ3-0dGW-tUqkCS
You can use the --segments argument of the pvs command to díspíay ínformatíon
Chapter 4. LVM Administration...
56
about each physícaí voíume segment. A segment ís a group of extents. A segment
víew can be usefuí íf you want to see whether your íogícaí voíume ís fragmented.
The pvs --segments command díspíays the foííowíng fíeíds by defauít: pv¸name,
vg¸name, pv¸fmt, pv¸attr, pv¸síze, pv¸free, pvseg¸start, pvseg¸síze. The díspíay ís sorted
by pv¸name and pvseg¸síze wíthín the physícaí voíume.
# pvs --segments
PV VG Fmt Attr PSíze PFree Start SSíze
/dev/hda2 VoíGroup00 ívm2 a- 37.16G 32.00M 0 1172
/dev/hda2 VoíGroup00 ívm2 a- 37.16G 32.00M 1172 16
/dev/hda2 VoíGroup00 ívm2 a- 37.16G 32.00M 1188 1
/dev/sda1 vg ívm2 a- 17.14G 16.75G 0 26
/dev/sda1 vg ívm2 a- 17.14G 16.75G 26 24
/dev/sda1 vg ívm2 a- 17.14G 16.75G 50 26
/dev/sda1 vg ívm2 a- 17.14G 16.75G 76 24
/dev/sda1 vg ívm2 a- 17.14G 16.75G 100 26
/dev/sda1 vg ívm2 a- 17.14G 16.75G 126 24
/dev/sda1 vg ívm2 a- 17.14G 16.75G 150 22
/dev/sda1 vg ívm2 a- 17.14G 16.75G 172 4217
/dev/sdb1 vg ívm2 a- 17.14G 17.14G 0 4389
/dev/sdc1 vg ívm2 a- 17.14G 17.14G 0 4389
/dev/sdd1 vg ívm2 a- 17.14G 17.14G 0 4389
/dev/sde1 vg ívm2 a- 17.14G 17.14G 0 4389
/dev/sdf1 vg ívm2 a- 17.14G 17.14G 0 4389
/dev/sdg1 vg ívm2 a- 17.14G 17.14G 0 4389
You can use the pvs -a command to see devíces detected by LVM that have not been
ínítíaíízed as LVM physícaí voíumes.
# pvs -a
PV VG Fmt Attr PSíze PFree
/dev/VoíGroup00/LogVoí01 -- 0 0
/dev/new¸vg/ívoí0 -- 0 0
/dev/ram -- 0 0
/dev/ram0 -- 0 0
/dev/ram2 -- 0 0
/dev/ram3 -- 0 0
/dev/ram4 -- 0 0
/dev/ram5 -- 0 0
/dev/ram6 -- 0 0
/dev/root -- 0 0
Obiect Selection
57
/dev/sda -- 0 0
/dev/sdb -- 0 0
/dev/sdb1 new¸vg ívm2 a- 17.14G 17.14G
/dev/sdc -- 0 0
/dev/sdc1 new¸vg ívm2 a- 17.14G 17.09G
/dev/sdd -- 0 0
/dev/sdd1 new¸vg ívm2 a- 17.14G 17.14G
The vgs Command
Tabíe 4.2, "vgs Díspíay Fíeíds" íísts the díspíay arguments of the vgs command,
aíong wíth the fíeíd name as ít appears ín the header díspíay and a descríptíon of
the fíeíd.
Argument Header Description
ív¸count #LV The number of íogícaí voíumes the voíume group
contaíns
max¸ív MaxLV The maxímum number of íogícaí voíumes aííowed ín
the voíume group (0 íf uníímíted)
max¸pv MaxPV The maxímum number of physícaí voíumes aííowed ín
the voíume group (0 íf uníímíted)
pv¸count #PV The number of physícaí voíumes that defíne the
voíume group
snap¸count #SN The number of snapshots the voíume group contaíns
vg¸attr Attr Status of the voíume group: (w)ríteabíe, (r)eadoníy,
resí(z)eabíe, e(x)ported, (p)artíaí and (c)íustered.
vg¸extent¸count #Ext The number of physícaí extents ín the voíume group
vg¸extent¸síze Ext The síze of the physícaí extents ín the voíume group
vg¸fmt Fmt The metadata format of the voíume group (ívm2 or
ívm1)
vg¸free VFree Síze of the free space remaíníng ín the voíume group
vg¸free¸count Free Number of free physícaí extents ín the voíume group
vg¸name VG The voíume group name
vg¸seqno Seq Number representíng the revísíon of the voíume group
vg¸síze VSíze The síze of the voíume group
vg¸sysíd SYS ID LVM1 System ID
Chapter 4. LVM Administration...
58
Argument Header Description
vg¸tags VG Tags LVM tags attached to the voíume group
vg¸uuíd VG UUID The UUID of the voíume group
Table 4.2. vgs Display Fields
The vgs command díspíays the foííowíng fíeíds by defauít: vg¸name, pv¸count,
ív¸count, snap¸count, vg¸attr, vg¸síze, vg¸free. The díspíay ís sorted by vg¸name.
# vgs
VG #PV #LV #SN Attr VSíze VFree
new¸vg 3 1 1 wz--n- 51.42G 51.36G
Usíng the -v argument wíth the vgs command adds the foííowíng fíeíds to the defauít
díspíay: vg¸extent¸síze, vg¸uuíd.
# vgs -v
Fíndíng aíí voíume groups
Fíndíng voíume group "new¸vg"
VG Attr Ext #PV #LV #SN VSíze VFree VG UUID
new¸vg wz--n- 4.00M 3 1 1 51.42G 51.36G
íxOI0a-ZKk0-OpMO-0118-níwO-wwqd-fD5D32
The lvs Command
Tabíe 4.3, "ívs Díspíay Fíeíds" íísts the díspíay arguments of the ívs command,
aíong wíth the fíeíd name as ít appears ín the header díspíay and a descríptíon of
the fíeíd.
Argument Header Description
chunksíze
chunk¸síze
Chunk Unít síze ín a snapshot voíume
copy¸percent Copy% The synchronízatíon percentage of a mírrored íogícaí
voíume; aíso used when physícaí extents are beíng
moved wíth the pv¸move command
devíces Devíces The underíyíng devíces that make up the íogícaí
Obiect Selection
59
Argument Header Description
voíume: the physícaí voíumes, íogícaí voíumes, and
start physícaí extents and íogícaí extents
ív¸attr Attr The status of the íogícaí voíume. The íogícaí voíume
attríbute bíts are as foííows:
Bít 1: Voíume type: (m)írrored, (M)írrored wíthout
ínítíaí sync, (o)rígín, (p)vmove, (s)napshot, ínvaííd
(S)napshot, (v)írtuaí
Bít2: Permíssíons: (w)ríteabíe, (r)ead-oníy
Bít 3: Aííocatíon poíícy: (c)ontíguous, (n)ormaí,
(a)nywhere, (í)nheríted. Thís ís capítaíízed íf the
voíume ís currentíy íocked agaínst aííocatíon changes,
for exampíe whííe executíng the pvmove command.
Bít 4: fíxed (m)ínor
Bít 5 State: (a)ctíve, (s)uspended, (I)nvaííd snapshot,
ínvaííd (S)uspended snapshot, mapped (d)evíce
present wíthout tabíes, mapped devíce present wíth
(í)nactíve tabíe
Bít 6: devíce (o)pen
ív¸kerneí¸maíorKMaí Actuaí maíor devíce number of the íogícaí voíume (-1
íf ínactíve)
ív¸kerneí¸mínorKMIN Actuaí mínor devíce number of the íogícaí voíume (-1
íf ínactíve)
ív¸maíor Maí The persístent maíor devíce number of the íogícaí
voíume (-1 íf not specífíed)
ív¸mínor Mín The persístent mínor devíce number of the íogícaí
voíume (-1 íf not specífíed)
ív¸name LV The name of the íogícaí voíume
ív¸síze LSíze The síze of the íogícaí voíume
ív¸tags LV Tags LVM tags attached to the íogícaí voíume
ív¸uuíd LV UUID The UUID of the íogícaí voíume.
mírror¸íog Log Devíce on whích the mírror íog resídes
moduíes Moduíes Correspondíng kerneí devíce-mapper target necessary
to use thís íogícaí voíume
move¸pv Move Source physícaí voíume of a temporary íogícaí voíume
created wíth the pvmove command
Chapter 4. LVM Administration...
60
Argument Header Description
orígín Orígín The orígín devíce of a snapshot voíume
regíonsíze
regíon¸síze
Regíon The unít síze of a mírrored íogícaí voíume
seg¸count #Seg The number of segments ín the íogícaí voíume
seg¸síze SSíze The síze of the segments ín the íogícaí voíume
seg¸start Start Offset of the segment ín the íogícaí voíume
seg¸tags Seg Tags LVM tags attached to the segments of the íogícaí
voíume
segtype Type The segment type of a íogícaí voíume (for exampíe:
mírror, stríped, íínear)
snap¸percent Snap% Current percentage of a snapshot voíume that ís ín
use
strípes #Str Number of strípes or mírrors ín a íogícaí voíume
strípesíze
strípe¸síze
Strípe Unít síze of the strípe ín a stríped íogícaí voíume
Table 4.3. lvs Display Fields
The ívs command díspíays the foííowíng fíeíds by defauít: ív¸name, vg¸name, ív¸attr,
ív¸síze, orígín, snap¸percent, move¸pv, mírror¸íog, copy¸percent. The defauít díspíay ís
sorted by vg¸name and ív¸name wíthín the voíume group.
# lvs
LV VG Attr LSíze Orígín Snap% Move Log Copy%
ívoí0 new¸vg owí-a- 52.00M
newvgsnap1 new¸vg swí-a- 8.00M ívoí0 0.20
Usíng the -v argauament wíth the ívs command adds the foííowíng fíeíds to the
defauít díspíay: seg¸count, ív¸maíor, ív¸mínor, ív¸kerneí¸maíor, ív¸kerneí¸mínor, ív¸uuíd.
# lvs -v
Fíndíng aíí íogícaí voíumes
LV VG #Seg Attr LSíze Maí Mín KMaí KMín Orígín Snap% Move Copy% Log LV
Obiect Selection
61
UUID
ívoí0 new¸vg 1 owí-a- 52.00M -1 -1 253 3
LBy1Tz-sr23-OísI-LT03-nHLC-y8XW-EhCí78
newvgsnap1 new¸vg 1 swí-a- 8.00M -1 -1 253 5 ívoí0 0.20
1ye1OU-1cIu-o79k-20h2-ZGF0-qCIm-CfbsIx
You can use the --segments argument of the ívs command to díspíay ínformatíon wíth
defauít coíumns that emphasíze the segment ínformatíon. When you use the
segments argument, the seg prefíx ís optíonaí. The ívs --segments command díspíays
the foííowíng fíeíds by defauít: ív¸name, vg¸name, ív¸attr, strípes, segtype, seg¸síze. The
defauít díspíay ís sorted by vg¸name, ív¸name wíthín the voíume group, and seg¸start
wíthín the íogícaí voíume. If the íogícaí voíumes were fragmented, the output from
thís command wouíd show that.
# lvs --segments
LV VG Attr #Str Type SSíze
LogVoí00 VoíGroup00 -wí-ao 1 íínear 36.62G
LogVoí01 VoíGroup00 -wí-ao 1 íínear 512.00M
ív vg -wí-a- 1 íínear 104.00M
ív vg -wí-a- 1 íínear 104.00M
ív vg -wí-a- 1 íínear 104.00M
ív vg -wí-a- 1 íínear 88.00M
Usíng the -v argument wíth the ívs --segments command adds the foííowíng fíeíds to
the defauít díspíay: seg¸start, strípesíze, chunksíze.
# lvs -v --segments
Fíndíng aíí íogícaí voíumes
LV VG Attr Start SSíze #Str Type Strípe Chunk
ívoí0 new¸vg owí-a- 0 52.00M 1 íínear 0 0
newvgsnap1 new¸vg swí-a- 0 8.00M 1 íínear 0 8.00K
The foííowíng exampíe shows the defauít output of the ívs command on a system
wíth one íogícaí voíume confígured, foííowed by the defauít output of the ívs
command wíth the segments argument specífíed.
# lvs
LV VG Attr LSíze Orígín Snap% Move Log Copy%
Chapter 4. LVM Administration...
62
ívoí0 new¸vg -wí-a- 52.00M
# lvs --segments
LV VG Attr #Str Type SSíze
ívoí0 new¸vg -wí-a- 1 íínear 52.00M
9.3. Sorting LVM Reports
Normaííy the entíre output of the ívs, vgs, or pvs command has to be generated and
stored ínternaííy before ít can be sorted and coíumns aíígned correctíy. You can
specífy the --unbuffered argument to díspíay unsorted output as soon as ít ís
generated.
To specífy an aíternatíve ordered ííst of coíumns to sort on, use the -O argument of
any of the reportíng commands. It ís not necessary to íncíude these fíeíds wíthín the
output ítseíf.
The foííowíng exampíe shows the output of the pvs command that díspíays the
physícaí voíume name, síze, and free space.
# pvs -o pv¸name,pv¸size,pv¸free
PV PSíze PFree
/dev/sdb1 17.14G 17.14G
/dev/sdc1 17.14G 17.09G
/dev/sdd1 17.14G 17.14G
The foííowíng exampíe shows the same output, sorted by the free space fíeíd.
# pvs -o pv¸name,pv¸size,pv¸free -O pv¸free
PV PSíze PFree
/dev/sdc1 17.14G 17.09G
/dev/sdd1 17.14G 17.14G
/dev/sdb1 17.14G 17.14G
The foííowíng exampíe shows that you do not need to díspíay the fíeíd on whích you
are sortíng.
# pvs -o pv¸name,pv¸size -O pv¸free
PV PSíze
/dev/sdc1 17.14G
Sorting LVM Reports
63
/dev/sdd1 17.14G
/dev/sdb1 17.14G
To díspíay a reverse sort, precede a fíeíd you specífy after the -O argument wíth the
- character.
# pvs -o pv¸name,pv¸size,pv¸free -O -pv¸free
PV PSíze PFree
/dev/sdd1 17.14G 17.14G
/dev/sdb1 17.14G 17.14G
/dev/sdc1 17.14G 17.09G
9.4. Specifying Units
To specífy the unít for the LVM report díspíay, use the --uníts argument of the report
command. You can specífy (b)ytes, (k)ííobytes, (m)egabytes, (g)ígabytes,
(t)erabytes, (e)xabytes, (p)etabytes, and (h)uman-readabíe. The defauít díspíay ís
human-readabíe. You can overríde the defauít by settíng the uníts parameter ín the
gíobaí sectíon of the ívm.conf fííe.
The foííowíng exampíe specífíes the output of the pvs command ín megabytes rather
than the defauít gígabytes.
# pvs --units m
PV VG Fmt Attr PSíze PFree
/dev/sda1 ívm2 -- 17555.40M 17555.40M
/dev/sdb1 new¸vg ívm2 a- 17552.00M 17552.00M
/dev/sdc1 new¸vg ívm2 a- 17552.00M 17500.00M
/dev/sdd1 new¸vg ívm2 a- 17552.00M 17552.00M
By defauít, uníts are díspíayed ín powers of 2 (muítípíes of 1024). You can specífy
that uníts be díspíayed ín muítípíes of 1000 by capítaíízíng the unít specífícatíon (B,
K, M, G, T, H).
The foííowíng command díspíays the output as a muítípíe of 1024, the defauít
behavíor.
# pvs
Chapter 4. LVM Administration...
64
PV VG Fmt Attr PSíze PFree
/dev/sdb1 new¸vg ívm2 a- 17.14G 17.14G
/dev/sdc1 new¸vg ívm2 a- 17.14G 17.09G
/dev/sdd1 new¸vg ívm2 a- 17.14G 17.14G
The foííowíng command díspíays the output as a muítípíe of 1000.
# pvs --units G
PV VG Fmt Attr PSíze PFree
/dev/sdb1 new¸vg ívm2 a- 18.40G 18.40G
/dev/sdc1 new¸vg ívm2 a- 18.40G 18.35G
/dev/sdd1 new¸vg ívm2 a- 18.40G 18.40G
You can aíso specífy (s)ectors (defíned as 512 bytes) or custom uníts.
The foííowíng exampíe díspíays the output of the pvs command as a number of
sectors.
# pvs --units s
PV VG Fmt Attr PSíze PFree
/dev/sdb1 new¸vg ívm2 a- 35946496S 35946496S
/dev/sdc1 new¸vg ívm2 a- 35946496S 35840000S
/dev/sdd1 new¸vg ívm2 a- 35946496S 35946496S
The foííowíng exampíe díspíays the output of the pvs command ín uníts of 4
megabytes.
# pvs --units 4m
PV VG Fmt Attr PSíze PFree
/dev/sdb1 new¸vg ívm2 a- 4388.00U 4388.00U
/dev/sdc1 new¸vg ívm2 a- 4388.00U 4375.00U
/dev/sdd1 new¸vg ívm2 a- 4388.00U 4388.00U
Specifying Units
65
66
LVM Configuration Examples
Thís chapter provídes some basíc LVM confíguratíon exampíes.
1. Creating an LVM Logical Volume on Three
Disks
Thís exampíe creates an LVM íogícaí voíume caííed new¸íogícaí¸voíume that consísts
of the dísks at /dev/sda1, /dev/sdb1, and /dev/sdc1.
1.1. Creating the Physical Volumes
To use dísks ín a voíume group, you íabeí them as LVM physícaí voíumes.
Caution
Thís command destroys any data on /dev/sda1, /dev/sdb1, and /dev/sdc1.
lroot@tng3-1 -|# pvcreate ldevlsda1 ldevlsdb1 ldevlsdc1
Physícaí voíume "/dev/sda1" successfuííy created
Physícaí voíume "/dev/sdb1" successfuííy created
Physícaí voíume "/dev/sdc1" successfuííy created
1.2. Creating the Volume Group
The foííowíng command creates the voíume group new¸voí¸group.
lroot@tng3-1 -|# vgcreate new¸vol¸group ldevlsda1 ldevlsdb1 ldevlsdc1
Voíume group "new¸voí¸group" successfuííy created
You can use the vgs command to díspíay the attríbutes of the new voíume group.
lroot@tng3-1 -|# vgs
VG #PV #LV #SN Attr VSíze VFree
new¸voí¸group 3 0 0 wz--n- 51.45G 51.45G
Chapter 5.
67
1.3. Creating the Logical Volume
The foííowíng command creates the íogícaí voíume new¸íogícaí¸voíume from the
voíume group new¸voí¸group. Thís exampíe creates a íogícaí voíume that uses 2GB of
the voíume group.
lroot@tng3-1 -|# lvcreate -L2G -n new¸logical¸volume new¸vol¸group
Logícaí voíume "new¸íogícaí¸voíume" created
1.4. Creating the File System
The foííowíng command creates a GFS fííe system on the íogícaí voíume.
lroot@tng3-1 -|# gfs¸mkfs -plock¸nolock -i 1
ldevlnew¸vol¸grouplnew¸logical¸volume
Thís wííí destroy any data on /dev/new¸voí¸group/new¸íogícaí¸voíume.
Are you sure you want to proceed? ly/n| y
Devíce: /dev/new¸voí¸group/new¸íogícaí¸voíume
Bíocksíze: 4096
Fííesystem Síze: 491460
Iournaís: 1
Resource Groups: 8
Lockíng Protocoí: íock¸noíock
Lock Tabíe:
Syncíng...
Aíí Done
The foííowíng commands mount the íogícaí voíume and report the fííe system dísk
space usage.
lroot@tng3-1 -|# mount ldevlnew¸vol¸grouplnew¸logical¸volume lmnt
lroot@tng3-1 -|# df
Fííesystem 1K-bíocks Used Avaííabíe Use% Mounted on
/dev/new¸voí¸group/new¸íogícaí¸voíume
Chapter 5. LVM Configuration ...
68
1965840 20 1965820 1% /mnt
2. Creating a Striped Logical Volume
Thís exampíe creates an LVM stríped íogícaí voíume caííed stríped¸íogícaí¸voíume that
strípes data across the dísks at /dev/sda1, /dev/sdb1, and /dev/sdc1.
2.1. Creating the Physical Volumes
Labeí the dísks you wííí use ín the voíume groups as LVM physícaí voíumes.
Caution
Thís command destroys any data on /dev/sda1, /dev/sdb1, and /dev/sdc1.
lroot@tng3-1 -|# pvcreate ldevlsda1 ldevlsdb1 ldevlsdc1
Physícaí voíume "/dev/sda1" successfuííy created
Physícaí voíume "/dev/sdb1" successfuííy created
Physícaí voíume "/dev/sdc1" successfuííy created
2.2. Creating the Volume Group
The foííowíng command creates the voíume group stríped¸voí¸group.
lroot@tng3-1 -|# vgcreate striped¸vol¸group ldevlsda1 ldevlsdb1 ldevlsdc1
Voíume group "stríped¸voí¸group" successfuííy created
You can use the vgs command to díspíay the attríbutes of the new voíume group.
lroot@tng3-1 -|# vgs
VG #PV #LV #SN Attr VSíze VFree
stríped¸voí¸group 3 0 0 wz--n- 51.45G 51.45G
2.3. Creating the Logical Volume
Creating a Striped Logical Volume
69
The foííowíng command creates the stríped íogícaí voíume stríped¸íogícaí¸voíume
from the voíume group stríped¸voí¸group. Thís exampíe creates a íogícaí voíume that
ís 2 gígabytes ín síze, wíth three strípes and a strípe síze of 4 kííobytes.
lroot@tng3-1 -|# lvcreate -i3 -l4 -L2G -nstriped¸logical¸volume striped¸vol¸group
Roundíng síze (512 extents) up to strípe boundary síze (513 extents)
Logícaí voíume "stríped¸íogícaí¸voíume" created
2.4. Creating the File System
The foííowíng command creates a GFS fííe system on the íogícaí voíume.
lroot@tng3-1 -|# gfs¸mkfs -plock¸nolock -i 1
ldevlstriped¸vol¸grouplstriped¸logical¸volume
Thís wííí destroy any data on /dev/stríped¸voí¸group/stríped¸íogícaí¸voíume.
Are you sure you want to proceed? ly/n| y
Devíce: /dev/stríped¸voí¸group/stríped¸íogícaí¸voíume
Bíocksíze: 4096
Fííesystem Síze: 492484
Iournaís: 1
Resource Groups: 8
Lockíng Protocoí: íock¸noíock
Lock Tabíe:
Syncíng...
Aíí Done
The foííowíng commands mount the íogícaí voíume and report the fííe system dísk
space usage.
lroot@tng3-1 -|# mount ldevlstriped¸vol¸grouplstriped¸logical¸volume lmnt
lroot@tng3-1 -|# df
Fííesystem 1K-bíocks Used Avaííabíe Use% Mounted on
/dev/mapper/VoíGroup00-LogVoí00
13902624 1656776 11528232 13% /
/dev/hda1 101086 10787 85080 12% /boot
tmpfs 127880 0 127880 0% /dev/shm
Chapter 5. LVM Configuration ...
70
/dev/stríped¸voí¸group/stríped¸íogícaí¸voíume
1969936 20 1969916 1% /mnt
3. Splitting a Volume Group
In thís exampíe, an exístíng voíume group consísts of three physícaí voíumes. If
there ís enough unused space on the physícaí voíumes, a new voíume group can be
created wíthout addíng new dísks.
In the ínítíaí set up, the íogícaí voíume myív ís carved from the voíume group myvoí,
whích ín turn consísts of the three physícaí voíumes, /dev/sda1, /dev/sdb1, and
/dev/sdc1.
After compíetíng thís procedure, the voíume group myvg wííí consíst of /dev/sda1 and
/dev/sdb1. A second voíume group, yourvg, wííí consíst of /dev/sdc1.
3.1. Determining Free Space
You can use the pvscan command to determíne how much free space ís currentíy
avaííabíe ín the voíume group.
lroot@tng3-1 -|# pvscan
PV /dev/sda1 VG myvg ívm2 l17.15 GB / 0 free|
PV /dev/sdb1 VG myvg ívm2 l17.15 GB / 12.15 GB free|
PV /dev/sdc1 VG myvg ívm2 l17.15 GB / 15.80 GB free|
Totaí: 3 l51.45 GB| / ín use: 3 l51.45 GB| / ín no VG: 0 l0 |
3.2. Moving the Data
You can move aíí the used physícaí extents ín /dev/sdc1 to /dev/sdb1 wíth the pvmove
command. The pvmove command can take a íong tíme to execute.
lroot@tng3-1 -|# pvmove ldevlsdc1 ldevlsdb1
/dev/sdc1: Moved: 14.7%
/dev/sdc1: Moved: 30.3%
/dev/sdc1: Moved: 45.7%
/dev/sdc1: Moved: 61.0%
/dev/sdc1: Moved: 76.6%
/dev/sdc1: Moved: 92.2%
/dev/sdc1: Moved: 100.0%
Splitting a Volume Group
71
After movíng the data, you can see that aíí of the space on /dev/sdc1 ís free.
lroot@tng3-1 -|# pvscan
PV /dev/sda1 VG myvg ívm2 l17.15 GB / 0 free|
PV /dev/sdb1 VG myvg ívm2 l17.15 GB / 10.80 GB free|
PV /dev/sdc1 VG myvg ívm2 l17.15 GB / 17.15 GB free|
Totaí: 3 l51.45 GB| / ín use: 3 l51.45 GB| / ín no VG: 0 l0 |
3.3. Splitting the Volume Group
To create the new voíume group yourvg, use the vgspíít command to spíít the voíume
group myvg.
Before you can spíít the voíume group, the íogícaí voíume must be ínactíve. If the
fííe system ís mounted, you must unmount the fííe system before deactívatíng the
íogícaí voíume.
You can deactívate the íogícaí voíumes wíth the ívchange command or the vgchange
command. The foííowíng command deactívates the íogícaí voíume myív and then
spííts the voíume group yourvg from the voíume group myvg, movíng the physícaí
voíume /dev/sdc1 ínto the new voíume group yourvg.
lroot@tng3-1 -|# lvchange -a n ldevlmyvglmylv
lroot@tng3-1 -|# vgsplit myvg yourvg ldevlsdc1
Voíume group "yourvg" successfuííy spíít from "myvg"
You can use the vgs command to see the attríbutes of the two voíume groups.
lroot@tng3-1 -|# vgs
VG #PV #LV #SN Attr VSíze VFree
myvg 2 1 0 wz--n- 34.30G 10.80G
yourvg 1 0 0 wz--n- 17.15G 17.15G
3.4. Creating the New Logical Volume
After creatíng the new voíume group, you can create the new íogícaí voíume yourív.
Chapter 5. LVM Configuration ...
72
lroot@tng3-1 -|# lvcreate -L5G -n yourlv yourvg
Logícaí voíume "yourív" created
3.5. Making a File System and Mounting the New
Logical Volume
You can make a fííe system on the new íogícaí voíume and mount ít.
lroot@tng3-1 -|# gfs¸mkfs -plock¸nolock -i 1 ldevlyourvglyourlv
Thís wííí destroy any data on /dev/yourvg/yourív.
Are you sure you want to proceed? ly/n| y
Devíce: /dev/yourvg/yourív
Bíocksíze: 4096
Fííesystem Síze: 1277816
Iournaís: 1
Resource Groups: 20
Lockíng Protocoí: íock¸noíock
Lock Tabíe:
Syncíng...
Aíí Done
lroot@tng3-1 -|# mount ldevlyourvglyourlv lmnt
3.6. Activating and Mounting the Original Logical
Volume
Sínce you had to deactívate the íogícaí voíume myív, you need to actívate ít agaín
before you can mount ít.
root@tng3-1 -|# lvchange -a y mylv
lroot@tng3-1 -|# mount ldevlmyvglmylv lmnt
lroot@tng3-1 -|# df
Fííesystem 1K-bíocks Used Avaííabíe Use% Mounted on
/dev/yourvg/yourív 24507776 32 24507744 1% /mnt
Making a File System and Mounting
73
/dev/myvg/myív 24507776 32 24507744 1% /mnt
4. Removing a Disk from a Logical Volume
Thís exampíe shows how you can remove a dísk from an exístíng íogícaí voíume,
eíther to repíace the dísk or to use the dísk as part of a dífferent voíume. In order to
remove a dísk, you must fírst move the extents on the LVM physícaí voíume to a
dífferent dísk or set of dísks.
4.1. Moving Extents to Existing Physical Volumes
In thís exampíe, the íogícaí voíume ís dístríbuted across four physícaí voíumes ín the
voíume group myvg.
lroot@tng3-1|# pvs -o+pv¸used
PV VG Fmt Attr PSíze PFree Used
/dev/sda1 myvg ívm2 a- 17.15G 12.15G 5.00G
/dev/sdb1 myvg ívm2 a- 17.15G 12.15G 5.00G
/dev/sdc1 myvg ívm2 a- 17.15G 12.15G 5.00G
/dev/sdd1 myvg ívm2 a- 17.15G 2.15G 15.00G
We want to move the extents off of /dev/sdb1 so that we can remove ít from the
voíume group.
If there are enough free extents on the other physícaí voíumes ín the voíume group,
you can execute the pvmove command on the devíce you want to remove wíth no
other optíons and the extents wííí be dístríbuted to the other devíces.
lroot@tng3-1 -|# pvmove ldevlsdb1
/dev/sdb1: Moved: 2.0%
...
/dev/sdb1: Moved: 79.2%
...
/dev/sdb1: Moved: 100.0%
After the pvmove command has fíníshed executíng, the dístríbutíon of extents ís as
foííows:
Chapter 5. LVM Configuration ...
74
lroot@tng3-1|# pvs -o+pv¸used
PV VG Fmt Attr PSíze PFree Used
/dev/sda1 myvg ívm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg ívm2 a- 17.15G 17.15G 0
/dev/sdc1 myvg ívm2 a- 17.15G 12.15G 5.00G
/dev/sdd1 myvg ívm2 a- 17.15G 2.15G 15.00G
Use the vgreduce command to remove the physícaí voíume /dev/sdb1 from the
voíume group.
lroot@tng3-1 -|# vgreduce myvg ldevlsdb1
Removed "/dev/sdb1" from voíume group "myvg"
lroot@tng3-1 -|# pvs
PV VG Fmt Attr PSíze PFree
/dev/sda1 myvg ívm2 a- 17.15G 7.15G
/dev/sdb1 ívm2 -- 17.15G 17.15G
/dev/sdc1 myvg ívm2 a- 17.15G 12.15G
/dev/sdd1 myvg ívm2 a- 17.15G 2.15G
The dísk can now be physícaííy removed or aííocated to other users.
4.2. Moving Extents to a New Disk
In thís exampíe, the íogícaí voíume ís dístríbuted across three physícaí voíumes ín
the voíume group myvg as foííows:
lroot@tng3-1|# pvs -o+pv¸used
PV VG Fmt Attr PSíze PFree Used
/dev/sda1 myvg ívm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg ívm2 a- 17.15G 15.15G 2.00G
/dev/sdc1 myvg ívm2 a- 17.15G 15.15G 2.00G
We want to move the extents of /dev/sdb1 to a new devíce, /dev/sdd1.
4.2.1. Creating the New Physical Volume
Create a new physícaí voíume from /dev/sdd1.
the New Logical Volume
75
lroot@tng3-1 -|# pvcreate ldevlsdd1
Physícaí voíume "/dev/sdd1" successfuííy created
4.2.2. Adding the New Physical Volume to the Volume
Group
Add /dev/sdd1 to the exístíng voíume group myvg.
lroot@tng3-1 -|# vgextend myvg ldevlsdd1
Voíume group "myvg" successfuííy extended
lroot@tng3-1|# pvs -o+pv¸used
PV VG Fmt Attr PSíze PFree Used
/dev/sda1 myvg ívm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg ívm2 a- 17.15G 15.15G 2.00G
/dev/sdc1 myvg ívm2 a- 17.15G 15.15G 2.00G
/dev/sdd1 myvg ívm2 a- 17.15G 17.15G 0
4.2.3. Moving the Data
Use the pvmove command to move the data from /dev/sdb1 to /dev/sdd1.
lroot@tng3-1 -|# pvmove ldevlsdb1 ldevlsdd1
/dev/sdb1: Moved: 10.0%
...
/dev/sdb1: Moved: 79.7%
...
/dev/sdb1: Moved: 100.0%
lroot@tng3-1|# pvs -o+pv¸used
PV VG Fmt Attr PSíze PFree Used
/dev/sda1 myvg ívm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg ívm2 a- 17.15G 17.15G 0
/dev/sdc1 myvg ívm2 a- 17.15G 15.15G 2.00G
/dev/sdd1 myvg ívm2 a- 17.15G 15.15G 2.00G
4.2.4. Removing the Old Physical Volume from the
Volume Group
Chapter 5. LVM Configuration ...
76
After you have moved the data off /dev/sdb1, you can remove ít from the voíume
group.
lroot@tng3-1 -|# vgreduce myvg ldevlsdb1
Removed "/dev/sdb1" from voíume group "myvg"
You can now reaííocate the dísk to another voíume group or remove the dísk from
the system.
Moving Extents to a New Disk
77
78
LVM Troubleshooting
Thís chapter províde ínstructíons for troubíeshootíng a varíety of LVM íssues.
1. Troubleshooting Diagnostics
If a command ís not workíng as expected, you can gather díagnostícs ín the
foííowíng ways:
º Use the -v, -vv, -vvv, or -vvvv argument of any command for íncreasíngíy verbose
íeveís of output.
º If the probíem ís reíated to the íogícaí voíume actívatíon, set 'actívatíon = 1' ín the
'íog' sectíon of the confíguratíon fííe and run the command wíth the -vvvv
argument. After you have fíníshed examíníng thís output be sure to reset thís
parameter to 0, to avoíd possíbíe probíems wíth the machíne íockíng duríng íow
memory sítuatíons.
º Run the ívmdump command, whích provídes and ínformatíon dump for díagnostíc
purposes. For ínformatíon, see the ívmdump(8) man page.
º Execute the ívs -v, pvs -a or dmsetup ínfo -c command for addítíonaí system
ínformatíon.
º Examíne the íast backup of the metadata ín the /etc/ívm/backup fííe and archíved
versíons ín the /etc/ívm/archíve fííe.
º Check the current confíguratíon ínformatíon by runníng the ívm dumpconfíg
command.
º Check the .cache fííe ín the /etc/ívm dírectory for a record of whích devíces have
physícaí voíumes on them.
2. Displaying lnformation on Failed Devices
You can use the -P argument of the ívs or vgs command to díspíay ínformatíon about
a faííed voíume that wouíd otherwíse not appear ín the output. Thís argument
permíts some operatíons even though the metatdata ís not compíeteíy consístent
ínternaííy. For exampíe, íf one of the devíces that made up the voíume group vg
faííed, the vgs command míght show the foííowíng output.
Chapter 6.
79
lroot@íínk-07 tmp|# vgs -o +devices
Voíume group "vg" not found
If you specífy the -P argument of the vgs command, the voíume group ís stííí
unusabíe but you can see more ínformatíon about the faííed devíce.
lroot@íínk-07 tmp|# vgs -P -o +devices
Partíaí mode. Incompíete voíume groups wííí be actívated read-oníy.
VG #PV #LV #SN Attr VSíze VFree Devíces
vg 9 2 0 rz-pn- 2.11T 2.07T unknown devíce(0)
vg 9 2 0 rz-pn- 2.11T 2.07T unknown devíce(5120),/dev/sda1(0)
In thís exampíe, the faííed devíce caused both a íínear and a stríped íogícaí voíume
ín the voíume group to faíí. The ívs command wíthout the -P argument shows the
foííowíng output.
lroot@íínk-07 tmp|# lvs -a -o +devices
Voíume group "vg" not found
Usíng the -P argument shows the íogícaí voíumes that have faííed.
lroot@íínk-07 tmp|# lvs -P -a -o +devices
Partíaí mode. Incompíete voíume groups wííí be actívated read-oníy.
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
íínear vg -wí-a- 20.00G unknown devíce(0)
strípe vg -wí-a- 20.00G unknown devíce(5120),/dev/sda1(0)
The foííowíng exampíes show the output of the pvs and ívs commands wíth the -P
argument specífíed when a íeg of a mírrored íogícaí voíume has faííed.
root@íínk-08 -|# vgs -a -o +devices -P
Partíaí mode. Incompíete voíume groups wííí be actívated read-oníy.
VG #PV #LV #SN Attr VSíze VFree Devíces
corey 4 4 0 rz-pnc 1.58T 1.34T my¸mírror¸mímage¸0(0),my¸mírror¸mímage¸1(0)
corey 4 4 0 rz-pnc 1.58T 1.34T /dev/sdd1(0)
Chapter 6. LVM Troubleshooting
80
corey 4 4 0 rz-pnc 1.58T 1.34T unknown devíce(0)
corey 4 4 0 rz-pnc 1.58T 1.34T /dev/sdb1(0)
lroot@íínk-08 -|# lvs -a -o +devices -P
Partíaí mode. Incompíete voíume groups wííí be actívated read-oníy.
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
my¸mírror corey mwí-a- 120.00G my¸mírror¸míog 1.95
my¸mírror¸mímage¸0(0),my¸mírror¸mímage¸1(0)
lmy¸mírror¸mímage¸0| corey íwí-ao 120.00G unknown
devíce(0)
lmy¸mírror¸mímage¸1| corey íwí-ao 120.00G /dev/sdb1(0)
lmy¸mírror¸míog| corey íwí-ao 4.00M /dev/sdd1(0)
3. Recovering from LVM Mirror Failure
Thís sectíon provídes an exampíe of recoveríng from a sítuatíon where one íeg of an
LVM mírrored voíume faíís because the underíyíng devíce for a physícaí voíume
goes down. When a mírror íeg faíís, LVM converts the mírrored voíume ínto a íínear
voíume, whích contínues to operate as before but wíthout the mírrored redundancy.
At that poínt, you can add a new dísk devíce to the system to use as a repíacement
physícaí devíce and rebuííd the mírror.
The foííowíng command creates the physícaí voíumes whích wííí be used for the
mírror.
lroot@íínk-08 -|# pvcreate ldevlsdlabcdefgh|l12|
Physícaí voíume "/dev/sda1" successfuííy created
Physícaí voíume "/dev/sda2" successfuííy created
Physícaí voíume "/dev/sdb1" successfuííy created
Physícaí voíume "/dev/sdb2" successfuííy created
Physícaí voíume "/dev/sdc1" successfuííy created
Physícaí voíume "/dev/sdc2" successfuííy created
Physícaí voíume "/dev/sdd1" successfuííy created
Physícaí voíume "/dev/sdd2" successfuííy created
Physícaí voíume "/dev/sde1" successfuííy created
Physícaí voíume "/dev/sde2" successfuííy created
Physícaí voíume "/dev/sdf1" successfuííy created
Physícaí voíume "/dev/sdf2" successfuííy created
Physícaí voíume "/dev/sdg1" successfuííy created
Physícaí voíume "/dev/sdg2" successfuííy created
Recovering from LVM Mirror Failure
81
Physícaí voíume "/dev/sdh1" successfuííy created
Physícaí voíume "/dev/sdh2" successfuííy created
The foííowíng commands creates the voíume group vg and the mírrored voíume
groupfs.
lroot@íínk-08 -|# vgcreate vg ldevlsdlabcdefgh|l12|
Voíume group "vg" successfuííy created
lroot@íínk-08 -|# lvcreate -L 750M -n groupfs -m 1 vg ldevlsda1 ldevlsdb1
ldevlsdc1
Roundíng up síze to fuíí physícaí extent 752.00 MB
Logícaí voíume "groupfs" created
You can use the ívs command to verífy the íayout of the mírrored voíume and the
underíyíng devíces for the mírror íeg and the mírror íog. Note that ín the fírst
exampíe the mírror ís not yet compíeteíy synced; you shouíd waít untíí the Copy%
fíeíd díspíays 100.00 before contínuíng.
lroot@íínk-08 -|# lvs -a -o +devices
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
groupfs vg mwí-a- 752.00M groupfs¸míog 21.28
groupfs¸mímage¸0(0),groupfs¸mímage¸1(0)
lgroupfs¸mímage¸0| vg íwí-ao 752.00M /dev/sda1(0)
lgroupfs¸mímage¸1| vg íwí-ao 752.00M /dev/sdb1(0)
lgroupfs¸míog| vg íwí-ao 4.00M /dev/sdc1(0)
lroot@íínk-08 -|# lvs -a -o +devices
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
groupfs vg mwí-a- 752.00M groupfs¸míog 100.00
groupfs¸mímage¸0(0),groupfs¸mímage¸1(0)
lgroupfs¸mímage¸0| vg íwí-ao 752.00M /dev/sda1(0)
lgroupfs¸mímage¸1| vg íwí-ao 752.00M /dev/sdb1(0)
lgroupfs¸míog| vg íwí-ao 4.00M í /dev/sdc1(0)
In thís exampíe, the prímary íeg of the mírror /dev/sda1 faíís. Any wríte actívíty to the
mírrored voíume causes LVM to detect the faííed mírror. When thís occurs, LVM
converts the mírror ínto a síngíe íínear voíume. In thís case, to trígger the
conversíon, we execute a dd command
Chapter 6. LVM Troubleshooting
82
lroot@íínk-08 -|# dd if=ldevlzero of=ldevlvglgroupfs count=10
10+0 records ín
10+0 records out
You can use the ívs command to verífy that the devíce ís now a íínear devíce.
Because of the faííed dísk, I/O errors occur.
lroot@íínk-08 -|# lvs -a -o +devices
/dev/sda1: read faííed after 0 of 2048 at 0: Input/output error
/dev/sda2: read faííed after 0 of 2048 at 0: Input/output error
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
groupfs vg -wí-a- 752.00M /dev/sdb1(0)
At thís poínt you shouíd stííí be abíe to use the íogícaí voíume, but there wííí be no
mírror redundancy.
To rebuííd the mírrored voíume, you repíace the broken dríve and recreate the
physícaí voíume. If you use the same dísk rather than repíacíng ít wíth a new one,
you wííí see "ínconsístent" warníngs when you run the pvcreate command.
lroot@íínk-08 -|# pvcreate ldevlsdal12|
Physícaí voíume "/dev/sda1" successfuííy created
Physícaí voíume "/dev/sda2" successfuííy created
lroot@íínk-08 -|# pvscan
PV /dev/sdb1 VG vg ívm2 l67.83 GB / 67.10 GB free|
PV /dev/sdb2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdc1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdc2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdd1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdd2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sde1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sde2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdf1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdf2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdg1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdg2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdh1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdh2 VG vg ívm2 l67.83 GB / 67.83 GB free|
Recovering from LVM Mirror Failure
83
PV /dev/sda1 ívm2 l603.94 GB|
PV /dev/sda2 ívm2 l603.94 GB|
Totaí: 16 l2.11 TB| / ín use: 14 l949.65 GB| / ín no VG: 2 l1.18 TB|
Next you extend the orígínaí voíume group wíth the new physícaí voíume.
lroot@íínk-08 -|# vgextend vg ldevlsdal12|
Voíume group "vg" successfuííy extended
lroot@íínk-08 -|# pvscan
PV /dev/sdb1 VG vg ívm2 l67.83 GB / 67.10 GB free|
PV /dev/sdb2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdc1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdc2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdd1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdd2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sde1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sde2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdf1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdf2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdg1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdg2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdh1 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sdh2 VG vg ívm2 l67.83 GB / 67.83 GB free|
PV /dev/sda1 VG vg ívm2 l603.93 GB / 603.93 GB free|
PV /dev/sda2 VG vg ívm2 l603.93 GB / 603.93 GB free|
Totaí: 16 l2.11 TB| / ín use: 16 l2.11 TB| / ín no VG: 0 l0 |
Convert the íínear voíume back to íts orígínaí mírrored state.
lroot@íínk-08 -|# lvconvert -m 1 ldevlvglgroupfs ldevlsda1 ldevlsdb1 ldevlsdc1
Logícaí voíume mírror converted.
You can use the ívs command to verífy that the mírror ís restored.
lroot@íínk-08 -|# lvs -a -o +devices
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
groupfs vg mwí-a- 752.00M groupfs¸míog 68.62
groupfs¸mímage¸0(0),groupfs¸mímage¸1(0)
Chapter 6. LVM Troubleshooting
84
lgroupfs¸mímage¸0| vg íwí-ao 752.00M /dev/sdb1(0)
lgroupfs¸mímage¸1| vg íwí-ao 752.00M /dev/sda1(0)
lgroupfs¸míog| vg íwí-ao 4.00M /dev/sdc1(0)
4. Recovering Physical Volume Metadata
If the voíume group metadata area of a physícaí voíume ís accídentaííy overwrítten
or otherwíse destroyed, you wííí get an error message índícatíng that the metadata
area ís íncorrect, or that the system was unabíe to fínd a physícaí voíume wíth a
partícuíar UUID. You may be abíe to recover the data the physícaí voíume by wrítíng
a new metadata area on the physícaí voíume specífyíng the same UUID as the íost
metadata.
Caution
You shouíd not attempt thís procedure wíth a workíng LVM íogícaí
voíume. You wííí íose your data íf you specífy the íncorrect UUID.
The foííowíng exampíe shows the sort of output you may see íf the metadata area ís
míssíng or corrupted.
lroot@íínk-07 backup|# lvs -a -o +devices
Couídn't fínd devíce wíth uuíd 'FmGRh3-zhok-íVI8-7qTD-S5BI-MAEN-NYM5Sk'.
Couídn't fínd aíí physícaí voíumes for voíume group VG.
Couídn't fínd devíce wíth uuíd 'FmGRh3-zhok-íVI8-7qTD-S5BI-MAEN-NYM5Sk'.
Couídn't fínd aíí physícaí voíumes for voíume group VG.
...
You may be abíe to fínd the UUID for the physícaí voíume that was overwrítten by
íookíng ín the /etc/ívm/archíve dírectory. Look ín the fííe VoíumeGroupName¸xxxx.vg for
the íast known vaííd archíved LVM metadata for that voíume group.
Aíternateíy, you may fínd that deactívatíng the voíume and settíng the partíaí (-P)
argument wííí enabíe you to fínd the UUID of the míssíng corrupted physícaí voíume.
lroot@íínk-07 backup|# vgchange -an --partial
Partíaí mode. Incompíete voíume groups wííí be actívated read-oníy.
Couídn't fínd devíce wíth uuíd 'FmGRh3-zhok-íVI8-7qTD-S5BI-MAEN-NYM5Sk'.
Recovering Physical Volume
85
Couídn't fínd devíce wíth uuíd 'FmGRh3-zhok-íVI8-7qTD-S5BI-MAEN-NYM5Sk'.
...
Use the --uuíd and --restorefííe arguments of the pvcreate command to restore the
physícaí voíume. The foííowíng exampíe íabeís the /dev/sdh1 devíce as a physícaí
voíume wíth the UUID índícated above, FmGRh3-zhok-íVI8-7qTD-S5BI-MAEN-NYM5Sk.
Thís command restores the physícaí voíume íabeí wíth the metadata ínformatíon
contaíned ín VG¸00050.vg, the most recent good archíved metatdata for voíume
group . The restorefííe argument ínstructs the pvcreate command to make the new
physícaí voíume compatíbíe wíth the oíd one on the voíume group, ensuríng that the
the new metadata wííí not be píaced where the oíd physícaí voíume contaíned data
(whích couíd happen, for exampíe, íf the orígínaí pvcreate command had used the
command ííne arguments that controí metadata píacement, or ít the physícaí
voíume was orígínaííy created usíng a dífferent versíon of the software that used
dífferent defauíts). The pvcreate command overwrítes oníy the LVM metadata areas
and does not affect the exístíng data areas.
lroot@íínk-07 backup|# pvcreate --uuid
"FmGRh3-zhok-iVl8-7qTD-S5Bl-MAEN-NYM5Sk" --restorefile
letcllvmlarchivelVG¸00050.vg ldevlsdh1
Physícaí voíume "/dev/sdh1" successfuííy created
You can then use the vgcfgrestore command to restore the voíume group's
metadata.
lroot@íínk-07 backup|# vgcfgrestore VG
Restored voíume group VG
You can now díspíay the íogícaí voíumes.
lroot@íínk-07 backup|# lvs -a -o +devices
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
strípe VG -wí--- 300.00G /dev/sdh1 (0),/dev/sda1(0)
strípe VG -wí--- 300.00G /dev/sdh1 (34728),/dev/sdb1(0)
The foííowíng commands actívate the voíumes and díspíay the actíve voíumes.
Chapter 6. LVM Troubleshooting
86
lroot@íínk-07 backup|# lvchange -ay ldevlVGlstripe
lroot@íínk-07 backup|# lvs -a -o +devices
LV VG Attr LSíze Orígín Snap% Move Log Copy% Devíces
strípe VG -wí-a- 300.00G /dev/sdh1 (0),/dev/sda1(0)
strípe VG -wí-a- 300.00G /dev/sdh1 (34728),/dev/sdb1(0)
If the on-dísk LVM metadata takes as íeast as much space as what overrode ít, thís
command can recover the physícaí voíume. If what overrode the metadata went
past the metadata area, the data on the voíume may have been affected. You míght
be abíe to use the fsck command to recover that data.
5. Replacing a Missing Physical Volume
If a physícaí voíume faíís or otherwíse needs to be repíaced, you can íabeí a new
physícaí voíume to repíace the one that has been íost ín the exístíng voíume group
by foííowíng the same procedure as you wouíd for recoveríng physícaí voíume
metadata, descríbed ín Sectíon 4, "Recoveríng Physícaí Voíume Metadata". You can
use the --partíaí and --verbose arguments of the vgdíspíay command to díspíay the
UUIDs and sízes of any physícaí voíumes that are no íonger present. If you wísh to
substítute another physícaí voíume of the same síze, you can use the pvcreate
command wíth the --restorefííe and --uuíd arguments to ínítíaííze a new devíce wíth
the same UUID as the míssíng physícaí voíume. You can then use the vgcfgrestore
command to restore the voíume group's metadata.
6. Removing Lost Physical Volumes from a
Volume Group
If you íose a physícaí voíume, you can actívate the remaíníng physícaí voíumes ín
the voíume group wíth the --partíaí argument of the vgchange command. You can
remove aíí the íogícaí voíumes that used that physícaí voíume from the voíume
group wíth the --removemíssíng argument of the vgreduce command.
It ís recommended that you run the vgreduce command wíth the --test argument to
verífy what you wííí be destroyíng.
Líke most LVM operatíons, the vgreduce command ís reversíbíe ín a sense íf you
ímmedíateíy use the vgcfgrestore command to restore the voíume group metadata to
íts prevíous state. For exampíe, íf you used the --removemíssíng argument of the
vgreduce command wíthout the --test argument and fínd you have removed íogícaí
Metadata
87
voíumes you wanted to keep, you can stííí repíace the physícaí voíume and use
another vgcfgrestore command to return the voíume group to íts prevíous state.
7. lnsufficient Free Extents for a Logical
Volume
You may get the error message "Insuffícíent free extents" when creatíng a íogícaí
voíume when you thínk you have enough extents based on the output of the
vgdíspíay or vgs commands. Thís ís because these commands round fígures to 2
decímaí píaces to províde human-readabíe output. To specífy exact síze, use free
physícaí extent count ínstead of some muítípíe of bytes to determíne the síze of the
íogícaí voíume.
The vgdíspíay command, by defauít, íncíudes thís ííne of output that índícates the
free physícaí extents.
# vgdisplay
--- Voíume group ---
...
Free PE / Síze 8780 / 34.30 GB
Aíternateíy, you can use the vg¸free¸count and vg¸extent¸count arguments of the vgs
command to díspíay the free extents and the totaí number of extents.
lroot@tng3-1 -|# vgs -o +vg¸free¸count,vg¸extent¸count
VG #PV #LV #SN Attr VSíze VFree Free #Ext
testvg 2 0 0 wz--n- 34.30G 34.30G 8780 8780
Wíth 8780 free physícaí extents, you can run the foííowíng command, usíng the
íower-case í argument to use extents ínstead of bytes:
# lvcreate -l8780 -n testlv testvg
Thís uses aíí the free extents ín the voíume group.
# vgs -o +vg¸free¸count,vg¸extent¸count
VG #PV #LV #SN Attr VSíze VFree Free #Ext
Chapter 6. LVM Troubleshooting
88
testvg 2 1 0 wz--n- 34.30G 0 0 8780
Aíternateíy, you can extend the íogícaí voíume to use a percentage of the remaíníng
free space ín the voíume group by usíng the -í argument of the ívcreate command.
For ínformatíon, see Sectíon 4.1.1, "Creatíng Línear Voíumes".
lnsufficient Free Extents for a Logical
89
90
LVM Administration with the
LVM GUl
In addítíon to the Command Líne Interface (CLI), LVM provídes a Graphícaí User
Interface (GUI) whích you can use to confígure LVM íogícaí voíumes. You can bríng
up thís utíííty by typíng system-confíg-ívm. The LVM chapter of the Red Hat Enterpríse
Línux Depíoyment Guíde provídes step-by-step ínstructíons for confíguríng an LVM
íogícaí voíume usíng thís utíííty.
In addítíon, the LVM GUI ís avaííaíbe as part of the Conga management ínterface.
For ínformatíon on usíng the LVM GUI wíth Conga, see the onííne heíp for Conga.
Chapter 7.
91
92
Appendix A. The Device
Mapper
The Devíce Mapper ís a kerneí dríver that provídes a generíc framework for voíume
management. It provídes a generíc way of creatíng mapped devíces, whích may be
used as íogícaí voíumes. It does not specífícaííy know about voíume groups or
metadata formats.
The Devíce Mapper provídes the foundatíon for a number of hígher-íeveí
technoíogíes. In addítíon to LVM, devíce-mapper muítípath and the dmraíd command
use the Devíce Mapper.
The user ínterface to the Devíce Mapper ís the íoctí system caíí.
LVM íogícaí voíumes are actívated usíng the Devíce Mapper. Each íogícaí voíume ís
transíated ínto a mapped devíce, Each segment transíates ínto a ííne ín the mappíng
tabíe that descríbes the devíce. The Devíce Mapper provídes íínear mappíng, stríped
mappíng, and error mappíng, amongst others. Two dísks can be concatenated ínto
one íogícaí voíume wíth a paír of íínear mappíngs, one for each dísk.
The dmsetup command ís a command ííne wrapper for communícatíon wíth the
Devíce Mapper. It provídes compíete access to the íoctí commands through the
ííbdevmapper command. For generaí system ínformatíon about LVM devíces, you
may fínd the dmsetup ínfo command to be usefuí.
For ínformatíon about the optíons and capabííítíes of the dmsetup command, see the
dmsetup(8) man page.
93
94
Appendix B. The LVM
Configuration Files
LVM supports muítípíe confíguratíon fííes. At system startup, the ívm.conf
confíguratíon fííe ís íoaded from the dírectory specífíed by the envíronment varíabíe
LVM¸SYSTEM¸DIR, whích ís set to /etc/ívm by defauít.
The ívm.conf fííe can specífy addítíonaí confíguratíon fííes to íoad. Settíngs ín íater
fííes overríde settíngs from earííer ones. To díspíay the settíngs ín use after íoadíng
aíí the confíguratíon fííes, execute the ívm dumpconfíg command.
For ínformatíon on íoadíng addítíonaí confíguratíon fííes, see Sectíon 2, "Host Tags".
1. The LVM Configuration Files
The foííowíng fííes are used for LVM confíguratíon:
/etc/ívm/ívm.conf
Centraí confíguratíon fííe read by the tooís.
etc/ívm/ívm¸hosttag.conf
For each host tag, an extra confíguratíon fííe ís read íf ít exísts: ívm¸hosttag.conf.
If that fííe defínes new tags, then further confíguratíon fííes wííí be appended to
the ííst of tííes to read ín. For ínformatíon on host tags, see Sectíon 2, "Host
Tags".
In addítíon to the LVM confíguratíon fííes, a system runníng LVM íncíudes the
foííowíng fííes that affect LVM system setup:
/etc/ívm/.cache
Devíce name fííter cache fííe (confígurabíe).
/etc/ívm/backup/
Dírectory for automatíc voíume group metadata backups (confígurabíe).
/etc/ívm/archíve/
Dírectory for automatíc voíume group metadata archíves (confígurabíe wíth
regard to dírectory path and archíve hístory depth).
95
/var/íock/ívm/
In síngíe-host confíguratíon, íock fííes to prevent paraííeí tooí runs from
corruptíng the metadata; ín a cíuster, cíuster-wíde DLM ís used.
2. Sample lvm.conf File
The foííowíng ís a sampíe ívm.conf confíguratíon fííe.
lroot@tng3-1 ívm|# cat ívm.conf
# Thís ís an exampíe confíguratíon fííe for the LVM2 system.
# It contaíns the defauít settíngs that wouíd be used íf there was no
# /etc/ívm/ívm.conf fííe.
#
# Refer to 'man ívm.conf' for further ínformatíon íncíudíng the fííe íayout.
#
# To put thís fííe ín a dífferent dírectory and overríde /etc/ívm set
# the envíronment varíabíe LVM¸SYSTEM¸DIR before runníng the tooís.
# Thís sectíon aííows you to confígure whích bíock devíces shouíd
# be used by the LVM system.
devíces {
# Where do you want your voíume groups to appear ?
dír = "/dev"
# An array of dírectoríes that contaín the devíce nodes you wísh
# to use wíth LVM2.
scan = l "/dev" |
# A fííter that teíís LVM2 to oníy use a restrícted set of devíces.
# The fííter consísts of an array of reguíar expressíons. These
# expressíons can be deíímíted by a character of your choíce, and
# prefíxed wíth eíther an 'a' (for accept) or 'r' (for reíect).
# The fírst expressíon found to match a devíce name determínes íf
# the devíce wííí be accepted or reíected (ígnored). Devíces that
# don't match any patterns are accepted.
# Be carefuí íf there there are symboííc íínks or muítípíe fííesystem
# entríes for the same devíce as each name ís checked separateíy agaínst
# the ííst of patterns. The effect ís that íf any name matches any 'a'
# pattern, the devíce ís accepted; otherwíse íf any name matches any 'r'
# pattern ít ís reíected; otherwíse ít ís accepted.
Appendix B. The LVM Configura...
96
# Don't have more than one fííter ííne actíve at once: oníy one gets used.
# Run vgscan after you change thís parameter to ensure that
# the cache fííe gets regenerated (see beíow).
# If ít doesn't do what you expect, check the output of 'vgscan -vvvv'.
# By defauít we accept every bíock devíce:
# Steeí Toe ínstaííed fííter -- use thís ííne whííe runníng tests
fííter = l "r/hda/", "r/dísk/", "a/.*/" |
# Steeí Toe ínstaííed fííter -- use thís ííne when ínstaíííng new kerneís
#fííter = l "r/dísk/", "a/.*/" |
# Excíude the cdrom dríve
# fííter = l "r|/dev/cdrom|" |
# When testíng I ííke to work wíth íust íoopback devíces:
# fííter = l "a/íoop/", "r/.*/" |
# Or maybe aíí íoops and íde dríves except hdc:
# fííter =l "a|íoop|", "r|/dev/hdc|", "a|/dev/íde|", "r|.*|" |
# Use anchors íf you want to be reaííy specífíc
# fííter = l "a|´/dev/hda8$|", "r/.*/" |
# The resuíts of the fííteríng are cached on dísk to avoíd
# rescanníng dud devíces (whích can take a very íong tíme). By
# defauít thís cache fííe ís hídden ín the /etc/ívm dírectory.
# It ís safe to deíete thís fííe: the tooís regenerate ít.
cache = "/etc/ívm/.cache"
# You can turn off wrítíng thís cache fííe by settíng thís to 0.
wríte¸cache¸state = 1
# Advanced settíngs.
# Líst of paírs of addítíonaí acceptabíe bíock devíce types found
# ín /proc/devíces wíth maxímum (non-zero) number of partítíons.
# types = l "fd", 16 |
# If sysfs ís mounted (2.6 kerneís) restríct devíce scanníng to
# the bíock devíces ít beííeves are vaííd.
# 1 enabíes; 0 dísabíes.
Sample lvm.conf File
97
sysfs¸scan = 1
# By defauít, LVM2 wííí ígnore devíces used as components of
# software RAID (md) devíces by íookíng for md superbíocks.
# 1 enabíes; 0 dísabíes.
md¸component¸detectíon = 1
}
# Thís sectíon that aííows you to confígure the nature of the
# ínformatíon that LVM2 reports.
íog {
# Controís the messages sent to stdout or stderr.
# There are three íeveís of verbosíty, 3 beíng the most verbose.
verbose = 0
# Shouíd we send íog messages through sysíog?
# 1 ís yes; 0 ís no.
sysíog = 1
# Shouíd we íog error and debug messages to a fííe?
# By defauít there ís no íog fííe.
#fííe = "/var/íog/ívm2.íog"
# Shouíd we overwríte the íog fííe each tíme the program ís run?
# By defauít we append.
overwríte = 0
# What íeveí of íog messages shouíd we send to the íog fííe and/or sysíog?
# There are 6 sysíog-ííke íog íeveís currentíy ín use - 2 to 7 íncíusíve.
# 7 ís the most verbose (LOG¸DEBUG).
íeveí = 0
# Format of output messages
# Whether or not (1 or 0) to índent messages accordíng to theír severíty
índent = 1
# Whether or not (1 or 0) to díspíay the command name on each ííne output
command¸names = 0
# A prefíx to use before the message text (but after the command name,
# íf seíected). Defauít ís two spaces, so you can see/grep the severíty
# of each message.
prefíx = " "
Appendix B. The LVM Configura...
98
# To make the messages íook símííar to the orígínaí LVM tooís use:
# índent = 0
# command¸names = 1
# prefíx = " -- "
# Set thís íf you want íog messages duríng actívatíon.
# Don't use thís ín íow memory sítuatíons (can deadíock).
# actívatíon = 0
}
# Confíguratíon of metadata backups and archívíng. In LVM2 when we
# taík about a 'backup' we mean makíng a copy of the metadata for the
# *current* system. The 'archíve' contaíns oíd metadata confíguratíons.
# Backups are stored ín a human readabíe text format.
backup {
# Shouíd we maíntaín a backup of the current metadata confíguratíon ?
# Use 1 for Yes; 0 for No.
# Thínk very hard before turníng thís off!
backup = 1
# Where shaíí we keep ít ?
# Remember to back up thís dírectory reguíaríy!
backup¸dír = "/etc/ívm/backup"
# Shouíd we maíntaín an archíve of oíd metadata confíguratíons.
# Use 1 for Yes; 0 for No.
# On by defauít. Thínk very hard before turníng thís off.
archíve = 1
# Where shouíd archíved fííes go ?
# Remember to back up thís dírectory reguíaríy!
archíve¸dír = "/etc/ívm/archíve"
# What ís the mínímum number of archíve fííes you wísh to keep ?
retaín¸mín = 10
# What ís the mínímum tíme you wísh to keep an archíve fííe for ?
retaín¸days = 30
}
# Settíngs for the runníng LVM2 ín sheíí (readííne) mode.
sheíí {
Sample lvm.conf File
99
# Number of íínes of hístory to store ín -/.ívm¸hístory
hístory¸síze = 100
}
# Mísceííaneous gíobaí LVM2 settíngs
gíobaí {
ííbrary¸dír = "/usr/ííb"
# The fííe creatíon mask for any fííes and dírectoríes created.
# Interpreted as octaí íf the fírst dígít ís zero.
umask = 077
# Aííow other users to read the fííes
#umask = 022
# Enabííng test mode means that no changes to the on dísk metadata
# wííí be made. Equívaíent to havíng the -t optíon on every
# command. Defauíts to off.
test = 0
# Whether or not to communícate wíth the kerneí devíce-mapper.
# Set to 0 íf you want to use the tooís to manípuíate LVM metadata
# wíthout actívatíng any íogícaí voíumes.
# If the devíce-mapper kerneí dríver ís not present ín your kerneí
# settíng thís to 0 shouíd suppress the error messages.
actívatíon = 1
# If we can't communícate wíth devíce-mapper, shouíd we try runníng
# the LVM1 tooís?
# Thís optíon oníy appííes to 2.4 kerneís and ís províded to heíp you
# swítch between devíce-mapper kerneís and LVM1 kerneís.
# The LVM1 tooís need to be ínstaííed wíth .ívm1 suffíces
# e.g. vgscan.ívm1 and they wííí stop workíng after you start usíng
# the new ívm2 on-dísk metadata format.
# The defauít vaíue ís set when the tooís are buíít.
# faííback¸to¸ívm1 = 0
# The defauít metadata format that commands shouíd use - "ívm1" or "ívm2".
# The command ííne overríde ís -M1 or -M2.
# Defauíts to "ívm1" íf compííed ín, eíse "ívm2".
# format = "ívm1"
Appendix B. The LVM Configura...
100
# Locatíon of proc fííesystem
proc = "/proc"
# Type of íockíng to use. Defauíts to íocaí fííe-based íockíng (1).
# Turn íockíng off by settíng to 0 (dangerous: rísks metadata corruptíon
# íf LVM2 commands get run concurrentíy).
# Type 2 uses the externaí shared ííbrary íockíng¸ííbrary.
# Type 3 uses buíít-ín cíustered íockíng.
íockíng¸type = 1
# If usíng externaí íockíng (type 2) and ínítíaíísatíon faíís,
# wíth thís set to 1 an attempt wííí be made to use the buíít-ín
# cíustered íockíng.
# If you are usíng a customísed íockíng¸ííbrary you shouíd set thís to 0.
faííback¸to¸cíustered¸íockíng = 1
# If an attempt to ínítíaííse type 2 or type 3 íockíng faííed, perhaps
# because cíuster components such as cívmd are not runníng, wíth thís set
# to 1 an attempt wííí be made to use íocaí fííe-based íockíng (type 1).
# If thís succeeds, oníy commands agaínst íocaí voíume groups wííí proceed.
# Voíume Groups marked as cíustered wííí be ígnored.
faííback¸to¸íocaí¸íockíng = 1
# Locaí non-LV dírectory that hoíds fííe-based íocks whííe commands are
# ín progress. A dírectory ííke /tmp that may get wíped on reboot ís OK.
íockíng¸dír = "/var/íock/ívm"
# Other entríes can go here to aííow you to íoad shared ííbraríes
# e.g. íf support for LVM1 metadata was compííed as a shared ííbrary use
# format¸ííbraríes = "ííbívm2format1.so"
# Fuíí pathnames can be gíven.
# Search thís dírectory fírst for shared ííbraríes.
# ííbrary¸dír = "/ííb"
# The externaí íockíng ííbrary to íoad íf íockíng¸type ís set to 2.
# íockíng¸ííbrary = "ííbívm2cíusteríock.so"
}
actívatíon {
# Devíce used ín píace of míssíng strípes íf actívatíng íncompíete voíume.
# For now, you need to set thís up yourseíf fírst (e.g. wíth 'dmsetup')
# For exampíe, you couíd make ít return I/O errors usíng the 'error'
# target or make ít return zeros.
Sample lvm.conf File
101
míssíng¸strípe¸fíííer = "/dev/íoerror"
# How much stack (ín KB) to reserve for use whííe devíces suspended
reserved¸stack = 256
# How much memory (ín KB) to reserve for use whííe devíces suspended
reserved¸memory = 8192
# Níce vaíue used whííe devíces suspended
process¸príoríty = -18
# If voíume¸ííst ís defíned, each LV ís oníy actívated íf there ís a
# match agaínst the ííst.
# "vgname" and "vgname/ívname" are matched exactíy.
# "@tag" matches any tag set ín the LV or VG.
# "@*" matches íf any tag defíned on the host ís aíso set ín the LV or VG
#
# voíume¸ííst = l "vg1", "vg2/ívoí1", "@tag1", "@*" |
# Síze (ín KB) of each copy operatíon when mírroríng
mírror¸regíon¸síze = 512
# 'mírror¸ímage¸fauít¸poíícy' and 'mírror¸íog¸fauít¸poíícy' defíne
# how a devíce faííure affectíng a mírror ís handíed.
# A mírror ís composed of mírror ímages (copíes) and a íog.
# A dísk íog ensures that a mírror does not need to be re-synced
# (aíí copíes made the same) every tíme a machíne reboots or crashes.
#
# In the event of a faííure, the specífíed poíícy wííí be used to
# determíne what happens:
#
# "remove" - Símpíy remove the fauíty devíce and run wíthout ít. If
# the íog devíce faíís, the mírror wouíd convert to usíng
# an ín-memory íog. Thís means the mírror wííí not
# remember íts sync status across crashes/reboots and
# the entíre mírror wííí be re-synced. If a
# mírror ímage faíís, the mírror wííí convert to a
# non-mírrored devíce íf there ís oníy one remaíníng good
# copy.
#
# "aííocate" - Remove the fauíty devíce and try to aííocate space on
# a new devíce to be a repíacement for the faííed devíce.
# Usíng thís poíícy for the íog ís fast and maíntaíns the
# abíííty to remember sync state through crashes/reboots.
Appendix B. The LVM Configura...
102
# Usíng thís poíícy for a mírror devíce ís síow, as ít
# requíres the mírror to resynchroníze the devíces, but ít
# wííí preserve the mírror characterístíc of the devíce.
# Thís poíícy acts ííke "remove" íf no suítabíe devíce and
# space can be aííocated for the repíacement.
# Currentíy thís ís not ímpíemented properíy and behaves
# símííaríy to:
#
# "aííocate¸anywhere" - Operates ííke "aííocate", but ít does not
# requíre that the new space beíng aííocated be on a
# devíce ís not part of the mírror. For a íog devíce
# faííure, thís couíd mean that the íog ís aííocated on
# the same devíce as a mírror devíce. For a mírror
# devíce, thís couíd mean that the mírror devíce ís
# aííocated on the same devíce as another mírror devíce.
# Thís poíícy wouíd not be wíse for mírror devíces
# because ít wouíd break the redundant nature of the
# mírror. Thís poíícy acts ííke "remove" íf no suítabíe
# devíce and space can be aííocated for the repíacement.
mírror¸íog¸fauít¸poíícy = "aííocate"
mírror¸devíce¸fauít¸poíícy = "remove"
}
####################
# Advanced sectíon #
####################
# Metadata settíngs
#
# metadata {
# Defauít number of copíes of metadata to hoíd on each PV. 0, 1 or 2.
# You míght want to overríde ít from the command ííne wíth 0
# when runníng pvcreate on new PVs whích are to be added to íarge VGs.
# pvmetadatacopíes = 1
# Approxímate defauít síze of on-dísk metadata areas ín sectors.
# You shouíd íncrease thís íf you have íarge voíume groups or
# you want to retaín a íarge on-dísk hístory of your metadata changes.
# pvmetadatasíze = 255
Sample lvm.conf File
103
# Líst of dírectoríes hoídíng ííve copíes of text format metadata.
# These dírectoríes must not be on íogícaí voíumes!
# It's possíbíe to use LVM2 wíth a coupíe of dírectoríes here,
# preferabíy on dífferent (non-LV) fííesystems, and wíth no other
# on-dísk metadata (pvmetadatacopíes = 0). Or thís can be ín
# addítíon to on-dísk metadata areas.
# The feature was orígínaííy added to símpíífy testíng and ís not
# supported under íow memory sítuatíons - the machíne couíd íock up.
#
# Never edít any fííes ín these dírectoríes by hand uníess you
# you are absoíuteíy sure you know what you are doíng! Use
# the suppííed tooíset to make changes (e.g. vgcfgrestore).
# dírs = l "/etc/ívm/metadata", "/mnt/dísk2/ívm/metadata2" |
#}
# Event daemon
#
# dmeventd {
# mírror¸ííbrary ís the ííbrary used when monítoríng a mírror devíce.
#
# "ííbdevmapper-event-ívm2mírror.so" attempts to recover from faííures.
# It removes faííed devíces from a voíume group and reconfígures a
# mírror as necessary.
#
# mírror¸ííbrary = "ííbdevmapper-event-ívm2mírror.so"
#}
Appendix B. The LVM Configura...
104
Appendix C. LVM Obiect Tags
An LVM tag ís a word that can be used to group LVM2 obíects of the same type
together. Tags can be attached to obíects such as physícaí voíumes, voíume groups,
and íogícaí voíumes. Tags can be attached to hosts ín a cíuster confíguratíon.
Snapshots cannot be tagged.
Tags can be gíven on the command ííne ín píace of PV, VG or LV arguments. Tags
shouíd be prefíxed wíth @ to avoíd ambíguíty. Each tag ís expanded by repíacíng ít
wíth aíí obíects possessíng that tag whích are of the type expected by íts posítíon on
the command ííne.
LVM tags are stríngs usíng lA-Za-z0-9¸+.-| of up to 128 characters. They cannot
start wíth a hyphen.
Oníy obíects ín a voíume group can be tagged. Physícaí voíumes íose theír tags íf
they are removed from a voíume group; thís ís because tags are stored as part of
the voíume group metadata and that ís deíeted when a physícaí voíume ís removed.
Snapshots cannot be tagged.
The foííowíng command íísts aíí the íogícaí voíumes wíth the database tag.
ívs @database
1. Adding and Removing Obiect Tags
To add or deíete tags from physícaí voíumes, use the --addtag or --deítag optíon of
the pvchange command.
To add or deíete tags from voíume groups, use the --addtag or --deítag optíon of the
vgchange or vgcreate commands.
To add or deíete tags from íogícaí voíumes, use the --addtag or --deítag optíon of the
ívchange or ívcreate commands.
2. Host Tags
In a cíuster confíguratíon, you can defíne host tags ín the confíguratíon fííes. If you
set hosttags = 1 ín the tags sectíon, a host tag ís automatícaííy defíned usíng the
machíne's hostname. Thís aííow you to use a common confíguratíon fííe whích can
105
be repíícated on aíí your machínes so they hoíd ídentícaí copíes of the fííe, but the
behavíor can díffer between machínes accordíng to the hostname.
For ínformatíon on the confíguratíon fííes, see Appendíx B, The LVM Confíguratíon
Fííes.
For each host tag, an extra confíguratíon fííe ís read íf ít exísts: ívm¸hosttag.conf. If
that fííe defínes new tags, then further confíguratíon fííes wííí be appended to the
ííst of fííes to read ín.
For exampíe, the foííowíng entry ín the confíguratíon fííe aíways defínes tag1, and
defínes tag2 íf the hostname ís host1.
tags { tag1 { } tag2 { host¸ííst = l"host1"| } }
3. Controlling Activation with Tags
You can specífy ín the confíguratíon fííe that oníy certaín íogícaí voíumes shouíd be
actívated on that host. For exampíe, the foííowíng entry acts as a fííter for actívatíon
requests (such as vgchange -ay) and oníy actívates vg1/ívoí0 and any íogícaí voíumes
or voíume groups wíth the database tag ín the metadata on that host.
actívatíon { voíume¸ííst = l"vg1/ívoí0", "@database" | }
There ís a specíaí match "@*" that causes a match oníy íf any metadata tag
matches any host tag on that machíne.
As another exampíe, consíder a sítuatíon where every machíne ín the cíuster has
the foííowíng entry ín the confíguratíon fííe:
tags { hosttags = 1 }
If you want to actívate vg1/ívoí2 oníy on host db2, do the foííowíng:
1. Run ívchange --addtag @db2 vg1/ívoí2 from any host ín the cíuster.
2. Run ívchange -ay vg1/ívoí2.
Appendix C. LVM Obiect Tags
106
Thís soíutíon ínvoíves storíng hostnames ínsíde the voíume group metadata.
Controlling Activation with Tags
107
108
Appendix D. LVM Volume
Group Metadata
The confíguratíon detaíís of a voíume group are referred to as the metadata. By
defauít, an ídentícaí copy of the metadata ís maíntaíned ín every metadata area ín
every physícaí voíume wíthín the voíume group. LVM voíume group metadata ís
smaíí and stored as ASCII.
If a voíume group contaíns many physícaí voíumes, havíng many redundant copíes
of the metadata ís íneffícíent. It ís possíbíe to create a physícaí voíume wíthout any
metadata copíes by usíng the --metadatacopíes 0 optíon of the pvcreate command.
Once you have seíected the number of metadata copíes the physícaí voíume wííí
contaín, you cannot change that at a íater poínt. Seíectíng 0 copíes can resuít ín
faster updates on confíguratíon changes. Note, however, that at aíí tímes every
voíume group must contaín at íeast one physícaí voíume wíth a metadata area
(uníess you are usíng the advanced confíguratíon settíngs that aííow you to store
voíume group metadata ín a fííe system). If you íntend to spíít the voíume group ín
the future, every voíume group needs at íeast one metadata copy.
The core metadata ís stored ín ASCII. A metadata area ís a círcuíar buffer. New
metadata ís appended to the oíd metadata and then the poínter to the start of ít ís
updated.
You can specífy the síze of metadata area wíth the --metadatasíze. optíon of the
pvcreate command. The defauít síze ís too smaíí for voíume groups wíth many íogícaí
voíumes or physícaí voíumes.
1. The Physical Volume Label
By defauít, the pvcreate command píaces the physícaí voíume íabeí ín the 2nd
512-byte sector. Thís íabeí can optíonaííy be píaced ín any of the fírst four sectors,
sínce the LVM tooís that scan for a physícaí voíume íabeí check the fírst 4 sectors.
The physícaí voíume íabeí begíns wíth the stríng LABELONE.
The physícaí voíume íabeí Contaíns:
º Physícaí voíume UUID
º Síze of bíock devíce ín bytes
109
º NULL-termínated ííst of data area íocatíons
º NULL-termínated íísts of metadata area íocatíons
Metadata íocatíons are stored as offset and síze (ín bytes). There ís room ín the
íabeí for about 15 íocatíons, but the LVM tooís currentíy use 3: a síngíe data area
píus up to two metadata areas.
2. Metadata Contents
The voíume group metadata contaíns:
º Informatíon about how and when ít was created
º Informatíon about the voíume group:
The voíume group ínformatíon contaíns:
º Name and uníque íd
º A versíon number whích ís íncremented whenever the metadata gets updated
º Any propertíes: Read/Wríte? Resízeabíe?
º Any admínístratíve íímít on the number of physícaí voíumes and íogícaí voíumes ít
may contaín
º The extent síze (ín uníts of sectors whích are defíned as 512 bytes)
º An unordered ííst of physícaí voíumes makíng up the voíume group, each wíth:
º Its UUID, used to determíne the bíock devíce contaíníng ít
º Any propertíes, such as whether the physícaí voíume ís aííocatabíe
º The offset to the start of the fírst extent wíthín the physícaí voíume (ín sectors)
º The number of extents
º An unordered ííst of íogícaí voíumes. each consístíng of
º An ordered ííst of íogícaí voíume segments. For each segment the metadata
íncíudes a mappíng appííed to an ordered ííst of physícaí voíume segments or
íogícaí voíume segments
Appendix D. LVM Volume Group ...
110
3. Sample Metadata
The foííowíng shows an exampíe of LVM voíume group metadata for a voíume group
caííed myvg.
# Generated by LVM2: Tue Ian 30 16:28:15 2007
contents = "Text Format Voíume Group"
versíon = 1
descríptíon = "Created *before* executíng 'ívextend -L+5G /dev/myvg/myív /dev/sdc'"
creatíon¸host = "tng3-1" # Línux tng3-1 2.6.18-8.eí5 #1 SMP Frí Ian 26 14:15:21 EST
2007 í686
creatíon¸tíme = 1170196095 # Tue Ian 30 16:28:15 2007
myvg {
íd = "0zd3UT-wbYT-íDHq-íMPs-EíoE-0o18-wL28X4"
seqno = 3
status = l"RESIZEABLE", "READ", "WRITE"|
extent¸síze = 8192 # 4 Megabytes
max¸ív = 0
max¸pv = 0
physícaí¸voíumes {
pv0 {
íd = "ZBW5qW-dXF2-0bGw-ZCad-2RíV-phwu-1c1RFt"
devíce = "/dev/sda" # Hínt oníy
status = l"ALLOCATABLE"|
dev¸síze = 35964301 # 17.1491 Gígabytes
pe¸start = 384
pe¸count = 4390 # 17.1484 Gígabytes
}
pv1 {
íd = "ZHEZIW-MR64-D3OM-Rv7V-Hxsa-zU24-wztY19"
devíce = "/dev/sdb" # Hínt oníy
status = l"ALLOCATABLE"|
dev¸síze = 35964301 # 17.1491 Gígabytes
pe¸start = 384
Sample Metadata
111
pe¸count = 4390 # 17.1484 Gígabytes
}
pv2 {
íd = "wCoG4p-55Uí-9tbp-VTEA-íO6s-RAVx-UREW0G"
devíce = "/dev/sdc" # Hínt oníy
status = l"ALLOCATABLE"|
dev¸síze = 35964301 # 17.1491 Gígabytes
pe¸start = 384
pe¸count = 4390 # 17.1484 Gígabytes
}
pv3 {
íd = "hGíUwí-zsBg-39FF-do88-pHxY-8XA2-9WKIíA"
devíce = "/dev/sdd" # Hínt oníy
status = l"ALLOCATABLE"|
dev¸síze = 35964301 # 17.1491 Gígabytes
pe¸start = 384
pe¸count = 4390 # 17.1484 Gígabytes
}
}
íogícaí¸voíumes {
myív {
íd = "GhUYSF-qVM3-rzOo-a6D2-o0aV-LOet-Ur9OF9"
status = l"READ", "WRITE", "VISIBLE"|
segment¸count = 2
segment1 {
start¸extent = 0
extent¸count = 1280 # 5 Gígabytes
type = "stríped"
strípe¸count = 1 # íínear
strípes = l
"pv0", 0
|
}
segment2 {
start¸extent = 1280
extent¸count = 1280 # 5 Gígabytes
Appendix D. LVM Volume Group ...
112
type = "stríped"
strípe¸count = 1 # íínear
strípes = l
"pv1", 0
|
}
}
}
}
Sample Metadata
113
114
lndex
A
actívatíng íogícaí voíumes
índívíduaí nodes, 51
actívatíng voíume groups, 31
índívíduaí nodes, 32
íocaí node oníy, 32
admínístratíve procedures, 17
aííocatíon
poíícy, 27
preventíng, 26
archíve fííe, 18, 33
B
backup
fííe, 18
metadata, 18, 33
backup fííe, 33
bíock devíce
scanníng, 24
C
cache fííe
buíídíng, 30
cíuster envíronment, 3, 17
CLVM
defínítíon, 3
cívmd daemon, 3
command ííne uníts, 21
confíguratíon exampíes, 67
creatíng
íogícaí voíume, 35
íogícaí voíume, exampíe, 67
LVM voíumes ín a cíuster, 17
physícaí voíumes, 23
stríped íogícaí voíume, exampíe, 69
voíume groups, 27
creatíng LVM voíumes
overvíew, 17
D
data reíocatíon, onííne, 50
deactívatíng voíume groups, 31
excíusíve on one node, 32
íocaí node oníy, 32
devíce numbers
maíor, 41
mínor, 41
persístent, 41
devíce path names, 21
devíce scan fííters, 49
devíce síze, maxímum, 28
devíce specíaí fííe dírectory, 28
díspíay
sortíng output, 63
díspíayíng
íogícaí voíumes, 43, 59
physícaí voíumes, 25, 55
voíume groups, 28, 58
E
extent
aííocatíon, 27
defínítíon, 9, 27
F
faííed devíces
díspíayíng, 79
feedback, x, x
fííe system
growíng on a íogícaí voíume, 18
fííters, 49
G
growíng fííe system
íogícaí voíume, 18
115
H
heíp díspíay, 22
l
ínítíaíízíng
partítíons, 24
physícaí voíumes, 23
Insuffícíent Free Extents message, 88
L
íínear íogícaí voíume
convertíng to mírrored, 40
creatíon, 35
defínítíon, 9
íoggíng, 19
íogícaí voíume
admínístratíon, generaí, 35
changíng parameters, 41
creatíon, 35
creatíon exampíe, 67
defínítíon, 1, 9
díspíayíng, 43, 51, 59
excíusíve access, 51
extendíng, 43
growíng, 43
íínear, 35
íocaí access, 51
ívs díspíay arguments, 59
mírrored, 38
reducíng, 47
removíng, 42
renamíng, 42
resízíng, 41
shrínkíng, 47
snapshot, 47
stríped, 38
ívchange command, 41
ívconvert command, 40
ívcreate command, 35
ívdíspíay command, 43
ívextend command, 43
LVM
archítecture overvíew, 2
cíustered, 3
components, 3, 7
custom report format, 51
dírectory structure, 28
heíp, 22
hístory, 2
íabeí, 7
íoggíng, 19
íogícaí voíume admínístratíon, 35
physícaí voíume admínístratíon, 23
physícaí voíume, defínítíon, 7
voíume group, defínítíon, 9
LVM1, 2
LVM2, 2
ívmdískscan command, 24
ívreduce command, 41, 47
ívremove command, 42
ívrename command, 42
ívs command, 51, 59
díspíay arguments, 59
ívscan command, 43
M
man page díspíay, 22
metadata
backup, 18, 33
recovery, 85
mírrored íogícaí voíume
convertíng to íínear, 40
creatíon, 38
defínítíon, 14
faííure recovery, 81
reconfíguratíon, 40
O
onííne data reíocatíon, 50
lndex
116
P
partítíon type, settíng, 23
partítíons
muítípíe, 8
path names, 21
persístent devíce numbers, 41
physícaí extent
preventíng aííocatíon, 26
physícaí voíume
addíng to a voíume group, 28
admínístratíon, generaí, 23
creatíng, 23
defínítíon, 7
díspíay, 55
díspíayíng, 25, 51
íííustratíon, 7
ínítíaíízíng, 23
íayout, 7
pvs díspíay arguments, 55
recovery, 87
removíng, 26
removíng from voíume group, 30
removíng íost voíume, 87
resízíng, 26
pvdíspíay command, 25
pvmove command, 50
pvremove command, 26
pvresíze command, 26
pvs command, 51
díspíay arguments, 55
pvscan command, 25
R
removíng
dísk from a íogícaí voíume, 74
íogícaí voíume, 42
physícaí voíumes, 26
renamíng
íogícaí voíume, 42
voíume group, 33
report format, LVM devíces, 51
resízíng
íogícaí voíume, 41
physícaí voíume, 26
S
scanníng
bíock devíces, 24
scanníng devíces, fííters, 49
snapshot íogícaí voíume
creatíon, 47
snapshot voíume
defínítíon, 15
stríped íogícaí voíume
creatíon, 38
creatíon exampíe, 69
defínítíon, 12
extendíng, 45
growíng, 45
T
troubíeshootíng, 79
U
uníts, command ííne, 21
V
verbose output, 21
vgcfbackup command, 33
vgcfrestore command, 33
vgchange command, 31
vgcreate command, 27
vgdíspíay command, 29
vgexport command, 34
vgextend command, 28
vgímport command, 34
vgmerge command, 33
vgmknodes command, 35
vgreduce command, 30
117
vgrename command, 33
vgs command, 51
díspíay arguments, 58
vgscan command, 30
vgspíít command, 32
voíume group
actívatíng, 31
admínístratíon, generaí, 27
changíng parameters, 31
combíníng, 33
creatíng, 27
deactívatíng, 31
defínítíon, 9
díspíayíng, 28, 51, 58
extendíng, 28
growíng, 28
mergíng, 33
movíng between systems, 34
reducíng, 30
removíng, 32
renamíng, 33
shrínkíng, 30
spííttíng, 32
exampíe procedure, 71
vgs díspíay arguments, 58
lndex
118

Sign up to vote on this title
UsefulNot useful