Managing virtual machines#
With Microsoft Hyper-V, you can use the PowerShell command-line interface or the Management Virtual Machine UI, which contains all your remote server administration tools to administer your hosted environment and resources.
The following instructions are for self-service. If you want the Rackspace Microsoft Hyper-V Support team to perform any of the following tasks, create a support ticket.
Start or resume a virtual machine#
- Use the following command to start or resume a virtual machine by using
PowerShell:
To start a particular virtual machine, run the following command with name of the virtual machine:
Start-VM -Name <virtualMachineName>
To resume a particular virtual machine that has been left in a paused state, run the following command with name of the virtual machine:
Resume-VM -Name <virtualMachineName>
- Use the following instructions to start or resume a virtual machine by using the
Management VM:
- To start up the virtual machine, select
Start
from the right-hand action list. - To resume the virtual machine from a paused state, click
Resume
from the right-hand action list.
- To start up the virtual machine, select
Shut down a virtual machine#
To shut down a virtual machine by using PowerShell through the guest operating system, use the following command for a graceful shut down:
Stop-VM -Name <virtualMachineName>
If the graceful shut down doesn’t work, you can force the VM to shut down by using the following command:
Stop-VM -Name <virtualMachineName> -TurnOff
Note
For more information on stopping VMs, see the Stop-VM Microsoft documentation.
To shut down a virtual machine by using the Management VM, select the virtual machine that you want to shut down from the centered list.
- To gracefully power down the virtual machine, select
Shut down
from the right-hand action list. - If the graceful shut down doesn’t work, you can force the VM to shut
down by selecting
Turn off
from the right-hand action list.
- To gracefully power down the virtual machine, select
Checkpoint a virtual machine#
Note
The Hyper-V PowerShell module has several aliases. The terms checkpoint
and snapshot
can be used interchangeably.
This document uses checkpoint.
Microsoft Hyper-V utilizes a standard checkpoint. A standard checkpoint takes a snapshot of the virtual machine and virtual machine memory state at the time the checkpoint is initiated. A checkpoint is not a full backup and can cause data consistency issues with systems that replicate data between different nodes, such as Active Directory.
Warning
As checkpoint files grow, it can affect all virtual machines on the hypervisor. For this reason, Rackspace recommends keeping no longer than a two-day checkpoint. After this time, you can delete the checkpoint, or Rackspace can revert to the checkpoint and original disks.
Use the following command to snapshot a virtual machine by using PowerShell:
Checkpoint-VM -Name <virtualMachineName>
Use the following instructions to create a checkpoint by using the Management VM:
- In the Management VM, select the virtual machine that you want to checkpoint.
- Right-click the name of the virtual machine, and then click
Checkpoint
. - When the process is complete, the checkpoint appears under
Checkpoints
in the Management VM.
Reverting a checkpoint#
If you want to revert your virtual machine to a previous point in time, you can apply an existing checkpoint.
Use the following commands to apply a checkpoint by using PowerShell:
Get a list of checkpoints for a virtual machine by using the following command:
Get-VMCheckpoint -VMName <virtualMachineName>
Apply the checkpoint by using the following command:
Restore-VMCheckpoint -Name <checkpointName> -VMName <virtualMachineName> -Confirm:$false
Use the following instructions to revert a checkpoint by using the Management VM:
In the Management VM, under
Virtual Machines
, select the virtual machine to which you want to apply a checkpoint.In the
Checkpoints
section, right-click the checkpoint that you want to use and clickApply
.A dialog box appears with the following options:
Create Checkpoint and Apply
: Creates a new checkpoint of the virtual machine before it applies the earlier checkpoint.Apply
: Applies only the checkpoint that you have chosen. You cannot undo this action.Cancel
: Closes the dialog box without doing anything.
Select either
Apply
option to create and apply the checkpoint.
Delete a checkpoint#
Deleting checkpoints can help create space on your Hyper-V host. Checkpoints are
stored as .avhdx
files in the same location as the .vhdx
files for the
virtual machine. When you delete a checkpoint, Hyper-V merges the .avhdx
and
.vhdx
files for you. After the merge completes, the checkpoint's .avhdx
file is deleted from the file system.
Note
You should not delete the .avhdx
files directly.
Use the following commands to delete a checkpoint by using PowerShell:
Remove-VMCheckpoint -VMName <virtualMachineName> -Name <checkpointName>
Use the following instructions to delete a checkpoint using the Management VM:
- In Management VM, in the
Checkpoints
section, right-click the checkpoint that you want to delete, and the clickDelete
. - Confirm that it is the correct checkpoint, and then click
Delete
.
- In Management VM, in the
For more information on managing Hyper-V checkpoints, see the Microsoft Work with Checkpoints.
Export virtual machines#
Note
The Hyper-V PowerShell module has several aliases. The terms export
and clone
can be used interchangeably.
This document uses export.
An export gathers all required files into one unit: virtual hard disk files, virtual machine configuration files, and any checkpoint files. This function can be performed when the machine is running or stopped.
To export a virtual machine by using PowerShell, open a session as Administrator and run the following command:
Export-VM -Name <virtualMachineName> -Path <path>
Use the following instructions to export a virtual machine by using the Management VM:
- In the Management VM, right-click the virtual machine that you want to
export and select
Export
. - Choose where to store the exported files, and then click
Export
.
- In the Management VM, right-click the virtual machine that you want to
export and select
Resize virtual hard disks#
Resizing a virtual hard disk shrinks or expands the size of the disk. Resizing the virtual hard disk is an offline operation. The virtual hard disk must not be attached when the operation is initiated.
Important
When considering resizing virtual hard disks, keep in mind that .vhd
files
cannot be shrunk, only expanded, whereas .vhdx
files can perform both functions.
Rackspace recommends using .vhdx
files.
Use the following command to resize a virtual hard disk by using PowerShell:
Resize-VHD -Path <path> -SizeBytes <size>
Note
-Path
and-SizeBytes
are required parameters when running this command. For more information, see the PowerShell documentation forresize-vhd
.Use the following instructions to resize a virtual hard disk by using the Management VM:
In the
Actions
pane, clickEdit Disk
.On the introductory page, click
Next
.Browse for the location of the disk that you want to edit.
Choose to
Expand
orShrink
(.vhdx
only) the virtual hard disk. If the VM is off, you will see additional options. ClickNext
.Choose the new size of the disk in GB, and then click
Next
.A progress dialog box appears. Shrinking a virtual hard disk happens instantly, but expanding takes some time.
Reimage a virtual machine ~~~~~~~~~~~~~~~~~~~~~~~~Z
Reimaging your virtual machine involves removing the primary operating system drive from the virtual machine and attaching a new one.
You might reimage your VM if you want to upgrade to a new version or to a completely new operating system.
If you have a managed or unmanaged virtual machine from Rackspace and you want to reimage, submit a ticket to your Rackspace Microsoft Hyper-V Support team
Making a virtual machine highly available#
Use the following commands to make a virtual machine highly available (HA) by using PowerShell:
Create a virtual machine specifically for HA. Ensure that the VM has a memorable name:
New-VHD -Path <PathToVHDXFile> -Dynamic -SizeBytes <size> –SwitchName <switchName> –BootDevice <deviceType> -VHDPath <PathToVHDXFile>
Assign the location and the memory size:
New-VHD -Name <name> -Path <PathToVMFolder> -Memory <memory>
Specify that this VM will be installed from an
.iso
file:Add-VMDvdDrive -VMName <virtualMachineName> –Path <PathtoISOFile>
Configure the virtual machine for high availability:
Set-VM –Name <virtualMachineName> –AutomaticStartAction Nothing
Add-ClusterVirtualMachineRole -VirtualMachine FailoverTest
Use the following instructions to make a virtual machine highly available by using the Management VM:
Ensure that the VM is built and is running on your local hypervisor.
In the left-hand panel, click on
Failover Cluster Manager
.Right click on
Roles
in the cluster manager and then clickConfigure Role
.The
High Availability Wizard
displays. ClickNext
to continue.Scroll through the dialog box and select the
Virtual Machine
role.Select the virtual machine(s) that you want to configure for high availability, and then click
Next
.The wizard configures your chosen VM as a highly available role.
Close the dialog once the wizard is complete.
Remove and delete virtual machines#
The Remove-VM
cmdlet deletes a virtual machine. Running this cmdlet deletes
the virtual machine's configuration file but does not delete any virtual hard
drives. If the virtual machine has any checkpoints, these are deleted and merged
into the virtual hard disk files after the virtual machine is deleted.
If you want to remove or delete a virtual machine from your environment, submit a ticket with your Rackspace Microsoft Hyper-V Support team.