Procedures (Virtual Machine): Difference between revisions
m (Update table formatting) |
m (→Increase Disk Size: Fixed internal link to VM troubleshooting) |
||
Line 83: | Line 83: | ||
The trick is to extend the logical partition within the OS. Depending on the original partition type and the OS, the options vary. | The trick is to extend the logical partition within the OS. Depending on the original partition type and the OS, the options vary. | ||
''In-case of problems, see - [[Troubleshooting_( | ''In-case of problems, see - [[Troubleshooting_(Virtual_Machine)#Can.27t_Increase_a_VM.27s_Disk|Can't Increase a VM's Disk]], or [[Windows_2008#Extend_Partition_Fails|Extend Partition Fails]] | ||
=== Increase Logical Partition === | === Increase Logical Partition === |
Revision as of 10:36, 2 July 2012
Basic Virtual Machine Tasks
Start / Stop / Bounce a VM
- Log into the Virtual Infrastructure
- Under the Inventory button, ensure Hosts and Clusters is ticked
- Highlight the Virtual Machine (VM) you want to affect
- Either right-click or use the commands in the right hand pane to Power off, Power on, Reset as required
This is the same as using the Power or Reset buttons on the front of a physical server. It's possible to send Windows shut down etc commands to the VM; right click over the VM and select the appropriate Shut Down Guest, Restart Guest command. This tells VM Tools to attempt to perform the required action, obviously open applications etc can inhibit the successful shutdown of an OS.
Remote Console (KVM like) Access
If possible, its preferable to use normal remote access software (eg RDP, or VNC). This ensures that load caused by remote access is contained within the VM, rather than the ESX.
- Log into the Virtual Infrastructure
- Under the Inventory button, ensure Hosts and Clusters is ticked
- Highlight the VM you want and either right click Open Console or use the Open Console command in the right hand pane
CD-ROM Access
There are essentially two ways to present a CD-ROM image to a Virtual Machine (VM), using an ISO image is by far and away the most flexible. Even if you only have a physical CD and expect to use it once, its still recommended that you create an ISO image from the CD and use that instead. The alternative is to put the physical media into the ESX hosting the VM (use Host Device when adding the CD to the VM).
To present an ISO image to a VM
- If its not already there, copy the ISO image to an NFS share or other ESX accessible datastore
- Log into the Virtual Infrastructure
- Under the Inventory button, ensure Hosts and Clusters is ticked
- Highlight the VM you want to attach the ISO image to
- Right-click and select Edit Settings...
- Highlight the CD/DVD Drive, and select the Datastore ISO file
- Hit Browse and go into the appropriate datastore
- Select the required ISO file
- Tick the Connected check box
- Hit OK, the ISO will be attached to the VM's CDROM drive as if you'd inserted a CD into a physical drive
- Once you've finished using the ISO, go back into the VM's settings and untick the Connected check box
- To boot a VM to a CD-ROM ISO, check the "Connected at power on" checkbox and restart the VM's OS
To create an ISO image
You'll need to download an ISO creator, there are many freeware utilities available, however one that's tried and tested is ISORecorder. Generally you can create ISO images from both a physical CD, or just the contents of a folder (if you have ISORecorder installed, right-click over the disk or folder and select "Create ISO image")
Change Network Connection
In similar fashion to being able to swap over a network cable for a physical server, the network connection of a virtual machine can be changed on the fly
- Log into the Virtual Infrastructure - Management Access
- Under the Inventory button, ensure Hosts and Clusters is ticked
- Highlight the VM you want to change the network connection on
- Right-click and select Edit Settings...
- Highlight the appropriate Network Adapter, and select the new Network Connection
- Change takes effect as soon as OK is hit
Add an Additional Network Connection
When adding additional network connections to any system you must consider network security, for example no system should ever be given access to both Private and Public networks.
- Shut down the Application and OS of the virtual machine
- Log into the Virtual Infrastructure - Management Access
- Under the Inventory button, ensure Hosts and Clusters is ticked
- Highlight the VM you want to add the network connection to
- Right-click and select Edit Settings...
- Hit the Add... button and select Ethernet Adapter, and hit Next
- Select the appropriate network connection and hit Next, and then Finish
- Power on the virtual machine
Change Physical Memory / CPU's Allocation
- Shut down the Application and OS of the virtual machine
- Log into the Virtual Infrastructure - Management Access
- Under the Inventory button, ensure Hosts and Clusters is ticked
- Highlight the VM you want to change the network connection on
- Right-click and select Edit Settings...
- Highlight the appropriate setting, Memory or CPUs, and edit as required.
- Apply the change by hitting OK
- Power on the virtual machine
Install/Upgrade VM Tools on Citrix/Terminal Services VM
In a Terminal Services VM you can't install VM Tools in the normal automated fashion.
- Go into install mode
change user /install
- Install/upgrade VM Tools as normal
- Reboot, if you don't reboot you must go back into normal exec mode
change user /exec
Increase Disk Size
Increasing the virtual disk size provided to a VM is straight forward (though be aware that snapshots need to be deleted 1st, if any exist)...
- Go into the VM's settings
- Increase the size of the disk and apply
- Within the VM's OS, rescan the disk, and the new space will be visible
The trick is to extend the logical partition within the OS. Depending on the original partition type and the OS, the options vary.
In-case of problems, see - Can't Increase a VM's Disk, or Extend Partition Fails
Increase Logical Partition
Generally boot or system disks cannot be extended whilst the OS is up, whereas normal data disk can be in later OS's, but this is still not ideal. Its generally most reliable to plan for system down time, and use a utility to extend the partition whilst its offline. Especially in a virtual environment there is no excuse for not making a backup of the partition 1st.
For Windows 2008 machines this isn't a problem.
For Windows 2003 machines...
Partition | Type | Options |
---|---|---|
System | Either | Cannot be extended |
Data | Basic | Cannot be extended, can convert to Dynamic, but this will require at least a brief IO interruption, but up to two reboots! |
Data | Dynamic | Can be extended on the fly, but a new volume is tagged onto the end of the existing partition to create a larger one made up of two volumes |
Download a copy of the GParted Live CD - http://gparted.sourceforge.net/livecd.php, this will need to be booted to by the VM
- Note There is a bug in some recent versions of GParted (v0.5.0-3 and v0.5.1-1 are known to have issues), whereby the boot fails with the following error, v0.4.6-1 is known to work
Unable to find a medium containing a live file system
- Increase the relevant VMDK size through the VM's options
- Start snapshoting (or take a full backup of the machine)
- Attach GParted ISO to VM and restart
- If VM doesn't boot to the ISO, force the VM to boot to BIOS (Options | Advanced | Boot Options in VM Settings) and change the VM's boot order
- Boot into GParted Live (accepting the default options, except setting language to English UK)
- Once in GParted, follow the interface, and apply changes to action
- Restart VM and verify all is good
- Turn off snapshoting
VM's With Lots Of Disks
It can be very difficult to identify the correct disk within VMware to increase when a VM has a large number of VMDK's.
- Disk numbering behalves differently, with Windows starting at Disk 0, and VMware starting a Disk 1
- SCSI ID's will match, but Windows SCSI bus numbers are normally 0, whereas VMware bus numbers will increment (so VM disk 35 (Win disk 34), could be 2:4 in VMware, but 0:4 within the OS)
- Disk size can be a useful method of validation (if differing disk sizes are used)
- Windows drive letters are useless, never assume D: is disk 2 for example
Rename a VM
Renaming a virtual machine just by right-clicking over the machine and renaming does not alter the underlying file and folder names.
This is much easier than it was since the advent of storage vMotion. Bear in mind that the vCenter uses the VM's current name in order to determine the naming of its files/folders at it's destination, so to completely rename a VM...
- Rename the VM within its OS and restart
- Rename the VM within vCentre
- Storage vMotion the VM (can be moved back after)
Legacy methods...
To ensure that these changes take place you must move the VM to another datastore, ie
- Shutdown the VM
- Rename the VM in vCenter
- Migrate the VM and move it to another Datastore
- Restart the VM
If you can't move the VM to another datastore then it gets much more complicated, requiring faffing around in the service console.
- Shutdown the VM
vmware-cmd -s unregister /vmfs/volumes/datastore/vm/vmold.vmx
mv /vmfs/volumes/datastore/vm-old /vmfs/volumes/datastore/vm-new
cd /vmfs/volumes/datastore/vm-new
vmkfstools -E vm-old.vmdk vm-new.vmdk
find . -name ‘*.vmx*’ -print -exec sed -e ‘s/vm-old/vm-new/g’ {} \;
- For every file that hasn’t been renamed (.vmsd etc.)
mv vm-old.vmx vm-new.vmx
vmware-cmd -s register /vmfs/volumes/datastore/vm-new/vm-new.vmx
The above was taxed from http://www.yellow-bricks.com/2008/02/10/howto-rename-a-vm/
VMware have now published an article on this VM KB 1029513
Clone a VM
This can done as
- Hot clone - Source VM is left running, its disks are quiesced, and cloned. Can cause problems as new machine behaves as if it was ungracefully shutdown when first started, but normally successful. Source machine needs to be relatively quiet.
- Cold clone - Source VM is shutdown 1st, preferable to a warm clone if possible.
Snapshots and Cloning
Snapshots are deleted during a clone, in that cloning a machine that has existing snapshots results in the post-snapshot changes being merged into the new machine.
In order to retain the snaphosts, the virtual machine needs to be cloned manually (untested procedure!!)...
- Copy all of the VMs files into a new directory (using vmkfstools --nosparse option).
- Correct the .vmx file to match new paths, update VM name, and delete the UUID line (VMware will prompt to generate a new one when the VM is started).
- Register the new VM in vCentre and double check the VM is as expected.
- Power on (you'll get an IP conflict if its on the same portgroup as the original)
Shutdown VM via Service Console
- To determine state of an Virtual Machine running from the local ESX
vmware-cmd /vmfs/volumes/SAN1/ServerA/ServerA.vmx getstate
getstate() = on
- Shutdown a Virtual Machine running from the local ESX gracefully
vmware-cmd /vmfs/volumes/SAN1/ServerA/ServerA.vmx stop trysoft
stop(hard) = 1
- Shutdown a Virtual Machine running from the local ESX forcefully
vmware-cmd /vmfs/volumes/SAN1/ServerA/ServerA.vmx stop hard
stop(hard) = 1
The vmware-cmd
command isn't available in ESXi, though it is available via the RCLI, in the following format...
vmware-cmd.pl /path/to/My_VM.vmx start --server MyESX --username root --password "RootPassword"
Upgrade ESX3 to ESX4
Preparation
- Clean up the VM
- Stop any snapshots, and ensure there's no remnant snapshot files (*.vmsd, *-0000x.vmdk, *-delta.vmdk)
- No CD/floppy file attached
- Clean up the guest OS
- Delete unnecessary files
- Ensure VM Tools is up to date
- Perform a reboot (without any changes)
- Check logs to ensure machine started without any significant errors
- Record IP settings (they will get lost!)
ipconfig/all
route print
if there might be static/persistent routes
- Ensure you know the machines admin account (inc domain if on domain)
- Shut the VM down
Procedure
Procedure assumes your migrating machines from a VI3 infrastructure to a new VI4/vSphere infrastructure. Note that you can you VMware Converter to copy machines between vCentre's if preferred.
- Export machine as a Virtual Appliance from VI3 infrastructure
- In the VI Client, select the VM and go to File | Virtual Appliance | Export...
- See Virtual Machine won't export in case of probs)
- Import machine into new vSphere infrastructure
- In the VI Client, select the VM and go to File | Deploy OVF Template..., and select the appropriate options in the resulting wizard
- Take a snapshot (if you make an irreversible mistake its quicker to revert to snapshot than reimport)
- Check the VM's settings, particularly Guest OS (which sometimes gets set to Other)
- Start the virtual machine, update VM Tools then shutdown
- Upgrade the virtual hardware
- Right-click and select Upgrade Virtual Hardware
- Upgrade the network adapter to VMXNET3
- Remove existing network adapters (note the networks they're connected to!), then add the same quota of VMXNET3 adapters (connected to the same networks in the same order)
- Upgrade the SCSI controller - part 1 (if required)
- Add a new temporary disk, on the next bus (eg SCSI node 1:x)
- Then change the new SCSI controller type to VMware Paravirtual
- Restore network config
- Restart VM, and re-apply recorded network config (answer Yes when asked whether to remove duplicate config on non-existent adapter)
- Upgrade the SCSI controller - part 2 (if required)
- Shutdown the VM, and remove the temporary disk added, and change the original SCSI controller to VMware Paravirtual (the other controller will automatically get removed from the config)
- Restart the machine.
- Delete/Commit the snapshot
Windows 2008 Install
Use VMXNET3 network adapter. Only use Paravirtual SCSI interface if you're running at least ESX v4.1. You need to boot with the drivers on a floppy http://www.virtualinsanity.com/index.php/2009/12/01/more-bang-for-your-buck-with-pvscsi-part-2/
Convert Hardware v7 to v3
You'll need to download and install VMware Converter Standalone if haven't already got it installed (its free). The local installation will suffice (client-server not require). Its possible that you could get away with using the inbuilt vCentre version as long as you're not trying to import a v7 VM on ESX4 to a v4 VM on ESX3 (which you probably are!).
- Start up VMware Converter
- Hit the Convert machine button, top left
- On the resultant Source System page...
- Change Select source type: to VMware Infrastructure virtual machine
- Enter login details for the vCentre or ESX your v7 VM is on
- On the Source Machine page locate your v7 VM
- On the Destination System page, enter the login details of the vCentre or ESX where you want your v4 VM to be
- On the Destination Virtual Machine page, edit the VM name (if required) and select the destination folder
- If you're migrating to an vSphere VC/ESX you must set the Virtual Machine Version on this page
- On the Destination Location page select an appropriate datastore
- On the Options' you can make any tweaks you might want to
- Finally confirm
- Once the machine is imported, boot it up to ensure all is OK
- VM Tools will need to explicitly uninstalled and then reinstalled
- Especially if VM is a template, the OS may want to adjust its drivers given that it'll be running on different (virtual) hardware)