Accessing External Hard Drives in a Virtual Machine

2017-12-11

This post explains how to access data stored on an external hard disk drive from within a virtual machine. The use case is to read from and write to files on external disks whose filesystem the host operating system doesn't support. For example, if your host machine runs Windows or macOS, you won't be able to natively access btrfs partitions or ext2 TrueCrypt volumes. Never format/initialize your external hard drive, as doing so will result in data loss! Moreover, don't attempt to mount your hard drive on your host operating system, since doing so might lead to data loss as well.

The following steps describe how to mount the partitions from an external USB drive on a Linux distribution running inside a virtual machine using VirtualBox:

  1. Download and install the latest stable version of VirtualBox for your host operating system. At the time of writing, this is version 5.2.2.
  2. Install the extension pack for VirtualBox.
  3. Create a virtual machine and install your Linux distribution of choice.
  4. If necessary, install the packages for accessing the specific filesystems inside your virtual machine. For example, zuluCrypt supports a variety of encrypted filesystems and offers a command-line interface as well as a graphical user interface.
  5. If you intend to share folders between the virtual machine host and guest, install the VirtualBox Guest Extensions on your Linux guest and follow the official instructions.
  6. Shut down the virtual machine.
  7. Attach the disk to your computer. Don't format/initialize the disk and don't even attempt to mount it!
  8. Under the VirtualBox settings for your virtual machine, go to Ports and switch to the USB tab.
  9. Check Enable USB Controller and select the corresponding controller version of your drive.
  10. Under USB device filters, go to the icons on the right and select the second icon from the top, i.e., click the + button that allows you to add a filter whose values are set to the values of a USB device which is attached to the host. Choose your USB drive as the device.
  11. Run your Linux virtual machine.
  12. In your virtual machine, mount the partition of your external drive using the appropriate tool as read-only or read-write. This tool can be mount(8) on the command line, zuluCrypt, VeraCrypt, or a file manager in case you installed a desktop environment.
  13. Read or write to files on the mounted partition inside your virtual machine, as you please.
  14. In your virtual machine, unmount the partition using a suitable tool. For example, the command umount(8) allows you to unmount filesystems on the command line.
  15. Detach the disk from your computer. There is nothing to do on the host operating system, since you hopefully didn't mount the disk there.

Permanent Link for Post

Accessing External Hard Drives in a Virtual Machine (2017-12-11)

Older Posts

  1. Managing Clipboards (2016-11-23)
  2. Multi-Screen Configuration Using Xrandr (2016-07-02)
  3. Email Backup and Migration using Thunderbird (2016-06-29)
  4. Automatic SSH Proxy Selection (2016-02-08)
  5. Set Color Temperature (2015-11-25)
  6. Completion Methods in Vim (2015-10-10)
  7. Fuzzing the mbed TLS Library (2015-09-26)
  8. SSH Weak Diffie-Hellman Group Identification Tool (2015-08-12)
  9. Building a Standing Desk for 50 Bucks (2015-01-25)
  10. High-DPI Displays under Linux (2014-12-23)
  11. Slow Wi-Fi on the Raspberry Pi (2014-06-15)
  12. XBMC on the Raspberry Pi (2014-06-14)
  13. Turning the Raspberry Pi into a Game Console (2014-06-12)
  14. ZFS Backups to External Hard Drives (2014-03-23)
  15. Display the I/O Usage of a Process (2014-02-21)
  16. Determining Wireless Network Channel Usage (2014-02-09)
  17. Managing Web Files through a Repository (2013-08-17)
  18. Simple HTTP File Servers (2013-08-16)
  19. Protect your SSH Private Keys (2013-06-16)
  20. Forward Secrecy for HTTPS and Ephemeral Diffie-Hellman (2013-06-14)
  21. Markdown Preview Chrome Extension (2013-06-13)