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:
- Login to the VM
- Run the following code:
sudo dd if=/dev/zero of=/tmp/nowt bs=4096k
sudo rm /tmp/nowt
- Shut down the VM
- Navigate to the folder containing the .vdi file
- Run this command:
VBoxManage modifymedium --compact [filename.vdi]
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"]
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
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:
Find the line ONBOOT and change to yes:
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 install gcc make kernel-devel
mount /dev/scd0 /media/cdrom