You may want to do this for a number of reasons, you may have a bootable USB thumb-drive / USB flash drive / USB stick (whatever you call it) containing Live CD, installation image etc. before you actually use it on your computer, or may be you don’t want to use that bootable USB on your computer, whatever that case might be.
Following are the 3 different methods you could use.
Method # 1: Create a pointer to your USB
I am using Ubuntu 18.04 LTS, but it could be any Linux OS/distro/flavor. If you have a bootable USB that you want to boot your VM from, go ahead and insert it.
First you need to find the logical device for your removable USB flash drive. One way to do it is to use lshw command (ls for hardware, get it?) It is recommended that you run this command as a super-user (sudo) otherwise “your output may be incomplete or inaccurate, you should run this program as super-user” warning would be displayed, which makes sense. If you need more information on lshw, including installation and basic usage, see this project website or this article.
Here is the raw command which shots of how KDE used to look like back in the day, in openSUSE 11.1 – this was the first ever Linux distro which got me hooked with Linux. To put things in perspective, openSUSE’s current version is 15.0 😉 will output EVERYTHING:
# "sudo lshw" shows everything $ sudo lshw -class volume -disable TEST -notime
And look for the entry associated with your hard drive’s label. Alternatively, following commands much more concise if you know what you are looking for:
$ sudo lshw -businfo -disable TEST | grep volume
In my case, from the first command above, it was /dev/sdb1.
Next, close each and every instances Virtual Box application, and run the following command as super-user:
$ sudo VBoxManage internalcommands createrawvmdk \ > -filename /home/atalati/Documents/ISOs/myusb.vmdk \ > -rawdisk /dev/sdb1
On success, you might see following message:
RAW host disk access VMDK file /home/atalati/Documents/ISOs/myusb.vmdk created successfully.
Now, you just need to attach the VMDK file we created above. [More details]
Method # 2 Create Virtual Box Drive
If the method above, simply did not work for you, then try running following command instead
$ sudo VBoxManage convertfromraw /dev/sdb1 usb.vmdk --format vmdk
Now, launch Virtual Box and create a new VM as you would normally do. Now, open settings and go to Storage section. You might see SATA controller by default but with a right mouse click you can add IDE controller.
Now boot your VM and boot from this drive.
Method # 3 USB to .iso
You can convert USB to raw CD image and directly boot from it. Here of stands for output file.
$ dd if=/dev/sdb1 of=myusbkey.iso
Method # 4 Bonus method!
Launch gnome-disks, and then use the more actions icon to choose Create Image.
There is a detailed article which explains how the same could be done using Microsoft Windows operating system.