Skip to content

Instantly share code, notes, and snippets.

@amulifts
Created February 26, 2023 16:34
Show Gist options
  • Save amulifts/191442f92a56c291f32b0b12c01e61c5 to your computer and use it in GitHub Desktop.
Save amulifts/191442f92a56c291f32b0b12c01e61c5 to your computer and use it in GitHub Desktop.
Connecting and Installing a USB Drive to a Virtual Machine Using VirtualBox

How to Connect a USB Drive to a Virtual Machine Using VirtualBox

Steps

  • Connect the USB drive to the host machine.
  • Open VirtualBox and navigate to the settings for your Linux virtual machine.
  • Select the "USB" tab in the settings menu.
  • Enable the USB 3.0 controller by ticking the "Enable USB Controller" box and selecting "USB 3.0 (xHCI) Controller" from the drop-down menu.
  • Add the USB device to the virtual machine's USB filters by clicking the "+" icon and selecting the appropriate device from the list.
  • Start the virtual machine.
  • On the VirtualBox top navigation bar, click "Devices" and select the USB drive from the list of available devices.

Installation

  • Check if the USB is inserted or not using the following command:
  lsblk

This will show all the block devices connected to your system, including the USB drive.

  • Navigate to the root directory by running the command:
  cd /

This will ensure that you are in the root directory of the filesystem.

  • Navigate to the /mnt directory using the command:
  cd mnt

This directory is used for mounting external devices.

  • Create a new directory for your mount point under /mnt using the command:
  sudo mkdir /mnt/data

This will create a new directory named data in the /mnt directory. This directory will be used as the mount point for the USB drive.

  • Mount the USB drive to the newly created mount point using the command:
  sudo mount /dev/sdb1 /mnt/data

Here, /dev/sdb1 is the device file for the USB drive, and /mnt/data is the mount point directory we created in the previous step.

  • To access the contents of the USB drive, navigate to the mount point directory using the command:
cd /mnt/data

This will change your current directory to /mnt/data, which is where the contents of the USB drive are accessible.

To unmount the USB drive and make its contents no longer accessible, run the command:

  sudo umount /mnt/data

This will unmount the USB drive from the /mnt/data directory.

FAQ

Why we mount and unmount:

  • Mounting allows you to access the contents of a file system or device by linking it to a directory in the filesystem.
  • Unmounting is necessary to safely remove the device or file system from the system, ensuring that all data is written and no files are in use before dismounting.

What happens if we don't mount and is mounting compulsory:

  • Without mounting, you cannot access the contents of a file system or device in the filesystem.
  • Mounting is necessary for most file systems and devices to access them, so it is generally compulsory to mount them before accessing their contents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment