Creating a new VirtualBox VM on the command line

I finally removed a computer that I’ve had running for quite a while, configuring another “intermittently operational” system to run all the time.  I’d like to have the old system run as a VirtualBox VM on the new system.  My VirtualBox VMs are running headless as services using VboxVMService.  Further, one of my VirtualBox VMs runs an Ubuntu guest which itself runs Linux Containers guests for some small, lightweight hosts on my network.

I’ve got a couple of existing LXC guests that do some monitoring for me using Nagios, run a Gitlab instance, and a couple of others that I no longer need and will probably remove.  I’d also like to set up a couple of new hosts to run a small, simple webserver for my home network “homepage” with links to things I commonly use and a Puppet system to manage my configurations a little bit more efficiently (especially credentials if I look to expand the number of Linux hosts on my network; I’d like the logins to be maintained automatically, and very preferably to be key based).

My straight Nagios monitoring takes a bit more thought to maintain than I’d like, given the number of things on my mind at any given time, so that’s one of the first things I’d like to simplify.  However, from the point of view of simplicity, creating a dead simple web host (though I’d like to eventually integrate some DNS service discovery…) is the simplest.

I spun up a new, basic LXC with Apache, RCS, and a few Perl modules to load Foswiki onto for a basic intranet home page.

Finally attempting to spin a new VM from the command line… fails

VBoxVMService does not allow you to run the VirtualBox GUI at the same time, as I understand it.  As such, I assume that I will need to create any new native (non-LXC) guests I require from the command line.  This Oracle reference describes how to configure the VM instances from the CLI using the ‘vboxmanage’ command.  However, upon issuing a ‘vboxmanage list ostypes’ command, I discovered that even the CLI version appears to be dependent upon the same COM configuration that prevents the GUI from running.  So, I configured as stated at http://sourceforge.net/p/vboxvmservice/wiki/Runing%20VirtualBox%20GUI%20together%20with%20VBoxVmService/.  This didn’t take immediately, so I restarted.

Numerous hassles

I had a lot of problems being able to get back into VirtualBox to work on setting up a VM to replace the machine I took down, generally appearing to be related to permissions.  I’d run across a batch file that someone had written that supposedly sets the permissions appropriately to allow you to switch back and forth between the VirtualBox GUI and VBoxVMService, but it didn’t seem to be very effective.  I was finally successful after uninstalling VirtualBox, deleting the VirtualBox directory, reinstalling, then going into DCOMConfig and setting permissions back to defaults (everything on Security tab as “Use Defaults” and the Identity tab as “Launching User”).  That let me get back in and do some things.

Using a physical/raw disk in a VM

I referenced these instructions to configure the disk I had pulled from my old system as a raw disk for the VM.  A couple of notes on items that proved handy:

  • The command wmic diskdrive list brief under Windows 7 helps to identify the correct PhysicalDrive setting to use in creating the VMDK.
  • User Account Control under Windows 7 is a turd for configuring the physical disk as a VMDK.  I was able to get around this by going into User Accounts -> Change User Account Control Settings and slid the bar all the way to the bottom – i.e., don’t prompt me for anything (I didn’t reboot as the system told me I had to).  I was then able to create the VMDK under my local account, which has administrative privileges (previously I had received the error “VBoxManage.exe: error: Cannot open the raw disk ‘\\.\PhysicalDrive1’: VERR_ACCESS_DENIED
    VBoxManage.exe: error: The raw disk vmdk file was not created” under my own account and “VBoxManage.exe: error: Failed to create the VirtualBox object!
    VBoxManage.exe: error: Code CO_E_SERVER_EXEC_FAILURE (0x80080005) – Server execution failed (extended info not available)
    VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running orfailed to start” under a “runas administrator” command window.

This was a great idea until I determined that I couldn’t (or at least there wasn’t a method I could find) grant my user account raw/physical disk access under Windows 7 Home.  I can run VirtualBox as an administrator and launch the machine, booting from the physical drive, and everything works.  Unfortunately I’d prefer not to run as an administrator, so I will probably need to work on converting the physical disk to an image.  My goal is ultimately to get everything copied off of that drive anyway and eliminate the machine; I had just thought this might be a shortcut to save a step or two.

Leave a Reply

Your email address will not be published. Required fields are marked *