[Solved] Prevent re-adding harddisk when it changed

Discussions related to using VirtualBox on Linux hosts.
Post Reply
hrniels
Posts: 2
Joined: 1. Sep 2009, 00:11
Primary OS: Ubuntu 8.10
VBox Version: OSE Debian
Guest OSses: my own

[Solved] Prevent re-adding harddisk when it changed

Post 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
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Prevent re-adding harddisk when it changed

Post 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.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
hrniels
Posts: 2
Joined: 1. Sep 2009, 00:11
Primary OS: Ubuntu 8.10
VBox Version: OSE Debian
Guest OSses: my own

Re: Prevent re-adding harddisk when it changed

Post 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!
Post Reply