Tải bản đầy đủ - 0 (trang)
Chapter 5. Using Prebuilt Guest Images

Chapter 5. Using Prebuilt Guest Images

Tải bản đầy đủ - 0trang

workingsystem.

ForLinux,itistypicaltodecomposetheguestimageintotwo

pieces:onefortherootfilesystemandoneforswapspace.You

canalsochoosetoconfigureswapspaceaspartoftherootfile

systeminLinux.Theadvantageofsplittingthemintoseparate

partitionsisbeneficialwhentakingsystembackups.When

backingupanoperatingsystem,thereisnoneedtorecordthe

fundamentallyvolatilecontentsofaswappartition.Similarly,

thereisnoneedtorepresentthecontentsofswapinsidea

guestimagefilethatyoubackuporsharewithothers.

Windows,incontrast,doesnottypicallyseparatetherootfile

systemfromtheswaparea.Instead,thepagefile(arough

equivalentofLinuxswapspace)isusuallystoredontheCdrive,

theLinuxrootfilesystemequivalent.AfterWindowsisinstalled,

youcanconfigureittostoreitspagefileonaseparatepartition

ordisk.Havingtherootfilesystemandswappartitionon

differentphysicaldiskscanincreaseoverallperformance

becausenormaldiskaccessesandpaging(orswapping)

accessescanbemanagedseparately.



OperatingSystemKernels

Theguestoperatingsystemkernelisafilethatcontainsthe

operatingsystemexecutablethatmanagesresourcesforall

userlevelapplications.Thekernelfilecanbestoredeither

withintheguestimageorinanexternalfileonDomain0.

Bootloaders,suchasGRUB,provideachoiceofkernelstoboot.

Thesedifferentkernelsmightusethesamerootfilesystem,or

guestimage.Inthecaseofaguest,thekernelcaneitherbea

Xen-compatiblekernel(forparavirtualizedguests)oran

unmodifiedkernel(forfullyvirtualguests).



ConfigurationFiles

AconfigurationfiledefinestheresourcesthattheDomUguest

willhaveusingasetofparameterspassedtotheXen

managementtool(xm).Inessence,theconfigurationfile



specifieswhetheravirtualmachinewillbePVorHVMandwhat

typeofdevicestheguestshouldbegrantedbytheXen

hypervisor.Theconfigurationfileisalwaysafilestoredexternal

totheguestyetaccessibletoDomain0.Unlikeguestimages

andtheoperatingsystemkernel,aconfigurationfiledoesnot

haveanequivalentfileinnonvirtualizedmachines.Themost

directcomparisoninanonvirtualizedenvironmentwouldbea

listofspecificationsofthephysicalhardware.

TheparametersintheconfigurationfilespecifytheCPU,

memory,disk,andnetworkresourcesforaguest.Forthis

chapter,wefocusmostlyonthediskparameterofthe

configurationfileandsavethemoreadvancedfunctionalityfor

Chapter6,"ManagingUnprivilegedDomains."Weneedother

parametersincludingthekernel(operatingsystemkernel),

ramdisk(initialRAMdisk),memory,vif(virtualinterfaces),and

bootloaderconfigurationparameterstomakeworkingguests,

butwecovereachoftheseparametersinmoredetailinlater

chaptersandAppendixC.

Thediskparameterisusedtoexportguestimages.The

generalformatforthediskparameterisanarrayofthreetuples.(Atupleisanorderedlistofitems.Athree-tuplehas

threelistitems).Thefirstitemofthethree-tupleisforthe

locationoftheguestimageasseenbyDomain0.Thesecond

itemofthethree-tupleisthelocationoftheguestimageas

seenbytheguest,orthedeviceonwhichtheguestimage

appearstothatDomU.Thethirditemofthethree-tupleisthe

accesspermissionthattheDomUhastotheguestimage.An

exampleofhowtousethediskparameterintheconfiguration

fileisshowninListing5.1.

Listing5.1.AnExampleoftheDiskParameter

disk=['phy:hda1,xvda1,w']



Listing5.1showsanexampleofthediskparameterlinethat

exportsDomain0'sphysicalpartition/dev/hda1totheDomUas

/dev/xvda1,withwritepermissions.Thefirstitemofthe3tuple,thephy:prefixisusedtoexportthephysicaldevice,

hda1,whichisthephysicalpartitiononDomain0.Otherpossible

prefixesusedtoexportrealorvirtualdevicesaretap:aio,

tap:qcowandfile:.Theseconditemofthethree-tupleis

xvda1,whichisthevirtualpartitionthatappearsontheDomU.

OtherpossiblevaluesforDomain0devicesarehda1andsda1.

Thethirditemofthethree-tuple,w,meansthattheDomUwill

haveread-writeaccesstotheblockdevice.Anotherpossible

accesspermissionisr,forread-only.

Blockdevicesarespecialfiles(ordevicenodes)thatthe

operatingsystemusestomovedataaround.Thedevicenodes

aretypicallybackedbyanonvolatilephysicallyaddressable

device,suchasaharddisk,CDorDVDROMdrive,thoughin

somecasesevenspecialmemoryregionscanbeblockdevices.

Blockdevicesmaybereadinanyorder.Thisisincontrastto

characterdeviceswhichmovedatatoandfromuserprocesses.

ForPVgueststhatsupporttheXenvirtualblockdevice(xvd)

interface(forexample,paravirtualizedguestssuchasLinux),it

istherecommendedwaytospecifyblockdevices.Thexvd

interfaceallowstheXenguesttounderstandthatithasvirtual

disksinsteadofnativehardware.Thexvdinterfaceexploitsthis

knowledgetoachievebetterperformance.Youcanthinkofxvd

asaprefixsimilartohdorsd(forexample,hdaorsdanotation

usedinmanysystemstodenoteIDEorSCSIdevices

respectively),whichisusedinthesamewayeventhoughit

doesn'ttrulyemulateeitherofthecommondisktypes,IDEor

SCSI,completely.WithHVMgueststhatdonothaveparavirtual

blockdevicedriversinstalled,youstillneedtousethehd(IDE)

andsd(SCSI)disksfortheDomU,because,bydefault,HVM

guestsdonothavesupportforxvdblockdevices.

Aswesawinthepreviousexample,Listing5.1,aphysical



devicenodeisspecifiedwiththephy:prefixandcanbeany

blockdevicefoundin/dev/,suchas/dev/hda1(the/dev

portionisdroppedwhenspecifyingthedeviceinthedisk

configurationline).Thephysicaldevicecanbeadiskor

partition,anditshouldbeexportedaccordinglytotheDomU,

usingthesecondelementofathree-tupleinthedisk

parameter.Ifyouexportanentirephysicaldisksuchashdaor

sda,itshouldbeexportedasanentiredisk—forexample,xvda

(orsimilarlysdaorhda)toDomU.Similarly,ifyouexportjust

onepartitionofphysicaldisksuchashda1orsda1,itshouldbe

exportedasapartition—suchasxvda1(orsimilarlysda1or

hda1)totheDomU.Agoodgeneralreferenceonpartitionsis

TheLinuxDocumentationProject'sLinuxPartitionHOWTO

(http://tldp.org/HOWTO/Partition/intro.html).

Thephy:prefixisnottheonlypossiblelocationfortheguest

image.Itcanalsobeapathtoafileinwhichaguestimageis

stored(forexampletap:aio:,file:,ortap:qcow:).Inthis

casetherecommendedprefixistap:aio:.ThistellsDomain0

tousetheblktapdriverwithasynchronousI/O(aio).The

tap:aio:prefixisthenfollowedbythepathtotheguestimage

filefoundwithintheDomain0filesystem.Anexampleusageof

tap:aiocanbefoundinListing5.2.Inthisexample,the

tap:aio:prefixisused,whichmeanstheblktapdriverwillbe

used.Thefileexportedis/xen/images/debian.partition.

DomUwillseetheimagepartitionas/dev/xvda1anditwill

havewriteaccess.

Listing5.2.SimpleExampleofUsingtap:aio:Prefixin

DiskParameter

disk=['tap:aio:/xen/images/debian.partition,xvda1,w']



NoticethatthefileisexportedtoDomUasxvda1justlikeinthe

caseofaphysicaldisk.FromtheDomU'sperspective,theyare

indistinguishable.YoucanalsousetheblktapdriverwithQEMU

Copy-On-Write(qcow)file-basedimagebyspecifyingthe

tap:qcow:prefix.OtherimageformatssuchasVMware's

VirtualDiskMachine(VMDK)andMicrosoft'sVirtualHardDisk

(VHD)arenotavailableforusedirectlywiththeopensource

versionofXenduetolicensingissues.However,Microsoft'sVHD

formatisavailableasofXenEnterpriseversion3.0,dueto

licensingagreementsbyXenSource.Microsoft'sVHDformathas

alsobeenreleasedbyMicrosoftinitsOpenSpecification

Promise,andasaresult,supportforthisformatisunder

developmentfortheopensourceversionofXen.Wedescribe

convertingimagesfromothervirtualizationsystemsinto

formatscompatiblewiththeopensourceversionofXenlaterin

thischapter.

Thereisanother,albeitdeprecated,waytospecifyaguest

imageintheDomain0filesystem,usingthefile:prefix,which

youarelikelytoseeinolderprebuiltimages.Whenthefile:

prefixisspecified,theloopbackdriverisusedratherthanthe

blktapdriver.Theloopbackdrivermakesuseofaspecial

variationofablockdevicebackedbyanordinaryfilecalleda

loopbackdevice.Problemsareoftenassociatedwithusing

loopbackdevices.Theperformance,scalability,andsafety

propertiesofthetheloopbackdriverareinferiortotheblktap

driver.Also,thenumberofloopbackdevicesislimitedbya

kernel/initrdoption(seethekernelmoduleparameter

CONFIG_BLK_DEV_LOOPfordetails),sothereisthedangerof

exceedingthatlimitwhenusingmanyfile-backedDomUguests.

Listing5.3showsanexampleofusingthefile:prefix,which

meanstheloopbackdriverwillbeused.Thefileexportedinthis

exampleis/xen/images/debian.partition.TheDomUwill

seetheimagepartitionatruntimeas/dev/xvda1,andthe

DomUwillhavewriteaccess.

Listing5.3.SimpleExampleofUsingtheDeprecated



file:PrefixinDiskParameter

disk=['file:/xen/images/debian.partition,xvda1,w']



Note

SomeinstallationsofXen,includingthe3.1version

installedonsomeUbuntu-basedsystems,suchas

Ubuntu7.04,haveabugcausingtap:aionottowork,

sofallingbacktofile:mightbenecessaryinsome

cases.Seethebugreportforbug#69389onUbuntu's

launchpadsystemat

https://bugs.launchpad.net/ubuntu/+source/xensource-2.6.17/+bug/69389.



XenDomUguestimagescanalsobeimportedoverthe

network,asisthecasewhenusingNFS(forexample,

nfs_server,nfs_path,androotparametersasshownlaterin

thischapteranddiscussedinmoredetailinChapter8,"Storing

GuestImages").Additionalmethodsofimportingaguestimage

overthenetwork,suchasiSCSIorATAoverEthernet(AoE),

usethephy:prefixbecauseDomain0seestheexported

networkblockdevicein/dev(ordirectorywithin/dev).In

thesecases,youshouldalsousethephy:prefixandspecifythe

pathtothenetworkblockdevicerelativeto/dev,justasifit

werealocaldisk.Forexample,whenusingiSCSI,youshould

usethedevicenodenamethatisgiventotheDomain0byudev

(theautomaticdevicemanagementsystemusedonmost

modernLinuxdistributions),becausethesd*blockdevicenode

willnotnecessarilybeconsistenteachtimetheiSCSIdeviceis

attached(toDomain0).Thebestwaytodothisisbyusingthe

disk/by-uuidentry,whichisactuallyasymboliclinktothe



corresponding/dev/sd*entry.

Listing5.4showsanexampleofiSCSI.Weexaminethedetails

ofiSCSIingreaterdetailinChapter8.Inthisexamplethe

exporteddevicewillbe/dev/disk/by-uuid/210936e7-6cc8401f-980f-d31ec982ffa5,whichisactuallyasymboliclinkthe

correspondingsd*devicenodefoundin/dev/.TheDomUwill

seethedeviceas/ev/xvda,anditwillhavewriteaccesstothe

device.Beadvisedthattheby-uuidsupportviathekerneland

udevwasnotsupportedinolderLinuxdistributions,although

wehavefoundgoodsupportinthemorerecentdistributions

thatwehavetested,suchasFedoraandUbuntu.

Listing5.4.AniSCSIExampleofaDiskParameterLine



disk=['phy:disk/by-uuid/210936e7-6cc8-401f-980f-d31ec982ffa5



ForAoE,asimilarstrategyusingudevisalsopossibleandhas

beenshowntoworkequallywell.However,AoEblockdevices

foundin/dev/etherd/shouldbecarefullymanagedina

consistentmanner,otherwisemultipleguestsmayusethesame

deviceandcausecorruption.InListing5.5,wedemonstrate

howyoumightexportanAoEdevicedirectlytoaDomU.We

examinethedetailsofAoEinChapter8.Inthisexample,the

exporteddevicewillbe/dev/etherd/e1.1,whichistheAoE

devicefoundinshelfoneandslotoneofthephysicalorlogical

Etherdrive.TheDomUwillseethedeviceas/dev/hda,andit

willhavereadaccesstothedevice.

Listing5.5.AnAoEExampleofaDiskParameterLine

disk=['phy:etherd/e1.1,hda,r']



ItisalsopossibletouseanNFSmountasarootfilesystemfor

yourDomU.Thismethod,however,isnotrecommendeddueto

performanceandstabilityissuesunderheavyload.Accordingto

theXenusermanual,theproblemsarewellknownintheLinux

NFSimplementationandarenotspecifictoXen.

ToconfigureanNFSservertobeusedfortherootfilesystemof

yourguest,youneedtospecifytherootconfiguration

parameteras/dev/nfs,specifythenfs_serverastheIP

addressoftheserver,andnfs_rootasthepathtotheexported

filesystemontheserver.Listing5.6showsanexampleofusing

NFSfortheDomUguestimage.Inthisexample,DomUuses

NFSasitsrootdevicewiththeserverandexportedpathas

specifiedbythenfs_serverandnfs_rootparameters.You

shouldbeawarethatnfs_rootsupportalsoneedstobe

compiledintotheDomUkernel.Thissupportisnottypically

compiledintothekernelbydefault.

TheNFSrootfilesystemmethoddoesnotrequiretheuseof

thediskparameter,becausetheDomUguestisusinganNFS

mountasitsrootfilesystem.Thediskparametercouldstillbe

usedtoaddothervirtualdrivesorpartitionsasdesired.AnNFS

rootexampleiscoveredinmoredetailinChapter8.

Listing5.6.AnNFSConfigurationExample



root='/dev/nfs'

nfs_server='2.3.4.5'#IPaddressofyourNFSserver

nfs_root='/export/myDomU'#exportedrootfilesystemonth



Weusedifferentvariationsofthediskparameterthroughout

thisandotherchapters.Forcompleteusageofthedisk

configurationoptionrefertoAppendixC,"XendConfiguration

Parameter."



Chapter5.UsingPrebuiltGuestImages

AgrowingnumberofprebuiltDomUguestimagesareavailable

fordownloadfromnumerouslocations.Theseimagesprovidea

quickwaytogetstartedrunningguestsonXen.Inthischapter,

wedemonstratehowtousethethreeprimaryprebuiltDomU

guestimagetypes:diskimages,partitionimages,and

compressedfilesystems.Weconsidertherelativeeaseand

spacerequirementsofeach.Additionally,thischapter

demonstrateshowtouseprebuiltimagesfromnon-Xen

virtualizationsystems,suchasVMware,andtoconvertthemto

becompatiblewithXen.



IntroductiontoDomUGuests

ADomUguestconsistsofthreethings:

Aguestimagethatcontainsasetoffilescomprisinga

completerootfilesystem

AnoperatingsystemkernelpossiblywithXenmodifications

Aconfigurationfilethatdescribestheresources,suchas

memory,CPUs,anddevicesgrantedbytheXenhypervisor

totheguest

Webeginbylookingateachofthesethreecomponentsin

detail.



GuestImages

Aguestimageisanyfile,physicaldiskpartition,orother

storagemediumthatcontainsthefullinstallationofan

operatingsystem.Thisincludessystemconfigurationfiles,

applicationbinaries,aswellasotherdatafiles.Thesimplest

andmostcommonexampleofaguestimageistheharddrive

ofatypicalnonvirtualizedcomputersystem.Inthiscase,the

operatingsystemisinstalledontoaphysicalharddrive,and

thustheharddrivecontainsallthefilesthatrepresentthe



workingsystem.

ForLinux,itistypicaltodecomposetheguestimageintotwo

pieces:onefortherootfilesystemandoneforswapspace.You

canalsochoosetoconfigureswapspaceaspartoftherootfile

systeminLinux.Theadvantageofsplittingthemintoseparate

partitionsisbeneficialwhentakingsystembackups.When

backingupanoperatingsystem,thereisnoneedtorecordthe

fundamentallyvolatilecontentsofaswappartition.Similarly,

thereisnoneedtorepresentthecontentsofswapinsidea

guestimagefilethatyoubackuporsharewithothers.

Windows,incontrast,doesnottypicallyseparatetherootfile

systemfromtheswaparea.Instead,thepagefile(arough

equivalentofLinuxswapspace)isusuallystoredontheCdrive,

theLinuxrootfilesystemequivalent.AfterWindowsisinstalled,

youcanconfigureittostoreitspagefileonaseparatepartition

ordisk.Havingtherootfilesystemandswappartitionon

differentphysicaldiskscanincreaseoverallperformance

becausenormaldiskaccessesandpaging(orswapping)

accessescanbemanagedseparately.



OperatingSystemKernels

Theguestoperatingsystemkernelisafilethatcontainsthe

operatingsystemexecutablethatmanagesresourcesforall

userlevelapplications.Thekernelfilecanbestoredeither

withintheguestimageorinanexternalfileonDomain0.

Bootloaders,suchasGRUB,provideachoiceofkernelstoboot.

Thesedifferentkernelsmightusethesamerootfilesystem,or

guestimage.Inthecaseofaguest,thekernelcaneitherbea

Xen-compatiblekernel(forparavirtualizedguests)oran

unmodifiedkernel(forfullyvirtualguests).



ConfigurationFiles

AconfigurationfiledefinestheresourcesthattheDomUguest

willhaveusingasetofparameterspassedtotheXen

managementtool(xm).Inessence,theconfigurationfile



specifieswhetheravirtualmachinewillbePVorHVMandwhat

typeofdevicestheguestshouldbegrantedbytheXen

hypervisor.Theconfigurationfileisalwaysafilestoredexternal

totheguestyetaccessibletoDomain0.Unlikeguestimages

andtheoperatingsystemkernel,aconfigurationfiledoesnot

haveanequivalentfileinnonvirtualizedmachines.Themost

directcomparisoninanonvirtualizedenvironmentwouldbea

listofspecificationsofthephysicalhardware.

TheparametersintheconfigurationfilespecifytheCPU,

memory,disk,andnetworkresourcesforaguest.Forthis

chapter,wefocusmostlyonthediskparameterofthe

configurationfileandsavethemoreadvancedfunctionalityfor

Chapter6,"ManagingUnprivilegedDomains."Weneedother

parametersincludingthekernel(operatingsystemkernel),

ramdisk(initialRAMdisk),memory,vif(virtualinterfaces),and

bootloaderconfigurationparameterstomakeworkingguests,

butwecovereachoftheseparametersinmoredetailinlater

chaptersandAppendixC.

Thediskparameterisusedtoexportguestimages.The

generalformatforthediskparameterisanarrayofthreetuples.(Atupleisanorderedlistofitems.Athree-tuplehas

threelistitems).Thefirstitemofthethree-tupleisforthe

locationoftheguestimageasseenbyDomain0.Thesecond

itemofthethree-tupleisthelocationoftheguestimageas

seenbytheguest,orthedeviceonwhichtheguestimage

appearstothatDomU.Thethirditemofthethree-tupleisthe

accesspermissionthattheDomUhastotheguestimage.An

exampleofhowtousethediskparameterintheconfiguration

fileisshowninListing5.1.

Listing5.1.AnExampleoftheDiskParameter

disk=['phy:hda1,xvda1,w']



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 5. Using Prebuilt Guest Images

Tải bản đầy đủ ngay(0 tr)

×