En/virtualbox usb install

From Studiosg
Jump to navigationJump to search

Welcome to Simone Giustetti's wiki pages.

Languages: English - Italiano

What follows is somewhat of a hack to install a VirtualBox virtual machine from an Usb stick instead of a Dvd or Iso image. An Usb install is impossible per se as the VirtualBox Bios does not support booting from an Usb device. A "lack" that limits user options when installing as well as when the machine is in need of a rescue system to solve operating system repair.

This limitation can however be circumvented by mean of a VirtualBox less known functionality. VirtualBox can run a machine from a physical disk or disk partition instead of an image file with *.vdi extension. This feature goes by the name of “raw hard disk access” whose details can be found in the emulator manual.

Raw Hard Disk Access

Permits a guest system to access a host hard disk or a disk partition bypassing the host machine file system. Direct access is a VMDK file format only feature, one of the many VirtualBox supported virtual machine formats. A VMDK image file is mandatory to take advantage of raw hard disk access. Once created, the image file can be used as any other virtual disk and assigned to a virtual machine.

Boot Image

In order to perform an installation from an Usb stick a boot image should be copied to the stick itself. Such images usually fill the whole stick despite of its partition count or its size. Given our final goal, we will presume that the device is used wholly and as such raw access for an entire hard disk will be configured.

Before creating the image we will prepare the device. Connect the Usb stick to the Pc and try and discover the associated system device handler. Start a root shell and run the dmesg command:

  clear;dmesg | tail -20
  [15044.405959] sd 8:0:0:0: [sdb] Assuming drive cache: write through
  [15044.405966]  sdb: sdb1
  [15364.740852] EXT4-fs (dm-4): mounted filesystem with ordered data mode. Opts: (null)
  [21920.056729] usb 1-1.4: new high speed USB device using ehci_hcd and address 3
  [21920.356397] usb 1-1.4: New USB device found, idVendor=0951, idProduct=1643
  [21920.356403] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
  [21920.356408] usb 1-1.4: Product: DataTraveler G3
  [21920.356412] usb 1-1.4: Manufacturer: Kingston
  [21920.356417] usb 1-1.4: SerialNumber: 001D0F0CAA77FAB136311317
  [21920.356948] scsi9 : usb-storage 1-1.4:1.0
  [21921.357935] scsi 9:0:0:0: Direct-Access::r  Kingston DataTraveler G3  1.00 PQ: 0 ANSI: 2
  [21921.358245] sd 9:0:0:0: Attached scsi generic sg4 type 0
  [21921.360988] sd 9:0:0:0: [sdc] 7557704 512-byte logical blocks: (3.86 GB/3.60 GiB)
  [21921.361616] sd 9:0:0:0: [sdc] Write Protect is off
  [21921.361624] sd 9:0:0:0: [sdc] Mode Sense: 03 00 00 00
  [21921.361629] sd 9:0:0:0: [sdc] Assuming drive cache: write through
  [21921.364828] sd 9:0:0:0: [sdc] Assuming drive cache: write through
  [21921.364836]  sdc:
  [21921.367956] sd 9:0:0:0: [sdc] Assuming drive cache: write through
  [21921.367964] sd 9:0:0:0: [sdc] Attached SCSI removable disk

Our stick was associated to device /dev/sdc by the operating system.

We can now copy the boot image of choice to the usb stick.

Please note: the stick data will be wholly overwritten and the device will not be usable again without proper formatting.

Le's suppose we went for a Slackware Linux 13.1 install image; the related file can be found inside the usb-and-pxe-installers directory of any install media or from a network Ftp repository. File name is usbboot.img. You are strongly suggested to read file README_USB.TXT located inside directory usb-and-pxe-installers for more information about the following procedure.

Command dd will be used to copy the image file to the media:

  dd if=<path>/usbboot.img of=<device> bs=512

Start a root shell and run the following line:

  dd if=/mnt/floppy/slackware/stable32/usb-and-pxe-installers/usbboot.img of=/dev/sdc bs=512

The installation media will be ready upon prompt return.

Virtual Disk

Creating a virtual disk from a hard disk in VirtualBox requires use of the VBoxManage command followed by a proper option list. The resulting image will contain no actual data. All data will be written into the physical drive.

VBoxManage is the command line interface (cli) for VirtualBox administration. Command syntax is very similar for Linux, MacOsX, Unix and Windows operating systems. Some differences remain in operating system specific areas like file system path names conventions.

  VBoxManage internalcommands createrawvmdk -filename <path>/<file.vmdk> -rawdisk <dev> -register


<path>/<file.vmdk> is the host machine file system absolute path to the image file.
<dev> is the host machine absolute path for the device file related to the stick (Unix-like systems. Please refer to the user manual for the Windows syntax).
Option register registers the newly configured device with the emulator available disks list. If omitted, the registration should be executed later recurring to the Gui.

All data will be read from and written to <dev>.

To create a virtual disk recurring to the cli interface, please run command:

  VBoxManage internalcommands createrawvmdk -filename /opt/vm/test.vmdk -rawdisk /dev/sdc -register
  Oracle VM VirtualBox Command Line Management Interface Version 3.2.10
  (C) 2005-2010 Oracle Corporation
  All rights reserved.

  RAW host disk access VMDK file /opt/vm/test.vmdk created successfully.

The newly created disk shall be assigned to the to be installed host machine. The command is:

  VBoxManage storageattach <virtual_machine> --storagectl "IDE Controller" --port <port> --device <device number> \
  --type hdd --medium <path>/<file.vmdk>


<virtual_machine> it's the virtual machine name.
<port> is the Ide channel identifier. use 0 for Primary or 1 for Secondary.
<device number> is the Ide device identifier. Use 0 for Master or 1 for Slave.
<path>/<file.vmdk> is the host system absolute path to the virtual disk.

Supposing to configure the Usb stick as a Secondary Master Ide device:

  VBoxManage storageattach vms131v32 --storagectl "IDE Controller" --port 1 --device 0 --type hdd \
  --medium /opt/vm/test.vmdk

The allocation procedure can be executed from the Gui too.

Starting the Installation

When the Usb boot stick is ready, start the virtual machine from the Gui. During the emulated boot phase press key F12 to select the booting device.

Select the Secondary Master ide device and if everything went well you should be welcomed by the Slackware 13.1 installation screen.

Virtualbox usb install.jpeg

For any feedback, questions, errors and such, please e-mail me at studiosg [at] giustetti [dot] net.

External links

Languages: English - Italiano