Tuesday, March 25, 2014

Virtualize physical OS X Server: Best practice

So you plan to virtualize a physical server running OS X?

Too bad all the tool for converting a physical server into a virtual server run on Windows or Unix.

Wenn, actually there is (quite) a simple way to do this. This method is independent of any product and can be used with any virtualization such as Parallels, VMware.

Just follow these steps:

On you physical server:

  1. Boot from an external volume and create a disk image of your server using 'Disk Utility'.
  2. After the disk image has been written, mount it and verify that it can be read and has all the data required on it.
  3. Select the image in the sidebar and run the menu 'Images > Scan Image for Restore'
  4. Turn off your physical server
Intermediate steps:
  1. Copy your disk image to a server that is accessible via AFP
  2. Note down the address, path and the credentials needed to access this image via AFP.
Inside virtualization:
  1. Create a new virtual machine for OS X.
  2. Make sure you have access to a bootable OS X media inside the virtualization. Normally this is done by using a disk image that is assigned to the virtual machine as a  CD ROM drive. If you are unsure how to create such a medium, you can use an app like DiskMaker X to create a bootable USB stick from which you can create a bootable disk image.
  3. Create a HDD in the virtual machine that is large enough.
  4. Create a network interface that has access to a network, preferably one that assigns addresses via DHCP.
  5. Start the virtual machine
Inside the virtual machine:
  1. The VM will now boot using the disk image supplied. In this example I am using a bootable "OS X 10.9 Mavericks" but the same method works with other versions.
  2. Don't start the installation process!!! Remember: we want a virtualized copy of our physical server, not a new server
  3. From the 'Utilities' menu select 'Terminal'.
  4. Once the terminal is running make sure we have an IP address by typing 'ifconfig'. The line starting with 'inet' should now show a valid IP address.
  5. Now we need to mount our disk image. There is a little trick involved here. As we have to mount our server via command line, we need a folder to attach our mount to it. In order to do so, we need a writable directory.
  6. One directory that is writeable is the Trash. So we cd into that directory by typing the command 'cd Library/.Trashes'.
  7. We are now in the directory '/var/root/Library/.Trashes'. Check that it is writeable by creating a folder using the command 'mkdir mnt'. If you see this 'mkdir: mnt: Read-only file system' you have to find another folder that is writable. There is always one as the system itself need to write certain files.
  8. So once we have created our directory, we can mount the AFP share that host our disk image. This is done by issuing the command (by replacing 'myusername', 'myserver' and 'mysharedvolume' with you own data as noted above)  'mount_afp -i afp://myusername@myserver/mysharedvolume mnt'   
  9. You are now requested for the password of the AFP user you use to mount the volume
  10. Once the volume has been mounted, you can verify everything is working by showing the contents of the mount volume by issuing the command 'ls -l mnt'.
  11. If your disk image is visible in here, we're almost done.
  12. Quit the Terminal
  13. Open 'Utilities > Disk Utility'
  14. Select the disk image of your virtual machine and go to the 'Restore' tab.
  15. In here, drag the disk you selected on the left that is now listed as 'Source' to the 'Destination field.
  16. Now we click on the button 'Image…' next to the 'Source' field. Here we select the image we created from our physical server that is now located on our AFP share we mounted in the steps above.
  17. Once this has been done, we can click on 'Restore'.
  18. The disk image of our physical server is now being restore to our virtual server.
  19. Once this has completed, we can quit 'Disk Utility' and go to 'Startup Disk…' that can be found in the menu under the Apple logo.
  20. Here we select our newly restored disk.
  21. Select 'Shut down' from the Apple menu
  22. Go to the settings of your VM and adjust network and RAM configurations as required. Detach the image file attached to the CD ROM drive.
  23. Start the VM.
  24. Et voilĂ  ! An exact copy of your physical server is now virtualized.

No comments: