Creating A Portable Linux Installation On A Flash Drive (Part 2)

In the previous post I described how to create a Linux bootable USB flash drive. However, sometimes you may want to run this installation in conjunction with your normal desktop rather than have it take over the whole system. In that case, you can boot the flash drive from within VirtualBox.

Granting The Proper Permissions

For this to work, VirtualBox must have the proper flash drive permissions. There are multiple ways to approach this but the one I like best is described in the answer to this question on Stack Exchange.

All it takes is to change to the /etc/udev/rules.d directory and create a new rules file (e.g., usb_virtualbox.rules) containing the line:

SUBSYSTEM=="block", ATTRS{idVendor}=="1d6b", ATTRS{idProduct}=="0003", ACTION=="add", RUN+="/bin/setfacl -m g:vboxusers:rw- /dev/$name"

The idProduct and idVendor must be changed to match the flash drive’s PID and VID. In short, this rule grants members of the vboxusers group read/write permission for the USB flash drive with the corresponding PID/VID when the drive is plugged in.

Attaching The USB Flash Drive

VirtualBox does not have the capability to boot directly from a USB drive. Instead, you’ll need to create a virtual hard drive that redirects access. These instructions are based upon those provided in this thread.

Insert the flash drive. Once it mounts open a terminal and execute the command:

$ lsblk

You’ll be able to identify the device name from the resulting output. In the case shown below, the flash drive device is /dev/sdb.

lsblk Output

In the terminal, switch to the directory where you want to store the virtual hard drive and execute the command:

$ sudo vboxmanage internalcommands createrawvmdk -filename vd_filename.vmdk -rawdisk device_name

where vd_filename is the name you want to give the virtual disk and device_name is the device name obtained from the output of the lsblk command.

Use the chown command to change the created file’s owner to the currently logged in user:

$ sudo chown user:user vd_filename.vmdk

where user is the currently logged in user.

To attach the drive to the virtual machine, go back to the VirtualBox main menu, select the virtual machine you created previously, and click Storage. Click the ‘+’ sign next to Controller: IDE and when prompted click Choose existing disk and select the virtual drive you just created.

Choose Existing Disk

Go back to the VirtualBox main form and click Start to start the virtual machine. It should boot from the USB flash drive just as if you had restarted the system and selected it from the boot menu.


Comments are closed.

DuWayne's Place

Computers, Electronics, and Amateur Radio from KC3XM

QRP HomeBuilder - QRPHB -

Computers, Electronics, and Amateur Radio from KC3XM

Open Emitter

Computers, Electronics, and Amateur Radio from KC3XM

Ripples in the Ether

Emanations from Amateur Radio Station NT7S

m0xpd's 'Shack Nasties'

Computers, Electronics, and Amateur Radio from KC3XM

%d bloggers like this: