Thursday, October 13, 2011

Migrating virtual machines with storage vmotion


Storage vmotion enables you to migrate virtual machine and its disk files from one datastore to another while the virtual machine is running. You can choose to place the virtual machine and all its disks in a single location, or select seperate locations for the virtual machine configuration file and each virtual disk.The virtual machine does not change execution host during a migration with Storage vMotion.

During a migration with Storage vMotion, you can transform virtual disks from think-provisioned to thin-provisioned or thin-provisioned to thick-provisioned.

Example cases for Storage vMotion use:
  • Upgrading datastores withput virtual machine downtime: You can migrate running virtual machines from a VMFS2 datastore to a VMFS3 datastore, and upgrade the VMFS2 datastore without any impact on virtual machines. Then use Storage vMotion to migrate virtual machines back to the original datastore without any virtual machine downtime.
  • Storage maintenance and reconfiguration: Use Storage vMotion to move virtual machines off of a storage device to allow maintenance or reconfiguration of the storage device without virtual machine downtime.
  • Redistributing storage load: Use to manually redistribute virtual machines or virtual disks to different storage volumes to balance capacity or improve performance.
Storage vMotion Requirements and Limitations
  • Virtual machines with snapshots cannot be migrated using Storage vMotion.
  • Virtual machine disks must be in persistent mode or be raw device mappings(RDMs). For virtual compatibility mode RDMs, you can migrate the mapping file or convert to thick-provisioned or thin-provisioned disks during migration as long as the destination is not a NFS datastore. If you convert the mapping file, a new virtual disk is created and the contents of the mapped LUN are copied to this disk. For physical compatibility mode RDMs, you can migrate the mapping file only.
  • Migration of virtual machine during VMware Tools installation is not supported.
  • The host on which the virtual machine is running must have a license thata includes Storage vMotion.
  • ESX/ESXi 3.5 hosts must be licensed and configured for vMotion. ESX/ESXi 4.0 and later hosts do not require vMotion configuration n order to perform migration with Storage vMotion.
  • The host on which the virtual machine is running must have access to both the source and target datastores.
  • vSphere supports a maximum of 8 simultaneous VMotion, cloning, deployment, or Storage VMotion accesses to a single VMFS3 datastore, and a maximum of 4 simultaneous VMotion, cloning, deployment, or torage VMotion access to a single NFS or VMFS2 datastore. A migration with VMotion involves one access to the datastore. A migration with Storage vMotion invloves one access to the source datastore and one access to the destination datastore.
Running svmotion in Interactive Mode
You can run svmotion in interactive mode using the --interactive option. The command prompts you for the information it needs to complete the storage migration.
svmotion <conn_options> --interactive
When you use --interactive, all other options are ignored.

Running svmotion in Noninteractive Mode
In noninteractive mode, the svmotion command uses the following syntax:
svmotion [standard vCLI options] --datacenter=<datacenter_name> --vm <VM config datastore path>:<new datastore> [--disks <virtual disk datastore path>:<new datastore>,  <virtual disk datastore path>:<new datastore>]
Square brackets indicate optional elements, not datastores.
The --vm option specifies the virtual machine and its destination. By default, all virtual disks are relocated to the same datastore as the virtual machine. This option requires the current virtual machine configuration file location. See “To determine the path to the virtual machine configuration file and disk file”.
The --disks option relocates individual virtual disks to different datastores. The --disks option requires the current virtual disk datastore path as an option. See “To determine the path to the virtual machine configuration file and disk file”.

To determine the path to the virtual machine configuration file and disk file
1 Run vmware-cmd -l to list all virtual machine configuration files (VMX files).
vmware-cmd -H <vc_server> -U <login_user> -P <login_password> -h <esx_host> -l

C:\>vmware-cmd.pl --server vcenter -U root -P esxsvr40  -H esx1 -l
No virtual machine found.

C:\>vmware-cmd.pl --server vcenter -U root -P esxsvr40  -H esx2 -l

/vmfs/volumes/4e77768a-5e318913-6036-000c29f15a51/RDM_VM1/RDM_VM1.vmx

2 Choose the VMX file for the virtual machine of interest.
By default, the virtual disk file has the same name as the VMX file but has a .vmdk extension.
3 (Optional) Use vifs to verify that you are using the correct VMDK file.

To relocate a virtual machine’s storage (including disks)
1 Determine the path to the virtual machine configuration file.
2 Run svmotion, for example:
svmotion  --url=https://myvc.mycorp.com/sdk --datacenter=DC1 --vm=”[storage1] myvm/myvm.vmx:new_datastore”
The example is for Windows. Use single quotes on Linux.

To relocate a virtual machine’s configuration file, but leave virtual disks
1 Determine the path to the virtual disk files and the virtual machine configuration file.
2 Run svmotion, for example:
svmotion  <conn_options>  --datacenter='My DC' --vm='[old_datastore] myvm/myvm.vmx:new_datastore' --disks='[old_datastore] myvm/myvm_1.vmdk:old_datastore, [old_datastore] myvm/myvm_2.vmdk:old_datastore'
This command relocates the virtual machineʹs configuration file to new_datastore, but leaves the two disks (myvm_1.vmdk and myvm_2.vmdk) in old_datastore. The example is for Linux. Use double quotes on Windows. The square brackets surround the datastore name and do not indicate an optional element.

C:\>vifs.pl --server esx1.virtuallab.com --username root --password esxsvr40 -listds

Content Listing
---------------
Storage1
iSCSI_Shared

C:\>vifs.pl --server esx2.virtuallab.com --username root --password esxsvr40 -listds

Content Listing
---------------
datastore1
iSCSI_Shared

C:\>svmotion.pl --url=https://vcenter.virtuallab.com --datacenter="Virtual Lab"  --vm "[iSCSI_Shared]RDM_VM1/RDM_VM1.vmx:Storage1"
Enter username: Administrator
Enter password:
The virtual machine must be powered-on.

Storage vMotioned: RDM_VM1 virtual machine from [iSCSI_Shared] to [Storage1]
C:\>svmotion.pl --url=https://vcenter.virtuallab.com --datacenter="Virtual Lab"  --vm "[iSCSI_Shared]RDM_VM1/RDM_VM1.vmx:Storage1"
Enter username: Administrator
Enter password:

C:\>vifs.pl --server esx1.virtuallab.com --username root --password esxsvr40 -dir [Storage1]

Content Listing
---------------
RDM_VM1/
esxconsole-4e792094-92da-7cff-a065-000c29f15a5b/

C:\>vifs.pl --server esx1.virtuallab.com --username root --password esxsvr40 -dir [Storage1]RDM_VM1

Content Listing
---------------
RDM_VM1-50d32978.vswp
RDM_VM1-rdm.vmdk
RDM_VM1.nvram
RDM_VM1.vmdk
RDM_VM1.vmsd
RDM_VM1.vmx
RDM_VM1.vmxf
vmware-0.log
vmware-1.log
vmware.log


A trial to move RDM_VM1 virtual machine files from [Storage1] which is local to ESX1 host to [datastore1] which is local to ESX2 host failed and displays error message as ESX1 host don't have access to the datastore which is local to ESX2 host.

C:\>svmotion.pl --url=https://vcenter.virtuallab.com --datacenter="Virtual Lab"  --vm "[Storage1]RDM_VM1/RDM_VM1.vmx:datastore1"
Enter username: Administrator
Enter password:
Received an error from the server:
SOAP Fault:
-----------
Fault string: Unable to access the virtual machine configuration: Unable to access file [datastore1]
Fault detail: CannotAccessVmConfig

Migrate RDM_VM1 virtual machine files back to original datastore which is [iSCSI_Shared].

C:\>svmotion.pl --url=https://vcenter.virtuallab.com --datacenter="Virtual Lab"  --vm "[Storage1]RDM_VM1/RDM_VM1.vmx:iSCSI_Shared"
Enter username: Administrator
Enter password:

C:\>vifs.pl --server esx1.virtuallab.com --username root --password esxsvr40 -dir [iSCSI_Shared]RDM_VM1

Content Listing
---------------
RDM_VM1-a8371505.vswp
RDM_VM1-rdm.vmdk
RDM_VM1.nvram
RDM_VM1.vmdk
RDM_VM1.vmsd
RDM_VM1.vmx
RDM_VM1.vmxf
vmware-0.log
vmware-1.log
vmware-2.log
vmware.log

RDM_VM1 virtual machine has RDM disk mapping to iSCSI volume and it can not me Storage vMotioned to NFSStorage.
C:\>svmotion.pl --url=https://vcenter.virtuallab.com --datacenter="Virtual Lab"  --vm "[iSCSI_Shared]RDM_VM1/RDM_VM1.vmx:NFSStorage"
Enter username: Administrator
Enter password:
Received an error from the server:
SOAP Fault:
-----------
Fault string: Virtual disk 'Hard disk 1' is a mapped direct-access LUN which is not supported on the datastore 'NFSStorage'.
Fault detail: RDMNotSupportedOnDatastore

After replacing RDM disk with virtual disk, RDM_VM1 virtual machine can be Storage vMotioned to NFSStorage.

C:\>svmotion.pl --url=https://vcenter.virtuallab.com --datacenter="Virtual Lab"  --vm "[iSCSI_Shared]RDM_VM1/RDM_VM1.vmx:NFSStorage"
Enter username: Administrator
Enter password:

C:\>vifs.pl --server esx1.virtuallab.com --username root --password esxsvr40 -dir [NFSStorage]RDM_VM1

Content Listing
---------------
RDM_VM1-17f58f58.vswp
RDM_VM1-flat.vmdk
RDM_VM1.nvram
RDM_VM1.vmdk
RDM_VM1.vmsd
RDM_VM1.vmx
RDM_VM1.vmxf
vmware-0.log
vmware-1.log
vmware-2.log
vmware-3.log
vmware-4.log
vmware-log


svmotion (In Windows, svmotion.pl) help
NAME
    svmotion - move the storage of a virtual machine while it is running

SYNOPSIS
     svmotion <connection_options> --interactive

     svmotion <connection_options>
             --datacenter=<datacenter name>
             --vm  <VM config datastore path>:
                   <new datastore name>
             [--disks <virtual disk datastore path>:
                   <new datastore>,
                   <virtual disk datastore path>:
                   <new datastore>]

DESCRIPTION
    The svmotion command moves a virtual machine's configuration file, and, optionally, its disks, while the virtual machine is running. The *Basic System Administration* manual discusses how to use svmotion. You can use svmotion to initiate migrations for virtual machines running on either ESX or ESXi hosts.

    When you run svmotion, "--server" must point to a vCenter Server system.

    The "--vm" option specifies the virtual machine and its destination. By default, svmotion relocates all virtual disks to the same datastore as the virtual machine. Use the "--disks" option to relocate individual virtual disks to different datastores. You cannot relocate a virtual disk without relocating the virtual machine configuration file.

    The svmotion command supports both interactive or noninteractive mode.

  Interactive Mode
    To use the command in interactive mode, type "svmotion --interactive". The command prompts you for the information necessary to complete the storage migration. Use quotes around special characters on Windows systems.

    When you specify "--interactive", all other options are ignored.

  Noninteractive Mode
    In noninteractive mode, the svmotion command uses the following syntax:

     svmotion [<connection_options]  --datacenter=<datacenter_name>  --vm <VM config_ds_path>:<new_ds>  [--disks <virtual_disk_ds_path>:<new_ds>, <vdisk_ds_path>:<new_ds>]

    Square brackets indicate optional elements, not datastores.

OPTIONS
    connection_options
        Specifies the target server and authentication information if required. Run svmotion with "--help" for a list of all connection options.

        In non-interactive mode, all vCLI common options are supported. In interactive mode, command-line options are ignored and svmotion uses user input instead.

    --help
        Prints a help message for each command-specific and each connection option. Calling the script with no arguments or with "--help" has the same effect.

    --usage
        Prints a short usage string. The usage string is also displayed when the number or format of input parameters is incorrect.

    --interactive
        Starts interactive mode, where svmotion prompts you for all arguments. In interactive mode, svmotion does a sanity test on each option.

        Note: You must enclose strings that contain special characters in quotes when responding to prompts.

    --datacenter <datacenter_name>
        Datacenter that contains the virtual machine to be migrated. Surround the name in quotes if it contains white spaces or special characters.

    --disks <virtual_disk_datastore_path>:<new_datastore>...
        Locations of individual disks. The format is datastore path of the disk, colon, name of the destination datastore. If the path contains spaces or special characters, you must quote it. You can specify multiple datastore and destination pairs, separated by commas. If you do not specify this option, all virtual disks associated with a virtual machine are relocated to the same datastore as the virtual machine configuration file. Specify this option to locate individual virtual disks to different datastores.

        To keep a virtual disk on its current datastore, use the "--disks" option for that disk, with its current datastore as the
        <new_datastore>.

    --vm <VM_config_ds_path>:<new_ds>
        Specifies which virtual machine to move and to which datastore.

        <VM_config_ds_path> is the path to the virtual machine configuration file. If the path contains spaces or other special characters, you must quote it.

        <new datastore> is the name of the new datastore for the virtual machine configuration file or disk.

EXAMPLES
    These examples are formatted for readability. In general, the command should be all on one line.

    Start the interactive version.

         svmotion --interactive

    Relocate a virtual machine's storage (including disks) to new_datastore:

         svmotion --url=https://myvc.mycorp.com/sdk  --username=me                         --password=secret   --datacenter=DC1  --vm='[old_datastore] myvm/myvm.vmx:new_datastore'

    Relocate a virtual machine's storage to new_datastore, but leave the two disks (myvm/myvm_1.vmdk and myvm/myvm_2.vmdk) in old_datastore:

         svmotion  --datacenter='My DC'  --vm='[old_datastore] myvm/myvm.vmx:new_datastore'          --disks='[old_datastore] myvm/myvm_1.vmdk:old_datastore, [old_datastore] myvm/myvm_2.vmdk:old_datastore'

No comments: