Physical to Virtual under VMware fusion
With El Capitan just around the corner I like to keep a copy of my currently running machine around just in case. I previously used a tortuous method of keeping my old Mountain Lion image around while migrating to Yosemite, which took about 3 attempts and over a week to get working. This time round, I've got a much easier method which uses no intermediate disk space making the process quicker as there is less copying of data around.
What you need:
- The Yosemite Install Image from the Mac store.
- A current version of VMware Fusion (I'm using version 7.1.2)
- Carbon Copy Cloner (I'm using version 4.1.3). Other disk cloning utility may work, but this is the one I use regularly for my backups and it works for me and the specifics in this tutorial will use CCC.
- A passing experience of using the terminal command line.
- Optional - A copy of 'Beamoff' to optimise the screen when running Yosemite in a VM. This utility, along with a discussion on why it is needed under Fusion 7, can be found at this insanely mac forum post. VMware have promised this will be in a future version of the vmware tools but, as of writing this, it is not included.
Method
- Create a new VMware fusion image. Use the 'Disc Image' open, and select Continue
- Now, use the finder to find the 'Install OS X Yosemite' application. It should be under /Applications. If it is not, then you may have to open the App store, go to 'Purchased Items' and download it again. Select this image and drag it onto the middle of the window. If you have problems, or it does not work, use the 'Select another disc image' button and navigate to the Yosemite Image and select it.
- Select the Yosemite image and press 'Continue'
- Click 'Customize Settings'. A new widow will pop up asking where the image is to be saved, and what name so complete this and continue. It will then create an installation image for a few minutes:
- Change whatever else is normally changed for your VM machine here. I like to remove the sharing of bluetooth devices or else my mouse and trackpad can often change their focus to be the VM and not my main mac which can be annoying.
However, the important step that needs to be followed is the creating of a new virtual disk which is the at least the same size as the physical disk from which you want to clone. You will notice that there are 2 disks initially; the reason for this is that 'Hard disk 2' is the temporary installation disk. - Select the 'Add Device' along the top, Select 'New Hard Disk' and the click 'Add' at the bottom of the tab. Select the correct size and click 'Apply'. I've chose an image of 1TB for my example below. Note that after you click 'Apply' all that will happen in the all the buttons grey out showing the task has been completed. Select 'Show All' to go back to the full setting list.
- Now, we're ready to install, so go ahead and start the VM and install Yosemite as normal.
- Skip all of the Apple ID stuff and just create a basic machine when the startup process asks for it. At the end of it all, the machine will boot, but you will get an error on the screen "The disk you inserted was not readable by this computer". This is the 2nd disk that was added in the stage above. Go ahead and select 'Initialize' which will start 'Disk Utility'.
- Select the large disk image from the left hand tab:
- Click 'Apply' and then the next popup and the new disk will be formatted. You may get a new pop-up asking if you want to use the disk as a time machine backup. You don't.
- Now quit disk utility and you should see the new disk appear on the desktop. At this point, click the 'Virtual Machine' menu from Fusion and select 'Install VMware tools' and then follow the prompts to install the tools, rebooting at the end as required.
- For the transfer of the image, you will need the network address of this machine, so open 'System Preferences' and select 'Network'. You should see a window line the one below with the active IP address of the machine. Make a note of this address.
- At the same time as this, you need to enable the remote login services under the 'sharing' preferences pane. Do this now, or else Carbon Copy Cloner will complain when you install it.
- On your physical machine, start up Carbon Copy Cloner and create a new task. As your source disk, select the physical disk you want to clone - normal 'Macintosh HD' and select 'All files' to clone
- Under Destination, under 'Other Destinations', select 'Remote Macintosh' and then put the IP address recorded above, and put the 'Path to destination folder' as /Volumes/<name of the 2nd disk>. e.g:
- Now, select the package just created on the desktop and drag it over your running VM. When you get over the virtual screen and release it, it should copy to the remote VM desktop.
- Before continuing, the CCC package just copied across needs to be changed slightly to work. CCC uses the same package on both source and destination machines to install the keys required to work but uses the hardware address to work out if the package is being run on a machine where there package was created. For a virtual machine, the HW addresses are the same so the installation script on the Virtual machine needs to be changed slightly so that the 'sourceHW' variable is different.
- Assuming the package is on the desktop, the following command line will change the contents of the package to work correctly and assume that this is a client machine for the purposes of Carbon Copy Cloner. Open the terminal and type the following command (all on one line - it may be split up when viewing here). I've used shell wild cards a lot here to reduce the amount needed to type and to fit on one line.
- (For those wishing to be more circumspect about changing this, what needs to occur is a change to the variable 'sourceHW' in the 'post flight' script contained within the package. It must be set to a different value to allow the package to install correctly.) The expanded path that needs to be edited is $HOME/Desktop/Authentication Credentials from*.pkg/Contents/Resources/postflight" where the name of the package will vary depending on the name of the machine on which it was created.
- Double click the package on the desktop of the VM to install it, and follow the prompts.
- The package the CCC created on your physical machine now needs to be run as well. Double click on the package created on your physical machine's desktop and follow the prompts.
- At this point, everything is set up for the copying of the Physical to the virtual machine. On CCC click the 'Clone' button and watch to see the data being transferred across.
- When the transfer has completed, shut down the virtual machine
- Click on the settings for the virtual machines and select the new virtual hard disk as the new boot drive in the setting section under "Startup Disk" and then click restart. The machine should now but up as a copy of the physical machine.
and then change the Partition Layout to '1 Partition' and ensure the Format is 'Mac OS Extended (Journaled)'; it must not be 'case sensitive'. Also, change the name to something reasonable:
Before continuing, click the 'Create Authentication Credentials package' button and follow the steps to create a package locally. Ideally, save this package on your desktop. After it has created the package, click 'OK'.
perl -pi -e 's/^s.*W=.*/sourceHW="deadbeef"/' ~/D*/Au*.pkg/C*/R*/p*t
Post Install Tasks
Now that this is complete, you'll notice on reboot a few things not quite working 100%. These are easy to fix.
- The VM machine will have the same as the physical machine. There will be a warning message popping up about two machines on the same network with the same name, but Yosemite will rename the VM to stop the conflict. If you want to change it to something better, go to 'System Preferences' -> 'Sharing' and change the 'Computer Name' to something you want.
- The install of VMware tools will have been overwritten. The tools will need to be re-installed so that the screen can be resized, drag and drop work etc.
That should be it all. Hopefully this will help others who have wanted to virtualize their macs.
Updating The Image
If you need to update the image with a later copy you should not use Carbon Copy Cloner to copy disk onto of the current running image. You need to do the following to the virtual Mac:
- Shut down the virtual Mac.
- In VMware tools, change the boot disk to be the initial disk you creating the initial OS image on. i.e. change it from the current disk to the other one.
- Save and restart. When the VM boots, the original OS image will be booted and you can carry on to clone the physical machine as in steps 22 and above.