Skip to content
OGAWAHirofumi edited this page Feb 5, 2013 · 4 revisions

KVM setup

Get distribution installer

You can download debian(testing) from

http://www.debian.org/devel/debian-installer/

Create the disk image

kvm has the command to create the disk image. This example creates 8GB disk image with qcow2 format. (qcow2 is supporting snapshot and copy-on-write)

$ qemu-img create -f qcow2 hdd.img 8G

Install distribution

Use dhcp to get IP in guest OS. By default (-net user) configuration, it provides dhcp server and firewall like NAT server by parsing packet and redirect to socket in userland. So, you can just use dhcp on installation process, and you don't need additional network configuration on host side.

$ kvm -boot once=d -cdrom debian-wheezy-DI-a1-amd64-netinst.iso -hda hdd.img

Create the disk image for tux3

This creates tux3 disk image with raw format. The raw format is simply regular file, so it would be easy to use/debug from host side.

$ qemu-img create -f raw tux3.img 8G
$ ../tux3/usr/tux3 mkfs -b 512 tux3.img

Boot tux3 kernel

kvm can boot "bzImage" directly by "-kernel", and can pass boot parameter by "-append".

$ kvm -kernel linux-3.6/arch/x86/boot/bzImage -append "root=/dev/sda1 ro" -hda hdd.img -hdb tux3.img

Now you should be able to mount tux3 on kvm.

$ tux3 mkfs /dev/sdb
$ mount -t tux3 /dev/sdb /mnt

KVM Tips

Some useful kvm options,

  • -snapshot
    use temporary file, instead of modifying the original disk image
  • -serial dev
    create serial device (file: is to write output to file)

With -serial and serial console, you can log the kernel output to host side file.

Clone this wiki locally