VirtualBox on the command line: Tricky bits from the last post
Posted in Today I Learned... on February 5th, 2010 by addie – Be the first to commentSince writing my last post (VirtualBox on the command line: Creating and deleting VMs), I’ve discovered some tricky bits that anybody relying on the post will run into if using the newest version of VirtualBox CSE (3.1.2 at the time of this writing). My past documentation was based on an older version of Ubuntu and an older version of VirtualBox. The work I’ve been doing the last week is on newer versions of both the operating system and the software, and there are some important differences that I’d like to account for here.
In some cases, things are a little easier, and in other cases, they seem more complicated. In the case of the more complicated steps, this is a sacrifice for greater power and control in the VM; unfortunately all my simpler setups won’t be taking advantage of these new features.
Three issues to discuss here.
One. Open Source Edition (OSE) vs Closed Source Edition (CSE).
The version of VirtualBox which comes with Synaptic on Ubuntu Karmic Koala is the Open Source Edition. Unfortunately, if you’re going to be configuring virtual machines on a headless server, you’ll need to use the Closed Source Edition (CSE). In my case, this is because I need RDP enabled. With a headless server, I don’t have a way to access the virtual machine for its operating system install without RDP. Using RDP, I can access the virtual machine from a computer that does have a graphical output, and do the operating system install / configure networking so I can ssh into the machine in the future.
If you’re really a die-hard for the OSE, there is a way to get around this, but it will require that you do all of the creation and setup of a virtual machine (i.e., what I have been documenting here) on a non-headless operating system. So you’ll create your vms with a computer that has the VirtualBox GUI, do everything that you need a graphical interface for (operating system install and initial network configuration), and then export the vm you’ve just created. Upload it to the headless server, and import it into your copy of VirtualBox on that server. According to documentation I’ve been reading while doing my research, this should work and allow you to get around installing the closed source version on your headless server.
In my case, it’s just easier to install the closed source version. RDP is occasionally useful post-OS install too - for instance, the times that the virtual machine I am ssh’ed into stop responding. Often I can load up a remote desktop of this VM and I’ll see a swap space error or some other diagnostic that allows me to figure out what exactly went wrong instead of “machine just froze”.
With this all explained, I’ll try to document where things are “OSE only” or “CSE only” and if I haven’t made note of it, it hopefully works in both editions.
One note with regards to the stuff I’ve already documented is that the CSE uses a “vboxusers” group to determine who can administrate virtualboxes and who cannot. So if you want to be able to run any of the commands I’ve documented with CSE, your user will need to be part of the “vboxusers” group first.
Two. Attaching Virtual Hard Drives, and Storage Control.
This is the one that really got me today! When I entered the command I listed in the last entry to add a virtual hard disk to a freshly-created VM:
VBoxManage modifyvm addievm --hda addievm.vdi
I got this error:
ERROR: Could not find a storage controller named 'IDE Controller'
Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component Machine, interface IMachine, callee nsISupports
Context: "AttachDevice(Bstr("IDE Controller"), 0, 0, DeviceType_HardDisk, uuid)" at line 556 of file VBoxManageModifyVM.cpp
I did some research online and discovered the solution. My understanding of what’s changed here: the newest version of VBoxManage allows for vastly improved control and flexibility with regards to controllers. Introduced to VBoxManage are a couple options related to these new powers: storagectl and storageattach. The drawback to this new amount of control is that the old “default” controller configuration no longer exists - you need to create it yourself.
The solution I found no longer uses the “modifyvm –hda” command. Instead, it looks like this:
VBoxManage storagectl addievm --name "IDE Controller" --add ide
VBoxManage storageattach addievm --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium addievm.vdi
The IDE controller, which used to be available sans configuration, is now created and attached to the VM using the first command. The second command attaches the hard drive to the controller.
I’ll be revisiting these commands in my next post, when I look more closely at the configuration required for operating system install.
Three. Networking.
Networking has never been my strong suit, but with the VirtualBox GUI, getting the guest machine to use the host machine’s internet was as simple as a matter of clicks. This was harder to do on the command line. On the old install of VirtualBox that I was working with up until this week, configuring a bridged connection between the host interface and the guest interface required a lot of additional work, which is documented here (see the heading “Host Networking in Ubuntu 8.04 and older”). The particular thing that actually spurred the upgrade to newer versions of Ubuntu and VirtualBox was networking - adding additional bridge ports to the bridge interface didn’t fix the networking problems I was having, despite following the documentation word-for-word. I read that newer versions of Ubuntu / VirtualBox don’t even require the complicated setup of a bridge interface and several additional bridge port interfaces, and I was sold on upgrading.
Ideally, setting up your network then looks something like it did in the last post (in this case, “eth0″ is the default network interface on the host machine):
VBoxManage modifyvm addievm --nic1 bridged
VBoxManage modifyvm addievm --bridgeadapter1 eth0
… but when I started up my OS install (the FreeBSD bootonly disk downloads the rest of the install and therefore requires an internet connection), my internet wasn’t working. The solution was to install some missing modules:
sudo modprobe vboxnetflt
This is documented in the same place I referenced earlier, Ubuntu documentation: VirtualBox Networking.
…
Now that these tricky bits are documented, it’s time to move on to attaching an ISO to the VM to allow for OS install, and using VRDP to facilitate that install. That will be the next entry, and hopefully with fewer corrections and caveats now that I’m up-to-date on my software.