How to use a virtual disk on a removable drive? (#17506)

Discussions related to using VirtualBox on Windows hosts.
dlippold
Posts: 11
Joined: 23. Jan 2018, 15:54

How to use a virtual disk on a removable drive? (#17506)

Post by dlippold »


[ ModEdit; related ticket: #17506: It should be possible to boot a guest with an unconnected hotplug disk ]
I have a virtual disk (VDI file) on a removable drive (an USB disk) connected to the Windows host. The virtual disk is mounted in the Linux guest only when needed ("noauto" mount option in /etc/fstab). When the removable drive is connected to the host everything works fine. But when the removable drive is not connected I cannot start the virtual machine because I get the following message:
Could not open the medium 'E:\VirtualBoxDisks\Lubuntu-16.04-Backup.vdi'.
VD: error VERR_PATH_NOT_FOUND opening image file 'E:\VirtualBoxDisks\Lubuntu-16.04-Backup.vdi' (VERR_PATH_NOT_FOUND).

Fehlercode:
E_FAIL (0x80004005)
Komponente:
MediumWrap
Interface:
IMedium {4afe423b-43e0-e9d0-82e8-ceb307940dda}
How can I configure VirtualBox so that it starts the guest even if the virtual disk (on the removable drive) is not available?

The VDI file is connected by a (virtual) SATA controller in VirtualBox. I already tested to mark the VDI file as "hotplug" but that didn't change anything. I also tested to connect the VDI file by a USB controller (with and without hotplug) but that also didn't change anything.

I use VirtualBox 5.2.4r119785 with a Windows 7 64bit (with Service Pack 1) host and Lubuntu 16.04 64bit (kernel "4.13.0-31-generic #34~16.04.1-Ubuntu SMP") as guest.

Output of "VBoxManage list extpacks":
Extension Packs: 1
Pack no. 0: Oracle VM VirtualBox Extension Pack
Version: 5.2.4
Revision: 119785
Edition:
Description: USB 2.0 and USB 3.0 Host Controller, Host Webcam, VirtualBox RDP, PXE ROM, Disk Encryption, NVMe.
VRDE Module: VBoxVRDP
Usable: true
Why unusable:
There is no "VirtualBox USB Driver" in my list of USB drivers of Windows 7 (I tried to install that but was not successful).

Out of the scope of this question only for information: I was not successful in using the USB drive directly in Linux. And I cannot use a shared folder because I need an ext4 file system (with support for hard links).
Last edited by socratis on 28. Jan 2018, 04:02, edited 1 time in total.
Reason: Added ticket related information.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to use a virtual disk on a removable drive?

Post by mpack »

I would like to ask why are you locating a VDI on an external drive? If all you want is for the guest to access removable storage then why not access the USB drive as a shared folder?

p.s. The extension pack is not relevant to your question. The extension pack is needed if you want to connect a USB device to the guest. That isn't happening here: the drive is attached to the host. VirtualBox is accessing files on a host drive exactly the same as any other drive.
dlippold
Posts: 11
Joined: 23. Jan 2018, 15:54

Re: How to use a virtual disk on a removable drive?

Post by dlippold »

I cannot use a shared folder because I need an ext4 file system (with support for hard links).

The VDI file should be on an external and removable drive because I want to use it to store backups on it and therefore I want to put the drive to a different (safe) place.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to use a virtual disk on a removable drive?

Post by mpack »

Well, as far as I know, VirtualBox has no support for not-present drives. I.e. if you tell VirtualBox that a VDI file should be present and it isn't, then you will get that error message.

The only way around this that I can think of (and have not tried) would be to attach drives at runtime using a script, by calling VBoxManage storageattach. I am not certain that even this would work, since I'm not sure if the media registration is permanent. If it is then you'd just postpone the error to the next session.

Generally speaking it is not common to attach or detach drives to the IDE or SATA buses while a PC is running. You may have a greater chance of success using the simulated USB mass storage or iSCSI buses.
Martin
Volunteer
Posts: 2561
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: How to use a virtual disk on a removable drive?

Post by Martin »

If you want to use all the available space on the disk for your backups, another workaround could be to create an USB filter for the disk and use it directly in the guest without a VDI.
dlippold
Posts: 11
Joined: 23. Jan 2018, 15:54

Re: How to use a virtual disk on a removable drive?

Post by dlippold »

mpack wrote:Well, as far as I know, VirtualBox has no support for not-present drives. I.e. if you tell VirtualBox that a VDI file should be present and it isn't, then you will get that error message.

The only way around this that I can think of (and have not tried) would be to attach drives at runtime using a script, by calling VBoxManage storageattach. I am not certain that even this would work, since I'm not sure if the media registration is permanent. If it is then you'd just postpone the error to the next session.

Generally speaking it is not common to attach or detach drives to the IDE or SATA buses while a PC is running. You may have a greater chance of success using the simulated USB mass storage or iSCSI buses.
Thanks for the suggestion. But what is the meaning/function of the "hotplug" attribute for a SATA drive? I search for that but didn't found an useful explanation.

My current workaround is to shutdown the guest and delete the virtual disk in the VirtualBox configuration before I disconnect the external drive and to add the virtual disk again before I start the guest after I connected the external drive the next time.
dlippold
Posts: 11
Joined: 23. Jan 2018, 15:54

Re: How to use a virtual disk on a removable drive?

Post by dlippold »

Martin wrote:If you want to use all the available space on the disk for your backups, another workaround could be to create an USB filter for the disk and use it directly in the guest without a VDI.
Yes, that would be a possibility (even though then I cannot use the drive in the Windows host anymore). But the main problem is that I was not successful in installing an USB filter for the disk (not even successful in installing the "VirtualBox USB Driver" in the Windows 7 host).
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to use a virtual disk on a removable drive?

Post by mpack »

dlippold wrote:But what is the meaning/function of the "hotplug" attribute for a SATA drive? I search for that but didn't found an useful explanation.
I don't know, it isn't described in the user manual. However from reading around I suspect that it allows you to allocate a channel/port on a SATA controller without providing the name of the media. I.e. it lets you create a empty slot on any disk controller that supports hot swapping. Otherwise, if you tried to add media to a running VM then it would fail because it has no free SATA ports to attach it to.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: How to use a virtual disk on a removable drive?

Post by socratis »

dlippold wrote:But when the removable drive is not connected I cannot start the virtual machine because (sic: the drive is not there)
If the drive is not available, you can't access anything from that drive, not just your VDI. You can't seriously expect that...
dlippold wrote:But what is the meaning/function of the "hotplug" attribute for a SATA drive? I search for that but didn't found an useful explanation.
That would be the exact same thing as if you had a physical computer that was working with hot-plug HDs. My 12-year old desktop has that capability for example, I expect newer models to have it as well. What does it to? Well, I have several SATA hard drives available, not enough slots/ports on the computer. What I do is I "eject" a SATA hard drive, like you would do for a USB device. Then I unplug that HD, and I replace it with another one, while the system is up and running. The OS treats it like a plug-and-play USB HD. You can't tell the difference pretty much.

If you have a Win guest and you enable that, you'll get an eject icon in your tray, and you can eject your hard drives at will, with one exception; the HD that Windows resides. :shock:
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
dlippold
Posts: 11
Joined: 23. Jan 2018, 15:54

Re: How to use a virtual disk on a removable drive?

Post by dlippold »

If the drive is not available, you can't access anything from that drive, not just your VDI. You can't seriously expect that...
Most of the time I don't want to access anything from that drive. It is not mounted in the guest. The guest OS is on another drive.

In fact, I only need the function "cold unplug". When my desktop is powered off and I remove an additional SATA drive and I power on the desktop the BIOS should and will not say: "There is a drive missing. Booting is not possible." And therefore VirtualBox should not say that.

I just tested the "hotplug" feature of the SATA controller for the VDI file again. In the running Linux guest I executed
echo 1 > /sys/block/sdb/device/delete
The result was that /dev/sdb and /dev/sdb1 were vanished. And I could remove the drive with the VDI file and could continue to work. But after power off the guest the power on was not possible anymore because VirtualBox output an error message. That seems to be strange.

I think that is a bug in VirtualBox.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: How to use a virtual disk on a removable drive?

Post by Perryg »

I think that your mount is what is causing the issue myself and not so much VirtualBox. fstab is unforgiving about booting properly if the drive you tell it to mount is not available. Instead you should create a manual mount with proper options and place the mount statement in /etc/rc.local if you want it mounted at boot or create a script to mount the drive and one to umount the drive that you can run from the terminal to accomplish your needs.
dlippold
Posts: 11
Joined: 23. Jan 2018, 15:54

Re: How to use a virtual disk on a removable drive?

Post by dlippold »

Perryg wrote:I think that your mount is what is causing the issue myself and not so much VirtualBox.
The mount cannot have any impact on the problem because the error message of VirtualBox occurs before the guest is started and further because the file system on the external drive is not mounted automatically (mount option "noauto") and further because the error message still occurs after I removed the file system on the external drive from /etc/fstab .
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: How to use a virtual disk on a removable drive?

Post by Perryg »

Very well. Thought I could help.
dlippold
Posts: 11
Joined: 23. Jan 2018, 15:54

Re: How to use a virtual disk on a removable drive?

Post by dlippold »

Perryg wrote:Very well. Thought I could help.
Thanks for the additional information about possible problems caused by inaccurate entries in fstab.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: How to use a virtual disk on a removable drive?

Post by Perryg »

I am not totally sure what exactly it is you are trying to accomplish or why you need an additional virtual hard drive (vdi) to make it happen, but for every layer of complexity you use there are more instances of potential issues. I do know from experience that even if you use a noauto statement in fstab it does not always work the way you think it should. Anyway if you want to see what I can come up with just explain how all of this is put together and why and I will see what I can do. If not, no problem. I will just continue on with other things as before.
Post Reply