Virtual Disk Manager Users Guide
Virtual Disk Development Kit
Virtual Disk Manager Users Guide
Virtual Disk Manager Users Guide Item: EN-000046-01
You can find the most up-to-date technical documentation on the VMware Web site at: http://www.vmware.com/support/ The VMware Web site also provides the latest product updates. If you have comments about this documentation, submit your feedback to: [email protected]
2008 VMware, Inc. All rights reserved. Protected by one or more U.S. Patent Nos. 6,397,242, 6,496,847, 6,704,925, 6,711,672, 6,725,289, 6,735,601, 6,785,886, 6,789,156, 6,795,966, 6,880,022, 6,944,699, 6,961,806, 6,961,941, 7,069,413, 7,082,598, 7,089,377, 7,111,086, 7,111,145, 7,117,481, 7,149,843, 7,155,558, 7,222,221, 7,260,815, 7,260,820, 7,269,683, 7,275,136, 7,277,998, 7,277,999, 7,278,030, 7,281,102, 7,290,253, 7,356,679, 7,409,487, 7,412,492, 7,412,702, 7,424,710, and 7,428, 636; patents pending. VMware, the VMware boxes logo and design, Virtual SMP, and VMotion are registered trademarks or trademarks of VMware, Inc. in the United States and/or other jurisdictions. All other marks and names mentioned herein may be trademarks of their respective companies.
VMware, Inc. 3401 Hillview Ave. Palo Alto, CA 94304 www.vmware.com
VMware, Inc.
Contents
AboutThisBook
5 7
UsingVMwareVirtualDiskManager
AboutVirtualDiskManager 7 UsesofVirtualDiskManager 8 VMwareDiskMount 8 RunningVirtualDiskManager 8 ExamplesUsingVirtualDiskManager 10 CreatingaVirtualDisk 10 ConvertingaVirtualDisk 10 IncreasingtheSizeofanExistingVirtualDisk 10 RenamingorRelocatingaVirtualDisk 11 DefragmentingaVirtualDisk 11 ShrinkingaVirtualDisk 12
VMware, Inc.
Virtual Disk Manager Users Guide
VMware, Inc.
About This Book
ThisVMwaremanual,theVirtualDiskManagerUsersGuide,providesanintroductiontousingthe vmware-vdiskmanagercommandlineutility.
Revision History
Thisbookisrevisedwitheachreleaseoftheproductorwhennecessary.Arevisedversioncancontainminor ormajorchanges.Table P1summarizesthesignificantchangesineachversionofthisguide. Table P-1. Revision History
Revision Date 20070420 20070607 20080128 20080407 20080407 Description of Changes FirstversionoftheVirtualDiskManagerUsersGuide. UpdatewithsupportforLinuxhostsandremotevirtualdisks. Added-toption5forthecompressedstreamvirtualdisktype. Added-Soptiontoswitchremotesystemfromtargettosource. ReissuedwithVMwareWorkstation6.5andVMwareServer2.0.
Intended Audience
ThisbookisintendedforanyonewhousesVMwareVirtualDiskManager.Userstypicallyincludepeoplewho dosoftwaredevelopmentandtestingorworkwithmultipleoperatingsystemsorcomputingenvironments: systemadministrators,applicationdevelopers,QAengineers,andanyonewhowantstocreate,manage,and modifyvirtualdiskfilesfromscriptsoratthecommandline.
Documentation Resources
ToaccessthecurrentversionsofVMwareAPIandSDKdocumentation,goto: http://www.vmware.com/support/pubs/sdk_pubs.html ToaccessthecurrentversionsofotherVMwaremanuals,goto: http://www.vmware.com/support/pubs
Documentation Feedback
VMwarewelcomesyoursuggestionsforimprovingourdocumentation.Sendyourfeedbackto: [email protected]
VMware, Inc.
Virtual Disk Manager Users Guide
Technical Support and Education Resources
Thefollowingsectionsdescribethetechnicalsupportandeducationalresourcesavailabletoyou.
Online Support
YoucansubmitquestionsorpostcommentstotheDeveloperCommunitySDKsandAPIsforum,whichis monitoredbyVMwaretechnicalsupportandproductteams.Toaccesstheforum,goto: http://communities.vmware.com/community/developer
Support Offerings
TofindouthowVMwaresupportofferingscanhelpmeetyourbusinessneeds,goto: http://www.vmware.com/support/services
VMware Professional Services
VMwareEducationServicescoursesofferextensivehandsonlabs,casestudyexamples,andcoursematerials designedtobeusedasonthejobreferencetools.Coursesareavailableonsite,intheclassroom,andlive online.Foronsitepilotprograms andimplementationbestpractices,VMwareConsultingServicesprovides offeringstohelpyouassess,plan,build,andmanageyourvirtualenvironment.Toaccessinformationabout educationclasses,certificationprograms,andconsultingservices,goto: http://www.vmware.com/services/
VMware, Inc.
Using VMware Virtual Disk Manager
VMwareVirtualDiskManager(vmware-vdiskmanager)isautilitythatallowsyoutocreate,manage,and modifyvirtualdiskfilesfromwithinscriptsoratthecommandline.ItrunsonWindowsandLinuxsystems, andhasthesamecommandlineoptionsonboth. Thischaptercontainsthefollowingsections: AboutVirtualDiskManageronpage 7 RunningVirtualDiskManageronpage 8 ExamplesUsingVirtualDiskManageronpage 10
About Virtual Disk Manager
VirtualDiskManagermanipulatesvirtualmachinedisk(VMDK)files,whichinVMwaresystemssubstitute forphysicaldisk.OneofVirtualDiskManagerskeyfeaturesistheabilitytocloneandconvertvirtualdisks fromthelocalsystemtoaremotesystem,orfromaremotesystemtothelocalsystem. Anotherfeatureallowsyoutoenlargeavirtualdisksothatitsmaximumcapacityislargerthanwhenyou createdit.Ifyouneedmorediskspaceonagivenvirtualdiskbutdonotwanttoaddanothervirtualdiskor useghostingsoftwaretotransferthedataonavirtualdisktoalargervirtualdisk,youcanalterthemaximum sizeofthedisk.Thisisnotpossiblewithphysicalharddrives. Anotherfeatureallowsyoutochangedisktypes.Whenyoucreateavirtualmachine,youspecifyhowdisk spaceisallocated.Youhavetwochoicesforatotaloffouroptions: PreallocatedorgrowableAllspaceforthevirtualdiskisallocatedinadvance(flat),orallocatedspace beginssmallbutgrowsasneededforthevirtualdisk(sparse). SingleormultiplefilesVirtualdiskisstoredinonebigfile(monolithic),orstoredasaseriesofsmaller virtualdiskfiles(split). WithVirtualDiskManageryoucanchangewhetherthevirtualdisktypeisflatorsparse,monolithicorsplit. Youcanchangepreallocateddiskintogrowablediskasneeded,andchangewhetherthevirtualdiskisstored inasinglefileorsplitintomultiple2GBfiles. Forexample,youmightallocateallthediskspaceforavirtualdisk,butlateryoumightneedtoreclaimhard diskspaceonthehost.Youcanconvertthepreallocatedvirtualdiskintoagrowabledisk,andremovethe originalvirtualdiskfile.Thenewgrowablevirtualdiskislargeenoughtocontainallthedataintheoriginal virtualdisk,andmoreoverisabletogrowwhenyouadddatatoit. Asanotherexample,youcouldmoveavirtualmachinefromanoldVMwareserverthatcouldnothandlefiles largerthan2GB,convertingthesplitvirtualdiskintoasinglegrowablefile. Asathirdexample,youcanconverthosteddisktomanageddiskinaVMFSfilesystemonanESXhost. NOTEVirtualdiskmustbeoffline,withthevirtualmachinepoweredoff,formostoperations.
VMware, Inc.
Virtual Disk Manager Users Guide
Uses of Virtual Disk Manager
YoucanuseVirtualDiskManagerto: Automatethemanagementofvirtualdiskswithscripts. Createvirtualdisksthatarenotyetassociatedwithaparticularvirtualmachine.Thisisusefulformaking templatestospeedcreationofvirtualmachine. ConvertanexistinglocalvirtualdisktoaremoteESXvirtualdisk. Createacompresseddiskoptimizedforstreaming. Switchthevirtualdisktypefrompreallocatedtogrowable,orfromgrowabletopreallocated.Whenyou changethedisktypetogrowable,youreclaimsomediskspace.Youcanshrinkthevirtualdisktoreclaim evenmorediskspace. Expandthesizeofavirtualdisksoitislargerthanthesizespecifiedwhenyoucreatedit. Defragmentvirtualdisks. Prepareandshrinkvirtualdiskswithoutpoweringonthevirtualmachine. Renameandmovevirtualdisks. NOTEYoucannotuseVirtualDiskManagertocreateortoshrinkphysicalharddrives. YoucanuseVirtualDiskManagerwithvirtualdiskscreatedunderVMwareServer,VMwareWorkstation5 orhigher,VMwareFusion,VMwarePlayer,VMwareGSXServer,VMwareACE(unencrypteddisksonly),and VMwareESX/ESXiserver(onlypreallocateddisksoftype4).
VMware Disk Mount
SomediskmanagementactivitiesrequireyoutomountaVMDKasavolumeorfilesystemavailabletothe hostorguestoperatingsystem.SeetherelatedmanualVMwareDiskMountUsersGuideformoreinformation.
Running Virtual Disk Manager
BackupyourvirtualdiskfilesbycopyingthemelsewherebeforemakingchangeswithVirtualDiskManager. To run Virtual Disk Manager 1 Openacommandpromptorterminalonthehost. PathisprobablysetcorrectlybytheVMwareinstallation,butyoumighthavetochangetothedirectory whereyouinstalledVMwareVirtualDiskManager. 2 Typethevmware-vdiskmanagercommandtodisplayusageinformation.
Thecommandsyntaxisoneof:
vmware-vdiskmanager <options> <diskname> vmware-vdiskmanager <options> <drive|mountpoint>
Use<diskname>tospecifythenameofavirtualdiskfile(VMDK)thatyouwanttocreate,manage,ormodify. Thevirtualdiskfilemusthavea.vmdkextension.Youmayspecifyapathinfrontofthefilename.Forexample: C:\DocumentsandSettings\<user>\My Documents\MyVirtualMachines\VMname\newvmdisk.vmdk (onaWindowshost)or/path/to/disk/newvmdisk.vmdk(onaLinuxhost).Ifyoumappedanetworkshare onthehost,youcancreatethevirtualdiskonthatsharebyprovidingpathinformationwiththediskname. Use<drive|mountpoint>tospecifythedriveletterormountpointassociatedwithavirtualdiskthatwas mountedusingVMwareDiskMount.Youmustmountavirtualdisktoprepareitforshrinking. SeeTable 1,VMwareVirtualDiskManagerOptions,onpage 9foradescriptionofcommandlineoptions. SeeExamplesUsingVirtualDiskManageronpage 10forsamplecommandstoperformvarioustasks.
VMware, Inc.
Using VMware Virtual Disk Manager
Table 1. VMware Virtual Disk Manager Options
Option Parameters -c -d -k Description Createsalocalvirtualdisk.The-a,-s,and-toptions,andavirtualdiskname specifiedby<diskname>,arerequiredwhencreatingavirtualdisk. Defragmentsthevirtualdiskspecifiedby<diskname>.Youcandefragmentonly growablevirtualdisks,notpreallocatedorremotevirtualdisks. Shrinksthevirtualdiskspecifiedby<diskname>.Beforeyoucanshrinkavirtual disk,youmustprepareallitsvolumesforshrinkingusingthe-poption.Youcan shrinkonlygrowablevirtualdisks,notpreallocatedorremotevirtualdisks. Renamesthevirtualdisknamedby<sourcedisk>tothevirtualdisknamedby <targetdisk>.Byspecifyingdirectorypaths,youcanplacetherenamedvirtual diskinadifferentdirectory,eitherwithitsoriginalnameorwithanewname. Preparesthevirtualdiskmountedat<drive>(Windows)orat<mountpoint> (Linux)forshrinking.Ifthevirtualdiskispartitionedintodifferentvolumesorfile systems,youmustseparatelymountandprepareeachoneforshrinking. Converts(clones)thevirtualdisknamedby<sourcedisk>,creatinganewvirtual disknamedby<targetdisk>. Forlocal<targetdisk>the-toptionisrequiredtospecifytype. Forremote<targetdisk>onanESXhost,usethe-h,-u,and-foptions. Forthevirtualmachinetorecognizetheconvertedvirtualdisk,editthevirtual machinesettingstoremovetheexistingvirtualdiskfromthevirtualmachine,then addtheconverteddisktothevirtualmachine. -x <n>[GB|MB|KB] Expands(grows)thevirtualdiskspecifiedby<diskname>tothegivencapacity <n>,whichyoucanspecifyingigabytes(GB),megabytes(MB),orkilobytes(KB). Thenewcapacitymustbegreaterthantheoriginalcapacity.Youcanexpandlocal virtualdisksonly.Youcannotchangethesizeofaphysicalharddrive. DisablesVirtualDiskManagerlogging. Otherwise,messagesthatVirtualDiskManagergeneratesarerecordedinalogfile vdiskmanager.logstoredinatemporarydirectory. -a [ide|buslogic|lsilogic] Specifiesthediskadaptertype.Thisoptionisrequiredwhenyoucreateavirtual disk.Chooseoneofthefollowingadaptertypes: ideanIDEadapter,forcompatibilitywitholdsoftware. buslogicaBusLogicSCSIadapter,forhighperformance. lsilogicLSILogicSCSIadapter,forhighperformanceonnewsystems. -s <n>[GB|MB|KB] Specifiesthesizeofthevirtualdisk.Thisoptionisrequiredwhenyoucreatea virtualdisk.Youcanspecifydisksize<n>ingigabytes(GB),megabytes(MB),or kilobytes(KB).Sizemustbe1MB(2000sectors)orgreater. Donotusethe-soptionwhenyouexpandavirtualdisk;specifydisksizeusing the-xoptioninstead. -t [0|1|2|3|4|5] Specifiesthevirtualdisktype.Thisoptionisrequiredwhenyoucreateorconvert avirtualdisk.Chooseoneofthefollowingtypes: 0createagrowablevirtualdiskcontainedinasinglefile(monolithicsparse). 1createagrowablevirtualdisksplitinto2GBfiles(splitsparse). 2createapreallocatedvirtualdiskcontainedinasinglefile(monolithicflat). 3createapreallocatedvirtualdisksplitinto2GBfiles(splitflat). 4createapreallocatedvirtualdiskcompatiblewithESXserver(VMFSflat). 5createacompresseddiskoptimizedforstreaming. -h <hostname> -u <username> -f <passwordfile> -P <portNumber> -S SpecifiesthehostnameorIPaddressofaremoteESXhost. SpecifiestheusernameforconnectingtoaremoteESXhost. Specifiesthenameandlocationofaplaintextfilethatcontainsthepasswordfor connectingtoaremoteESXhost. SpecifiesaTCPportnumberforcommunicatingwiththeremoteESXhost.Thisis optionalanddefaultsto902. Switchestomakethesourcevirtualdiskremote,insteadofthetargetdiskremote.
-n <sourcedisk> <targetdisk>
-p
-r <sourcedisk> <targetdisk>
-q
VMware, Inc.
Virtual Disk Manager Users Guide
Examples Using Virtual Disk Manager
ThefollowingexamplesillustratehowtouseVirtualDiskManager. NOTEAlwaysbackup(copy)yourvirtualdiskfilesbeforechangingsize,defragmenting,orrenamingthem.
Creating a Virtual Disk
To create a new virtual disk ChangedirectorytothelocationwhereyouwantthenewVMDKandtypethiscommand:
vmware-vdiskmanager -c -a lsilogic -s 40GB -t 0 mydisk.vmdk
Thiscreatesa40GBSCSIvirtualdisknamedmydisk.vmdk.Typezeromeansthatthespaceiscontainedina singlevirtualdiskfile,andthatdiskspaceisgrowable,notpreallocated.
Converting a Virtual Disk
To convert a virtual disk from preallocated to growable AssumingsourceDisk.vmdkexistsastype2or3,typethiscommandtoconvertit:
vmware-vdiskmanager -r sourceDisk.vmdk -t 0 targetDisk.vmdk
ThisconvertsthediskfromitsoriginalpreallocatedtypetoagrowablevirtualdiskconsistingofoneVMDK file.VirtualDiskManagerreclaimssomespaceinthevirtualdisk,sotheVMDKneedstobeonlyaboutaslarge asthedataitcontainedatconversiontime. To convert a local virtual disk to a remote ESX virtual disk Forthisconversion,specifytype4forVMFSvirtualdisk,withremotediskoptions:
vmware-vdiskmanager -r sourceDisk.vmdk -t 4 -h esx3.example.com -u admin -f password.txt "[storage1] <VMname>/targetDisk.vmdk"
ThisconvertsthelocalvirtualdisktoremotevirtualdisklocatedonthespecifiedESXhost.Afterconversion iscompleteandyouhavetestedtheconvertedvirtualdisktomakesureitworksasexpected,youmaydelete theoriginalvirtualdiskfile.Ifyoudeletetheoriginalfile,alsoremoveitfromanyvirtualmachinethatusesit. Toremoveit,chooseVM>Settings>Hardware,selectthevirtualdisk,andclickRemove. FortheESXhosttorecognizetheconvertedvirtualdisk,youmustaddthedisktothevirtualmachine.Choose Inventory>VirtualMachine>EditSettings,clickAdd,andfollowthewizardpromptstoaddtheconverted virtualdiskfile. CAUTIONWhencloningtoaremoteESXhost,VirtualDiskManageroverwritesanypreexistingVMDKfile. Thiscouldresultinlossofdata.Whencloningtolocaldisk,thedestinationVMDKisnotoverwritten.
Increasing the Size of an Existing Virtual Disk
To expand (grow) a virtual disk SpecifysizeandgivethefullpathtotheVMDK,orchangedirectorytoitslocation:
vmware-vdiskmanager -x 80GB mydisk.vmdk
Thisincreasesthemaximumcapacityofthevirtualdiskto80GB.Unlikedefragmentingandshrinking,you mayincreasethesizeofpreallocatedvirtualdisks(flattype2or3). VirtualDiskManagerexpandsthevirtualdiskbutdoesnotmodifyitscontents,sothepartitioninformation remainsthesame.Manyoperatingsystemscannotalterpartitionsizeaftercreation,soyoumighthaveto obtainthirdpartysoftware,suchasPartitionMagicorGNUParted,todothis.Suchsoftwareallowsyouto alterdiskpartitionssoavirtualmachinecanaccesstheadditionaldiskspace. Anothermethodofincreasingpartitionsize,easierinsomecases,wouldbetouseVMwareConverter.
10
VMware, Inc.
Using VMware Virtual Disk Manager
Renaming or Relocating a Virtual Disk
To rename or relocate a virtual disk 1 Removethevirtualdiskfromanyvirtualmachinethatcontainsthedisk. ChooseVM>Settings>Hardware,selectthevirtualdisk,andclickRemove. 2 Typeoneofthefollowingcommands: Torenamethevirtualdiskandkeepitinthesamelocation,type:
vmware-vdiskmanager -n mydisk.vmdk myNewDisk.vmdk
Torenamethevirtualdiskandlocateitinadifferentdirectory,type:
vmware-vdiskmanager -n mydisk.vmdk "..\<Another Path>\myNewDisk.vmdk"
OnLinuxhosts,type:
vmware-vdiskmanager -n mydisk.vmdk ../<anotherPath>/myNewDisk.vmdk
Tokeepthesamenamebutlocatethediskinadifferentdirectory,type:
vmware-vdiskmanager -n mydisk.vmdk "..\<Another Path>\mydisk.vmdk"
OnLinuxhosts,type:
vmware-vdiskmanager -n mydisk.vmdk ../<anotherPath>/
Addthevirtualdiskbacktoanyvirtualmachinesthatuseit. ChooseVM>Settings>Hardware,clickAdd,andfollowtheinstructionsinthewizard.
Defragmenting a Virtual Disk
To defragment a virtual disk Todefragmentalocalvirtualdisk,typethiscommand.
vmware-vdiskmanager -d myDisk.vmdk
Defragmentconsolidatessparsedisk,movingdatatolowernumberedsectors.Thisisindependentofany defragmentationtoolsintheguestoperatingsystem,whichworkonvolumesstoredinsidetheVMDK. Defragmentingdoesnotreclaimunusedspaceonavirtualdisk;todothis,youmustshrinkthedisk. Youcannotdefragment: Preallocatedvirtualdisks(flattype2or3) Physicalharddrives Virtualdisksthatareassociatedwithsnapshots. Followthisorderofstepswhendefragmentingandshrinkingvirtualdisk: 1 Runadiskfragmentationtoolinsidethevirtualmachine.Forexample,withaWindows98guestoperating system,runtheWindows98defragmentationtool. VMwarerecommendsthatyoudefragmentaguestsvirtualdiskbeforetakingthefirstsnapshotofa guest,orafterdeletingsnapshots.Otherwiseyoulosetheabilitytodefragmenttheguestsvirtualdisk, becauseafterasnapshot,changesaremadetotheredolog,nottheoriginalvirtualdisk.Moreover, defragmentationcanheavilymodifythevirtualdiskimage,resultinginaverylargeredolog. 2 3 4 Powerdownthevirtualmachineandusevmware-vdiskmanager-dtodefragmentitsvirtualdisk.This isthesameasclickingHardDisk>Utilities>Defragmentintheuserinterface. Runadiskfragmentationtoolonthehostcomputer,ifneeded.ModernfilesystemssuchasNTFSand Linuxext2andespeciallyext3arerelativelyresistanttodefragmentation. ShrinkthevirtualdiskasdescribedinShrinkingaVirtualDiskonpage 12.
VMware, Inc.
11
Virtual Disk Manager Users Guide
Shrinking a Virtual Disk
Ifyouhaveavirtualdiskthatgrowsasyouadddata,youcanshrinkthediskinordertoreclaimunusedspace. Ifthereisemptyspaceinthevirtualdisk,shrinkingreducestheamountofspacethattheVMDKfileoccupies onthehost.Shrinkingavirtualdiskdoesnotchangethemaximumcapacityofthevirtualdiskitself. PoweroffthevirtualmachinebeforeusingVirtualDiskManagertoprepareandshrinkgrowablevirtualdisks. Youcannotshrink: Preallocatedvirtualdisks(flattype2or3) Physicalharddrives Virtualdisksthatareassociatedwithsnapshots. Toprepareandshrinkthevirtualdiskinitscurrentstate,firstusethesnapshotmanagertodeleteexisting snapshots.Todiscardchangesmadesinceyoutookasnapshot,reverttothesnapshot. To shrink a virtual disk 1 UsetheVMwareDiskMountutilitytomountavolumeofthevirtualdisk.TheVMwareDiskMount utilityandtheVMwareDiskMountUsersManualareavailableontheVMwareWebsite. Changedirectorytothelocationofthevirtualmachine,forexampleWindows98,andrunvmware-mount:
cd C:\Documents and Settings\user\My Documents\My Virtual Machines\Windows98 vmware-mount M: Windows98.vmdk
OnLinuxhosts,type:
vmware-mount /path/to/vmware/guest/Windows98.vmdk /mnt/win98
UseVirtualDiskManagertopreparethevolumeforshrinking. OnWindowstypethiscommand,whereM:isthedriveletterwiththemountedvolume:
vmware-vdiskmanager -p M:
OnLinuxhosts,specifythemountpointinsteadofthedrive:
vmware-vdiskmanager -p /mnt/win98
Theprepareoperationzeroesoutunusedsectorssothatshrinkrecognizesthesesectorsasunusedspace. 3 UnmountthevolumeusingtheVMwareDiskMountutility:
vmware-mount /d M:
OnLinuxhosts,type:
vmware-mount -d /mnt/win98
4 5
Repeatthemounting,preparing,andunmountingstepsforeachvolumeofthevirtualdisk. NowuseVirtualDiskManagertoshrinkthevirtualdisk:
vmware-vdiskmanager -k Windows98.vmdk
12
VMware, Inc.