VirtualBox users of all levels (from beginner to dev) have numerous scenarios where they require access to a USB device from VirtualBox vms via USB passthrough. Specifically, accessing USB devices that are connected with a host computer.
How do vboxusers successfully conduct VirtualBox USB passthrough within VMs to access their USB hardware devices over ethernet (or other network connections)?
We’ll answer that below...
This article provides step-by-step instructions to show vboxusers how to enable SD card hardware access from an Ubuntu Linux VirtualBox guest machine on a host machine running Windows operating systems over ethernet (or any other network connection.)
Prior to following any of the steps below, ensure that all drivers are updated on all machines participating in the USB passthrough.
Regardless of platform, tool, or OS (VboxManage, Ubuntu, XP, VirtualBox Extension Packs, etc) dev and new vboxusers alike need their drivers to be up to date (or compatible with the version of VirtualBox Extension Pack being used) to maximize successful usb passthrough.
Step 1-1: Open the Command Prompt (or Windows PowerShell on Windows operating systems- like XP Pro) as an administrator (for example: “Windows” key + “x”. Then select “Command prompt (admin)”)
Step 1-2: Use the wmic command (or the lsusb command on Linux) to list the disc drives. This should be done prior to inserting the SD card into the PC.
wmic diskdrive list brief
Output should read as follows:
Caption | DeviceID | Model | Partitions | Size |
SAMSUNG MZFLV256HCHP-000MV | \\.\PHYSICALDRIVE0 | SAMSUNG MZFLV256HCHP-000MV | 3 | 256052966400 |
Step 1-3: Insert the SD card into the machine and run the same command as before (on a Linux operating system, it would be the lsusb command to list info regarding specific details about USB buses, etc)
Users should see an additional line showing the SD card’s DeviceID. In the following example, the ID reads: “\\.\PHYSICALDRIVE1“.
Caption | DeviceID | Model | Partitions | Size |
Generic- USB3.0 CRW -SD USB Device | \\.\PHYSICALDRIVE1 | Generic- USB3.0 CRW -SD USB Device | 2 | 31914086400 |
SAMSUNG MZFLV256HCHP-000MV | \\.\PHYSICALDRIVE0 | SAMSUNG MZFLV256HCHP-000MV | 3 | 256052966400 |
Devs and vboxusers should note: users should know whether they’re using a 3.0 USB device, or a 2.0 (EHCI) USB. “EHCI” stands for: “Enhanced Host Controller Interface”.
Step 2-1: Transfer the folder to the VirtualBox installation folder. In the following example, it will be: “C:\Program Files\Oracle\VirtualBox\”.
cd "C:\Program Files\Oracle\VirtualBox\"
Step 2-2: Using the “VBoxManage.exe” create the SD card’s VMDK file. The final argument regards the SD cards DeviceID (review steps 1-1 to 1-3)
.\VBoxManage.exe internalcommands createrawvmdk -filename C:\sdcard.vmdk -rawdisk
\\.\PHYSICALDRIVE1
If all is well, the output will read “sdcard.vmdk”, and is then created within the C-drive’s root folder.
RAW host disk access VMDK file C:\sdcard.vmdk created successfully.
Step 3-1: As the Administrator, launch the VirtualBox GUI
Step 3-2: Within the VirtualBox GUI, navigate as follows: “Setting>Storage”
Step 3-3: Click “Controller: SATA”
Step 3-4: Check the checkbox beside “Use Host I/O Cache”
Step 3-5: Now click the “Adds Hard Disk” icon (shown in the visual aid below)
Step 3-6: Select “Choose Existing Disk”
Step 3-7: Go to the C-drive and choose the “sdcard.vmdk” file (the file we created in Step 2)
Launch the Virtual Machine and begin verification. In this example, it looks like: “/dev/sdb” (Raspbian OS image in 32GB SD card).
$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 29.8 GiB, 32010928128 bytes, 62521344 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb1d773dc
Device | Boot Start | End | Sectors | Size | Id | Type |
/dev/sdb1 | 8192 | 96453 | 88262 | 43.1M | c | W95 FAT32 (LBA) |
/dev/sdb2 | 98304 | 31116287 | 31017984 | 14.8G | 83 | Linux |
Unfortunately, while attempting to use the SD card, numerous errors arose. Below are some troubleshooting options for VirtualBox SD card passthrough.
Troubleshooting Option 1:
The Error: “I/O cache encountered an error while updating data in medium “ahci-0-1” (rc=VERR_ACCESS_DENIED)”
For users who experience the error above, return to Step 2 and ensure the “Use Host I/O Cache” checkbox is checked.
Troubleshooting Option 2
The Error: “UUID of the medium does not match the value stored in the media registry.
From within the VirtualBox installation folder, run the following command:
.\VBoxManage.exe list hdds
Users will then have the ability to locate the UUID within the error details
UUID: 5b951504-358d-4a6e-bb8f-61be3ec32367
Parent UUID: base
State: inaccessible
Type: normal (base)
Location: C:\Users\max\Desktop\sdcard.vmdk
Storage format: VMDK
Capacity: 0 MBytes
Encryption: disabled
Use the command below (by specifying the UUID) to remove the disk:
.\VBoxManage.exe closemedium disk 5b951504-358d-4a6e-bb8f-61be3ec32367