MacOS Compact VDI file

In order to compact a virtualbox VDI file and recover some of the lost space (especially useful when using a VM for your development databases) then its really rather simple:

  1. Login to the VM
  2. Run the following code:

sudo dd if=/dev/zero of=/tmp/nowt bs=4096k
sudo rm /tmp/nowt

  1. Shut down the VM
  2. Navigate to the folder containing the .vdi file
  3. Run this command:

VBoxManage modifymedium --compact [filename.vdi]

Vagrant – Errors trying to start

Using Vagrant as a dev environment is great apart from when it goes arry after an OS crash, or battery fault…

Chriss-MacBook-Pro:ceta chris$ vagrant reload

[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory

VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterface, interface IHostNetworkInterface
VBoxManage: error: Context: "int handleCreate(HandlerArg*, int, int*)" at line 68 of file VBoxManageHostonly.cpp

The only way I have found to fix this is to restart the VirtualBox service:

> sudo /Library/StartupItems/VirtualBox/VirtualBox restart

And then re-up it

> vagrant up


Setting up CentOS with no X Window Manager

For a nice VM I needed a Linux server, but no need for a GUI, so went for CentOS.

Installed fine, but no networking. How do I install that? Turns out, it is installed, just disabled by default:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Find the line ONBOOT and change to yes:

HWADDR=00:00:00:00:00:00:00 TYPE=ETHERNET
UUID=some guid string

Then just restart networking at you should be up and running:

service network restart

Test by entering ifconfig and you should see the loopback address.

If you need to install Guest Additions on VirtualBox:

yum update
yum install gcc make kernel-devel
mkdir /media/cdrom
mount /dev/scd0 /media/cdrom
sh /media/cdrom/