DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Hands-On with Azure Local via the Azure Portal
  • Optimizing Java Applications for Arm64 in the Cloud
  • KubeVirt: Can VM Management With Kubernetes Work?
  • Spark Job Optimization

Trending

  • Securing Everything: Mapping the Right Identity and Access Protocol (OIDC, OAuth2, and SAML) to the Right Identity
  • Why Knowing Your LLM Hallucinated Is Not Enough
  • How AI Is Rewriting Full-Stack Java Systems: Practical Patterns with Spring Boot, Kafka and WebSockets
  • AWS vs GCP Security: Best Practices for Protecting Infrastructure, Data, and Networks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How to Mount USB Drives on VirtualBox

How to Mount USB Drives on VirtualBox

Sometimes you just need to access a USB drive from a VirtualBox VM! We take a look at how to make this happen in this post.

By 
Peter Leung user avatar
Peter Leung
·
Feb. 02, 18 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
147.1K Views

Join the DZone community and get the full member experience.

Join For Free

This is part three of a three-part series on VirtualBox. Parts one and two demonstrate how to install VirtualBox on a Debian host, and to build a FreeBSD virtual machine. This post shows you how to access, from your guest OS, a flash drive mounted on the Debian host.

Prerequisites

The VirtualBox extension pack must be installed on the VirtualBox host. See part 2 for instructions.

Configuring USB

Follow the steps below to configure the VirtualBox USB.

  1. Add the user to the vboxusers group. VirtualBox access to the host's USB drives is only granted to users of the vboxusers group. As root on the host, run the following command to add each VirtualBox user (e.g., peter) to the group.

     # usermod -aG vboxusers peter
  2. Power off VM. VirtualBox defaults to using USB Controller 1.1 (OHCI). Modern hardware uses USB Controller 2.0 (EHCI) and USB Controller 3.0 (xHCI). Before you can change the USB controller protocol, the virtual machine must be powered off.

  3. Open VirtualBox Manager, click Settings, and select USB.

  4. Specify USB Controller.

    Select either USB 2.0 (EHCI) Controller or USB 3.0 (xHCI) Controller according to your actual hardware.

    Note that you can add USB Device Filters to define the types of USB drives which will be automatically made visible to the guest OS. Be forewarned that the USB drive, once made visible to the guest OS, will no longer be available to the host. More on the use of device filters in the next section.

Accessing the USB Drive

Below is the step-by-step procedure to mount and access a flash drive.

  1. Insert the flash drive into your host machine's USB port.

  2. Unmount the flash drive (if it is auto-mounted on your host).
    Making it available to the guest will automatically and instantly unmount it from the host. To avoid any data loss due to pending writes to the drive, it is a good practice to explicitly unmount the drive prior to handing control to the guest.

  3. Power on the FreeBSD guest.

  4. Assign the USB drive to the guest OS.


    Open the virtual system console, and right click the USB drive icon.


    Click to select your USB drive.

    Note, this is a one-time assignment only. Please see instructions at the end of the section on how to automatically assign this particular USB drive for all subsequent sessions.
  5. Login to FreeBSD, and mount the drive. You can mount an MS-DOS-based flash drive by running the following commands as root. Replace /dev/da0s1 with the proper device identifier for your USB drive (you can find out the exact device ID by first running dmesg to identify the device name, e.g. da0, and fdisk to reveal the disk partition structure, e.g., s1).

     # mkdir -p  /media/usb
     # mount -t msdosfs  /dev/da0s1  /media/usb

    To unmount the drive,

     # umount /media/usb

To always automatically assign a particular USB drive to the guest OS, open the VirtualBox Manager, click Settings, and then USB.

Finally, click the Add USB device filter (with the + sign) icon, and select the USB drive that is currently inserted into the host.

USB Virtual Machine VirtualBox Host (Unix)

Published at DZone with permission of Peter Leung. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Hands-On with Azure Local via the Azure Portal
  • Optimizing Java Applications for Arm64 in the Cloud
  • KubeVirt: Can VM Management With Kubernetes Work?
  • Spark Job Optimization

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook