Virtual Machine options

Booting and installing sidux to a KVM Virtual Machine

KVM is a full virtualisation solution for Linux on x86 hardware containing virtualisation extensions (Intel VT or AMD-V).

Prerequisites

To ascertain whether your hardware supports KVM, ensure that KVM is enabled in the BIOS (in some cases on an Intel VT or AMD-V system it may not evident as to where the switch is, therefore assume that it is in a KVM state). The way to check is in a console run:

cat /proc/cpuinfo | egrep --color=always 'vmx|smx'

If you see smx or vmx in the cpu flags field, your system supports KVM. (Otherwise go back to the BIOS if you believe it is supported and check again, else search the internet as to where in the BIOS menus KVM 'enable' could be hiding).

Should your BIOS not support KVM refer to Virtualbox or QEMU

To install and run KVM, firstly ensure that Virtualbox modules are not loaded, (--purge them is the best option), then depending on your chipset:

For vmx:

apt-get install qemu-kvm
modprobe kvm_intel

For smx:

apt-get install qemu-kvm
modprobe kvm_amd

Another option is reboot as the qemu-kvm initscripts will take care of loading the modules.

Using KVM to boot a sidux-*.iso

As user:

$ kvm -net nic,model=virtio -net user -soundhw ac97 -m 512 -monitor stdio -cdrom <sidux.iso>
Installing a sidux-*.iso to a KVM image

First create a hard disk image, (this image will be minimal and only grow as required due to qcow2 compression ratios):

$ qemu-img create -f qcow2 sidux-20xx-*-.img 12G

Boot the sidux-*.iso with the following parameters to enable KVM to recognise that there is an QEMU hard disk image available:

$ kvm -net nic,model=virtio -net user -soundhw ac97 -m 512 -monitor stdio -cdrom </path/to/sidux.iso> -boot d </path/to/sidux-20xx-*-.img>

Once the cdrom has booted up click on the sidux installer icon to activate the installer, (or use the menu), click on the Partitioning tab and you should see on the left hand side a box that has a disk ready for partitioning and formatting, most likely noted as /dev/sda. Underneath that are the options for partitioning, choose gparted.

gparted kvm hard disk naming

In the Gparted menu you can confirm that Gparted sees the image with View>Device Information which should state it is a ATA QEMU Harddisk and most likely noted as /dev/sda,(in this example), as this will be crucial when moving back to the installer and choosing where to put Grub, as it needs to go to /dev/sda.

Next, in the Partition menu choose Device>Create Partiton Table and create the partition table.

Then format the partition table with ext4 and also include a swap of 2 gig. The formatting will take time so be patient.

After formatting has completed, click OK to be returned to the installer and proceed as if you are performing a standard install, (again, be patient). Note: Install the Grub to /dev/sda.

You now have a sidux-*-VM ready for use:

$ kvm -net nic,model=virtio -net user -soundhw ac97 -m 512 -monitor stdio -drive if=virtio,boot=on,file=<absolute/path/to/sidux-20xx-*.img>

If the guest does not support virtio, or you do not specify an absolute path, use:

$ kvm -net nic,model=virtio -net user -soundhw ac97 -m 512 -monitor stdio -hda </path/to/sidux-20xx-*.img>

See also:

$ man kvm
Managing your KVM virtual machine installations
apt-get install aqemu

When using AQEMU ensure that you choose the KVM mode from the drop down box for 'Emulator Type' in the 'General' tab. (Documentation for AQEMU is basically non existent, therefore a few 'trials by error' will be required to figure out the easy to use GUI, however a good start is to use first use the 'VM' menu followed by the 'General' tab.

Booting and installing sidux to a VirtualBox Virtual Machine

The Steps.

Requirements

Recommended ram: 1 gig : Ideally 512 MB for the guest and 512 MB for the host. (it can be run on less, but do not expect to have good performance).

Hard disk space: While VirtualBox itself is very lean (a typical installation will only need about 30 MB of hard disk space), the virtual machines will require fairly huge files on disk to represent their own hard disk storage. So, to install MS Windows XP (TM), for example, you will need a file that will easily grow to several GB in size. To have sidux in VirtualBox you need to allocate a 5 gig image plus a swap allocation.

Installation:

apt-get update
apt-get install virtualbox-ose-qt virtualbox-ose-source dmakms module-assistant

Then prepare the module:

m-a prepare
m-a a-i virtualbox-ose-source

Then activate Dynamic Module-Assistant Kernel Module Support for virtualbox, so that the next time the Linux kernel is updated a virtualbox module is prepared for it too, without manual intervention. To do that, add virtualbox-ose-source to the /etc/default/dmakms configuration file.

mcedit /etc/default/dmakms
virtualbox-ose-source

Then reboot the computer.

This is essential reading on dmakms

Installing sidux to the virtual machine

Use virtualbox's wizard to create a new virtual machine for sidux, then follow the instructions for a regular sidux-installation.

VirtualBox has a comprehesive PDF Help, that you can download

Booting and installing sidux to a QEMU Virtual Machine

A QT GUI tool is available to help configure QEMU:

apt-get install qtemu

Creating the hard disk image

To run qemu you will probably need a hard disk image. This is a file which stores the contents of the emulated hard disk.

Use the command:

qemu-img create -f qcow sidux.qcow 3G

To create the image file named "sidux.qcow". The "3G" parameter specifies the size of the disk - in this case 3 GB. You can use suffix M for megabytes (for example "256M"). You shouldn't worry too much about the size of the disk - the qcow format compresses the image so that the empty space doesn't add up to the size of the file.

Installing the operating system

This is the first time you will need to start the emulator. One thing to keep in mind: when you click inside qemu window, the mouse pointer is grabbed. To release it press :

Ctrl+Alt

If you need to use a bootable floppy, run Qemu with:

qemu -floppy sidux.iso -net nic -net user -m 512 -boot d sidux.qcow

If your CD-ROM is bootable, run Qemu with:

qemu -cdrom sidux.iso -net nic -net user -m 512 -boot d sidux.qcow

Now install sidux as if you were going to install it on a real HD

Running the system

To run the system simply type:

qemu [hd_image]

A good idea is to use overlay images. This way you can create hard disk image once and tell Qemu to store changes in external file. You get rid of all the instability, because it is so easy to revert to previous system state.

To create an overlay image, type:

qemu-img create -b [[base''image]] -f qcow [[overlay''image]]

Substitute the hard disk image for base_image (in our case sidux.qcow). After that you can run qemu with:

qemu [overlay_image]

The original image will be left untouched. One hitch, the base image cannot be renamed or moved, the overlay remembers the base's full path.

Using any real partition as the single primary partition of a hard disk image

Sometimes, you may wish to use one of your system partition from within qemu (for instance, if you wish booting both your real machine or qemu using a given partition as root). You can do this using software RAID in linear mode (you need the linear.ko kernel driver) and a loopback device: the trick is to dynamically prepend a master boot record (MBR) to the real partition you wish to embed in a qemu raw disk image.

Suppose you have a plain, unmounted /dev/sdaN partition with some filesystem on it you wish to make part of a qemu disk image. First, you create some small file to hold the MBR:

dd if=/dev/zero of=/path/to/mbr count=32

Here, a 16 KB (32 * 512 bytes) file is created. It is important not to make it too small (even if the MBR only needs a single 512 bytes block), since the smaller it will be, the smaller the chunk size of the software RAID device will have to be, which could have an impact on performance. Then, you setup a loopback device to the MBR file:

losetup -f /path/to/mbr

Let's assume the resulting device is /dev/loop0, because we wouldn't already have been using other loopbacks. Next step is to create the "merged" MBR + /dev/sdaN disk image using software RAID:

 modprobe linear
 mdadm --build --verbose /dev/md0 --chunk=16 --level=linear --raid-devices=2 /dev/loop0 /dev/sdaN

The resulting /dev/md0 is what you will use as a qemu raw disk image (don't forget to set the permissions so that the emulator can access it). The last (and somewhat tricky) step is to set the disk configuration (disk geometry and partitions table) so that the primary partition start point in the MBR matches the one of /dev/sdaN inside /dev/md0 (an offset of exactly 16 * 512 = 16384 bytes in this example). Do this using fdisk on the host machine, not in the emulator: the default raw disc detection routine from qemu often results in non kilobyte-roundable offsets (such as 31.5 KB, as in the previous section) that cannot be managed by the software RAID code. Hence, from the the host:

 fdisk /dev/md0

There, create a single primary partition corresponding to /dev/sdaN, and play with the 's'ector command from the 'x'pert menu until the first cylinder (where the first partition starts), matches to the size of the MBR. Finally, 'w'rite the result to the file: you are done. You now have a partition you can mount directly from your host, as well as part of a qemu disk image:

 qemu -hdc /dev/md0 [...]

You can of course safely set any bootloader on this disk image using qemu, provided the original /boot/sdaN partition contains the necessary tools.

Using the QEMU Accelerator Module

The developers of qemu have created an optional kernel module to accelerate qemu to sometimes near native levels. This should be loaded with the option

major=0

to automate the creation of the required /dev/kqemu device. The following command

echo "options kqemu major=0" >> /etc/modules

This will amend modprobe.conf to ensure that the module option is added every time the module is loaded.

qemu [...] -kernel-kqemu

This enables full virtualization and thus improves speed considerably.

To activate qemu:

qemu -cdrom /tmp/pkg/sidux-debug.iso -net nic -net user -m 512

The official documentation of the QEMU Project

Some content for QEMU for the sidux-manual was accessed off this site under GNU Free Documentation License 1.2 and modified for the sidux-manual

Page last revised 13/04/2010 1450 UTC