• Export and import of a Hyper-V virtual machine. Exporting Hyper-V virtual machines. Script v2.0

    Annotation: This practical work is a detailed examination of the processes of exporting and importing virtual machines standard means Hyper-V and the concept of virtual machine snapshot.

    Export virtual machine

    Note. The practice material is based on the "Local Desktop Virtualization" section of the book "Understanding Microsoft Virtualizations Solutions" by M. Tulloch (Chapter 2).

    Export process virtual machine using Hyper-V is not difficult. The only parameter that needs to be specified is the path to save the virtual machine files. To export a VM, you need:

    The file storage location can be specified not only as a logical volume of the local hard drive, but also a directory on an external hard drive or remote server.

    The following figure shows the contents of the exported virtual machine folder:


    Rice. 10.3.

    config.xml- a file containing information about the original location of virtual files hard drives exported machine.

    In folder Virtual Machines there is a .exp file containing information about the exported virtual machine. During the import given file is converted into a configuration xml - file .

    In folder Virtual Hard Disks the virtual hard disk files of the exported machine are located.

    In folder Snapshots contains information about virtual machine snapshots (.avhd , .vsv , .bin ).

    Importing a virtual machine

    Note the features of importing Hyper-V virtual machines:

    1. You can import into Hyper-V only virtual machines of another Hyper-V server. Import virtual Machines Virtual PC or Virtual Server is not possible because the configuration of virtual machines created by these solutions differs from Hyper-V, despite the fact that all solutions use .vhd - virtual hard disk files.
    2. A virtual machine can only be exported once. As already noted, the .exp file created during export - a file of information about the virtual machine, is converted into an xml - configuration file during the import process. In this regard, if import errors occur, the only way to continue working with the imported virtual machine is to create a new one with a similar configuration based on the existing virtual hard disk files.

    To import a virtual machine, you need:

    We note once again that in case of an import error, in order to continue working with the virtual machine, you must create a new one, and at the connection stage virtual hard disk specify the hard disk file of the imported machine (see Fig. 10.6)

    Snapshots of the virtual machine (snapshot)

    A snapshot is the state of a virtual machine at a particular point in time. Snapshots are used to store information about states and return to them, if necessary (cancel changes since the picture was taken).

    You cannot take a snapshot of a suspended virtual machine. When creating several images, their chronological sequence can be formed - a tree of images.

    To create a snapshot, select the Snapshot item from the drop-down menu.


    Rice. 10.7.

    Once a snapshot has been created, an icon will appear in the Snapshots panel of Hyper-V Manager.

    To return a virtual machine to a snapshot state, you must apply it to the virtual machine (see Figure 10.9).


    Rice. 10.9.

    As shown in fig. 10.9, the following snapshot actions are available:

    • Apply- copy the state of the virtual machine from the selected snapshot to the active virtual machine. This returns the virtual machine to the state described in the selected snapshot. Any unsaved data in the active virtual machine will be lost.
    • Rename- command allows changes to the snapshot name.
    • Delete picture- command to delete files associated with the selected snapshot, the files of other snapshots will not be affected. Deleting does not change the current state of the active virtual machine.
    • Delete snapshot tree- allows you to delete the selected snapshot and all snapshots hierarchically subordinate to it. Deleting does not change the current state of the active virtual machine.

    Brief summary.

    As part of this practice, Hyper-V capabilities for exporting and importing virtual machines, as well as creating snapshots of the state of a virtual machine, were considered. The export and import functions are used to transfer a virtual machine from one Hyper-V server to another.

    Snapshots are typically used during the development, testing, and deployment of applications. Snapshots allow you to return the state of the virtual machine to the moment they were created, while any changes made since that time will be lost.

    Hyper-V - network configuration, creation of control points, import and export of virtual machines.

    By default, all Hyper-V virtual machines are essentially sandboxed and completely isolated from other computers and networks. And if you want your VM to interact with other VMs, physical computers, network and internet, you need to create a virtual switch. You can do this in the Hyper-V manager by clicking Virtual Switch Manager on its right panel.

    But first you must decide which virtual switch you are creating. And Virtual Switch Manager offers text description each type of switch.

    If you want yours to see and access files on the host PC and on your network, you need to select an external switch. The same option gives the VM access to the Internet. The internal and private switch options allow Hyper-V virtual machines to only communicate with each other. Once you have decided on this option, click on the button to create a virtual switch.

    Next, you must configure your virtual switch options. Here it is important to determine which network adapter of your computer you are connecting it to. Your computer may have a wired and wireless connection. Choose the right one.

    Clue. Let's say you want your virtual machine to access files on the host PC, but don't have access to the network or the internet. If your computer has a wired and wireless connection, connect the switch to something you don't use to access the internet. If you don't have a physical network cable, choose not WiFi connection. So the VM will only have access to the main PC and will be isolated from malicious software and external attacks.

    After you have created a virtual switch, you need to connect it to the virtual machine. In the central area of ​​the Hyper-V manager, click on the appropriate VM. Then in the lower right area, click on settings. Which will open the virtual machine settings.

    In the left pane, click the connection adapter option. If you don't see this option, click Add Hardware, and add network adapter. Useful feature- Bandwidth management that can control VM usage bandwidth your network. This adjustment ensures that the virtual machine has the necessary network connection, but it does not consume extra resources.

    At the very top of the network adapter settings, select the virtual switch you created and click OK. There is no need to configure anything else. Your virtual machine now has network access.

    Attention. Although many options can be changed in the settings of the VM itself, some of them that were set when the virtual machine was created can only be changed by turning it off.

    Create Hyper-V checkpoints

    If you, in your Windows 8.1, make any significant changes, such as installing desktop program or windows updates, a system restore point is created. That is, a copy of critical operating system files is saved, such as Windows registry before they change. And if something goes wrong, the change can be rolled back and reverted back to an earlier state of Windows.

    Hyper-V also has its own checkpoint function - . You can create this snapshot at any time. To do this, in the central panel of the Hyper-V manager, select the VM for which you want to create a snapshot and in the lower right corner of the control window, click on the checkpoint link.

    Created checkpoints displayed in the Hyper-V Manager Center. You can click on any of them and roll back the virtual machine to that point, export the snapshot, or delete it.

    Hyper-V - import and export of virtual machines

    Sometimes you may need to create a virtual machine and use it on another computer or keep a copy of the VM. Just create a VM, copy this file to another computer, and you won't be able to open it there. To import a virtual machine into Hyper-V, there is a special import and export option. To export a VM, select this option in Hyper-V Manager. In the lower right corner of the Hyper-V manager window, export options will be displayed. Click on it and you will be asked in which folder you want to save your copy of the VM. The export process is invisible and quite fast.

    • You can import a virtual machine that was previously exported to Hyper-V. To do this, without selecting the VM in the upper right corner of the Hyper-V manager window, click on the Import virtual machine link.

    • The Import Virtual Machine Wizard will open and ask you in which folder (not file) the saved copy of the VM is located.

    • Then you will see the name of the VM and the details of its creation. If this is what you need, click next.

    • Now you will be asked how you want to import the VM. There are three possibilities for this:
    1. Registered virtual machine. Used if you are doing a direct import. The VM is in the same folder it was exported to and you want to leave it there.
    2. Restoring a virtual machine. Used if the VM is not located in the folder where it was exported. For example, this is a copy made from the main image on the server.
    3. Copy of the virtual machine. It is used if you want to create a local copy of an existing VM, leaving the "master" intact, for example, to import it later on another PC. This option is also used if you are creating a copy of an already imported VM.

    Attention. If you import a VM without making a copy of it, any changes you make to it and any problems will remain with it, and you will effectively lose your clean master copy.

    • If you want to create a copy of the virtual machine, you will be asked where you want to save it.

    • The last step is to confirm the selected settings.

    Integrating additional services into the virtual machine

    Some operating systems, especially older ones Windows versions, do not provide network access or other desired functions. And you'll have to turn additional functions VM. You need to do this in a running virtual machine.

    These additional features, which are required for some operating systems, include the ability to move the mouse cursor between the main desktop and an open virtual machine. It also includes networking and USB support.

    On the action menu, click Install Integration Services. And you will load ISO file, containing software improving the functionality of the virtual machine.

    June 3, 2011 at 20:40

    PowerShell+Hyper-V

    • Virtualization

    I can't use gui...

    This is how my conversation began with a friend who, in a short period of time, had to export virtual machines from Hyper-V several times in a row. Typically, Hyper-V Manager (HVM) is used for this, which is installed along with the Hyper-V role under Windows Server 2008R2. I must confess that the interface of this program does not cause me any negative emotions. Of all the management software that Microsoft ships with Server, this one seems to me the most convenient and understandable (I compare, for example, with IIS Manager, which causes bewilderment among new users and outrage among those who used IIS 6 in 2003 Server). However, if you need to export or import a virtual machine in the amount of N-pieces in a period of t-time, then using Hyper-V Manager you can break the mouse button and hate Hyper-V terribly. This is where PowerShell comes to the rescue.
    Import-Module HyperV
    … And of course there is no such module in PowerShell by default. Microsoft decided that no one would write cmdlets to manage Hyper-V (really a wild idea). On the other hand, this world is full of people who are able and ready to simplify life for themselves and other users. This is how the PowerShell management Library for Hyper-V was born.
    The first thing to do is download this module + documentation, to your liking. (Both available at: http://pshyperv.codeplex.com/releases)
    Then you need to install this module. The process is not complicated (the installed install file gives itself away).
    Now you can work. We launch PowerShell, import the module (what is written in the subheading).
    And all the functions that we could use through HVM are available to us, here are some of them:

    Connecting to a virtual machine
    New-VMConnectSession

    Manipulating the state of virtual machines
    Get-VMState, Set-VMState, Convert-VmState,
    Ping-VM, Test-VMHeartBeat, Shutdown-VM, Start-VM, Stop-VM, Suspend-VM
    Get-VMKVP, Add-KVP, Remove-KVP, Get-VMJPEG

    Ability to make backups, export virtual machines and take snapshots
    Export-VM, Import-VM, Get-VMSnapshot, Choose-VMSnapshot, Apply-VMSnapshot, New-VMSnapshot ,Remove-VMSnapshot, Rename-VMSnapShot, Update-VMSnapshot, Get-VMSnapshotTree, Get-VmBackupScript

    Adding and removing Wirth. machines, setting their properties
    New-VM, Remove-VM, Set-VM, Get-VMCPUCount, Set-VMCPUCount, Get-VMMemory, Set-VMMemory, Set-VMSerialPort

    Disk controller management
    Get-VMDiskController
    Add-VMSCSIController, Remove-VMSCSIcontroller
    Get-VMDriveByController, Add-VMDRIVE, Remove-VMdrive
    Get-VMDiskByDrive, Add-VMDISK, Set-VMDisk, Get-VMDisk
    Get-VMFloppyDisk, Add-VMFloppyDisk
    Add-VMNewHardDisk

    Network interface management
    Get-VMNic, List-VMNic, Choose-VMNIC, Add-VMNIC, Remove-VMNIC, Set-VMNICAddress, Set-VMNICConnection, Get-VMNicport,
    Get-VMnicSwitch, Choose-VMSwitch, New-VMSwitchPort, Get-VMByMACaddress, Choose-VMExternalEthernet,
    New-VMExternalSwitch, New-VMInternalSwitch,New-VmPrivateSwitch

    Working with VHD files
    Get-VHDDefaultPath, Get-VHDInfo, New-VHD, Compact-VHD, Test-VHD,Convert-VHD,Merge-VHD,Mount-VHD, Unmount-VHD

    All the above commands speak for themselves.
    For example, to get the state of a virtual machine, just enter:
    List-VMState name virt. cars
    and as a result:

    In my example, there is only one virtual machine => I did not specify the parameters, but if you have a lot of them, then you should probably explicitly specify its name if you don’t want to wade through the console output later.
    It is just as easy, for example, to find out about the used network interfaces for virtual machines, just enter:
    Get-VMNic
    and we get:

    Well, the most, what my friend needed was the ability to export in the background, on schedule. To do this, you can write a cmdlet that you can then push into the Scheduler. For example, this cmdlet stops the virtual machine for me, exports it, starts it again and sends me a letter about the error or success of the cmdlet. After that, control is transferred to another script that archives and sends the backup to a remote ftp.
    Export: export-vm -vm MyVM1 -path D:\backups\VM -copystate -wait -force
    The -copystate option tells you to copy everything (including virtual disk=> the size of the export output can be very large)

    Instead of a conclusion
    As you can see, managing your virtual machines from PowerShell can be very convenient and stress-free. You just need to read the parameters of those commands that you need and write your own script.

    P.S. I don’t pretend to “discover America” at all, I just decided that someone will find information about this useful module useful. I have described only the most simple options for which you can use the PowerShell management library for Hyper-V. If anyone knows or wrote their own more handy tools to optimize the work with Hyper-V, I will only be glad to learn about them.

    Working with virtualization, periodically there is a need to transfer virtual machines from one type of hypervisor to another. Since each virtualization system works with its own formats, it will not be possible to simply transfer the machine, you will need to convert it to the format of the desired hypervisor. Today we will tell you how to do this for the two most popular systems VMWare virtualization and Hyper-V.

    Any virtual machine, regardless of the platform, consists of two main parts: the virtual machine itself - a text or XML file describing its configuration and a virtual hard disk. It makes no sense to transfer the virtual machine itself, we don’t transfer hardware, if we need to run the system on another PC, it’s enough to transfer the virtual disk.

    Formats virtual disks different hypervisors are also different, but this is not difficult - it is enough to use specialized software for converting. The only subtlety is that the guest OS must be supported by both types of hypervisor. Otherwise, additional measures will have to be taken to ensure normal operation however, this topic is beyond the scope of this article.

    Consider the process for real example. One of our clients purchased a boxed version of "Megaplan", which developers distribute very original way: as a virtual machine image of the format Open Virtualization Format (OVF) which support VMWare And virtual box. Actually, inside the virtual machine contains Ubuntu 12.04 with a configured web server, DBMS and other components necessary for the operation of Megaplan, which is a regular web application. Wherein license agreement Denies access to the guest OS.

    Let's leave the licensing policy behind the scenes and be surprised only that when selling, and not cheap, enterprise-level server software, developers completely ignore serious hypervisors in general, suggesting using desktop hypervisors of the second type.

    If the virtual machine was already running on VMWare platform(as most often happens), then remove VMWare Tools from it and turn off the machine.

    Now you can start converting the virtual disk. For this we use free utility StarWind V2V Converter. Its interface and use is extremely simple. Select the source virtual disk (file with the extension vmdk).

    At the end of the conversion, once again go to the properties of the hard disk and select the VHDX image there, confirm the changes and start the virtual machine. Making sure everything works fine, old VHD disk can be deleted.

    Converting Hyper-V virtual machines to VMWare is done in a similar way. We convert the virtual disk to VMDK, if a VHDX format disk was used, then it must first be converted to VHD using Hyper-V in the same way as we did above. Then we create a virtual machine in VMWare for the used guest system with identical parameters and in the disk settings we specify to use the disk that we converted to VMDK. After starting the virtual machine, do not forget to install the VMWare Tools package necessary for full-fledged work guest system.

    • Tags:

    Please enable JavaScript to view the