16
August
2023
Using Virtualbox with a USB flash drive
17:35

Using Virtualbox with a USB flash drive

16 August 2023 17:35

This article is about how to set up an Oracle VirtualBox virtual machine on a computer running Linux Ubuntu / Mint / Debian for direct access to a USB flash, for storing the guest operating system on it.

System Requirements

1. oracle VirtualBox 6.x and 7.x require processor hardware support for hardware virtualization options VT-X.

  • Intel processor manufactured later than 2011("Sandy Bridge" and newer). For example, Intel Core i5-3330 was released in 2012 with VT-X support for Socket 1155.
  • almost all Intel Atom.
  • Pentium Dual-Core E5500 regardless of marking, some E5300, E5400 for Socket 775.
  • Core 2 Duo "Conroe" E6300...E6850 with Wolfdale-2M core. There should be a menu item "Virtualization technology" in the BIOS - enable it.

Intel® Core 2 Duo "Allendale" E4300...E4700 and Intel® Pentium® D Processor 945, Pentium® Dual-Core E2200 and Celeron processors released before 2010 do not support VT-X virtualization.

U AMD hardware virtualization technology is called AMD-V™.
It is implemented in the AMD Athlon 64 ("Orleans"), Athlon 64 X2 ("Windsor"), Athlon 64 FX ("Windsor") processors, the family of processors for socket AM2 - Athlon 64 and Athlon 64 X2 steps of versions "F" or "G", Turion 64 X2 and Opteron 2nd and 3rd generations, Phenom and Phenom II.
Naturally, all newer AMD Ryzen processors (Zen, Zen 2, Zen 3, Zen 4 architectures) support hardware virtualization.

You can find out the processor model with the command:

sudo lshw -class cpu

Then check the manufacturer's website to find out about VT-X support. If the processor does not support VT-X, you need to roll back to Oracle VirtualBox version 5.22 (see last paragraph).

In the BIOS or UEFI BIOS, the menu item to enable virtualization is called "Virtualization technology" or SVM or VT-X- it must be turned on -Enabled. It is also desirable to have VT-D virtualization for forwarding I/O ports and PCI devices (analogous to IOMMU from AMD).

2. requires processor support for instructions SSE2(Streaming SIMD Extensions 2). Supported by most processors - IA-32 hardware class also designated i486, i586 and i686 or later (x64): almost all Intel and AMD processors. These instructions are not implemented in processors prior to the Athlon 64 (for example, Athlon XP).

3. USB flash with a capacity of 8 GB or more.

4. Connect to the Internet to download the ISO file of the guest OS installation disk.

Methods to start the operating system from a USB drive

Option #1. A flash drive is used to store the ISO file of the installation disk, and a virtual hard disk file (for example, VHD) is created on a local hard drive or SSD. The boot ISO file is selected in Oracle VM when the virtual machine is created and the VM is then booted from the ISO file and run in Live mode or installed the operating system.

Advantage: you can store several ISO files on a flash drive.
Disadvantage: for each VM you need to create your own virtual hard disk on the PC, which is expensive when using an SSD drive, because When using virtual machine (VM) files, you quickly run out of space.

Option #2. bootable USB flash drive - the prepared bootable disk is launched in the Oracle VM. A physical disk - a “flash drive” with a system image is used using a VMDK file as a virtual AHCI controllerSATA 0.

Advantage: saving space on the hard drive, the guest OS is stored only on USB Flash media.
Disadvantage: initial initialization is more difficult (see below) and access speed is lower than with a local SSD.

Option #3. the bootable flash drive is not used in Oracle VM, but directly on the hardware - when you start the computer, you need to enter the boot "Boot menu" by pressing the F9 or F12 button when turning on the computer (or go to the BIOS Setup menu, where you specify the HDD startup priority. For example, "HDD USB General Udisk"). We turn on the PC or reboot the PC - the OS starts from the USB Flash drive. This option will not be considered, except for advice on creating a bootable flash drive in end of article.

Option No. 4 special utilities "Ventoy", "YUMI", "WinSetupFromUSB" and others, for creating bootable flash drives for several operating systems ("multi-boot flash drive") - the virtual machine is not used, and the system starts as in option No. 3, but with the ability to select the operating system. I don’t consider this option, because... I'm interested in a way to configure a Linux virtual machine to use a "flash drive" as a storage device for the real OS, and not an ISO image.

Advantage: ease of implementation (just write a flash drive using dd or "Balena Etcher"), loading when choosing to launch from a USB HDD on most PCs, the possibility of "Persistence" (storing session data on a flash drive) in the Linux antiX and MX Linux distribution with special markup in Rufus or MX_Live_USB_Maker. Save space on SSD disk.
Disadvantages: not all computers can boot from USB flash; some old PCs can only boot from CD/DVD. Inability to start a UEFI flash drive on a computer with BIOS. The need to manipulate the Boot Menu when starting the PC. To write a flash drive with Persistence you need to use non-utilities DD or "Balena Etcher", and rufus or MX_Live_USB_Maker. See detailed article about writing a bootable USB flash drive with persistence.

This article will mainly discuss Option No. 2— launching a virtual machine in Oracle VirtualBox from a prepared USB flash drive and a VMDK file for emulation using a USB flash AHCI controller. The so-called “direct access” to a USB flash drive from a virtual machine. The live image of the machine is stored on a flash drive, the file system of which is in RAW format.

Which distribution version should I choose for the VirtualBox guest OS - x86 or x64?

If the operating system of the main “host” PC - the host - has full x64 support and the processor is modern - supports VT-X or AMD-V hardware virtualization - you can safely choose x64 OS (the ISO file contains the mark “x64” in the file name).

If the OS is x86 or the processor does not support VT-X, you have to choose the i386 - i486 or i686 versions (the ISO file usually contains "x86" in the file name).

Installing Oracle VirtualBox 6.1 from the Ubuntu repository for processors with VT-X

If the processor supports hardware virtualization, VirtualBox 6.1 (Attention! 6.1 is not the newest version!) from the Ubuntu or Linux Mint repository will work with kernel 5.15 and higher.

Installing VirtualBox 6.1 is simple:

sudo apt update
sudo apt install --reinstall linux-headers-$(uname -r) virtualbox-dkms dkms virtualbox-qt
sudo reboot

After which, you need to restart the PC.

sudo reboot

After the reboot, run the module load command as superuser vboxdrv:

sudo modprobe vboxdrv

Now you can launch virtualbox either from the menu or with a console command

virtualbox

If an error occurs when starting a virtual machine VT-x is not available(VERR_VMX_NO_VMX). Error code: NS_ERROR_FAILURE (0x80004005), which means the processor does not support VT-X hardware virtualization. The problem can be solved by upgrading the motherboard and processor.

Refusal of VirtualBox 6 and installation of VirtualBox 7 for new processors with VT-X

This method is relevant for modern Linux operating systems, for processors that support VT-X or AMD-V.

If you install VirtualBox from the repository (apt install virtualbox), Ubuntu 22.04 will install VirtualBox 6.1. While the newer version of Oracle Virtualbox 7.0 was released on July 18, 2023.

Uninstalling Virtualbox 6.1:

sudo apt remove --purge virtualbox virtualbox-guest-utils

Detailed article on installing VirtualBox 7.0 on linuxcapable.com in English.

Installing Oracle VirtualBox 7.0, 7.1 or 7.2 on Linux:

sudo apt update
sudo apt upgrade
sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https curl -y

Importing the gpg key for the repository

curl -fSsL https://www.virtualbox.org/download/oracle_vbox_2016.asc | gpg --dearmor | sudo tee /usr/share/keyrings/virtualbox.gpg > /dev/null
  • For Ubuntu 26.04 "Resolute"

    echo deb [arch=amd64 signed-by=/usr/share/keyrings/virtualbox.gpg] http://download.virtualbox.org/virtualbox/debian resolute contrib | sudo tee /etc/apt/sources.list.d/virtualbox.list

  • For Ubuntu 24.04 "Noble" and its derivatives (Linux Green 22, Linux Mint 22).

echo deb [arch=amd64 signed-by=/usr/share/keyrings/virtualbox.gpg] http://download.virtualbox.org/virtualbox/debian noble contrib | sudo tee /etc/apt/sources.list.d/virtualbox.list

  • For Ubuntu 22.04 "jammy" and its derivative OS (Linux Green 21 "Victoria" based on Ubuntu 22.04 LTS or Linux Mint 21 package):

    echo deb [arch=amd64 signed-by=/usr/share/keyrings/virtualbox.gpg] http://download.virtualbox.org/virtualbox/debian jammy contrib | sudo tee /etc/apt/sources.list.d/virtualbox.list

  • For Ubuntu 20.04 "focal" and its derivative OS:

    echo deb [arch=amd64 signed-by=/usr/share/keyrings/virtualbox.gpg] http://download.virtualbox.org/virtualbox/debian focal contrib | sudo tee /etc/apt/sources.list.d/virtualbox.list

VirtualBox versions 7.0-7.2 available for Debian 11-13: "Bullseye", "Bookworm", "Trixie".

The following command displays the repository package names that begin with the word "virtualbox":

sudo apt update
apt-cache search virtualbox | grep "^virtualbox*" 

Installing linux-headers kernel module dependencies:

sudo apt install linux-headers-$(uname -r) dkms virtualbox-dkms build-essential module-assistant -y

Then install virtualbox itself, version 7.0, 7.1 or 7.2

sudo apt install virtualbox-7.0

or

sudo apt install virtualbox-7.1

or

sudo apt install virtualbox-7.2

7.0 major major release. 7.1/7.2 expands compatibility with new host OS releases and resolves compatibility issues (especially with new versions of macOS and the Linux kernel). Version 7.2 is the most secure of the three. Therefore, this article is for version 7.2.

After installing the "virtualbox-7.2" package, I start the "vboxdrv" service:

sudo systemctl enable vboxdrv --now

I enable the VM driver in the kernel:

sudo modprobe vboxdrv

I remove traces of drivers from the old VM. Otherwise, driver version mismatch error and VM version

sudo mv /lib/modules/$(uname -r)/updates/dkms/vbox* /tmp

where $(uname -r) substitutes the version of the kernel used by the operating system, for example 5.15.0-79.

Installing drivers for the new Oracle VM (!)

sudo /sbin/vboxconfig

Method No. 1 - Creating a VM using an ISO file and a local virtual machine file on the PC hard drive

  • Launch the application Oracle VirtualBox manager(terminal command virtualbox or "Start" - "All Applications" - "Oracle VirtualBox")
  • menu "Machine" - "Create"
  • specify a name, for example “sparky” (the guest OS image can be downloaded from the website SourceForge)
  • leave the default folder (/home/user/VirtualBox VMs)
  • select ISO image, file *.iso
    *Next.

Method No. 2 - Creating a virtual machine using a bootable USB flash drive

We create a file of type VMDK. It will simulate an AHCI controller on a physical RAW flash drive.

We connect a blank flash drive with a capacity of 8 or 16 GB and wait until the contents are shown (an empty folder).

To find out the device name, run the command:

lsblk

Based on the disk capacity, we find the flash drive and look at the name - sdb or sdc.

sdd 8:48 1 7.5G 0 disk
└─sdd1 8:49 1 7.5G 0 part

VirtualBox version 5.2

Accessing a physical device using the RawDisk option is not supported. (The VMDK method is useless; this article does not apply to version 5.2). It is only possible to create a VDI or VHD virtual hard disk on the local hard drive of the computer and install the OS from a regular ISO file).

VirtualBox version 6.0 - 6.1

sudo VBoxManage internalcommands createrawvmdk --filename=/home/user/usb_harddisk.vmdk  --rawdisk /dev/sdc

or

sudo VBoxManage internalcommands createrawvmdk --variant RawDisk --format=VMDK --filename=/home/user/usb_harddisk.vmdk --property RawDrive=/dev/sdc

where /dev/sdc we replace the name with your own case, for example, it could be /dev/sdd.

VirtualBox versions 7.0, 7.1 and 7.2 have a new command syntax - the "createmedium" parameter:

Run the command in the terminal:

sudo VBoxManage createmedium --variant RawDisk  --format=VMDK --filename=/home/user/usb_harddisk.vmdk --property RawDrive=//dev/sdc

Result:

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Medium created. UUID: ab7b961b-b901-4d96-b676-ef5cdb13488e

If the usb_harddisk.vmdk file already exists, it will not be overwritten and a runtime error will occur.
Each run of sudo VBoxManage createmedium --variant RawDisk --format=VMDK creates a new UUID,
which is saved to a file on the hard drive in the text file /home/user/usb_harddisk.vmdk (with root-only access).

Run Oracle VirtualBox as root user
(Since a regular user does not have access to USB for writing through the virtual SATA controller).

sudo VirtualBox
  • Oracle VirtualBox menu: "car" - "Create"

    deb01

  • come up with a name for the virtual machine. In this example, the name is sparky.
    deb02

  • in the “ISO image” item we do not select anything

  • other items: Linux Debian (64 bit)

    deb03

  • next, next, ready
    deb04

Let's change the parameters of the newly created virtual machine: parameters - section "Media".
deb05

Let's indicate our USB Flash media and bootable ISO file.

In the item "Use an existing virtual hard disk" - select the file
\.vmdk(in this example it is called "usb_harddisk.vmdk") on the local computer.

deb06

As a result, the vmdk controller for our USB Flash will appear in the virtual target settings in the “SATA Controller” section:

deb07

Uncheck Audio. You can enable I/O caching.

deb08

Now let's connect a virtual CD/DVD drive to boot from the ISO image of the guest OS to install it.

deb09

In the window, add a drive by clicking on the "Plus" button as shown in the figure.

deb10

Select the ISO boot disk image file. In this case it is Sparky Linux. With this we add the ISO to the virtual CD/DVD drive.

deb11

Select
deb12

CD/DVD boot disk has been added.
Let's remove the "Empty" entry from the IDE controller.
deb13

The boot disk "Sparky Linux" is installed in the virtual CD/DVD drive,everything is ready to start.
deb14
deb15
Let's start the virtual machine:

deb16

I will leave the steps for installing Sparky in a virtual machine without comment, because... Everything is clear from the pictures.
deb17
deb18
deb19
deb20
deb21
deb22
deb23
deb24
deb25
deb26
deb27
deb28
deb29
deb30
deb31

Installation of Sparky Linux on a virtual machine stored on a USB Flash was successful!


Migration to VirtualBox 5.2 for older processors without VT-X

In versions 6.0 and 7.0, on processors without hardware virtualization (or when the corresponding BIOS parameter is disabled), the error VERR_CMX_NO_VMX is displayed. The only way out is to roll back the version to 5.2.

V! Virtualbox 5.2 for Ubuntu 18.04 "Bionic Beaver" was released in July 2020, during the time of kernels 5.0 - 5.6. VirtualBox 5.2 can only be run in a maximum of Linux Mint 19.3 "Tricia"(19.3 Mate) or Ubuntu 20.04 OS (currently supported - until April 2025) or Russian Linux Lite 5.6 OS, developed on the basis of Ubuntu 20.04.
The latest Linux Mint 22.04 does not run either the 5.6 kernel or VirtualBox 5.2.
In version 5.2 there is no way to connect to a physical flash drive as a RAW device (the main topic of this article), it is only possible (https://www.virtualbox.org/manual/ch01.html#intro-starting-vm-first-time)[installing the OS from an ISO file] to a virtual hard disk.

1) Before installing VirtualBox 5.2, you must remove traces of the old version of VirtualBox 6 or 7

sudo apt remove virtualbox-6.1 virtualbox-7.0
sudo mv /lib/modules/$(uname -r)/updates/dkms/vbox* /tmp

2) Download VirtualBox 5.2 (for Ubuntu 18.04 / 18.10 / 19.04).

*Download_Old_Builds_5_2

3) Install dependencies for VirtualBox 5.2 - libvpx5 library and python 2.7 programming environment.

sudo apt update
sudo apt install ca-certificates
wget http://ftp.de.debian.org/debian/pool/main/libv/libvpx/libvpx5_1.7.0-3+deb10u1_amd64.deb
sudo dpkg -i libvpx5_1.7.0-3+deb10u1_amd64.deb

Checked the python version:

python -v

If python 2 is not installed (Linux Mint 19.3 has it by default and no installation is required), install it:

sudo apt install python2

Python version 2.7 is required.
If the main virtualbox package does not install without errors, the command may help sudo apt install python-is-python2.

The last dependency that needs to be resolved manually is the libqt5opengl5 library:

sudo apt install libqt5opengl5

5) Installing kernel 5.0, 5.4, 5.6 or 5.10 for VirtualBox 5.2

In Linux Mint 19.3 "Tricia" the default kernel is 5.0 - suitable for VirtualBox. There is no need to install anything.
Packages included with Linux Mint 19.3:
*linux-headers-5.0.0-32*
linux-headers-5.0.0-32-generic
linux-image-5.0.0-32-generic
linux-modules-5.0.0-32-generic
linux-modules-extra-5.0.0-32-generic.
linux-tools-5.0.0-32-generic**

There is no need to install kernel 5.4. However, VirtualBox will start with the 5.4 kernel, which can be installed from the packages:
*linux-headers-5.4.0-100*
linux-headers-5.4.0-100-generic
linux-image-5.4.0-100-generic
linux-modules-5.4.0-100-generic
linux-modules-extra-5.4.0-100-generic.
linux-tools-5.4.0-100-generic**

In Ubuntu 20.04 (Linux Lite 3.6), you can update the Linux Kernel to version 5.6: in the "Update Manager" - View - Linux Kernel, install kernel 5.6 (linux-image-5.6.0-1028-oem). Or install packages in Synaptic:
*linux-headers-5.6.0-1028-oem*
linux-image-5.6.0-1028-oem
linux-modules-5.6.0-1028-oem
linux-modules-extra-5.6.0-1028-generic**.
*linux-tools-5.6.0-1028-oem

Installing the Linux Kernel 5.10 possible in Linux 20.04: in the "Update Manager" - View - Linux Kernel, install kernel 5.10 (linux-image-5.10.0-1016-oem). Or install packages in Synaptic:
*linux-headers-5.10.0-1016-oem*
linux-image-5.10.0-1016-oem
linux-modules-5.10.0-1016-oem
linux-modules-extra-5.10.0-1016-generic**.
*linux-tools-5.10.0-1016-oem

This operation is only possible on Ubuntu 20.04 and earlier, such as 19.04, 18.10, 18.04, or 16.04. On the latest Ubuntu 22.04 or Linux Mint 21.x, older kernels do not work due to unmet dependencies.

If you have updated the kernel, reboot and in the Grub2 menu in the additional launch parameters select kernel 5.4, 5.6 or 5.10:

sudo reboot

Select kernel 5.0, 5.4, 5.6 or 5.10 and press Enter.

If after loading kernels above 5.0 the resolution is 640 x 480, and not what was expected, edit /etc/default/grub and add the line to it
GRUB_GFXMODE=1280x1024#your monitor resolution

Then we perform
sudo update-grub

And once again we reboot the PC with the same kernel selected. Now the display resolution is normal.

6)Installing Virtual Box 5.2
We remove the previous installation of VirtualBox 5.2 if it turned out to be not configured (with errors).

sudo apt --fix-broken install

Install virtualbox with the command:

sudo ~/Downloads
sudo dpkg -i virtualbox-5.2_5.2.44-139111~Ubuntu~bionic_amd64.deb

7) Install kernel drivers for virtualbox 5.2 into the kernel.

sudo /sbin/vboxconfig

8) Checks:

lsmod | grep vbox
sudo systemctl status vboxdrv

9) Launch is done through the "Start" menu (search by name VirtualBox).
Or from the command line:

 virtualbox

virtualbox=> Help => About the program shows version 5.2.44.

In VirtualBox 5.2 and a processor without VT-X support, only 32-bit versions of distribution kits (i386 - i486 - i586 - i686) can be installed in a virtual machine.

Tip for installation option #3. The best ways to create a bootable USB flash drive

How to make a regular bootable USB flash drive (for startup method No. 3, through the computer’s boot menu):

Except copying dd if=some.iso of=/dev/sdc bs=1M, there are two new ways:

In Windows - program rufus:
*https://rufus.ie/ru/

On Linux:
*https://etcher.balena.io/

The Balena Etcher application writes bootable USB flashes in CD-R ISO9660 format ("Read Only"). To write a USB flash drive with the persistence function, see article "How to burn a bootable USB flash for antiX / MX Linux with persistence".


Sources:
VirtualBox Documentation
Virtualization Technology support for processors
*Tips from askubuntu.com users

Documentation:
VirtualBox 5.2.44 UserManual.pdf
VirtualBox 6.1.46 UserManual.pdf
*VirtualBox 7.0.10 UserManual.pdf


Last modified: 01.06.2026



Related publications