VirtualBox

VirtualBox is free for private use and simulates a complete PC including its peripherals under Linux. Different operating systems can be installed.

Figure 16.4. Virtualbox and compiz is running Ubuntu and XP

virtual box and compiz


Under Gentoo run emerge virtualbox or its binary version emerge virtualbox-bin . It uses /dev/vboxdrv from the virtualbox-modules package.

The group of the users vboxusers have access. So you might put yourself to this group usermod -a -G vboxusers<thats me> and login log out and log in to make the system aware of it.

Since VirtualBox uses kernel modules that do not come with the kernel source they must be loaded. lsmod | grep 'vbox' will show if they are running

VirtualBox is the command to start it. The configuration is done via a GUI and a wizard.

Some vocabulary to learn:

  1. Guest is the virtual PC

  2. Host is your physical PC

The right Ctrl key is per default the host key. Its function is to toggle the capture of the mouse and keyboard between host and guest.

The manual: http://www.virtualbox.org/manual/UserManual.html

Note

~/.VirtualBox holds the configuration. Before working with Virtual box go in the Settings of the VirtualBox Manager and select the default directory where you want to install, this might be important if you want to backup or synchronizing your virtual machines. Be aware that a lot of memory will be occupied since a regular virtual hard disk will have about 20GBytes.

Guest additions

The guest will see rather simple generic PC hardware, with a low performance graphic card and low resolution, so it is time to add some more functionalities. VBoxGuestAdditions is a iso image found at /usr/share/virtualbox/VBoxGuestAdditions.iso that can be inserted into the virtual boxes CD drive.

For gentoo emerge virtualbox-additions

Note

Since it runs on the guest machine it just has some impact on the guest machine. If virtualbox gets reinstalled on a new machine and the guest disk is copied to the new machine than the guest additons are already installed and do not need to be reinstalled

Start the virtual machine and run the guest additions:

  1. On Linux mount the ISO image /opt/VirtualBox/additions/VBoxGuestAdditions.iso. Maybe your guest operating system uses autorun when the iso image is found, there is also a menu item to install it or open the iso image in the guest Linux and run autorun.sh

  2. When you run Windows as a guest, you have now a CD with the guest additions probably in drive D:. Go there and start it.

Caution

For Gentoo there is also virtualbox-guest-additions that is for gentoo guests and comes with an OpenRC service. This is not the iso image. So do not emerge it whan not having a gentoo guest.

Run a ISO CD image

Run a ISO CD image is easy, create a virtual machine with no operating system and no hard disk. The select the ISO image under CD drives and up to go.

Back to the past

This is a hack but maybe necessary to not find yourself in big troubles.

An example: Assuming you developed a product with electronic chips and this product is in production for some years and everything looks OK. After some years you need to do a modification to your old design. The old tools were free, but with a expiry date. The old tool does not run on the new operating system. The company that created the tool does not exist anymore and there is no new tool. The new tool is no more compatible to the old design and chip.

To not find you in a bad situation you could do a snapshot with virtual box and set the clock back to the time of the snapshot.

Shared folders

Data between host and guest system can be exchanged using shared folders (guest-additions need to be installed). In Virtual Box set the folder to be shared on the host. Then go to the guest systems:

  1. On a Ubuntu guest system (where no root exist sudo needs to be used) open a terminal and type the following to mount a folder: sudo mount -t vboxsf<name of the shared folder><mounting point on guest> or to make sure you get access: sudo mount -t vboxsf -o uid=1000 -o gid=1000<name of the shared folder> <mounting point on guest> and to unmount: sudo umount<mounting point on guest>

  2. On Widows XP just attach yourself on a network drive using the Windows-Explorers pull down menu Extra > Network drive. Alternatively you could use samba to communicate to the host system.

USB devices

USB support for USB1 goes directly without additional installation. For USB2 and USB3 the extension pack needs to be installed. For gentoo emerge app-emulation/virtualbox-extpack-oracle

Select in VirtualBox the USB devices (not just usb sticks) that you want to make available to the virtual machine.

Using Serial port

On the Linux host make sure the hardware is detected and that you have the necessary permission to access it. ls -l /dev/ttyS0 will show the group as uucp, usermod -a -G uucp <thats me> add it to the group and cat /etc/group | grep 'uucp' will verify it.

Then test it with a terminal program. If it fails and sees no port check with lsmod | grep 8250 if the serial port drivers are loaded. If not, check the kernel if the drivers are included in the kernel or select kernel option to create the 8250 driver. Check the serial port chapter for the details. In Virtualbox map COM1 to the host device as /dev/ttyS0.

If you have Windows XP and you don't see any COM port, you need to scan for new installed hardware. Then it is worth to test it with hyperterminal.

Note

When using this method the virtual PC does not care about USB when you have a USB to RS232 adapter. Alternatively you could map the USB device to the virtual PC, and install there the Windows driver for the USB RS232 cable.

Running FreeDos

Check http://wiki.freedos.org/wiki/index.php/VirtualBox create the virtual machine and insert the iso Freedos image.

C:\FDOS\DN2\DN is something as mc filemanager

FDIMPLES with the freeDOS image in the CD drive installs programs

Data can be exchanged if FreeDos is not running by mounting its virtual harddisk (if format is supported).

Snapshots

A snap shot of the virtual machines can be made. When after a snap shot the virtual machines installation got damaged (virus, installation of applications) then it can be reverted to the status when the snap shot has taken place.

When a disk is created a VDI (Virtual Disk Image) file is created. When a snapshot is created also a vdi file is created, but this file contains just the difference to the base vdi file.

Once a VDI file is created, the size is fixed and can not simply be enlarged. Note then when creating dynamic VDI file, the actual size of VDI file on the physical hard disk is smaller than the virtual size of the disk. So be a bit optimistic and add larger VDI file size. Be aware that your host computer does not run out of disk size, since this can cause bad data losses. It is wise to put the vdi files to a separate partition to prevent such crashes.

To expand a a VDI file special dedicated tools as VDIclone are available. An other alternative is clonezilla, where you first add an empty VDI file as second hard disk to your computer. Then start the iso live CD image of clonezilla and copy the small VDI disk image to the second larger disk.

Warning

Be aware that you have enough physical disk space when you try to do such actions.

Audio

When no audio is required then select: Host Audio Driver > Null Audio Driver

Import and export VM

To backup and synchronizing Virtual machines among different computers the internals of Vbox need to be understood.

There are two key files:

  1. An xml file that holds all the settings of the virtual PC. This file has either xml or vbox extension and its file name corresponds to the name of the Vitrual machine.

  2. A file the holds the contents of the hard disk used. It usually has the extension vdi (Virtual Disk Image) but depending on the format chosen it can differ. After an ova import and export the file will be converted to vmdk (VMWare ).

Note

As with any other program, vbox also gets evolved ant therefor the data and it directory structure might become old an even on day no more supported. Importing and exporting the virtual machines and its hard disks as described below will update them to the newest version.

In the past a different directory structure Additionally there are other subdirectories as Logs and Snapshots, that contain files matching the purpose of their subdirectory names.

To backup the virtual machines those files can be directly accessed but the VirtualBox Manager offers also some more safe gui tools for manipulating as:

Virtual media manager that offers commands dealing with the virtual hard disks (copy, modify, release, remove,... ).

Virtual machines can be easily modified by selection the settings tab. They can also be copied selecting clone.

Adding a vbox file will add the virtual machines including its disk to VirtualBox

Finally they can be imported and exported using a single TAR archive. This TAR archive is called Open Virtualization Format Archive or ova format. This archive holds three files:

  1. The disk image is moved to a vmdk file.

  2. The xml file ovf containing the description of the virtual PC

  3. An optional manifest file with the mf extension that holds the checksums.

Note

Be aware that snapshots disappear when importing and exporting

Mounting Virtual Harddisks

It might be desirable to mount the virtual harddisks under the real PC. When done, then also the restricted directories (as android has) can be read and backup gets easy. Be aware that this topic might be quite experimental and in general it should be avoided when the virtual PC accesses this hard disk. Depending on the file format of the virtual hard disk there are some options.

vmdk harddisks

For vmdk there is the command vmware-mount that mounts them easily under Linux. http://www.vmware.com/pdf/VMwareDiskMount.pdf shows the details. After emerge vmware-workstation the command can be found under /opt/vmware/bin/vmware-mount

/opt/vmware/bin/vmware-mount -p <path to vmdk file> shows its partitions

/opt/vmware/bin/vmware-mount <path to vmdk file> /mnt/vmware/ mounts

/opt/vmware/bin/vmware-mount <path to vmdk file> 2 /mnt/vmware/ mounts 2nd partition

/opt/vmware/bin/vmware-mount -x unmounts everything

vdi harddisks

For vdi it is quite experimental and not mentioned in the VirtualBox documentation. The forum https://forums.virtualbox.org/viewtopic.php?t=52 says:

  1. use a fixed size vdi file

  2. make sure it does not contain a snapshot

  3. have just one primary partition

  4. don't have VirtualBox running and accessing this file

The vdi file contains the disk, but also additional information, therefore the offset has to be know that separates the additional information from the file system. The offset can be found by:

vditool DUMP<my>.vdi

or by using a HEX editor and finding the string MSDOS in the file, then subtract 3 from its address or use the od (object dump) command:

Knowing the offset the vdi file can be mounted as

mount -o loop,offset=34304,umask=000<path and name of the vdi file> /mnt/vdifs

The the vdi file can be mounted with a script like this:

Example 16.1. Mount vdi

#!/bin/bash
VDI=mydisk.vdi
OFFSET=$(./vditool DUMP $VDI|perl -ne 'print 32256+$1 if m/offData=(\d+)/')
sudo mount -o ro,noatime,noexec,loop,offset=$OFFSET $VDI loopmnt/  


To mount the first partition type:

./mount_vdi.sh /home/lindegur/.VirtualBox/HardDisks/FreeDos.vdi /home/lindegur/VM/FreeDos/ 1

Mount vhd

libguestfs can do it. See http://wiki.freedos.org/wiki/index.php/VirtualBox_-_Chapter_6 to mount guestmount -a FreeDOS_1.2.vhd -m /dev/sda1 /home/username/vhd to unmount guestunmount /home/username/vhd

Virtual Box Networking

Networking can be come tricky. There are different options:

NAT

Network Address Translation (NAT) is the default setting. It connects the virtual machine to the Internet and needs no special setup. Drawbacks are that the VM can not act as an device connected to to local intra-net.

Bridged

In this mode the VM acts as a computer on the hosts Ethernet, resulting in a setting to be made, a (or the) host network adapter.

It can do what ever other computers can do as accessing the Internet.

Host only networking

A network is created that connects all VM to the host. The host would have to act as an router to have the VM's acting the Intranet or Internet. Per default the host gets address 192.168.56.1 and the devices when obtaining their address via virtualbox's dhcp server get addresses starting from 192.168.56.101.

There are some settings to be done on the host to recognize this new network.


Linurs Servernest startpage