I’ve recently bought a Mac Mini so I will have access to a machine for development purposes, a remote home server and and taking advantage of my super-fast home connection. In this post, I will share the steps taken and my configuration in case anyone is interested. If I have missed something, please feel free to let me know.
Use your favorite SSH client to connect to your OSX server. Once you have done that, you are ready to begin. In the example below, please note, we are forwarding port 5000 to the server’s port 5000. This will be explained later.
$ ssh -L 5000:localhost:5000 your.home.server
First, OSX has quite optimal power-saving features enabled by default. When OSX sleeps, your guests will pause. So, you need to configure it not to sleep. This is quick and easy.
$ sudo pmset -a sleep 0
In this example, I use Scientific Linux as the guest operating platform since it is a RedHat Enterprise Server respin. If you do not have it, go ahead and download the image of your choice. I prefer the boot-only iso and perform a network install.
$ curl -o SL-65-x86_64-2013-12-05-boot.iso http://ftp1.scientificlinux.org/linux/scientific/6x/x86_64/iso/SL-65-x86_64-2013-12-05-boot.iso
Now, it is time to install VirtualBox. Head over to virtualbox.org and download the latest OSX package along with the extension pack. Once you have these two files, you need to install the application from the dmg. First, mount the dmg volume and execute the installer with root privileges. Once this is done, you should then detach the volume. You will now have VirtualBox installed.
$ hdiutil attach VirtualBox-4.3.12-93733-OSX.dmg
$ sudo installer -pkg /Volumes/VirtualBox/VirtualBox.pkg -target /Volumes/Macintosh\ HD
$ hdiutil info # You may not need this but it lists the device path below
$ hdiutil detach /dev/disk1s2
At this point, you may install guests. However, for various reasons, the extension pack is preferred. If you would like to use the remote desktop connection, you will need it. I strongly recommend installation.
$ sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack
$ VBoxManage extpack cleanup # In case of failure, run this command and try again
You now have an optimal environment for running VirtualBox guests headless with complete command-line access and control along with remote desktop connections. However, there is no guests. As such, let’s install one!
You will need to instruct VirtualBox to register a guest. In this instance, the name of the guest will be SL6-1 of type RedHat 64 bit.
$ VBoxManage createvm --name SL6-1 --ostype RedHat_64 --register
As long as the previous command did not return an error, the registration should be successful. However, this is only the beginning. There is information required such as the amount of memory, storage and network configuration. The ‘modifyvm’ subcommand allows one to specify a plethora of information. In this example, I am alloting 512 MB RAM, enabling ACPI, configuring boot from DVD, bridging virtual Ethernet adapter one to the host’s ‘en0’ and enabling the remote desktop port on 5000.
$ VBoxManage modifyvm SL6-1 --memory 512 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 en0 --vrdeport 5000
Now, create the virtual hard drive file of size ten gibibytes. Please note, this file will normally be placed in ~/VirtualBox VMs/SL6-1/ directory since the SL6-1 is the name of this guest. You can either create this file in that directory, or move it there after you have created it.
$ VBoxManage createhd --filename SL6-1_Main.vdi --size 10000
The storage disks need a controller. In this case, I will use SATA for the storage disks and IDE for the DVD. The DVD controller is necessary for installation of the platform and guest additions.
$ VBoxManage storagectl SL6-1 --name "SATA Controller" --add sata --controller IntelAhci
$ VBoxManage storagectl SL6-1 --name "IDE Controller" --add ide --controller PIIX4
Since the controller now exists, you can attach the storage medium to it. The SATA disk will be the file we have just created. The IDE disk, or DVD, will be the downloaded ISO file for installation of Scientific Linux. We are only using one disk on each type, so use port and device zero.
$ VBoxManage storageattach SL6-1 --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "SL6-1_Main.vdi"
$ VBoxManage storageattach SL6-1 --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium ~/Downloads/SL-65-x86_64-2013-12-05-boot.iso
The guest is completely configured with RAM, network interface, storage devices and display console. It is configured to boot from DVD which has been “inserted”. Now, it is time to turn it on
$ VBoxManage startvm SL6-1 --type headless
Assuming no typo’s, or non-default configuration, you should now have a VM guest running and prompting on installation. If you recall, we ssh’d in with port 5000 forwarded. This is because we configured RDP on port 5000. You can open your favorite remote desktop connection client and connect to localhost:5000 now. The point of this article does not cover installation of Scientific Linux. However, you will need to provide the following URL to the installation medium if you do not have it. The download at the beginning does not.
http://ftp1.scientificlinux.org/linux/scientific/6.5/x86_64/os/
Once the installation is complete, it will ask you to reboot the machine. Instead of selecting that, you can simply power off the guest. You will need to remove the DVD by providing ‘none’ as the medium.
$ VBoxManage controlvm SL6-1 poweroff
$ VBoxManage storageattach SL6-1 --storagectl "IDE Controller" --port 0 --device 0 --medium none
Once this is complete, you have a fully functioning guest. However, there are VirtualBox guest additions that provide features you may desire in the future. The VirtualBox installation comes with a virtual DVD iso. You need to find the path and then mount it to the same device/controller as the Scientific Linux medium.
$ find /Applications/VirtualBox.app/ -iname '*.iso'
/Applications/VirtualBox.app//Contents/MacOS/VBoxGuestAdditions.iso
$ VBoxManage storageattach SL6-1 --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso
Now, power on the guest with the same command used to start the installation. The guest will boot to login. You may now login with the credentials you provided. In order to install the guest additions, there are certain package necessary. The following command will install these.
# yum install gcc kernel-devel perl
The DVD was “inserted” and now needs mounted manually. Create the directory to mount to, mount the dvd and run the additions installer.
# mkdir /media/dvd
# mount /dev/dev /media/dvd
# /media/dvd/VBoxLinuxAdditions.run
Again, assuming all is well and no errors, you may reboot the guest and enjoy a fully-functioning VirtualBox system with all extensions and guest additions.