Last active
August 29, 2015 14:19
-
-
Save tbnorth/3d17d0ee5d2027950417 to your computer and use it in GitHub Desktop.
vbox error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The problem seems to be that createhd / storageattach do not register the | |
# media in any media registry, so non-standard media locations aren't | |
# findable. | |
# | |
# The quick hack vb_register_drive.py below can be used to register the media in | |
# either Virtualbox.xml or the .vbox file of a machine, and then everything works. | |
# vb_register_drive.py is a quick and dirty hack with lots of assumptions | |
# this is my recipe for making a vm on a headless machine which fails as seen | |
# below | |
DRIVE_PATH=/home/share/images/vbox/hdds/chk5.vdi | |
VM_NAME=chk5 | |
VBoxManage createhd --filename $DRIVE_PATH --diffparent \ | |
> c885180a-173c-447f-9150-1ae2fe368f63 | |
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | |
Disk image created. UUID: 0677f50a-9ba2-4991-b5c6-7b30711877e8 | |
VBoxManage createvm --name $VM_NAME --ostype Ubuntu_64 \ | |
> --register --basefolder /home/share/images/vbox/vms | |
Virtual machine 'chk5' is created and registered. | |
UUID: a398cb5d-fa53-410c-808c-6b318c6979de | |
Settings file: '/home/share/images/vbox/vms/chk5/chk5.vbox' | |
VBoxManage list vms | |
"u1404base" {63b15952-f945-4f6b-9f66-5e623723d8bc} | |
"chk5" {a398cb5d-fa53-410c-808c-6b318c6979de} | |
VBoxManage modifyvm $VM_NAME --hwvirtex on --pae on --ioapic on - | |
-cpus 2 \ | |
> --memory 2024 --acpi on | |
VBoxManage list vms | |
"u1404base" {63b15952-f945-4f6b-9f66-5e623723d8bc} | |
"chk5" {a398cb5d-fa53-410c-808c-6b318c6979de} | |
VBoxManage storagectl $VM_NAME --name "SATA Controller" --add sat | |
a \ | |
> --controller IntelAhci --bootable on | |
VBoxManage list vms | |
"u1404base" {63b15952-f945-4f6b-9f66-5e623723d8bc} | |
"chk5" {a398cb5d-fa53-410c-808c-6b318c6979de} | |
VBoxManage storageattach $VM_NAME --storagectl "SATA Controller" | |
\ | |
> --port 0 --device 0 --type hdd \ | |
> --medium $DRIVE_PATH | |
VBoxManage list vms | |
"u1404base" {63b15952-f945-4f6b-9f66-5e623723d8bc} | |
"chk5" {a398cb5d-fa53-410c-808c-6b318c6979de} | |
VBoxManage modifyvm $VM_NAME --nic1 nat \ | |
> --natpf1 ,tcp,,20022,,22 | |
VBoxManage list vms | |
"u1404base" {63b15952-f945-4f6b-9f66-5e623723d8bc} | |
"chk5" {a398cb5d-fa53-410c-808c-6b318c6979de} | |
VBoxManage modifyvm $VM_NAME --natpf1 ,tcp,,28082,,8082 | |
VBoxManage list vms | |
"u1404base" {63b15952-f945-4f6b-9f66-5e623723d8bc} | |
"chk5" {a398cb5d-fa53-410c-808c-6b318c6979de} | |
VBoxManage showvminfo $VM_NAME | |
VBoxManage: error: Could not find a registered machine named 'chk5' | |
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee nsISupports | |
VBoxManage: error: Context: "FindMachine(Bstr(VMNameOrUuid).raw(), machine.asOutParam())" at line 2610 of file VBoxManageInfo.cpp | |
VBoxManage list vms | |
"u1404base" {63b15952-f945-4f6b-9f66-5e623723d8bc} | |
"<inaccessible>" {a398cb5d-fa53-410c-808c-6b318c6979de} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is just an assumption laden hack to make things work | |
import subprocess | |
import sys | |
from lxml import etree | |
VB = "http://www.innotek.de/VirtualBox-settings" | |
NS = {'vb': VB} | |
machine_xml = sys.argv[1] | |
drive_file = sys.argv[2] | |
dom = etree.parse(open(machine_xml)) | |
cmd = subprocess.Popen(["VBoxManage", "showhdinfo", drive_file], | |
stdout=subprocess.PIPE) | |
out, err = cmd.communicate() | |
drive_uuid = out.split()[1] | |
parent_uuid = out.split()[4] | |
print "Drive UUID", drive_uuid | |
print "Parent UUID", parent_uuid | |
hds = dom.xpath("//vb:HardDisks", namespaces=NS)[0] | |
hd = hds.xpath('.//vb:HardDisk[@uuid="{%s}"]' % drive_uuid, namespaces=NS) | |
if hd: | |
raise Exception("Drive already registered for machine") | |
if parent_uuid != 'base': | |
parent = hds.xpath('.//vb:HardDisk[@uuid="{%s}"]' % | |
parent_uuid, namespaces=NS) | |
if not parent: | |
cmd = subprocess.Popen(["VBoxManage", "showhdinfo", parent_uuid], | |
stdout=subprocess.PIPE) | |
out, err = cmd.communicate() | |
out = out.split() | |
parent_location = out[out.index("Location:")+1] | |
parent = etree.Element("{%s}HardDisk" % VB) | |
parent.set('uuid', "{%s}" % parent_uuid) | |
parent.set('format', 'VDI') | |
parent.set('type', 'Normal') | |
parent.set('location', parent_location) | |
hds.append(parent) | |
else: | |
parent = hds | |
hd = etree.Element("{%s}HardDisk" % VB) | |
hd.set('uuid', "{%s}" % drive_uuid) | |
hd.set('location', drive_file) | |
hd.set('format', 'VDI') | |
if parent_uuid == 'base': | |
hd.set('type', 'Normal') | |
parent.append(hd) | |
open(machine_xml+'.bak', 'w').write(open(machine_xml).read()) | |
open(machine_xml, 'w').write(etree.tostring( | |
dom, xml_declaration=True, pretty_print=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment