Running Virtual Machines on KVM and QEMU from command line on Ubuntu 14.04
The aim of this post is to document how to get a Lubuntu 14.04 instance, a Windows 7 instance and an Android-86 instance running on KVM (running on QEMU in most cases).
[NB: This is not yet complete, so it may serve only as pointers and not a full guide…]
Install the prerequisites:
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
Check if Virtualization is supported on your machine (or virtual machine, if you’re trying to nest VMs) using the kvm-ok command
Method 1: Using the libvirt library / package / set of tools:
NB: I used this to get the lubuntu instance running
sudo apt-get install virtinst
sudo virt-install -n testLubuntu -r 512 \ --disk path=/home/USERNAME/Desktop/VMDisks/testLubuntu.img,bus=virtio,size=6 -c \ lubuntu-14.04.iso --network network=default,model=virtio \ --graphics vnc,listen=0.0.0.0 --noautoconsole -v
Check which VMs are running:
virsh -c qemu:///system list
Stop an instance:
virsh -c qemu:///system shutdown
NB: Replace the with the name of the instance, e.g. in my case “testLubuntu”
Start an instance:
virsh -c qemu:///system start
Destroy and undefine an instance:
virsh -c qemu:///system destroy
virsh -c qemu:///system undefine
Method 2: Using the kvm package directly:
NB: I used this to get the Android-x86 instance running … but without a WiFI network (as of now…)
Create a virtual disk image file
qemu-img create android-4.4.img 8G
Install the Android OS using a virtualized CD-Rom that points to a bootable Android image:
kvm -m 2048 -hda android-4.4.img -cdrom <Bootable-Android-ISO.iso> -boot d
Create a partition that is bootable and writable when the cfdisk prompts you to do so.
I haven’t been able to get the networking part right because it involves some bridging … which is a bit mind-boggling.
Resources:
-
KVM:
- https://help.ubuntu.com/community/KVM/Installation
- http://www.linux-kvm.org/page/Documents
- http://en.wikibooks.org/wiki/QEMU
- https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt
- https://help.ubuntu.com/14.04/serverguide/libvirt.html
- http://www.techotopia.com/index.php/Installing_a_KVM_Guest_OS_from_the_Command-line_(virt-install)
- http://spica-and-roid.blogspot.se/2012/07/howto-porting-android-x86-onto-qemu-kvm.html
- http://virt-tools.org/learning/install-with-command-line/
- http://en.wikipedia.org/wiki/Book:Virtualization
- https://shanetomlinson.com/2009/bridging-a-wireless-card-in-kvmqemu/
- http://blog.bodhizazen.net/linux/bridge-wireless-cards/
- http://www.linux-kvm.org/page/Networking
- http://unix.stackexchange.com/questions/118891/wireless-bridged-networking-in-kvm-why-is-it-so-complicated
- http://blog.alantan.com/2007/01/qemu-tap-bridge-network-configuration.html
Networking:
Conversion from KVM qcow2 (from proxmox) to Virtualbox VDI
Method 1:
Convert first from qcow2 to RAW using qemu-utils in an Ubuntu Linux machine
sudo apt-get install qemu-utils qemu-img convert -f qcow2 <qcow2_VM_filename> -O raw <RAW_file_VM_filename>
Convert from RAW to VDI using VBoxManage on any machine that has Virtualbox Installed
VBoxManage convertfromraw <RAW_file_VM_filename> <VDI_Output_file_VM_filename> \
--format vdi
The “\” is just a line-break because the command doesn’t fit in one line on this page
Method 2:
Use qemu-img directly in a Linux machine:
qemu-img convert -f qcow2 <qcow2_VM_filename> -O vdi <RAW_file_VM_filename>
NB: For some strange reason Method 1 worked once and failed the 2nd time, Method 2 was always successful. So i suggest using Method 2