Virtual Machine options

The following examples use aptosid, simply substitute aptosid with the distribution of your choice.

Installing other distributions to a VM image

Note: If and when you wish to install to a virtual machine image, most Linux distributions will probably only need an allocation of 12G. However if you have a requirement to have MS Windows in a virtual machine, you will need to allocate about 30G, or more, to the image. All image allocation sizes ultimately depend on your requirements.

Generally, an image allocation size, will not take up additional hard drive space until data is installed. Even then, it will only take space dynamically on a hard drive, contingent to the actual amount of data that expands on the image. This is due to the compression ratios of qcow2.

Enabling a KVM Virtual Machine

KVM is a full virtualisation solution for Linux running on x86 CPU with 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|svm'

If you see svm 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):

apt-get install qemu-system-x86 qemu-utils

When you start your system the qemu-system-x86 initscripts will take care of loading the modules.

Using KVM to boot an aptosid-*.iso

For 64 bit as user:

$ QEMU_AUDIO_DRV=alsa qemu-system-x86_64 -machine accel=kvm:tcg -net nic,model=virtio -net user -soundhw hda -m 1024 -monitor stdio -cdrom <aptosid.iso>

For 32 bit replace qemu-system-x86_64 with qemu-system-i386.

Installing aptosid 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 aptosid-VM.img 12G

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

$ QEMU_AUDIO_DRV=alsa qemu-system-x86_64 -machine accel=kvm:tcg -net nic,model=virtio -net user -soundhw hda -m 1024 -monitor stdio -cdrom </path/to/aptosid-*.iso> -boot d </path/to/aptosid-VM.img>

For 32 bit replace qemu-system-x86_64 with qemu-system-i386.

Once the cdrom has booted up click on the aptosid installer icon to activate the installer, (or use the menu), click on the Partitioning tab and launch the partition application you prefer. For the partitioning you can follow the instructions from Partitioning the Hard Drive - Traditional, GPT and LVM (do not forget to add a swap partition If you are short of memory). Please be aware that formatting will take time so be patient.

gparted kvm hard disk naming

You now have a VM ready for use:

$ QEMU_AUDIO_DRV=alsa qemu-system-x86_64 -machine accel=kvm:tcg -net nic,model=virtio -net user -soundhw hda -m 1024 -monitor stdio -drive if=virtio,boot=on,file=<path/to/aptosid-VM.img> 

Some guests do not support virtio, therefore you need to use other options when launching KVM, for example:

$ QEMU_AUDIO_DRV=alsa qemu-system-x86_64 -machine accel=kvm:tcg -net nic, -net user -soundhw hda -m 1024 -monitor stdio -hda </path/to/your_guest.img > -cdrom your_other.iso -boot d 

or

$ QEMU_AUDIO_DRV=alsa qemu-system-x86_64 -machine accel=kvm:tcg -net nic, -net user -soundhw hda -m 1024 -monitor stdio -hda </path/to/your_guest.img> 

See also: KVM documentation.

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 to a VirtualBox Virtual Machine

The Steps.

Requirements

Recommended ram: 2 gig : Ideally 1024 MB for the guest and 1024 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 aptosid 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-source dmakms module-assistant

Then prepare the module:

m-a prepare
m-a a-i virtualbox-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-source to the /etc/default/dmakms configuration file.

mcedit /etc/default/dmakms
virtualbox-source

Then reboot the computer.

This is essential reading on dmakms

Installing aptosid to the virtual machine

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

VirtualBox has a comprehesive PDF Help, that you can download

Booting and installing 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 aptosid-VM.img 3G

To create the image file named "aptosid-VM.img". 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 want to use a bootable floppy, run Qemu with:

qemu -floppy aptosid.iso -net nic -net user -m 1024 -boot d aptosid-VM.img

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

qemu -cdrom aptosid.iso -net nic -net user -m 1024 -boot d aptosid-VM.img

Now install aptosid 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 aptosid-VM.img). 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.

The official documentation of the QEMU Project

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

Page last revised 04/10/2013 1320 UTC