Skip to content

Instantly share code, notes, and snippets.

@sitecode
Last active March 17, 2024 02:14
Show Gist options
  • Save sitecode/6ca5448e671ff34453984d1c39000a85 to your computer and use it in GitHub Desktop.
Save sitecode/6ca5448e671ff34453984d1c39000a85 to your computer and use it in GitHub Desktop.
Fix auto command

Boot from attached USB drive in guest virtual machine using VirtualBox on host machine running linux

The one step out of the ordinary of creating a new virtual machine, is creating the virtual hard disk (.vmdk) that points to the usb drive. It requires running a command in your favorite CLI/terminal. After being created it can then be added to a new VirtualBox virtual machine.

Command

Command to create a virtual hard disk pointing to your usb drive of choice. Adjust the command to your needs like specifying a different path. Plugin the usb drive. Verify the assigned device name and update the cammand. Then run it.

$ VBoxManage internalcommands createrawvmdk -filename sdb.vmdk -rawdisk /dev/sdb
RAW host disk access VMDK file sdb.vmdk created successfully.

Now that the disk created successfully, use it as you would any other virtual hard disk and add it to a new virtual machine and start her up.

Common Errors

Error Access Denied

When running the command an error output looks somethnig like this:

VBoxManage: error: Cannot open the raw disk '/dev/sdb': VERR_ACCESS_DENIED
VBoxManage: error: The raw disk vmdk file was not created

The solution is to grant permission to the usb drive for your host user before running the command.

One time fix

Likely the next time that you plugin the usb hard drive or after a reboot, the following command will need to be ran again.

echo $(DEVNAME=sdb; USERNAME=username; sudo /bin/setfacl -m u:$USERNAME:rw- /dev/$DEVNAME && echo "Added $DEVNAME permissions for $USERNAME")

Auto fix (new udev rule)

Plug in the usb drive. Update evironment vars DEVNAME to the current usb device name and USERNAME to the host user in the command below. Then run it. Re-plug the usb drive and try running the command above again.

echo $(DEVNAME=sdb; USERNAME=username; ID_SERIAL_SHORT=$(udevadm info -n /dev/$DEVNAME | grep ID_SERIAL_SHORT | cut -d '=' -f 2); sudo echo -e SUBSYSTEM==\"block\",  ATTRS{serial}==\"$ID_SERIAL_SHORT\", ACTION==\"add\", RUN+=\"/bin/setfacl -m u:$USERNAME:rw- /dev/\$name\""\n"SUBSYSTEM==\"block\",  ATTRS{serial}==\"$ID_SERIAL_SHORT\", ACTION==\"remove\", RUN+=\"/bin/setfacl -x u:$USERNAME: /dev/\$name\" | sudo dd of=/etc/udev/rules.d/99-usbdrive.$USERNAME.rules status=none && sudo udevadm control --reload && echo "Added $DEVNAME permissions for $USERNAME in file /etc/udev/rules.d/99-$DEVNAME.$USERNAME.rules")

Error Incompatible Config

When booting the new virtual machine with the new virtual hard drive pointing to the usb drive, the error looks something like this in the popup:

Incompatible configuration requested. (VERR_INCOMPATIBLE_CONFIG).

Result Code: NS_ERROR_FAILURE (0x80004005)
Component: ConsoleWrap
Interface: IConsole {872da645-4a9b-1727-bee2-5585105b9eed}

There are many posted possible solutions to this. For example check that all bios settings are set to support this action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment