Page 1 of 1

[Solved] Prevent re-adding harddisk when it changed

Posted: 1. Sep 2009, 00:25
by hrniels
Hi!

I'm developing my own OS and want to test it with VirtualBox. All stuff (kernel, driver, user-apps, ...) is stored on a hard disk image that is generated by me. So as soon as any of these change the disk image has to be changed, too. As soon as the disk image changed VirtualBox complains about it with something like:
VirtualBox wrote:VM cannot start because the hard disk '/home/hrniels/escape/source/vmware/vmwarehddimg.vmdk' is not accessible (Actual UUID {6967a079-685d-4a98-894c-74d8058715b3} of the hard disk image '/home/hrniels/escape/source/vmware/vmwarehddimg.vmdk' doesn't match UUID {c66e84ad-1ca2-4c7e-9307-4bc63ccb9a46} stored in the registry).
In the long run it is a little bit annoying that I have to release and remove the disk, add it again and assign it to my VM everytime to be able to start it again.
So my question is: Is there a way to tell VirtualBox that it should ignore it and simply use the image although it has changed? Or is it possible (not too complicated) to generate the UUID on my own from the disk image and change it in the config so that VirtualBox doesn't notice the change? Or any other way to automate it?

Thanks!
hrniels

Re: Prevent re-adding harddisk when it changed

Posted: 1. Sep 2009, 10:56
by Sasquatch
You can get it's UUID by running VboxManage showhdinfo <path+filename>. However, it's possible that you get an error that a similar hard drive is already attached. But you at least get to see the UUID. After that, you can edit the two XML files (VirtualBox.xml and <machine>.xml) and change the existing UUID with the new one. Does about the same. It's possible to script it, closemedium, then openmedium and modifyvm. Doing the same as with the GUI, only automated through CLI/script.

Re: Prevent re-adding harddisk when it changed

Posted: 1. Sep 2009, 16:59
by hrniels
Ok, its working now :)
If somebody has the same problem, here is the shellscript I'm using:

Code: Select all

#!/bin/bash

# check arguments
if [ $# -ne 2 ]; then
	echo "Usage: $0 <vmName> <pathToVDI>" 1>&2
	exit 1
fi

# check if the UUID has changed
if [ "`VBoxManage showhdinfo \"$2\" | grep 'Access Error'`" != "" ]; then
	# first detach disk from vm
	VBoxManage modifyvm "$1" --hda none
	# remove disk
	VBoxManage closemedium disk "$2"
	# add disk again
	VBoxManage openmedium disk "$2"
	# attach to vm
	VBoxManage modifyvm "$1" --hda "$2"
fi;
Surely not perfect (e.g. I'm assuming that the disk is just attached to one vm) but works and is enough for my purposes.

Thank you for your help!