Sie sind auf Seite 1von 10

redhat.

com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

Issue#9July2005

THELINUXLOGICALVOLUMEMANAGER
byHeinzMauelshagenandMatthewO'Keefe

Introduction BasicLVMcommands DifferencesbetweenLVM1andLVM2 Summary Abouttheauthors

Storagetechnologyplaysacriticalroleinincreasingtheperformance,availability,and manageabilityofLinuxservers.OneofthemostimportantnewdevelopmentsintheLinux2.6 kernelonwhichtheRedHatEnterpriseLinux4kernelisbasedistheLinuxLogicalVolume Manager,version2(orLVM2).Itcombinesamoreconsistentandrobustinternaldesignwith importantnewfeaturesincludingvolumemirroringandclustering,yetitisupwardlycompatible withtheoriginalLogicalVolumeManager1(LVM1)commandsandmetadata.Thisarticle summarizesthebasicprinciplesbehindtheLVMandprovideexamplesofbasicoperationstobe performedwithit.

Logicalvolumemanagementisawidely-usedtechniquefordeployinglogicalratherthan physicalstorage.WithLVM,"logical"partitionscanspanacrossphysicalharddrivesandcanbe resized(unliketraditionalext3"raw"partitions).Aphysicaldiskisdividedintooneormore physicalvolumes(Pvs),andlogicalvolumegroups(VGs)arecreatedbycombiningPVsas showninFigure1.LVMinternalorganization(#fig-internal).NoticetheVGscanbeanaggregateof PVsfrommultiplephysicaldisks.

Introduction

1 of 10

Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

Figure1.LVMinternalorganization

Figure2.Mappinglogicalextentstophysicalextents (#fig-mapping)showshowthelogical volumesaremappedontophysicalvolumes.EachPVconsistsofanumberoffixed-sizephysical extents(PEs);similarly,eachLVconsistsofanumberoffixed-sizelogicalextents(LEs).(LEs andPEsarealwaysthesamesize,thedefaultinLVM2is4MB.)AnLViscreatedbymapping logicalextentstophysicalextents,sothatreferencestologicalblocknumbersareresolvedto physicalblocknumbers.Thesemappingscanbeconstructedtoachieveparticularperformance, scalability,oravailabilitygoals.

2 of 10

Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

Figure2.Mappinglogicalextentstophysicalextents

Forexample,multiplePVscanbeconnectedtogethertocreateasinglelargelogicalvolumeas showninFigure3.LVMlinearmapping(#fig-linear).Thisapproach,knownasalinearmapping, allowsafilesystemordatabaselargerthanasinglevolumetobecreatedusingtwophysical disks.Analternativeapproachisastripedmapping,inwhichstripes(groupsofcontiguous physicalextents)fromalternatePVsaremappedtoasingleLV,asshowninFigure4.LVM stripedmapping(#fig-striped).Thestripedmappingallowsasinglelogicalvolumetonearly achievethecombinedperformanceoftwoPVsandisusedquiteoftentoachievehigh-bandwidth disktransfers.

Figure3.LVMlinearmapping

3 of 10

Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

Figure4.LVMstripedmapping(4physicalextentsperstripe)

Throughthesedifferenttypesoflogical-to-physicalmappings,LVMcanachievefourimportant advantagesoverrawphysicalpartitions:

1. Logicalvolumescanberesizedwhiletheyaremountedandaccessiblebythedatabaseorfile system,removingthedowntimeassociatedwithaddingordeletingstoragefromaLinux server 2. Datafromone(potentiallyfaultyordamaged)physicaldevicemayberelocatedtoanother devicethatisnewer,fasterormoreresilient,whiletheoriginalvolumeremainsonlineand accessible 3. Logicalvolumescanbeconstructedbyaggregatingphysicaldevicestoincreaseperformance (viadiskstriping)orredundancy(viadiskmirroringandI/Omultipathing) 4. Logicalvolumesnapshotscanbecreatedtorepresenttheexactstateofthevolumeata certainpoint-in-time,allowingaccuratebackupstoproceedsimultaneouslywithregular systemoperation

BasicLVMcommands
TouseLVM,partitionsandwholedisksmustfirstbeconvertedintophysicalvolumes(PVs) usingthepvcreatecommand.Forexample,toconvert/dev/hdaand/dev/hdbintoPVs usethefollowingcommands:
Initializingdisksordiskpartitions

pvcreate /dev/hda pvcreate /dev/hdb

IfaLinuxpartitionistobeconvertedmakesurethatitisgivenpartitiontype0x8Eusingfdisk, thenusepvcreate:

4 of 10

Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

pvcreate /dev/hda1

Creatingavolumegroup

Onceyouhaveoneormorephysicalvolumescreated,youcancreateavolumegroupfromthese PVsusingthevgcreatecommand.Thefollowingcommand:

vgcreate

volume_group_one /dev/hda /dev/hdb

createsanewVGcalledvolume_group_onewithtwodisks,/dev/hdaand/dev/hdb,and 4MBPEs.Ifboth/dev/hdaand/dev/hdbare128GBinsize,thentheVG volume_group_onewillhaveatotalof2**16physicalextentsthatcanbeallocatedtological volumes. AdditionalPVscanbeaddedtothisvolumegroupusingthevgextendcommand.The followingcommandsconvert/dev/hdcintoaPVandthenaddsthatPVto volume_group_one:

pvcreate /dev/hdc vgextend volume_group_one /dev/hdc

ThissamePVcanberemovedfromvolume_group_onebythevgreducecommand:

vgreduce volume_group_one /dev/hdc

NotethatanylogicalvolumesusingphysicalextentsfromPV/dev/hdcwillberemovedas well.ThisraisestheissueofhowwecreateanLVwithinavolumegroupinthefirstplace.

Creatingalogicalvolume

Weusethelvcreatecommandtocreateanewlogicalvolumeusingthefreephysicalextentsin theVGpool.ContinuingourexampleusingVGvolume_group_one(withtwoPVs/dev/hda

5 of 10

Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

and/dev/hdbandatotalcapacityof256GB),wecouldallocatenearlyallthePEsinthe volumegrouptoasinglelinearLVcalledlogical_volume_onewiththefollowingLVM command:

lvcreate -n logical_volume_one

--size 255G volume_group_one

InsteadofspecifyingtheLVsizeinGBwecouldalsospecifyitintermsoflogicalextents.First weusevgdisplaytodeterminethenumberofPEsinthevolume_group_one:

vgdisplay volume_group_one | grep "Total PE"

whichreturns

Total PE

65536

Thenthefollowinglvcreatecommandwillcreatealogicalvolumewith65536logicalextents andfillthevolumegroupcompletely:

lvcreate -n logical_volume_one

-l 65536 volume_group_one

Tocreatea1500MBlinearLVnamedlogical_volume_oneanditsblockdevicespecialfile /dev/volume_group_one/logical_volume_oneusethefollowingcommand:

lvcreate -L1500 -n logical_volume_one volume_group_one

Thelvcreatecommanduseslinearmappingsbydefault. Stripedmappingscanalsobecreatedwithlvcreate.Forexample,tocreatea255GBlarge

6 of 10

Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

logicalvolumewithtwostripesandstripesizeof4KBthefollowingcommandcanbeused:

lvcreate -i2 -I4 --size 255G -n logical_volume_one_striped volume_group_one

ItispossibletoallocatealogicalvolumefromaspecificphysicalvolumeintheVGbyspecifying thePVorPVsattheendofthelvcreatecommand.Ifyouwantthelogicalvolumetobe allocatedfromaspecificphysicalvolumeinthevolumegroup,specifythePVorPVsattheend ofthelvcreatecommandline.Forexample,thiscommand:

lvcreate -i2 -I4 -L128G -n logical_volume_one_striped volume_group_one /dev/hda /dev/hdb

createsastripedLVnamedlogical_volume_onethatisstripedacrosstwoPVs(/dev/hda and/dev/hdb)withstripesize4KBand128GBinsize. AnLVcanberemovedfromaVGthroughthelvremovecommand,butfirsttheLVmustbe unmounted:

umount /dev/volume_group_one/logical_volume_one lvremove /dev/volume_group_one/logical_volume_one

NotethatLVMvolumegroupsandunderlyinglogicalvolumesareincludedinthedevicespecial filedirectorytreeinthe/devdirectorywiththefollowinglayout:

/dev/<volume_group_name>/<logical_volume_name>

sothatifwehadtwovolumegroupsmyvg1andmyvg2andeachwiththreelogicalvolumes namedlv01,lv02,lv03,sixdevicespecialfileswouldbecreated:

7 of 10

Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

/dev/myvg1/lv01 /dev/myvg1/lv02 /dev/myvg1/lv03 /dev/myvg2/lv01 /dev/myvg2/lv02 /dev/myvg2/lv03

AnLVcanbeextendedbyusingthelvextendcommand.Youcanspecifyeitheranabsolutesize fortheextendedLVorhowmuchadditionalstorageyouwanttoaddtotheLVM.Forexample:

Extendingalogicalvolume

lvextend -L120G /dev/myvg/homevol

willextendLV/dev/myvg/homevolto12GB,while

lvextend -L+10G /dev/myvg/homevol

willextendLV/dev/myvg/homevolbyanadditional10GB.Oncealogicalvolumehasbeen extended,theunderlyingfilesystemcanbeexpandedtoexploittheadditionalstoragenow availableontheLV.WithRedHatEnterpriseLinux4,itispossibletoexpandboththeext3fsand GFSfilesystemsonline,withoutbringingthesystemdown.(Theext3filesystemcanbeshrunkor expandedofflineusingtheext2resizecommand.)Toresizeext3fs,thefollowingcommand

ext2online /dev/myvg/homevol

willextendtheext3filesystemtocompletelyfilltheLV,/dev/myvg/homevol,onwhichit resides. Thefilesystemspecifiedbydevice(partition,loopdevice,orlogicalvolume)ormountpoint mustcurrentlybemounted,anditwillbeenlargedtofillthedevice,bydefault.Ifanoptional sizeparameterisspecified,thenthissizewillbeusedinstead.

8 of 10

Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

ThenewreleaseofLVM,LVM2,isavailableonlyonRedHatEnterpriseLinux4andlater kernels.ItisupwardlycompatiblewithLVM1andretainsthesamecommandlineinterface structure.Howeveritusesanew,morescalableandresilientmetadatastructurethatallowsfor transactionalmetadataupdates(thatallowquickrecoveryafterserverfailures),verylarge numbersofdevices,andclustering.ForEnterpriseLinuxserversdeployedinmission-critical environmentsthatrequirehighavailability,LVM2istherightchoiceforLinuxvolume management.Table1.AcomparisonofLVM1andLVM2 (#tb-compare)summarizesthe differencesbetweenLVM1andLVM2infeatures,kernelsupport,andotherareas.

DifferencesbetweenLVM1andLVM2

Features

LVM1

LVM2

RHELAS2.1support RHEL3support RHEL4support Transactionalmetadataforfastrecovery SharedvolumemountswithGFS ClusterSuitefailoversupported Stripedvolumeexpansion MaxnumberPVs,LVs Maxdevicesize Volumemirroringsupport
Table1.AcomparisonofLVM1andLVM2

No Yes No No No Yes No 256PVs,256LVs 2Terabytes No

No No Yes Yes Yes Yes Yes 2**32PVs,2**32LVs 8Exabytes(64-bitCPUs) Yes,inFall2005

Summary

TheLinuxLogicalVolumeManagerprovidesincreasedmanageability,uptime,andperformance forRedHatEnterpriseLinuxservers.YoucanlearnmoreaboutLVMbyvisitingtofollowing websites:

LVMHOWTO LVM2ResourcePage

Abouttheauthors
9 of 10 Friday 01 July 2011 11:36 AM

redhat.com | The Linux Logical Volume Manager

http://www.redhat.com/magazine/009jul05/features...

From1990toMay2000,MatthewO'Keefetaughtandperformedresearchinstoragesystemsandparallelsimulationsoftwareasaprofessorof electricalandcomputerengineeringattheUniversityofMinnesota.HefoundedSistinaSoftwareinMayof2000todevelopstorage infrastructuresoftwareforLinux,includingtheGlobalFileSystem(GFS)andtheLinuxLogicalVolumeManager(LVM).Sistinawasacquired byRedHatinDecember2003,whereMatthewnowdirectsstoragesoftwarestrategy. Startingin2000,HeinzMauelshagenbeganworkingondevicemapperandLVMatSistinaSoftware.SistinawasacquiredbyRedHatin December2003.HeinzMauelshageniscurrentlycontinuinghisworkonclusteringandstorageasaRedHatdeveloperinGermany.Before joiningSistina,HeinzwasaseniorsystemadministratoratT-Systemsforadecade.

Copyright2011RedHat,Inc.Allrightsreserved. :::::

10 of 10

Friday 01 July 2011 11:36 AM

Das könnte Ihnen auch gefallen