Friday, September 16, 2011

Using a single Windows 7 install with Boot Camp and VMware Fusion

09/17/2011- Update: Updated the power on-vm-custom script to add /persistent:yes.  Without this extra parameter the drive mapping immediately disconnects when the login scripts finish which is not what we are looking for.

I recently put a SSD drive into my iMac running OSX Lion. When I did this I also decided to create a single Windows 7 install for use in Boot camp and VMware Fusion. Below is a brief overview of the process and the decisions I made along the way.

I started out by using the Boot Camp Assistant to create a 20 GB(Probably should have been closer to 30GB) partition on the SSD drive(120 GB) I installed. I will only be using this partition for the operating system and drivers and have a 700GB external Firewire drive for all other data.

I installed Windows 7 64bit on this volume and loaded it with the proper Windows 7 Boot camp drivers and all the Windows Updates.

Next I installed VMware Fusion 3 created a new Virtual Machine with the Boot Camp partition.  This is only a pointer to the partition and not a copy and as such the VM itself is only a few megabytes.  After this was done I booted up the VM and configured the VMware tools.

I now have a single operating system that can be used in the VM or as a native OS.  To simplify the switching between the two Operating Systems I also installed BootCamp.

Next I configured Windows to automatically log in when booting to speed the startup/reboot times.  To do this open Window, press Command-R, and enter control userpassword2. not uncheck the option to require users to login and enter the username and password you want to automatically log in with.

Setting up shared access to a NTFS partition from both Boot Camp and VMware Fusion.

Next up is tackling the problem of the second hard drive.  I could have just created one large partition and been done now but the SSD eliminates the option.  Also I can't directly attach the external firewire drive to Windows XP become there is another partition on is for use in OSX.  As a result I am limited to make a few modifications to make it usable.  First off I configured the drive with two large partitions with Disk Utility(The first is a HFS+ volume with my OSX home directory and documents).  Then I Booted into Boot Camp and formatted the second column as NTFS for use in windows.  This drive will now automatically connet when booting in Boot Camp as E:\.

This was only half the battle though as previously mentioned when booting in VMware this column isn't accessible.  The solution to this is to enable Sharing in the Virtual Machine settings.  Now click Add, select the proper volume, and make sure it is set to Read & Write.  Note that you definitely want to leave Mirrored folders off here or you will have problems when booting back to Boot Camp.  You can also add other folders to share here like tour home folder or other external volumes.

Now you may have noticed that this volume is Read Only.  This is a limitation of OSX but there is a NTFS-3G Driver that will enable write access to the drive.  When installing be sure to chose the Cache option as the performance is needed and on a power failure only the programs will be vulnerable, not the OS itself.  Once installed you don't need to reboot, just click the X at the last screen then un mount the column and user Disk Utility to re-mount it.  You can now write to the NTFS volume all be it as a slightly reduced speed.

Upon booting VMware we not get a Z:\ shared folder with this external drive listed within it.  This will not work though as the applications will not be installed in the same location in both modes.  To fix this we need to create a login and logout scrip in VMware.  Open up C:\Program Files\VMware\VMware Tools  and make copies of the poweron-vm-default and poweroff-vm-default scripts.  Now open up My Computer, Z:\, and the shared external volume.  Copy the full path from the address bar at the top of the window.

Edit the poweron-vm-copy script and add the following line where DRIVE is the drive letter expected in windows and PATH is the path copied previously.
net use DRIVE: "PATH" /persistent:yes
Edit the poweroff-vm-copy script and add the following line where DRIVE is the same drive letter again.
net use DRIVE: /delete

For example here are mine:
net use e: "\\vmware-host\Shared Folders\Windows HD" /persistent:yes
net use e: /delete

Finally open up VMware tools and change the Shut Down Guest and Power On Guest scripts to point to the appropriate files we just created.  Now reboot and enjoy seamless reboots and convenience.

Other notes:
  • With this setup and the SSD I can switch back and forth between anteing and emulated environments in less them a minute.  
  • I also have both operating systems configured to load the majority of their applications and data onto the external drive and hold only the OS and working files on the SSD.  The only real exceptions to this are in OSX where most applications are acutely on the SSD as in both OS's the user profiles are still on the SSD.  I all detail my OSX setup in a future post.
  • You will notice that you can't use BootChamp to reboot when the VM is running.  You need to shut down Windows first before you can reboot to Boot Camp.  VMware does not acutely need to be exited and I tend to leave the application running and the VM set to auto start so that earn I boot back to OSX the VM automatically starts back up.