Jump to content
Covecube Inc.
  • 0
otispresley

Migrating from ESXi to Hyper-V

Question

This is what I recently had to do, so I thought I would post about my experiences in case it might help someone else.  The first question you may ask about this topic is, "Why?".  I recently upgraded my server hardware and bought a new SAS controller that was not supported by ESXI.  It was nearly half the price of all other similar RAID controllers, so I really did not want to have to return it and end up taking up multiple PCI Express slots with multiple cards.

 

A long time ago, I had used the original Hyper-V server 2008 and migrated to ESXi due to limitations in the original Hyper-V and due to the fact that I wanted to be able to use OVF/OVA templates.  It turns out that the OVA files can just be extracted with 7-zip and there you have the disks and virtual machine information you need to convert the VMDK files to VHD files; however, I had never found this out until recently.

 

This brings us to the first issue...how to get your virtual machines from ESXi into Hyper-V.  If you have the luxury of being able to have both servers online at the same time, the migration is really easy with several different tools.  For most of us at home, this is not an option.  I had been using the great free script, ghettoVCB, in a cron job on the ESXi host to back up my VM's to an eSATA dock with a drive in it and had used it for restore operations several times over the years.  

 

Since the disks are converted offline, the CPU and memory assignments from the VM's in ESXi were recorded for VM creation once Hyper-V was installed.  I used the ESXi client to download all the backups to an NTFS volume so I could read it from my Windows PC and access the backed up VMDK files.  I ended up running into problems with one of my Ubuntu Server VM's after the conversion and had to install a new one from scratch.

 

This means I needed something that could read a VMDK file with Linux partitions from my Windows PC.  For this part, I used Diskinternals Linux Reader that also supports VMFS volumes to access the VMFS volume and copy all the VMDK files from my backups.

 

Anyway, back to converting the VMDK files to VHD.  There are quite a few tools available to perform this conversion, but the one I settled on was 2tware Convert VHD.  It was easy to use, fast, and free!

 

At this point, I installed Hyper-V Server 2012 R2, performed initial setup, re-partitioned and formatted my RAID for VM storage and my backup disk, and configured remote management and remote desktop.  I changed the default location for VHD and VM storage to point to my VM RAID in Hyper-V settings.  Then, I shared my drive with the VHD files on it and used the Hyper-V Server CLI to transfer all the VHD files to the virtual hard disks directory and created my Virtual Machines; you should definitely enable dynamic memory on all your VM's.  It works on Ubuntu 13.10 and up.  Also, don't forget to update Integration Services on your VM's where needed and remove VMware Tools from them.  No tools are necessary for Hyper-V in Linux, because they are built into the kernel.

 

With Hyper-V Server 2012 R2, configuring remote management and remote desktop is easy using the setup menu you see when you log in.  You need to install Hyper-V Manager on the machine you want to use to manage your Hyper-V server from, in my case a Windows 8.1 PC.  Then you can create a Microsoft Management Console to manage everything from one place.  In this console, I put the following all pointing to the hyper-V server:

  • Hyper-V Manager
  • Computer Management 
  • Group Policy
  • Windows Firewall

In order to access the Hyper-V server from your PC, you need to edit your %WINDIR%\System32\drivers\etc\hosts file and add an entry for your Hyper-V server, because it must be added by name rather than IP Address.  It must also be in the same work group as the PC you are managing it from, or else you will need to update some firewall rules.

 

You will also want to create a share on your Hyper-V server for uploading ISO files for VM installations and such.  This makes things much easier.

 

For scheduled backup of my VM's, I decided to use HV Backup after reading that the wbadmin tool places the VM in a saved state while backing it up.  This was easy to set up; I just unzipped it and copied the folder into my upload directory from above.

 

I also needed to back up the OS on the Hyper-V server, which I was not doing on ESXi...shame on me!  For this, I had to install Windows Server Backup using the command: dism /online /enable-feature:WindowsServerBackup.

 

When a backup task finishes, I wanted to receive an email stating that it was done so I could review the logs to make sure there were no errors.  In order to be able to execute the PowerShell script, you have to enter the following at the Hyper-V Server CLI: set-executionpolicy remotesigned

 

I named the script SendEmail.ps1 and added the HV Backup log file as an attachment.  Edit it as needed for your environment:

Write-Host "Sending Email"

#SMTP server name
$smtpServer = "<server_name_or_ip>"
$file = "lastlog_out.txt"

#Creating a Mail object
$msg = new-object Net.Mail.MailMessage

#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$att = new-object Net.Mail.Attachment($file)

#Email structure 
$msg.From = "<from_email_address>"
$msg.ReplyTo = "<reply_to_email_address>"
$msg.To.Add("<to_email_address>")
$msg.subject = "<subject>"
$msg.body = "A backup task has completed.  See log files at 'C:\Windows\Logs\WindowsServerBackup\' for information about the system backup.  Refer to the attached file for details about virtual machine backups."
$msg.Attachments.Add($att)

#Sending email 
$smtp.Send($msg)
$att.Dispose()

Here is where I created a batch script in the same directory that HV Backup was in.  I called it HVBackup.bat and put the following lines in it where F: is the backup drive and C: is the OS drive.  It first deletes any zip files older than 14 days in order to better manage space.  I am managing the OS backups manually.  Edit it as needed for your environment:

@ECHO OFF
forfiles /p f:\ /m *.zip /d -14 /c "cmd /c del @path"
wbadmin start backup -backupTarget:f: -include:c: -quiet -allCritical
.\HVBackup.exe -a -o f:\ 1> lastlog_out.txt 2> lastlog_err.txt
Powershell.exe -executionpolicy remotesigned -File  .\SendEmail.ps1

That was pretty much it.  The server has been running great for me with all my storage disks passed through to my Windows Server 2012 Essentials VM, and network performance with DrivePool seems to be more stable so far than they were in ESXi with RDM disks.  I hope this is helpful to someone.

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Well, if you backup the volume with the HyperV VMs and VHDs, then it shouldn't put the VMs into a saved state. Or at least, that's the behavior I've noticed on my system.

 

Specifically, I use:

"wbadmin start backup -backupTarget:\\?\Volume{GUID} -include:C:,H:,W:,\\?\Volume{GUID}\ -systemState -allcritical -quiet"

The "H:\" volume is the HyperV volume, and having that selected means that the VMs are not put into a saved state, apparently. 

 

And yeah:

http://blogs.msdn.com/b/virtual_pc_guy/archive/2013/02/25/backing-up-hyper-v-virtual-machines-from-the-command-line.aspx

 

 

Wbadmin will always warn you that the virtual machine will be put into a saved state for backup.  This is wrong.  The virtual machine will only be put into a saved state if it is not running the latest virtual machine additions (or is not a Windows virtual machine).

 

Other than that, it's a very comprehensive write.

Thank you for that!

Share this post


Link to post
Share on other sites
  • 0

Hi Christopher, thanks for that!  I was not aware that would allow you to backup the VM files while running as well!  One thing I do like about HV Backup is that it places each VM backup into its own separate zip file.  I suppose I could still script that once the wbadmin backup finishes, but I like to keep things simple when possible.

 

Well, if you backup the volume with the HyperV VMs and VHDs, then it shouldn't put the VMs into a saved state. Or at least, that's the behavior I've noticed on my system.

 

Specifically, I use:

"wbadmin start backup -backupTarget:\\?\Volume{GUID} -include:C:,H:,W:,\\?\Volume{GUID}\ -systemState -allcritical -quiet"

The "H:\" volume is the HyperV volume, and having that selected means that the VMs are not put into a saved state, apparently. 

 

And yeah:

http://blogs.msdn.com/b/virtual_pc_guy/archive/2013/02/25/backing-up-hyper-v-virtual-machines-from-the-command-line.aspx

 

 

 

Other than that, it's a very comprehensive write.

Thank you for that!

Share this post


Link to post
Share on other sites
  • 0

You are very welcome. 

As I've said, I've been backing up my VMs for a while (and actually, I work from one of them!)

 

As for the HV Backup, an archive of each VM is very nice. A bit simpler to migrate/restore than Server Backup (that link has the commands to backup and restore specific VMs, which isn't exactly simple).

 

As for scripting, I meant to mention it before, but you could use the Task Scheduler to script stuff. Anything that creates a Event Viewer ... event can be used to trigger a task.

In fact, I've set this up so that I backup to an internal drive, and once that's finished, it backs up to an external drive as well.

Though, this may be more difficult to setup on a server core installation (such as HyperV Server), but if you are able to enable all the remote management stuff, you should be able to do it from the other system. 

Share this post


Link to post
Share on other sites
  • 0

You would think so.  I looked into this and the option to "Attach Task To This Event" is grayed out for me from my remote management console, and I have not been able to discover how to enable it or else how to do it from PowerShell.  It will require more research.

Share this post


Link to post
Share on other sites
  • 0

Most likely, you need to allow remote management of the event viewer. 

This link should help.

http://blogs.technet.com/b/server_core/archive/2008/01/14/configuring-the-firewall-for-remote-management-of-a-workgroup-server-core-installation.aspx

This is EXACTLY what you're looking for, and it covers MORE than just the event viewer. It should cover EVERYTHING that exists in the Computer Management console, which is even better. :)

 

Personally, I went and set up a group policy for this on my domain, so I don't have to do anything ever again. :)

Share this post


Link to post
Share on other sites
  • 0

Thank you for this write-up. Although I have no intention of converting, my primary task for the day was to set up backups for my ESXi system, guests and host, and right here you have set me on my way. I'm also looking at some other solutions, any recommendations you might have would be greatly appreciated.

Share this post


Link to post
Share on other sites
  • 0

Hi RobbieH,

 

I only ever used ghettoVCB with my ESXi system.  There are other free solutions, but they generally require you to install an agent on the VMs so they can do OS backups as well.  In my case, I didn't care about incremental or file-level restores; full VM restores worked fine for me as I did a backup once per week and kept 3.

 

As far as backing up the host goes, you can just back up your settings and then just apply them to a new install of ESXi as it is about the same thing anyway.  Here is an article on doing that:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...