Table of Contents

Back to igraltist's experiences/KVM on RSBAC

Howto setup a kvm user on gentoo

Software packages

The listed software packages are required:

Other packages should be installed on default installation.

Create an user kvm

Using `RSBAC` User Managmant (UM)
$rsbac_group add kvm
$rsbac_user add -g kvm -c 'User to run kvm-guests' -s /bin/sh   kvm
Using linux pam
#adduser -U  -m -c "kvm user" kvm
Fix for LVM

Fixme: Wrapper for kvm-disk-user

Only if you using LVM as guest harddrives.

$rsbac_usermod -G disk kvm
#gpasswd -a kvm disk

grep block.*disk.*MODE /etc/udev/rules.d/*

* if it empty create a file

touch /etc/udev/rules.d/70-kvm-rules

* now change insert the follow udev rule, because the diskgroup need read and write access on the device

SUBSYSTEM=="block", GROUP="disk", MODE="0660"

Udev Modification

Now modify the udev 70-kvm.rules, that while booting all will be done automatic.

Note: In Udev rules there was a changing. Now the parameter NAME is not valid anymore. As example i have this file now under /etc/udev/rules.d

KERNEL=="tun", MODE="0660", GROUP="kvm", OPTIONS+="ignore_remove"
KERNEL=="kvm", MODE="0660", GROUP="kvm"

Create directories

#mkdir /var/run/kvm
#chown kvm:kvm /var/run/kvm/
#chmod 750 /var/run/kvm


When using files as guest harddrives.

For example:

#mkdir /var/lib/kvm 
#chmod 770 /var/lib/kvm
#chgrp kvm /var/lib/kvm
su - kvm -c "qemu-img create /var/lib/kvm/test.img 1MB" 
Formatting '/var/lib/kvm/tester.img', fmt=raw size=1048576 
ls -la /var/lib/kvm/
insgesamt 8
drwxrwx---  2 root kvm     4096 10. Nov 15:27 .
drwxr-xr-x 22 root root    4096 10. Nov 15:25 ..
-rw-r--r--  1 kvm  kvm  1048576 10. Nov 15:27 test.img

Network

This site will describe on some example howto setup the Network.

kvm-admin

I use my own scripts to manage the kvm guest's.

It can be found here http://hg.kasten-edv.de/kvm-tools/

Example configuration

All guest configuration files located in '/etc/kvm/domains/'.

############################
# sample option for a disk #
############################
drive = file=/dev/mapper/VG-example,if=virtio,index=0,media=disk,boot=off,cache=none
# sample option for a cdrom, can also be a second disk
drive = file=/path/to/my_cd_img.iso,if=virtio,index=1,media=cdrom,boot=on
 
########################
# settings for network #
########################
net = nic
# use tap device for briding
net = tap,bridge=br0
 
############################################################################
# use monitor option other the default unix socket or override the default #
############################################################################
# example for overridding the default
# monitor = unix,path_to_your_own_socketfile,server,nowait
# use tcp socket, every guest have to use a different port
monitor = tcp,localhost,4444,server,nowait

Test example config

Befor start check the Network.

kvm-admin example show
This string would executed:
/usr/bin/kvm -uuid 0bcd5138-41bf-a5c0-0627-4e0b65d3871f -monitor tcp,localhost,4444,server,nowait -rtc clock=host,base=utc -runas kvm -M pc -drive file=/dev/mapper/VG-example,if=virtio,index=0,media=disk,boot=off,cache=none -drive file=/path/to/my_cd_img.iso,if=virtio,index=1,media=cdrom,boot=on -daemonize -net nic -net tap,ifname=example,script=/etc/kvm/scripts/kvm-ifup,downscript=/etc/kvm/scripts/kvm-ifdown -cpu core2duo -pidfile /var/run/kvm/example.pid -name example,process=example

Top