VirtualBox on the command line: Summary so far
The last few entries have explained, command-by-command, how to create virtual machines and prepare them for OS installation, with some details about how to unwind this work (i.e. delete everything cleanly). In the process of writing the entries, I’ve learned new details about how to attach / remove storage devices (like hard drives and DVDs) in VirtualBox 3.1.2, which requires an extra layer of abstraction.
I thought I’d stick all the commands together in sequence for easy reference. Of course, I’m doing the same thing as a shell script right now to create some real machines of my own. As a result, I’m using the “-q” option in all commands to suppress the standard headers that appear after the typical VBoxManage command is run.
Creating a VM, attaching a hard drive and OS ISO, enabling networking and VRDP
This particular VM has 50 GB hard drive, 1024 MB RAM, FreeBSD 8.0 for AMD 64 as its OS, main bridged interface named eth0, and VRDP port 3390.
VBoxManage -q createhd --filename addievm.vdi --size 50000 --format VDI --variant Standard
VBoxManage -q createvm --name addievm --ostype FreeBSD_64 --register
VBoxManage -q modifyvm addievm --memory 1024 --nic1 bridged --bridgeadapter1 eth0 --vrdp on --vrdpport 3390
VboxManage -q --storagectl addievm --name "IDE Controller" --add ide
VBoxManage -q storageattach addievm --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium addievm.vdi
VBoxManage -q storageattach addievm --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /home/addie/8.0-RELEASE-amd64-disc1.iso
After running all of these commands, you should have a VM that is ready to be started up for OS install.
If something went horribly wrong, you may want to remove all your work and start again (I’ve had to do this more times than I’d care to admit). So here are the commands for unwinding all of the work you’ve just done without leaving extra traces lying around (the one thing left registered after this process will be the DVD used for install; I don’t remove it because I end up re-using it soon enough).
Removing the VM I just created - and its attachments
VBoxManage -q storageattach addievm --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium none
VBoxManage -q storageattach addievm --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium emptydrive
VBoxManage -q storagectl addievm --name "IDE Controller" --remove
VBoxManage -q closemedium disk addievm.vdi
rm /home/addie/.VirtualBox/HardDisks/addievm.vdi
VBoxManage -q unregistervm addievm --delete
That’s all for the summary - now on to new VirtualBox tasks!