Page 1 of 1

USB Device mounts on Host and Guest both

Posted: 30. Aug 2010, 07:48
by jivabill
When I was reading the help files to find out how to use a USB Stick on my Guest I found a section that cautioned against having a USB drive mounted on the Host and then having it mount on the Guest. Because, they said, that could cause "data loss" (I read that as damage) to the USB drive.

Running Ubuntu 10.04LTS Host. My guest is XP Pro.

I am using a USB Cruzer 1gb Stick for experiments as I can afford to have it trashed.

So I thought I could solve the problem by not plugging the USB Stick in until the XP Pro Guest was up and running. Problem is, the Guest is rather slow about recognizing and mounting the USB Stick. Meanwhile, the Host, Ubuntu 10.04LTS sees the Stick and mounts it before the Windows Guest is done with the mounting process.

I assume that means that the USB Stick was unceremoniously disconnected from the Host and then mounted on the Windows Guest. Not good.

I am looking for some advice about how to handle this situation so I don't destroy one of my external hard drives that cost real money.
thanks for reading

Re: USB Device mounts on Host and Guest both

Posted: 30. Aug 2010, 10:38
by hank_se
Yes, the default behavior is not really good, I've solved it this way:

1. add a file /etc/udev/rules.d/11-vboxdrv.rules with the following content:

Code: Select all

SUBSYSTEM=="usb_device", GROUP="root", MODE="0664"
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GROUP="root", MODE="0664"
This is to override the default 10-vboxdrv.rules and set GROUP back to root which is the distros default.

2. add a file /etc/udev/rules.d/12-vboxdrv.rules, in my case it looks loke this:

Code: Select all

KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="root", MODE="0600"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0421", ATTRS{idProduct}=="01c8", GROUP="vboxusers", MODE="0664"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0421", ATTRS{idProduct}=="01c7", GROUP="vboxusers", MODE="0664"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0b0c", ATTRS{idProduct}=="002e", GROUP="vboxusers", MODE="0664"
One line SUBSYSTEMS... for each device I want to pass to VirtualBox, idVendor and idProduct can be found with the command lsusb -v.
Now issue the command -sudo udevadm trigger- and see if it works as you wish it to do.

I intentionally avoid to just edit the file /etc/udev/rules.d/10-vboxdrv as it will be overwritten on every upgrade.

Re: USB Device mounts on Host and Guest both

Posted: 30. Aug 2010, 19:47
by jivabill
Hi Hank, nice to meet you.
Thank you for the code to fix the default mounting of my USB devices. I'll ponder it and see how that works with Ubuntu 10.04, could be it is the same as your distro. Sounds like a good fix.
bill

Re: USB Device mounts on Host and Guest both

Posted: 30. Aug 2010, 21:59
by Sasquatch
Can you tell me where in the manual (chapter/section) where you read it can damage or corrupt your USB stick? This is the first time I've heard it. When you send a USB device to a VM, you simply unplug it from the computer so to speak and plug it into another. This is what the Host sees, the device is unplugged. The Guest then sees a USB device being plugged in.

Re: USB Device mounts on Host and Guest both

Posted: 30. Aug 2010, 22:20
by jivabill
Sasquatch wrote:Can you tell me where in the manual (chapter/section) where you read it can damage or corrupt your USB stick? This is the first time I've heard it. When you send a USB device to a VM, you simply unplug it from the computer so to speak and plug it into another. This is what the Host sees, the device is unplugged. The Guest then sees a USB device being plugged in.
About your question above, I found a short paragraph in the Help files related to Virtualbox. It said that IF the USB device was mounted on the Host when the Guest tried to capture it the Host USB device would be disconnected without being properly shutdown which could cause data loss. I'll have to research it and see if I can find that reference for you.
thanks
bill

Re: USB Device mounts on Host and Guest both

Posted: 30. Aug 2010, 22:26
by Perryg
jivabill wrote:
Sasquatch wrote:Can you tell me where in the manual (chapter/section) where you read it can damage or corrupt your USB stick? This is the first time I've heard it. When you send a USB device to a VM, you simply unplug it from the computer so to speak and plug it into another. This is what the Host sees, the device is unplugged. The Guest then sees a USB device being plugged in.
About your question above, I found a short paragraph in the Help files related to Virtualbox. It said that IF the USB device was mounted on the Host when the Guest tried to capture it the Host USB device would be disconnected without being properly shutdown which could cause data loss. I'll have to research it and see if I can find that reference for you.
thanks
bill
Chapter 3.10. USB support in the users manual
Note:
(1) Be careful with USB devices that are currently in use on the host! For example, if you allow your guest to connect to your USB hard disk that is currently mounted on the host, when the guest is activated, it will be disconnected from the host without a proper shutdown. This may cause data loss.

I have been preaching from the rafters about this forever. I suggest sharing HDD's so you don't forget.

Re: USB Device mounts on Host and Guest both

Posted: 30. Aug 2010, 22:48
by jivabill
Alright! Thanks for posting the reference. I just also found the section and here is a more complete snip from it:

3.10. USB support
3.10.1. USB settings
The "USB" section in a virtual machine's Settings window allows you to configure VirtualBox's sophisticated USB support.
VirtualBox can allow virtual machines to access the USB devices on your host directly. To achieve this, VirtualBox presents the guest operating system with a virtual USB controller. As soon as the guest system starts using a USB device, it will appear as unavailable on the host.
Note
Be careful with USB devices that are currently in use on the host! For example, if you allow your guest to connect to your USB hard disk that is currently mounted on the host, when the guest is activated, it will be disconnected from the host without a proper shutdown. This may cause data loss.

================

So this section has been the source of my concern about USB devices. As I mentioned, I tried to work around the problem by unmounting the USB Stick on the Host and then starting the Guest VB but still before the guest had recognized and mounted the USB Stick the Host had once again see it and mounted it. Same thing happened when I booted up my Linux Host with the USB Stick removed. Then I started the Guest VB and plugged the USB Stick in hoping that the Guest would capture it. But the Linux Host was faster and mounted it first. Leading to the problem of the device being wrenched free of the Host to be attached to the Guest. At the moment I am at a loss as to how to solve the problem.
bill
bill

Re: USB Device mounts on Host and Guest both

Posted: 30. Aug 2010, 22:57
by Perryg
I don't think there is so much to worry about with other devices than HDD's. These are rotating devices that should be parked before you unplug them. Memory sticks and devices that are not, seem to be able to handle the transition but you still need to try to make sure that you are not writing to the memory stick when the transition happens. (But here again this is just my opinion). I also don't use snap shots so just call me paranoid.

Re: USB Device mounts on Host and Guest both

Posted: 31. Aug 2010, 02:27
by jivabill
Hi Perry, and thank you for finding that reference in the User Manual.

I am thinking that maybe that remedy you mentioned, Sharing a HDD, might be the solution when attaching an external drive to the Guest. I have a Western Digital Passport that I keep all my backup files on and other things that I want to be stored off the machine(s). I have not read on that yet but I think I understand that to mean that through a sharing arrangement both the Host and the Guest can simultaneously have the device mounted. I will study on that.
regards
bill