Android Virtual Device (AVD) extremely slow

So I started to look at writing an Android app. I took a class on Android and wrote a prototype Android App in fall of 2011. Well, I have a need to write an Android App again.

I am a C# developer and while I am comfortable with Java, I prefer C# so I am going to use MonoDroid.

I installed everything very easily using the MonoDroid installer. However, when I went to launch an Android Virtual Device (AVD) it seemed to start but even after leaving it over night, it didn’t finish booting.

So I did some research and the recommendation was to install the Hardware Accelerated Execution Manager.

So I had to:
1. Open the Android SDK Manager and install the Intel x86 Emulator Accelorator (HAXM).

2. Run the installer I found here:
C:\Users\jbarneck\AppData\Local\Android\android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager\IntelHaxm.exe

After that, opening an AVD was plenty fast.

Sharing checked out source between Visual Studio instances on Virtual Machines using a network share

I have a lot of Virtual Machines and having to checkout a large code base from source control to each box is annoying and time consuming. There are a couple of branches that take almost an hour to get the latest code.

I am using Visual Studio and TFS. Visual Studio and TFS is installed on all my VMs. So I set out to have the VM host store the source and then all the Virtual Machines map a drive to the host.

At first this appeared to work just fine, but then I started to run into errors. I fixed the errors one at a time.

There were a few things I had to do to make this work and I thought I would share them:

System Changes

  1. Map the drive and make it persistent. That means the drive stays mapped after reboot.
  2. Add the mapped drive as a local intranet site in Internet Explorer’s Security settings.

Visual Studio Changes

  1. Make sure to always log into to TFS in Visual Studio with the same user account. There will be TFS problems if you use a different user account.
  2. Add the loadFromRemoteSources tag to the section of the devenv.exe.config file and set it to true:

    Note: I had to run Notepad++ as administrator to make this change.

    Visual Studio 2010:
    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.configVisual Studio 2012
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe.config

  3. Add the loadFromRemoteSources tag to other .config files.
    Note: In order to debug a web service, I had to also add this tag to the  WcfSvcHost.exe.config.

    Visual Studio 2010:
    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfSvcHost.exe.config

    Visual Studio 2012
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\WcfSvcHost.exe.config

    In that IDE folder there were a 22 .config files in VS 2010 and 32 in VS 2012. I am not sure which ones will ever need this. There are two schools of thought: 1. Add the loadFromRemoteSources tag to all of the config files or 2. Add them only when you encounter and error. Since I am in a lab environment and everything is on one physical box (the host and the hosted VMs) I went ahead and added this to all the config files.

  4. Sometimes when running Visual Studio as administrator, the mapped drive appears off line. Simple click File | Open | File and browse to the network drive. You don’t have to actually open anything. Just click cancel. It seems as soon as you browse to the mapped drive, Visual Studio knows about it and everything works fine.This doesn’t seem to work as well in VS 2012 on Windows Server 2012.  You may even have to have the drive mapped twice. Once as the logged in user and once as the Administrator. To do this open two command prompts: 1. A regular command prompt. 2. A command prompt running as Administrator. Run the mapped drive command in both: (Yes, use the same drive letter in both on Windows 2013 or Windows 8)

    net use z: \\pcname.domain.tld\yourshare /PERSISTENT:YES

Be aware you’ll get more prompts

I noticed than when running executables orVBScripts or PowerShell scripts, that I was prompted. This is because your running them from a network share, which is completely fine as long as you trust the network share.

Conclusion

Having all your Virtual Machines share the same source repository is possible and saves a lot of time checking out code as you don’t have to do it an each Virtual Machine.

Doing this for multiple users did not work well as the we used TFS and the source seemed to be tied to the user.

I have not yet tried to share between VS 2010 and VS 2012. I hope that works…I’ll update when I know.

Best Practices for Preparing a Windows Virtual Machine

If you use Virtual Machines  in your lab (either with Hyper-V, VMWare Workstation, Virtual Box or other), you probably would love to have a list of steps to create a nice usable Virtual Machine. There are probably annoyances you have with your Virtual Machines that if you only knew how you could make them go away.

Also, it is frustrating to revert and have to redo settings, so knowing when is best to snapshot is also nice.

This document is to help you with just that: Creating the perfect Virtual Machine that is easy to use and avoids annoyances.

Note: I have been using VMWare Workstation since 2004. I have also used ESX, Virtual Box, and Hyper-V. I have worked with lab environments the most, but I have also worked with Virtual Machines in production and consider myself highly experienced.

Setting up a new Virtual Machine

Note: These steps provide general guidelines for when to snaphsot

  1. Create a new VM in your favorite Virtual Machine Manager.
    Note: I have used VMWare Workstation and ESX, Virtual Box, and Hyper-V and find I like them all fine.
  2. Use a very large disk image size, but do not choose to use allocate disk space now.
    Note: It is very frustrating to run out of space, so avoid this.
  3. Delete the floppy disk if the hardware configuration has one.
    Note: VMWare workstation will annoy you to no end if you leave a floppy on the system.
  4. Install Windows.
  5. Note: Do not activate or enter a Product Key if it allows you to skip this step.
    Note: I will use Windows Server 2008 R2 for this example.
  6. Create a snapshot called “Clean Install” here.
  7. Apply all patches and updates and driver updates.
  8. Add a secondary admin account in case you forget the primary admin account.
  9. Create Snapshot called clean install with Patches.

Windows Activation

If this is to be a base OS to use to clone other Virtual Machines, never activate the base Operating System, only activate a Virtual Machine after it has been cloned and after you are sure the Virtual Machine will not be discarded as lab Virtual Machines can be discarded often.

Activation can be a delicate balance. You don’t want to active every time, but at the same time, you don’t to revert a virtual machine and have to activate again. As soon as you know you will use the Virtual Machine for a while, activate it and snapshot it. Hopefully you never have to revert to a state before it was activated.

Making the Virtual Machine Easier to Use

Allow the Virtual Machine to Shutdown from the Login Screen

  1. Run gpedit.msc to launch the Local Group Policy Editor.
  2. Click to expand Computer Configuration | Windows Settings |Security Settings |Local Policies | Security Options.
  3. Scroll down in the right pane and right click on “Shutdown: Allow system to be shut down without having to log on” and choose Properties.
  4. Click Enabled and then OK.

Disable the shutdown event tracker

Virtual Machines, especially in a lab, shutdown often and unlike production machines, tracking these shutdowns is not necessary, so lets turn this off.

  1. Run gpedit.msc to launch the Local Group Policy Editor.
  2. Click to expand Computer Configuration | Administrative Templates |System.
  3. Scroll down in the right pane and right click on “Display Shutdown Event Tracker” and choose Edit.
  4. Click Disabled and then OK.

Disable Internet Explorer Enhanced Security Configuration

It is a pain in a lab to be prompted on every web site and for every download. Labs usually trade security for speed and agility.

  1. Go to Server Manager.
  2. Under Security Information on the right, click on Configure IE ESC.
  3. Set the values to Off.
  4. CLick OK.

Making the Virtual Machine more efficient

Turn off unnecessary services

If you need to run a lot of Virtual Machines and you need to squeeze every last bit of processor power out of your Virtual Machines, then they should only run the bare minimum they need to run.

Make a list of services you do not need but are running by default and disable them.

Note: Google search for “Services you can turn off in Server 2008” or whatever Operating System you are using.

Note: Often developers install Visual Studio, which includes SQL Express, and even if they never use SQL Express, they leave the service running. Stop such services and set them to manual so they don’t restart every reboot.

Software on the Virtual Machine

Install commonly used software

This one appears easy at first. However, it is different and there is more to it than you think.

  1. Make a list of software you use on your Virtual Machine. Here are a few examples:
    Notepad++
    7zip
    Acrobat Reader
    Firefox or Chrome (or your favorite browser)
    etc…
  2. Install your desired software.
  3. Update your software.
  4. Snapshot.

Delete Unique Values for Some Software

If you are going to use this as a base Virtual Machine to clone other Virtual Machines, then you don’t want anything that should be unique to be the same on each machine. Any software that has unique values should have those unique values removed. I’ve seen VPN software have unique values, the LANDesk Agent, etc… Remove these unique value before you Sysprep.

Using Virtual Machines with Active Directory

Using the Virtual Machine as a base

If you are going to create a base Virtual Machine that  you will clone often, just never join it to the domain. Instead, take the time to get the system perfect and sysprep the Virtual Machine so it will join the domain and prompt for a computer name on first boot.

Sysprepping a Virtual Machine

Sysprep is eithe ron the ISO or already installed.

  1. Run c:\windows\system32\sysprep\sysprep.exe.
    (Or find sysprep on the ISO)
  2. For System Cleanup Action, choose Enter System Out-of-Box Experience (OOBE)
  3. For Shutdown Options, choose Shutdown.
  4. Click OK.
  5. Snapshot once the machine has shutdown.

Prevent the Virtual Machine from ever losing a trust with the domain

When a Windows Virtual Machine is joined to the domain, reverting can cause a huge delay, especially if the snapshot is from a while ago, because a machine and the domain have a trust based on a system password (that is all under the covers) and this password can update. When reverting after the password has changed, your reverted state will no longer have a trust with the domain. This can be prevented.

  1. Join your machine to the domain.
  2. Apply DisablePasswordChange registry key.
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Netlogon\Parameters]
    "DisablePasswordChange"=dword:00000001
    
  3. Create a snaptshot called “Machine joined to domain, DisablePasswordChange set”.

For more information, read this post: Virtual Machines, Snapshots, Domain Membership, and trust relationship

Change the domain password requirements to be easy or off

Again, in lab environments, security is often traded for speed and efficiency. You may want to allow passwords that are blank or two characters.

Also, because of snapshots and reverting it will eliminate Virtual Machine problems if passwords never expire.

If your Active Directory server is also in your lab, you may be able to change the passwords requirements to be easy or even turn them off completely. If your Active Directory server is not in your lab, you may have to live with them.

Don’t clone machines joined to the domain

If you clone a machine joined to the domain, you have created two machines that have the same domain membership, which should be unique. If one machine changes, it can break the trust relationship for the other machine.

The only time you should clone a machine that is joined to the domain is when you plan to discard the Virtual Machine you are cloning from.

Other Steps

Everyone has unique needs, and these are supposed to be general needs. You should document your needs and add them to your Virtual Machine creation.

If you have an idea that isn’t listed here and it is a general step, please comment.

Is Windows 8 Pro Hyper-V the end of VMWare Workstation?

So I have had a license for VMWare Workstation through work since 2004. I have been a loyal user for eight years. However, my current job is not going to provide any further VMWare Workstation licenses.

Price of VMware Workstation vs Hyper-V

Because Hyper-V is included in Windows 8 Pro and the Microsoft Windows 8 Pro Upgrade is under $70 for a full version (not upgrade) of Windows 8 Professional System Builder DVD 64-Bit you are only looking at over $125.00 on sale (normally $199). VMWare Workstation alone is $249. VMWare Workstation is $50 more expensive than paying full retail price for the full version of Windows 8. If you are planning to buy Windows 8 Pro anyway, then technically, VMWare Workstation $249 too much.

Hyper-V vs VMWare Workstation

Having used both, I am going to mention some differentiating features.

  • Hyper-V virtual machines seem to snapshot and revert must faster than VMWare Workstation.
  • VMWare auto sizes the screen does, Hyper-V doesn’t.
  • VMWare workstation has a cool mode where you can run apps from the virtual machine as if they were regular desktop apps.
  • VMWare workstation works better with alternate operating systems.

There are advanced features that I haven’t tested. For example, when I worked at LANDesk we need to test PXE Booting so the ability for the virtual machine to PXE Boox was extremely important, and VMWare worked really well with PXE Booting. I haven’t tested Hyper-V with PXE Booting, so if you have please post and let me know if how it works.

Of course, don’t forget about Virtual Box. The open source edition, Virtual Box OSE, is free no matter what operating system is the host, whether it is Windows 8 or FreeBSD or Linux. It has been free for a while and yet VMWare Workstation is still popular so maybe it will remain popular despite Windows 8 Pro?

Installing VMWare Tools on FreeBSD 9

Virtualizing a FreeBSD server is common place. Knowing how to install VMWare Tools on a FreeBSD server without X11 is going to be extremely important. This article will provide the steps.

Lets get started.

Step 1 – Install FreeBSD as VMWare Guest.

Instructions for installing FreeBSD 9 are found here: How do I install FreeBSD 9?

It shouldn’t be much of an effort to follow these steps inside a VMWare guest.

Note: You may consider taking a snapshot here to save your current state.

Step 2 – Update FreeBSD and Install ports

Instructions for updating FreeBSD and installing ports are found here:
Update FreeBSD and Install ports

Note: You may consider taking a snapshot here to save your current state.

Step 3 – Install Prerequisites

Step 3.1 – Install Perl

Installing Perl is easy. Use either of the following commands.

From ports

# cd /usr/ports/lang/perl5.12
# make install

From packages

# pgk_add -r perl

Step 3.2 – Install compat6x-amd64

The compat6x-amd64 port is also easily installed.

From ports

# cd /usr/ports/misc/compat6x/
# make install

From packages

# pkg_add -r compat6x-amd64

Step 4 – Take a VMWare Snapshot

Important! Take a snapshot here! Do not skip this step.

Step 5 – Mount the VMWare Tools ISO

I am using VMWare workstation. Some steps may be slightly different if you are using ESXi or other VMWare solution.

  1. In VMWare Workstation, choose VM | Install VMWare Tools.
  2. In FreeBSD as root, create a directory to mount the CD-Rom to.
    # mkdir /cdrom
    
  3. Mount the cd-rom.
    # mount -t cd9660 /dev/cd0 /cdrom
    

Note: You may consider taking a snapshot here to save your current state.

Step 6 – Extract the vmware-freebsd-tools.tar.gz

Now that the drive is mounted, it should be easy to get to the vwmare-tools file.

  1. Copy the vmware-freebsd-tools.tar.gz file to a local location.
    # cp /cdrom/vmware-freebsd-tools.tar.gz /root
    
  2. Extract the vmware-freebsd-tools.tar.gz file.
    # cd /root
    # tar -xzf vmware-freebsd-tools.tar.gz
    

VMWare tools should now be extracted.

Step 7 – Recompile VMWare Tools Modules

Before you install VMWare tools on FreeBSD 9, you need the modules to work with FreeBSD 9. VMWare is slow to update the vmware tools for the FreeBSD guest. So you are just going to have to update them yourself.

Note: We are now at the point where we are going to do more and install more than you want to for your nice new clean server, but that is ok, because we have a snapshot and once we get the files compiled you can revert to the clean snapshot. Alternately if you have another FreeBSD system, you can do these steps on that system.

If you install without recompiling as of May 10, 2012, you will get this result.

Starting VMware Tools services in the virtual machine:
   Switching to guest configuration:                                   done
   Guest memory manager:                                              failed
   Blocking file system:                                              failed
   Guest operating system daemon:                                      done
Unable to start services for VMware Tools

Execution aborted.

Compiling the modules first should prevent the above failures.

Step 7.1 – Get FreeBSD Source

Download the FreeBSD Source as described here.

How to download FreeBSD source using svn?

Step 7.2 – Configure the /etc/make.conf

Right now there is a move toward compiling with clang over gcc. Because of changes due to this, you need to add the following line to your /etc/make.conf to compile with gcc. I have not tried to compile with clang yet.

  1. As root open the /etc/make.conf file with you favorite editor and add the following line:
    MK_CLANG_IS_CC=no
    
  2. Save and close the /etc/make.conf file.

Your /etc/make.conf is now configured.

Note 1: You may want to compile a custom kernel while you are at this. If so, check out this article: How to build and install a custom kernel on FreeBSD? If you do this, remember that you have to copy the new kernel to your clean system too.

Step 7.3 – Compile the vmmemctl module

Recompile vmmemctl using these steps.

  1. Go to the lib/modules/source directory under where you extracted vmware-freebsd-tools.tar.gz.
    # cd /root/vmware-tools-distrib/lib/modules/source/
    
  2. Extract vmmemctl.tar
    # tar -xf vmmemctl.tar
    
  3. Change to the vmmemctl-only directory.
    # cd vmmemctl-only
    
  4. Run make.
    # make
    
  5. Run make install.
    # make install
    

You have now built and installed the vmmemctl module.

Step 7.4 – Compile the vmblock module

  1. Go to the lib/modules/source directory under where you extracted vmware-freebsd-tools.tar.gz.
    # cd /root/vmware-tools-distrib/lib/modules/source/
    
  2. Extract vmblock.tar
    # tar -xf vmblock.tar
    
  3. Change to the vmblock-only directory.
    # cd vmblock-only
    
  4. Run make.
    # make
    
  5. Run make install.
    # make install
    

You have now built and installed the vmblock module.

Step 8 – Install VMWare Tools

You are now ready to install the VMWare Tools.

Note: If you are trying to keep you server clean and pristine, then copy the /root/vmware-tools-distrib directory off the server somewhere. THen revert to the snapshot you took just before Step 4. Copy the directory back to your clean snapshot and continue.

  1. Move into the directory created by the extraction.
    # cd /root/vmware-tools-distrib/
    
  2. Run vmware-install.pl
    # ./vmware-install.pl
    
  3. Select all the defaults.

Your vmware tools installation should go smoothly.