Trying to reattach old .vdi

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
BoiledFrog
Posts: 23
Joined: 22. Jun 2012, 04:22
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux
Location: Vancouver, BC

Trying to reattach old .vdi

Post by BoiledFrog »

I used the some instructions at an unspecified location to try and expand the hard drive of my Windows 7 guest on my Mac OS X Lion host. It turns out it didn't work so I just want to get back to the original hard drive. However, I can't attach an "existing disk" to my VM if it exists in my ~/Library directory because VirtualBox won't show me the directory. I decided to hard link (with ln) to my home directory so I could see it but now it says:
Failed to open the hard disk /Users/Stephen/Windows 7.vdi.

Cannot register the hard disk '/Users/Stephen/Windows 7.vdi' {0b4e77a9-b593-4c06-8c31-f97a2f6d7c53} because a hard disk '/Users/Stephen/Library/VirtualBox/HardDisks/Windows 7.vdi' with UUID {0b4e77a9-b593-4c06-8c31-f97a2f6d7c53} already exists.

Result Code: NS_ERROR_INVALID_ARG (0x80070057)
Component: VirtualBox
Interface: IVirtualBox {c28be65f-1a8f-43b4-81f1-eb60cb516e66}
However, I have deleted all the hard disks on my controller so where is it getting this information from?
Zium
Posts: 69
Joined: 16. Oct 2009, 23:09
Primary OS: MS Windows XP
VBox Version: OSE other
Guest OSses: Win98, WinXP, Win2003

Re: Trying to reattach old .vdi

Post by Zium »

Remove the old disk from Virtual Media Manager.
BoiledFrog
Posts: 23
Joined: 22. Jun 2012, 04:22
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux
Location: Vancouver, BC

Re: Trying to reattach old .vdi

Post by BoiledFrog »

That didn't work. I can't remove the .vdi because the "Remove" icon is greyed out. I did remove the UUID from underneath the .vdi but I am still getting the same error.

I was running an older version of VirtualBox but I just upgraded to 4.2.1 and it has the same problem.
Zium
Posts: 69
Joined: 16. Oct 2009, 23:09
Primary OS: MS Windows XP
VBox Version: OSE other
Guest OSses: Win98, WinXP, Win2003

Re: Trying to reattach old .vdi

Post by Zium »

Your vdi is still attached to a VM, try releasing it first in the VMM.
BoiledFrog
Posts: 23
Joined: 22. Jun 2012, 04:22
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux
Location: Vancouver, BC

Re: Trying to reattach old .vdi

Post by BoiledFrog »

It doesn't appear to be. I only have one VM and the IDE Controller for that is empty other than an optical drive.
Why can't I reattach my old drive?
Why can't I reattach my old drive?
Empty IDE Controller.jpg (72.91 KiB) Viewed 7714 times
Zium
Posts: 69
Joined: 16. Oct 2009, 23:09
Primary OS: MS Windows XP
VBox Version: OSE other
Guest OSses: Win98, WinXP, Win2003

Re: Trying to reattach old .vdi

Post by Zium »

And what shows the VMM ?
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Trying to reattach old .vdi

Post by mpack »

BoiledFrog wrote:I can't remove the .vdi because the "Remove" icon is greyed out.
The Remove icon is grayed out if a running VM is still using the disk. Make sure VMs are shut down, not suspended. Snapshots may also cause this problem: seems likely but I can't be totally sure since I never use snapshots.
BoiledFrog
Posts: 23
Joined: 22. Jun 2012, 04:22
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux
Location: Vancouver, BC

Re: Trying to reattach old .vdi

Post by BoiledFrog »

The VM is not running but I do have a snapshot. Is there a way to delete (or merge) the snapshot? I don't think I can restore it since I've got data on the drive I don't want to lose.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Trying to reattach old .vdi

Post by mpack »

I think there are a few misconceptions roaming around in this thread.

I am assuming that the following is what you did (correct me if any point is false and I will adjust the advice accordingly):
  1. You wanted to enlarge a disk, but you were nervous of damaging the VM, so you sensibly made a backup of the base VDI (actually you really ought to back up the entire VM folder, particularly if you use snapshots).
  2. You went through the "VBoxManage modifyhd --resize" malarky to resize the disk.
  3. When you reran the VM you found that the disk size had not changed (that's because the VM doesn't have the base VDI mounted, it has the snapshot mounted).
  4. So, you tried to restore the original VDI by remounting it. Bad for two reasons: first the VM is supposed to be using the the snapshot, second none of your previous steps unregistered the base VDI. The correct procedure was simply to use the host OS to copy the backup VDI back to the VM folder, overwriting your modified base VDI. This works fine provided the backup was a simple copy made by the host OS, not a clone made with VirtualBox.
The easiest repair depends on the current state of play. If the VM still runs then doing a full clone of the current state will give you a stand-alone clone VM with a merged disk (no snapshots) which you can easily resize.
BoiledFrog
Posts: 23
Joined: 22. Jun 2012, 04:22
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux
Location: Vancouver, BC

Re: Trying to reattach old .vdi

Post by BoiledFrog »

I followed these instructions to expand the hard drive. It appears that this is the hard way of doing things. I am not sure what terms I used to find that page but that's what I found.

To summarize:

1. Created two larger .vdis
2. Formatted the .vdis inside Windows 7 guest.
3. Cloned original drive using clonezilla and saved it on one of the new drives.
4. Restored image to other new drive.
5. Reconfigured to try and use new drive as the boot disk.

I think step #5 is where things went wrong.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Trying to reattach old .vdi

Post by mpack »

Yes, step 5 will definitely go wrong: you can't mount a cloned drive in a VM which uses snapshots - the snapshot control information confuses everything. What you need to do instead is ignore the original VM and build a new VM around the cloned disk (or: full clone of VM current state, then replace the hd in the clone VM, then release/remove/delete the replaced disk). Eventually delete the old VM after testing that the new VM works.

And yes, the advice you followed was obsolete and overly complicated even in 2009. It's very annoying that it keeps getting passed around. Even on its own terms it is needlessly complicated: I'm pretty sure CloneZilla can clone drive A directly to drive B, there was never a need to make an intermediate copy.
BoiledFrog
Posts: 23
Joined: 22. Jun 2012, 04:22
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux
Location: Vancouver, BC

Re: Trying to reattach old .vdi

Post by BoiledFrog »

I cloned it but it Windows 7 thinks the installation is damaged. I tried to repair it but it's not working. Can I just restore my old VM from Time Machine? What would I need to recover?
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Trying to reattach old .vdi

Post by mpack »

I'm afraid "it's not working" is not enough for a diagnosis. I also can't give advice on Time Machine because I'm not a Mac user. However, if you can restore the contents of the VM folder to before you made the first change then it should work.
BoiledFrog
Posts: 23
Joined: 22. Jun 2012, 04:22
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux
Location: Vancouver, BC

Re: Trying to reattach old .vdi

Post by BoiledFrog »

The Windows repair is not working. I can't tell you much more than that. Windows boots, tries to repair itself, and fails. There doesn't seem to be a problem with VirtualBox itself.
BoiledFrog
Posts: 23
Joined: 22. Jun 2012, 04:22
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux
Location: Vancouver, BC

Re: Trying to reattach old .vdi

Post by BoiledFrog »

I renamed $HOME/Library/Virtualbox and restored a copy from TIme Machine and I'm back to square one. My Windows 7 VM boots up without error now. I will try and expand the disk the easy way now.
Post Reply