KVM: Difference between revisions

From Q
Jump to navigation Jump to search
Tgurr (talk | contribs)
No edit summary
Tgurr (talk | contribs)
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Description ==
== Description ==
Setting up the Kernel-based Virtual Machine including network configuration and beeing able to create and run new machines as a normal user without requiring root privileges.
Setting up the Kernel-based Virtual Machine including network configuration and being able to create and run new machines as a normal user without requiring root privileges.


== Packages ==
== Packages ==
{{Box Code|emerge kvm -pv|
{{Code|cave resolve qemu-kvm|
<pre>
<pre>
[ebuild  N   ] net-misc/vde-2.2.2  461 kB
* media-libs/libsndfile [N 1.0.20]
[ebuild  N    ] media-sound/alsa-headers-1.0.19  2,829 kB
    Reasons: *net-wireless/bluez-4.39-r2:0::gentoo
[ebuild  N   ] media-libs/alsa-lib-1.0.19  USE="midi python -alisp -debug -doc" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" 775 kB
    alsa -jack -minimal -sqlite build_options: -optional_tests -split strip -trace
[ebuild  N   ] app-text/texi2html-1.78  443 kB
    "A C library for reading and writing files containing sampled sound"
[ebuild  N    ] app-emulation/kvm-kmod-85  296 kB
    905.69 kBytes to download
[ebuild  N    ] media-libs/libsdl-1.2.13-r1  USE="X alsa audio joystick opengl video xinerama xv -aalib -arts -custom-cflags -dga -directfb -esd -fbcon -ggi -libcaca -nas -oss -pulseaudio (-svga)" 3,295 kB
* dev-libs/libnl [N 1.1-r2]
[ebuild  N   ] app-emulation/kvm-85-r1  USE="alsa modules ncurses sdl vde -esd -gnutls -havekernel -pulseaudio -test" 4,192 kB
    Reasons: *net-wireless/bluez-4.39-r2:0::gentoo
    build_options: -optional_tests -split strip -trace
    "A library for applications dealing with netlink socket"
    282.16 kBytes to download
* net-wireless/bluez [N 4.39-r2]
    Reasons: *app-emulation/qemu-kvm-0.11.0:0::gentoo
    alsa consolekit cups -debug -doc -gstreamer -old-daemons -test-programs usb build_options: -optional_tests -split strip -trace
    "Bluetooth Tools and System Daemons for Linux"
    974.81 kBytes to download
* media-libs/libsdl [N 1.2.14]
    Reasons: *app-emulation/qemu-kvm-0.11.0:0::gentoo
    X -aalib alsa audio -custom-cflags -dga -directfb -fbcon -ggi joystick -libcaca -nas opengl -oss (-ps3) -pulseaudio (-svga) -tslib video -xinerama xv build_options: -optional_tests -split strip -trace
    "Simple Direct Media Layer"
* net-misc/vde [N 2.2.3]
    Reasons: *app-emulation/qemu-kvm-0.11.0:0::gentoo
    -pcap ssl build_options: -optional_tests -split strip -trace
    "vde2 is a virtual distributed ethernet emulator for emulators like qemu, bochs, and uml."
    511.71 kBytes to download
* app-text/texi2html [N 1.78]
    Reasons: *app-emulation/qemu-kvm-0.11.0:0::gentoo
    build_options: -optional_tests -split strip -trace
    "Perl script that converts Texinfo to HTML"
    442.60 kBytes to download
* app-emulation/qemu-kvm [N 0.11.0] <target>
    alsa bluetooth -esd -gnutls ncurses -pulseaudio -sasl sdl vde QEMU_SOFTMMU_TARGETS: -arm -cris i386 -m68k -mips -mips64 -mips64el -mipsel -ppc -ppc64 -ppcemb -sh4 -sh4eb -sparc x86_64 QEMU_USER_TARGETS: -alpha -arm -armeb -cris i386 -m68k -mips -mips64 -mips64el -mipsel -ppc -ppc64 -ppc64abi32 -sh4 -sh4eb -sparc -sparc32plus -sparc64 x86_64 build_options: -split strip -trace
    "QEMU + Kernel-based Virtual Machine userland tools"
    4.18 MBytes to download
</pre>
}}
 
{{Code|cave resolve iptables bridge-utils usermode-utilities|
<pre>
* net-firewall/iptables [N 1.4.5] <target>
    ipv6 build_options: -optional_tests -split strip -trace
    "Linux kernel (2.4+) firewall, NAT and packet mangling tools"
    450.66 kBytes to download
* net-misc/bridge-utils [N 1.4] <target>
    build_options: -optional_tests -split strip -trace
    "Tools for configuring the Linux kernel 802.1d Ethernet Bridge"
    31.89 kBytes to download
* sys-fs/fuse [N 2.8.1]
    Reasons: *sys-apps/usermode-utilities-20070815:0::gentoo
    build_options: -optional_tests -split strip -trace
    "An interface for filesystems implemented in userspace."
    481.32 kBytes to download
* sys-apps/usermode-utilities [N 20070815] <target>
    build_options: -optional_tests -split strip -trace
    "Tools for use with Usermode Linux virtual machines"
    48.98 kBytes to download
</pre>
</pre>
}}
}}


== USE-Flags ==
== USE-Flags ==
{{Box File|/etc/portage/package.use|
{{File|/etc/paludis/use.conf|
<pre>
<pre>
app-emulation/kvm -esd vde
*/* QEMU_SOFTMMU_TARGETS: -* i386 x86_64
*/* QEMU_USER_TARGETS: -* i386 x86_64
app-emulation/qemu-kvm vde
</pre>
</pre>
}}
}}


== Installation ==
== Installation ==
{{Root|# emerge kvm}}
{{Root|cave resolve qemu-kvm}}


== Kernel Configuration ==
== Kernel Configuration ==
{{Box Kernel|
Please see: [[Kernel#KVM_host|KVM Kernel Configuration for a KVM Host]]
<pre>
Networking  support --->
  Networking options  --->
    [*] 802.1d Ethernet Bridging
Device Drivers  --->
  [*] Network device support  --->
    <*>  Universal TUN/TAP device driver support
 
Enable once kvm is fixed for VT-D-Support:
 
Bus options (PCI etc.)  --->
  [ ] Support for DMA Remapping Devices (EXPERIMENTAL)
</pre>
}}


== Network configuration ==
== Network configuration ==
{{Box File|/etc/conf.d/net|
{{File|/etc/conf.d/net|
<pre>
<pre>
config_eth0=( "null" )
config_eth0=( "null" )
Line 59: Line 95:
}}
}}


{{Root|# /etc/init.d/}}
{{Root|/etc/init.d/}}
 
{{Root|ln -s net.lo net.br0}}
 
{{Root|ln -s net.lo net.tap0}}
 
{{Root|rc-update add net.br0 default}}
 
{{Root|rc-update add net.tap0 default}}
 
{{File|/etc/conf.d/vde|
<pre>
VDE_MODPROBE_TUN="no"
</pre>
}}
 
{{Root|rc-update add vde default}}
 
 
== Add existing user to the necessary groups ==
 
{{Root|usermod -a -G kvm,qemu username}}
 
== Usage ==
=== Generate random MAC adresses ===
{{Command|<nowiki>echo -n DE:AD:BE:EF ; for i in `seq 1 2` ; do echo -n `echo ":$RANDOM$RANDOM" | cut -n -c -3` ;done</nowiki>}}
 
 
You can always setup new machines in your home directory, but here we assume we have a separate mount-point/partition which we mount at /mnt/kvm.
 
 
{{Root|mkdir -p /mnt/kvm}}
 
 
{{File|/etc/fstab|
<pre>
/dev/sda4              /mnt/kvm        ext4            defaults,auto,user 0 1
</pre>
}}
 
 
{{Root|chown -R root:kvm /mnt/kvm}}
 
{{Root|chmod -R g+w /mnt/kvm}}
 
{{Command|qemu-img create -f qcow2 /mnt/kvm/linux-test.img 15G}}


{{Root|# ln -s net.lo net.br0}}
{{Command|<nowiki>vdeq qemu /mnt/kvm/linux-test.img -cdrom /dev/cdrom -soundhw es1370 -usb -m 1024 -k de -smp 1 -vga std -localtime -net nic,vlan=0,macaddr=DE:AD:BE:FF:15:33 -net vde,vlan=0,sock=/var/run/vde.ctl</nowiki>}}


{{Root|# ln -s net.lo net.tap0}}


{{Root|# rc-update add net.br0 default}}
{{Command|qemu-img create -f qcow2 /mnt/kvm/windows-test.img 15G}}


{{Root|# rc-update add net.tap0 default}}
{{Command|<nowiki>vdeq qemu /mnt/kvm/windows-test.img -cdrom /dev/cdrom -soundhw es1370 -usb -m 1024 -k de -smp 1 -vga std -localtime -net nic,vlan=0,macaddr=DE:AD:BE:EF:14:32 -net vde,vlan=0,sock=/var/run/vde.ctl</nowiki>}}


Once done installing and after enabling the remote desktop access in Windows you can add the -nographic switch and start the kvm machine via a login script for example.


== Setup user permissions ==
{{Command|<nowiki>vdeq qemu /mnt/kvm/windows-test.img -nographic -soundhw es1370 -usb -m 1024 -k de -smp 1 -vga std -localtime -net nic,vlan=0,macaddr=DE:AD:BE:EF:14:32 -net vde,vlan=0,sock=/var/run/vde.ctl</nowiki>}}


{{Root|# usermod -a -G kvm,qemu username}}
You really want to use an RDP session to connect to your Windows Boxes since the mouse movement is horrible slow and laggy when using the SDL client.

Latest revision as of 13:40, 6 July 2012

Description

Setting up the Kernel-based Virtual Machine including network configuration and being able to create and run new machines as a normal user without requiring root privileges.

Packages

Code: cave resolve qemu-kvm
* media-libs/libsndfile [N 1.0.20]
    Reasons: *net-wireless/bluez-4.39-r2:0::gentoo
    alsa -jack -minimal -sqlite build_options: -optional_tests -split strip -trace
    "A C library for reading and writing files containing sampled sound"
    905.69 kBytes to download
* dev-libs/libnl [N 1.1-r2]
    Reasons: *net-wireless/bluez-4.39-r2:0::gentoo
    build_options: -optional_tests -split strip -trace
    "A library for applications dealing with netlink socket"
    282.16 kBytes to download
* net-wireless/bluez [N 4.39-r2]
    Reasons: *app-emulation/qemu-kvm-0.11.0:0::gentoo
    alsa consolekit cups -debug -doc -gstreamer -old-daemons -test-programs usb build_options: -optional_tests -split strip -trace
    "Bluetooth Tools and System Daemons for Linux"
    974.81 kBytes to download
* media-libs/libsdl [N 1.2.14]
    Reasons: *app-emulation/qemu-kvm-0.11.0:0::gentoo
    X -aalib alsa audio -custom-cflags -dga -directfb -fbcon -ggi joystick -libcaca -nas opengl -oss (-ps3) -pulseaudio (-svga) -tslib video -xinerama xv build_options: -optional_tests -split strip -trace
    "Simple Direct Media Layer"
* net-misc/vde [N 2.2.3]
    Reasons: *app-emulation/qemu-kvm-0.11.0:0::gentoo
    -pcap ssl build_options: -optional_tests -split strip -trace
    "vde2 is a virtual distributed ethernet emulator for emulators like qemu, bochs, and uml."
    511.71 kBytes to download
* app-text/texi2html [N 1.78]
    Reasons: *app-emulation/qemu-kvm-0.11.0:0::gentoo
    build_options: -optional_tests -split strip -trace
    "Perl script that converts Texinfo to HTML"
    442.60 kBytes to download
* app-emulation/qemu-kvm [N 0.11.0] <target>
    alsa bluetooth -esd -gnutls ncurses -pulseaudio -sasl sdl vde QEMU_SOFTMMU_TARGETS: -arm -cris i386 -m68k -mips -mips64 -mips64el -mipsel -ppc -ppc64 -ppcemb -sh4 -sh4eb -sparc x86_64 QEMU_USER_TARGETS: -alpha -arm -armeb -cris i386 -m68k -mips -mips64 -mips64el -mipsel -ppc -ppc64 -ppc64abi32 -sh4 -sh4eb -sparc -sparc32plus -sparc64 x86_64 build_options: -split strip -trace
    "QEMU + Kernel-based Virtual Machine userland tools"
    4.18 MBytes to download
Code: cave resolve iptables bridge-utils usermode-utilities
* net-firewall/iptables [N 1.4.5] <target>
    ipv6 build_options: -optional_tests -split strip -trace
    "Linux kernel (2.4+) firewall, NAT and packet mangling tools"
    450.66 kBytes to download
* net-misc/bridge-utils [N 1.4] <target>
    build_options: -optional_tests -split strip -trace
    "Tools for configuring the Linux kernel 802.1d Ethernet Bridge"
    31.89 kBytes to download
* sys-fs/fuse [N 2.8.1]
    Reasons: *sys-apps/usermode-utilities-20070815:0::gentoo
    build_options: -optional_tests -split strip -trace
    "An interface for filesystems implemented in userspace."
    481.32 kBytes to download
* sys-apps/usermode-utilities [N 20070815] <target>
    build_options: -optional_tests -split strip -trace
    "Tools for use with Usermode Linux virtual machines"
    48.98 kBytes to download

USE-Flags

File: /etc/paludis/use.conf
*/* QEMU_SOFTMMU_TARGETS: -* i386 x86_64
*/* QEMU_USER_TARGETS: -* i386 x86_64
app-emulation/qemu-kvm vde

Installation

# cave resolve qemu-kvm

Kernel Configuration

Please see: KVM Kernel Configuration for a KVM Host

Network configuration

File: /etc/conf.d/net
config_eth0=( "null" )

tuntap_tap0="tap"
config_tap0=( "null" )

brctl_br0=( "setfd 9" "sethello 2" "setmaxage 12" "stp off" )
config_br0=( "192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255" )
routes_br0=( "default via 192.168.0.1" )

bridge_add_eth0="br0"
bridge_add_tap0="br0"
# /etc/init.d/
# ln -s net.lo net.br0
# ln -s net.lo net.tap0
# rc-update add net.br0 default
# rc-update add net.tap0 default
File: /etc/conf.d/vde
VDE_MODPROBE_TUN="no"
# rc-update add vde default


Add existing user to the necessary groups

# usermod -a -G kvm,qemu username

Usage

Generate random MAC adresses

$ echo -n DE:AD:BE:EF ; for i in `seq 1 2` ; do echo -n `echo ":$RANDOM$RANDOM" | cut -n -c -3` ;done


You can always setup new machines in your home directory, but here we assume we have a separate mount-point/partition which we mount at /mnt/kvm.


# mkdir -p /mnt/kvm


File: /etc/fstab
/dev/sda4               /mnt/kvm        ext4            defaults,auto,user 0 1


# chown -R root:kvm /mnt/kvm
# chmod -R g+w /mnt/kvm
$ qemu-img create -f qcow2 /mnt/kvm/linux-test.img 15G
$ vdeq qemu /mnt/kvm/linux-test.img -cdrom /dev/cdrom -soundhw es1370 -usb -m 1024 -k de -smp 1 -vga std -localtime -net nic,vlan=0,macaddr=DE:AD:BE:FF:15:33 -net vde,vlan=0,sock=/var/run/vde.ctl


$ qemu-img create -f qcow2 /mnt/kvm/windows-test.img 15G
$ vdeq qemu /mnt/kvm/windows-test.img -cdrom /dev/cdrom -soundhw es1370 -usb -m 1024 -k de -smp 1 -vga std -localtime -net nic,vlan=0,macaddr=DE:AD:BE:EF:14:32 -net vde,vlan=0,sock=/var/run/vde.ctl

Once done installing and after enabling the remote desktop access in Windows you can add the -nographic switch and start the kvm machine via a login script for example.

$ vdeq qemu /mnt/kvm/windows-test.img -nographic -soundhw es1370 -usb -m 1024 -k de -smp 1 -vga std -localtime -net nic,vlan=0,macaddr=DE:AD:BE:EF:14:32 -net vde,vlan=0,sock=/var/run/vde.ctl

You really want to use an RDP session to connect to your Windows Boxes since the mouse movement is horrible slow and laggy when using the SDL client.