Accessing External Hard Drives in a Virtual Machine
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:
- 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.
- Install the extension pack for VirtualBox.
- Create a virtual machine and install your Linux distribution of choice.
- 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.
- 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.
- Shut down the virtual machine.
- Attach the disk to your computer. Don't format/initialize the disk and don't even attempt to mount it!
- Under the VirtualBox settings for your virtual machine, go to Ports and switch to the USB tab.
- Check Enable USB Controller and select the corresponding controller version of your drive.
- 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.
- Run your Linux virtual machine.
- 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.
- Read or write to files on the mounted partition inside your virtual machine, as you please.
- 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.
- 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
- Managing Clipboards (2016-11-23)
- Multi-Screen Configuration Using Xrandr (2016-07-02)
- Email Backup and Migration using Thunderbird (2016-06-29)
- Automatic SSH Proxy Selection (2016-02-08)
- Set Color Temperature (2015-11-25)
- Completion Methods in Vim (2015-10-10)
- Fuzzing the mbed TLS Library (2015-09-26)
- SSH Weak Diffie-Hellman Group Identification Tool (2015-08-12)
- Building a Standing Desk for 50 Bucks (2015-01-25)
- High-DPI Displays under Linux (2014-12-23)
- Slow Wi-Fi on the Raspberry Pi (2014-06-15)
- XBMC on the Raspberry Pi (2014-06-14)
- Turning the Raspberry Pi into a Game Console (2014-06-12)
- ZFS Backups to External Hard Drives (2014-03-23)
- Display the I/O Usage of a Process (2014-02-21)
- Determining Wireless Network Channel Usage (2014-02-09)
- Managing Web Files through a Repository (2013-08-17)
- Simple HTTP File Servers (2013-08-16)
- Protect your SSH Private Keys (2013-06-16)
- Forward Secrecy for HTTPS and Ephemeral Diffie-Hellman (2013-06-14)
- Markdown Preview Chrome Extension (2013-06-13)