Installing deepOfix using KVM
This page is to help you get a fully-fledged Deepofix OS on your own machine in no time using the KVM virtual machine software.
What is KVM?
KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. KVM also requires a modified QEMU although work is underway to get the required changes upstream.
Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.
The kernel component of KVM is included in mainline Linux, as of 2.6.20.
KVM is open source software.
My Test Machine
I will be using an Intel machine with a HDD of 320GB and 4GB RAM. I am currently running Ubuntu 9.04, but the installation will be similar in all Debian based system.
How to get started?
Step 1: Let us first install QEMU and KVM using apt-get.
$sudo apt-get install qemu $sudo apt-get install kvm
Steps to create the image of deepOfix using an iso
Step 2: Let us create a virtual drive where deepOfix will be installed. This drive, usually called the image is where the deepOfix will be installed and in future you can always run this image using KVM in any system to have a installed deepOfix running in no time.
$sudo qemu-img create deepOfix.img -f qcow 5G
The first bit is self explanatory, create an image (virtual drive) named deepOfix.img. The next bit ”-f qcow” tells it to format it in an inflatable structure. The 5G means a maximum physical size of 5 gig real hard drive space. The nice thing about this format is, if your VM installed only takes up 2.5 gig, then the virtual drive only takes up 2.5 gig of space on your real hard drive.
Step 3: Let us now install DeepOfix using the iso of deepOfix.
$sudo kvm -cdrom /path/to/deepofix-iso -hda deepOfix.img -m 512 -boot d
First this calls kvm and tells it that the .iso image is actually a CD-drive, then the ”-hda deepOfix.img” is its hard drive. The ”-m 512” tells it that its a computer with 512 Mb of memory. Careful here because this is the amount of physical memory that its going to block out for itself. Rule of thumb is no more than 1/2 of your actual physical memory. The final bit is -boot d, it tells it to boot from the cdrom drive.
Please note here that you can also install deepOfix in the above step directly using the CD. Only a small change has to be made in the above command.
$sudo kvm -cdrom /dev/cdrom -hda deepOfix.img -m 512 -boot d
In the above command, you are pointing the KVM to directly use the real CD drive.
Step 4: If the above command was executed successfully, a new window is opened and an installtion screen for deepOfix is shown. Please go through the installtion page to install deepOfix. Steps for installation of deepOfix does not change if you are installing in a virtual machine. The installation should take upto 15-30 mins depending on your system configuration.
Creating bridge network
Step 5: Before we can start the installed system, we need to set our network settings such that a bridge is created between our host OS and deepOfix OS so that deepOfix OS can be connected with your local LAN. First let us create a tap0 interface.
$sudo ifconfig tap0 <GATEWAY-ADDRESS>
tap0 is the virtual ethernet network device. <GATEWAY ADDRESS> is the gateway address entered while installing deepOfix OS.
This step can be avoided if you use kvm-ifup file.
Step 5a: Create a file named “kvm-ifup” in /etc/ .
$sudo touch /etc/kvm-ifup
Step 5b: Enter the following contents in it.
$sudo cat >>/etc/kvm-ifup <<END >#!/bin/sh >sudo -p "Password for $0:" /sbin/ifconfig $1 <GATEWAY ADDRESS> >END
Step 5c: Make the kvm-ifup file executable
$sudo chmod +x /etc/kvm-ifup
Hence this will ensure that everytime KVM is started, the tap0 interface is also started.
Step 6: Enable packet forwarding.
$sudo echo 1 > /proc/sys/net/ipv4/ip_forward
Step 7:
$sudo iptables -t nat -I POSTROUTING -o eth0 -j SNAT --to-source <IP-ADDRESS>
<IP-ADDRESS> is the ip-address of the host OS.
Back-up of the image
Step 8: This is important because whenever a virtual machine running is stopped abnormally, there is a good chance of the image getting corrupted. Hence it is better to have a back-up of the image so that you dont have to create an image again.
$cp deepOfix.img deepOfix_backup.img
Starting a installed image
Step 9: Once the installation is over, you can start the installed system using the following command.
$sudo kvm -hda deepOfix.img -net nic -net tap -m 512
Here we start the virtual system using KVM. The first argument ”-hda deepofix.img” tell which image to use to start the virtual system. ”-net nic” creates a new network interface card in the virtual system and connects it to VLAN. We can also provide different attributes for the ethernet device like MAC address, model, name for the ethernet device. ”-net tap” connects the host TAP network interface to VLAN. Hence making both the host OS and deepOfix OS on the same VLAN. ”-m 512” assigns the virtual machine to use 512 Mb of your system's RAM.
Step 10: Once the system is booted up, one of the first thing to do is make the firewall of the system to except all connections allowing you to freely test the system.
$/var/firewall/firewall-accept-all
This should give you a complete working deepOfix virtual machine running in your system.
FAQ:
1) tap0 is not working? or Getting the following error: “SIOCSIFADDR: No such device, tap0: ERROR while getting interface flags: No such device” ?
ANShttp://ubuntuforums.org/showthread.php?t=12088
2) ”/etc/kvm-ifup: could not launch network script” ?
ANS You have not either created the kvm-ifup file or have not given it executable permissions. Please follow Step 5a to resolve this error.
3) My virtual machine's image got corrupted. I have the backup image but is there anyway to get back the data I have in the corrupted image.
ANS You can mount the the corrupted image once you have started the backup image using kvm. But you need to make sure that you have added the image as a secondary drive.
$kvm -hda deepOfix_backup.img -hdb deepOfix.img -net nic -net tap -m 512
Here we are specifying the primary drive as deepOfix_backup.img and secondary drive as deepOfix.img. After you have booted up, you can mount the secondary drive and get the data from it.
4) “Could not initialize SDL – exiting” ?
ANS Your system does not support SDL. Normally, QEMU uses SDL to display the VGA output. This can be altered by using ”-curses” option in KVM. With this option, QEMU can display the VGA output when in text mode using a curses/ncurses interface. Nothing is displayed in graphical mode.
Note: Please go through man pages of KVM and QEMU to know more features of KVM and QEMU.