itramblings

Ramblings from an IT manager and long time developer.

By

Lanuching Visual Studio Android Emulator from the command line

Quick command line to launch the Visual Studio Android Emulator for Lollipop

%ProgramFiles(x86)%Microsoft
XDE10.0.1.0xde.exe /sku Android /displayName "VS Emulator 5"
Lollipop (5.0) XXHDPI Phone" /memSize 2048 /diagonalSize 5 /video
"1080x1920" /vhd
"%LOCALAPPDATA%MicrosoftVisualStudioEmulatorAndroidContai‌
​nersLocalDevicesvhd5_Lollipop_(5.0)_XXHDPI_Phoneimage.vhd" /name
"VS Emulator 5-inch Lollipop (5.0) XXHDPI Phone.%USERNAME%" 

By

Nesting Hyper-V with VMware Workstation 8 and ESXi 5

Original Source Post: http://www.veeam.com/blog/nesting-hyper-v-with-vmware-workstation-8-and-esxi-5.html

 

As Veeam moves forward and starts to become focused two virtualization platforms, I thought to myself now is the time to work out how I’m going to introduce Microsoft Hyper-V in my lab environment. I wanted to know if it could be virtualized running inside a VMware virtual machine of some sorts. Veeam has been very successful in presenting its solutions through the use of portable labs running for example on laptops nested under VMware Workstation. We would often have a nested ESX server, vCenter, DC and Veeam apps running on a single laptop and I wanted to know if Hyper-V could be thrown into the mix.

This post will function as a how-to guide and provide a step-by-step process to run Hyper-V virtual machines on either VMware Workstation 8 or ESXi 5.

For a long time, I was told it was impossible, and a few months ago, I heard a passing rumour that it would be possible when ESXi 5 came out. I’d also heard that ESXi 5 running on Intel Nehalem or Intel Core i7 was going to allow nested hypervisors to also contain running, nested 64bit virtual machines. So firstly, I went about making sure that when I was due for a new laptop, I would have this Intel architecture, or equivalent AMD, in my system. I also managed to build a lab with the same architecture that I plan to use on the road for events.

Through Twitter, someone sent me a link to a few blogs that helped me start my quest:

http://www.vcritical.com/2011/07/vmware-vsphere-can-virtualize-itself/#comment-12442

http://www.virtuallyghetto.com/2011/07/how-to-enable-support-for-nested-64bit.html

By the time I’d gotten a chance to give it a whirl, ESXi had gone GA. What I found from the blogs posted above was there were some great pointers, but when I followed either post’s instructions, all I got was a blank Black Screen like a few other people were reporting. No matter what additional information I gave, it just would not work. Undeterred, I decided to try something different. I installed VMware Workstation 8 instead of ESXi 5 and managed to get a nested Hyper-VM working. At this point, I knew my hardware was going to be compatible with nesting Hyper-V. The blog posts above stated the key to making it work is a feature found in your CPU/BIOS called Intel EPT. Now, I read that if you have Nehalem/Core i7, you should have Intel EPT; the blog posts suggested that it should be enabled through the BIOS. However, I didn’t find this option in either of my system BIOS.

While testing what would work, I decided to use Windows 2008 R2 Standard and enable Hyper-V as a Role rather than install the standalone Hyper-V product. I only did this to make my life easier, but the standalone Hyper-V product is a fine option as well.

Nesting a Hyper-VM on VMware Workstation 8

So, following are the steps to create a Microsoft Hyper-V VM running in VMware Workstation 8, but later I’ll show you how to do it in ESXi 5 as well:

1. Create a New VM with version 8 hardware

clip_image002

2. Give it 4 GB RAM and 2 x vCPUs with about 80-100 GB disk space, depending upon how many VMs you wanted nested underneath Hyper-V.

3. The instructions lead you to believe that you should pick a VMware ESX option as the guest OS… STOP! DON’T! Select Windows 2008 R2 x64.

clip_image004

4. When you are finished, make sure you add another NIC to the VM used as the Hyper-V virtual network,

5. Under the settings of the VM > CPU, make sure you have the option to pass-through the Intel VT-x/EPT feature.

clip_image006

6. Make sure you have set the VM to boot from Windows 2008 R2 x64 media ISO.

7. Before booting, you should edit the config file .vmx and add the parameter: hypervisor.cpuid.v0 = “FALSE”

clip_image008

8. Now Boot and Install Windows 2008 R2 x64.

9. Once finished, open up Server Manager and click “Add Role”.

clip_image010

10. Select and install the Hyper-V option. At this point, you will know if your system is working correctly and passing the Intel EPT feature, because if it doesn’t, you won’t be able to go past this point.

clip_image012

11. You’ll also have to select the network adapter used for the virtual network.

clip_image014

12. Now install Hyper-V, which will need a reboot.

13. After it is completed, open Server Manager drill down to Hyper-V and connect to the local server.

clip_image016

14. Now create and install a virtual machine.

clip_image018

Once done, you should be able to use it as normal, albeit slow.

Nesting Hyper-VM running ESXi 5

Now, doing the same thing on ESXi 5 is a little trickier although some of the steps are the same.

1. Before anything you need to place an entry in the /etc/vmware/config file found in the tech support mode on your ESXi 5. I enabled SSH through the security profile in the vSphere Client. Then used putty SSH into the ESXi system.

2. From there I executed the following command which is needed to allow nested hypervisors :

# echo 'vhv.allow = "TRUE" ' >> /etc/vmware/config

Notice the use of single and double quotes in the command-line

3. Now create a virtual machine using version 8 hardware, 4GB (or as much as you can spare), 2 x vCPUs, 2 or more vNICs and a 100GB virtual disk.

4. Before booting up the VM and installing Hyper-V we need to add two lines the virtual machines config file .vmx

You can try this through the vSphere Client in the settings of the virtual machine > Configuration Parameters, whereas I had better luck doing it from command-line

clip_image020

clip_image022

To add them using command-line move back in SSH > change into the directory where you Hyper-V VM is installed

# echo 'vhv.allow = "TRUE" ' >> /etc/vmware/config

In my example the config file is called Hyper-V.vmx. Type the following commands:

# echo 'monitor.virtual_exec = "hardware" ' >> Hyper-V.vmx
# echo 'hypervisor.cpuid.v0 = "FALSE" ' >> Hyper-V.vmx

5. Now back in the VM settings > Options > CPU/MMU Virtualization make sure you have the option to pass the Intel EPT feature.

clip_image024

6. Now in the Options area > CPUID Mask click on Advanced

clip_image026

7. Add the following CPU mask Level ECX: —- —- —- —- —- —- –H- —-

clip_image028

8. Now Install Hyper-V or Windows 2008 R2 and enable the Hyper-V role.

9. You are ready to roll.

Gotchas/Tips

Here are a few tips from Ricky to avoid any of the stopping points along the way:

  • On my system part way through install of Microsoft Hyper-V the OS requires a reboot. When you do this after Hyper-V has been installed it blue screens…DON’T PANIC because it doesn’t blue screen while actually using Hyper-V
  • With both my server and laptop I had no way of telling if my systems had Intel EPT it was a case of seeing if VMware passed Intel EPT without complaining and if Hyper-V spotted it. The give a way for me was when I’d tried VMware Workstation first and it worked straight off. I’ve read a million and 1 things about this subject, but my gut feeling is if you look for Nehalem or Core i7 and a motherboard that supports Intel VT. I think that is a safe bet. I read you need Intel VT –x2 which I don’t have (I don’t think) so that was misleading…If I can narrow the field of information I will update this post.
  • Remember nesting a hypervisor means it’s going to run very, very slow…however installing the nested hypervisor in a datastore that is on SSD disks helps big time.
  • The 2 blogs linked above presented 2 methods for creating the VM using version 4/7 hardware or version 8 hardware. I first went with version 8 hardware and no joy at all. All I got was a blank black screen. I actually tried a combination of the tweaks in both methods and that is what worked for me.
  • The port group that the nested Hyper-V machine resides on should be set to Promiscuous Mode: Accept
  • In one of the blogs there was a note suggesting making the entries manually in the config files (instead of using the GUI) was more stable. I found this too, so hence why I changed the config files in a shell session using putty.

By

Improving Performance of your Virtual Machine

http://www.howtogeek.com/howto/31303/improve-vmware-vm-performance-by-defragmenting-virtual-disks/

 

Improve VMware VM Performance by Defragmenting Virtual Disks

Have you noticed your VMware virtual machines sees like they’re sluggish and slow to respond?  Here’s how you can quickly defragment your virtual disks to make them fast as they were originally.

Just like a hard drive on a normal computer, the virtual hard drive on a virtual machine can become defragmented over time.  In fact, if your virtual disk is setup to dynamically expand over time, then fragmentation can become a serious problem, especially if your hard drive is low on free space.  You may notice your virtual machines running slower or being less responsive, and VMware itself may even notify you that your virtual disk is too fragmented.

Here’s what you’ll need to do.  First, while your virtual machine is running, run the default disk defragmenter as normal inside the virtual machine.  This may take some time if you haven’t done it in a while, and may also slow your whole computer down while it’s running.

Once the virtual machine’s OS has finished defragmenting, shut down the virtual machine.  Then, open your VMware virtual disk properties.  To do this in VMware Workstation, double-click on the Hard Disk info on the virtual machine’s main page.

Alternately, if you’re using VMware Player, right-click on the virtual machine’s name and select Virtual Machine Settings.

Then select the Hard Disk entry from the Hardware tab if it’s not already selected.  If your virtual machine has multiple virtual disks, you may wish to repeat these steps on each virtual disk.

Click the Utilities button

VMware will start defragmenting your virtual disk.  This may take a while depending on your virtual machine’s size and how often you defragment it.

Once it’s done, you’ll be notified that the defragment is completed.

To improve performance even more, you should also regularly defragment your host computer’s hard drive.  This is not much of a problem in Windows 7 and Vista since they automatically keep your hard drive defragmented, but if you’re using XP, you might want to setup automatic disk defragmenting.  Alternately, if you’d like more defragmenting control, you can always run the defrag command in an elevated command prompt for a wide range of analysis and defrag options.

Most of us don’t think much about defragmenting virtual machines, but it can seriously improve your virtual machines’ performance.  We’re big fans of the free VMware Player, and if you have more advanced needs, VMware Workstation is a great option as well.  The great thing is, no matter which one you’re using, you can still keep your virtual machines running at top speed with a quick defrag. 

[Updated]  The opensource UltraDefrag might be a better option to use as it will defrag files of any size

By

How to automatically shut down VMware ESXi gracefully during power failure using an APC UPS

 

In this latest post by TechHead guest contributor James Pearce he covers a topic near and dear to many of us – how to get VMware ESX/ESXi and its VMs to shut down gracefully upon power failure to the host.  Tighter integration between a UPS and a VMware ESX/ESXi host is no doubt something that will become more mature over time though for now it can be an issue for many administrators especially those running the free version of ESXi.  So read on to find out how James overcame this issue in his virtualization lab.

 

A Nearly Free UPS

I recently acquired an APC Smart UPS that was being chucked out from work (having never worked) for my home lab along with an ancient AP9606 management card. With the batteries changed the UPS burst into life – but after some messing about getting the right firmware on it, I was disappointed to find no easy way to get it to shutdown my ESXi box when it needed to.

 

VMware License Restriction

The VMware management appliance (vima) can shutdown only paid-for installations of ESXi (using apcupsd and VMware community member lamw’s scripts) – the necessary interfaces on the free version have been made read-only since ESXi v3.5 U3.

 

Burp Suite

VMware ESX ESXi - How to shut down using APC UPSI’ve been finding a lot of use recently for network sniffers, so thought I’d have a look at how the VMware vSphere Client works, as obviously that can shut down the host. As luck would have it, the client is nothing more than a glorified web browser with the slight complication that it’s talking over SSL – but that’s no problem for PortSwigger’s Burp suite in its transparent proxy mode.

The traffic captures revealed that only three frames would be needed to perform the shutdown (hello, authenticate, and shutdown). A little manipulation is needed to get the session keys in, but that is basically it. ESXi’s startup and shutdown policy will do the work suspending or shutting down individual VMs, as configured through the vSphere Client.

 

The Script – shutdown.bat

Using this newly found knowledge I’ve created a Windows batch file (with a few supporting text files which are basically HTTP requests) that takes the hostname, username and password as parameters and will then shut down the host cleanly. The script needs something to launch it –APC PowerChute Network Shutdown in my case – and a utility to send the commands over SSL, for which I’ve used Nmap ncat (which just needs to be installed).

I have put all the necessary script files into a single convenient zipped file which you can download from here – the scripts are fairly well commented so you should be able to follow what is happening.

 

APC PowerChute

A potential issue is that APC’s PowerChute Network Shutdown utility will always shut down the Windows machine it’s running on. I’ve therefore used a separate Windows management VM to host PowerChute and my script, since I wanted everything else just suspended.

PowerChute has an option to ‘run this command’ but it’s limited to 8.3 paths and won’t accept command line parameters. A separate batch file is needed (poweroff.bat) that runs the shutdown script with the parameters – but that could shut down other ESXi boxes as well if required. Also the PowerChute service needs to be run as local Administrator as the default Local System account doesn’t have sufficient rights.

 

Testing the Scripts

VMware ESX ESXi - How to shut down using APC UPS

Download the ZIP and extract the files – I’ve assumed the package will be extracted to c:scriptsesxi; update the path in poweroff.bat otherwise. Also the hostname, username and password also need to be specified in poweroff.bat.

Next install and configure PowerChute (in particular change the service user account) and enter the script in the ‘run this command’ box – I also increased the time allowed, but in practice it runs in a few seconds.

VMware ESX ESXi - How to shut down using APC UPS

Some waiting around can be avoided when testing by setting the UPS low-battery duration as high as it will go – just remember to change it back.

Next open up vSphere Client from a real machine, pull the UPS plug and once the battery get’s down to the specified number of minutes remaining, the script should run and the tasks will appear in vSphere Client.  Shortly afterwards the VM used to launch the script will itself shutdown under the control of PowerChute!

 

In Summary

The complete set of files can be downloaded here, and nMap ncat installation for Windows from here. Then a UPS management application is needed, for APC Smart UPSs use PowerChute for Windows.

The shutdown script includes logging and should report most errors. Bear in mind though that once a host is shutdown, it probably won’t be restarted when utility power is restored.

Burp Suite is a handy utility to bypass device limitations by enabling the scripting of management tasks that are only usually available through a web interface. I’ve used it to build scripts to regularly reboot home-spec routers every couple of weeks to keep them stable, and to set the time on the APC AP9606 management card daily since it doesn’t support NTP – and here to build a UPS shutdown script for ESXi; functionality that should really be built into ESXi in the first place.

By

Configuring Network Interfaces in VMWare Player7 and VMWare Workstation 7

VMWare Player is a free verson of VMWare Workstation with reduced functionality — mainly you cannot easily create new Virtual Machines and you cannot take advantage of advanced features like Snapshots and Teams.  Outside of that it is an incredible product that can provide huge benefits to Admins and Developers alike.

One topic that comes up now and again is how to modify the default network settings that ALL virtual machines on a specific computer use. These are used for concepts like NAT and HOST ONLY network access.  For this cases VMWare will assign a set of IP addresses from a specific group.  It is usefull from time to time to be able to change these settings.

 

The easiest way to do this is to look inside the installation path of the VM player. For example, C:Program FilesVMwareVMware Player

Note: For VMWare workstation, simple go to the main Edit Menu and select “Virtual Network Editor”

Here, you can find an executable named as vmnetcfg.exe

You should see a window that looks like this open up.

 

Select the network interface that you want to change (in the case above I am changing the IP addresses that are used for NAT interfaces).

Then edit the Subnet IP (and Subnet mask if you need to).  In the case above, I have already changed the address from 192.168.137.0 (the default) to 192.168.138.0

Once you have made you changes, click OK and you are done.

By

How to reset the UUID for a Virtual Hard Drive

<PATH TO VIRTUAL BOX>VBoxManage internalcommands sethduuid <PATH TO VHD>
VirtualBox Command Line Management Interface Version 2.1.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

UUID changed to: 46a453bd-4d03-4988-a066-6ecfc6ced308

By

Hyper-V Script: Compact VHD

http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/06/11/hyper-v-script-compact-vhd.aspx

By

Resizing a VHD drive

Resizing a VHD drive is not particularly complicated, it just involves a number of steps.

To Shrink

  1. Mount the VHD in Windows 7/2008 using Disk Management Tools (or DISKPART)
  2. Defragment the drive, makeing sure the free space is also defragmented (UltraDefrg in Optimize mode is a good free tools for this)
  3. Resize the main parition using Disk Management Tools (or DISKPART)
  4. Unmount the VHD Drive
  5. Resize the actual VHD file (VHDResizer is a great tool for this)
    1. http://sysadmingeek.com/articles/how-to-resize-a-microsoft-virtual-hard-drive-vhd-file/

To Expand

Resize the actual VHD file (VHDResizer is a great tool for this)

  1. http://sysadmingeek.com/articles/how-to-resize-a-microsoft-virtual-hard-drive-vhd-file/
  2. Mount the VHD in Windows 7/2008 using Disk Management Tools (or DISKPART)
  3. Defragment the drive, makeing sure the free space is also defragmented (UltraDefrg in Optimize mode is a good free tools for this)
  4. Resize the main parition using Disk Management Tools (or DISKPART)
  5. Unmount the VHD Drive