Quickly mount USB drive as Shared Folder for VirtualBox

in Tools


You want to access a USB flash drive connected to your host machine from VirtualBox. You use a GUI tool on your host machine to manage your VirtualBoxes. The flash drive you want to use is connected to your host machine.

  1. Create a Shared Folder Launch the "VirtualBox Manager" tool and go to your VM settings. Open the "Shared Folders" tab. Click the little + icon on the right.

    • Folder Path: point to your flash drive or a folder inside it, e.g. /Volumes/MemoryCard/Music
    • Folder Name: arbitrary share name you will refer to later, e.g. MyMusic
    • Mount Point: path on the guest OS where the shared folder is mounted, e.g. /mnt/Music
    • Read-only, Auto-mount, Make Permanent: unchecked
  2. Mount the shared folder in your guest OS

    mkdir /mnt/Music
    mount -t vboxsf -o rw,dmode=0777,fmode=0777 MyMusic /mnt/Music

    That's it. Try it: echo "hello world!" > /mnt/Music/test.txt. You should see the file appear on your connected flash drive using host OS file browser.

Node.JS Gotcha

vboxsf is VirtualBox's special filesystem for shared folders between the host and guest. Even if the files look accessible (rwxrwxrwx), vboxsf has quirky permission handling, and Node.js (especially recent versions) can run into EPERM errors because of how it uses lower-level file operations.

Error: EPERM: operation not permitted, open '/mnt/MyMount/node-app/index.js'
    at Object.openSync (node:fs:600:3)
    at Object.readFileSync (node:fs:468:35)
    at Module._extensions..js (node:internal/modules/cjs/loader:1243:18)
    at Module.load (node:internal/modules/cjs/loader:1089:32)
    at Module._load (node:internal/modules/cjs/loader:930:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  errno: -1,
  syscall: 'open',
  code: 'EPERM',
  path: '/mnt/MyMount/node-app/index.js'
}

This is a common known issue with Node.js + vboxsf.

In addition to the above, symlink can be an issue too. Even as root, VirtualBox shared folders (vboxsf) do not support symbolic links from the guest (your VM). That’s a hard limitation of vboxsf, not a permissions issue.

Best fix: Copy the entire project out of the shared folder to a native Linux directory inside the VM. This negates the point of having a shared folder, but could still work if your project is working with large files that you can keep on the shared folder, while the project itself can be moved to the VM.

#virtualbox