Originally the first to achieve KVM on Gentoo, and then play On Debian: http://blog.csdn.net/cenziboy/article/details/6957890
Later, I thought it was necessary to sum up the summary. It was just a review, so this article appeared.
1. Preparations before installation
1. KVM requires hardware support and enables CPU Virtualization in BIOS
2. Configure the kernel
KVM Module
[*] Virtualization alization ---> --- virtualization alization <m> kernel-based Virtual Machine (KVM) Support <m> KVM for Intel processors support # I am an Intel CPU <> KVM for AMD processors support
3. tun/TAP module, used for bridging Networks
Device Drivers ---> [*] Network device support ---> <M> Universal TUN/TAP device driver supportNetworking support ---> Networking options ---> <*> 802.1d Ethernet Bridging <*> 802.1Q VLAN Support
4. Semi-virtualization (optional, based on your needs)
Processor type and features ---> [*] Paravirtualized guest support ---> [*] KVM paravirtualized clock [*] KVM Guest support -*- Enable paravirtualization code [*] Paravirtualization layer for spinlocks
Compile and install the kernel (module)
# make# make install# make modules_install
Install qemu
KVM is a kernel module and cannot be directly used by users. Here we will use qemu (also called the KVM prefix) to use KVM
1. First check qemu-KVM:
# emerge -pv qemu-kvmThese are the packages that would be merged, in order:Calculating dependencies... done![ebuild R ] app-emulation/qemu-kvm-0.15.1-r1 USE="aio alsa jpeg ncurses png pulseaudio sdl ssl vhost-net -bluetooth -brltty -curl -debug (-esd) -fdt -hardened -nss -qemu-ifup (-rbd) -sasl -spice -threads -vde -xattr -xen" QEMU_SOFTMMU_TARGETS="x86_64 -arm -cris -i386 -m68k -microblaze -mips -mips64 -mips64el -mipsel -ppc -ppc64 -ppcemb -sh4 -sh4eb -sparc -sparc64" QEMU_USER_TARGETS="-alpha -arm -armeb -cris -i386 -m68k -microblaze -mips -mipsel -ppc -ppc64 -ppc64abi32 -sh4 -sh4eb -sparc -sparc32plus -sparc64 -x86_64" 0 kBTotal: 1 package (1 reinstall), Size of downloads: 0 kB
Of course, I have installed [ebuild R] on my system.
2. Then, change the use, qemu_softmmu, and qemu_user_targets variables (compare the parameters and results twice ):
# USE="-jpeg -png" QEMU_SOFTMMU="i386" QEMU_USER_TARGETS="i386 x86_64" emerge -pv qemu-kvmThese are the packages that would be merged, in order:Calculating dependencies... done![ebuild R ] app-emulation/qemu-kvm-0.15.1-r1 USE="aio alsa ncurses pulseaudio sdl ssl vhost-net -bluetooth -brltty -curl -debug (-esd) -fdt -hardened -jpeg* -nss -png* -qemu-ifup (-rbd) -sasl -spice -threads -vde -xattr -xen" QEMU_SOFTMMU_TARGETS="x86_64 -arm -cris -i386 -m68k -microblaze -mips -mips64 -mips64el -mipsel -ppc -ppc64 -ppcemb -sh4 -sh4eb -sparc -sparc64" QEMU_USER_TARGETS="i386* x86_64* -alpha -arm -armeb -cris -m68k -microblaze -mips -mipsel -ppc -ppc64 -ppc64abi32 -sh4 -sh4eb -sparc -sparc32plus -sparc64" 0 kBTotal: 1 package (1 reinstall), Size of downloads: 0 kB
3. Of course, you can install the-PV after emerge. As shown in the following figure (use, qemu_softmmu, and qemu_user_targets are modified as needed ):
# emerge qemu-kvm
Start 3
1. To allow common users to use KVM, add users to the KVM User Group
# Gpasswd-A <User Name> KVM
2. Create a Virtual Disk
qemu-img create -f qcow2 gentoo.img 10G
4. Bridging Network
Because the network is required to install certain systems (Gentoo), you must configure the network first.
1. edit/etc/CONF. d/net (here only the static IP method is provided, and others have not been done)
# Config_eth0 = "10.65.10.80/16" # comment out the previous network interface eth0 # routes_eth0 = "Default via 10.65.0000254" # comment out the previous gateway config_eth0 = "null" Authorization = "eth0" config_br0 = "10.65.10.80/16" # original eth0 address brctl_br0 = "setfd 0 sethello 30 STP off" routes_br0 = "Default via 10.65.255.254"
2. Install the bridge network tool:
Net-MISC/Bridge-utils: Use the brctl command.
Sys-apps/usermode-utilities: tunctl command to use
# emerge bridge-utils# emerge usermode-utilities
3. Create br0 and set startup.
# Cd/etc/init. d # ln-s net. Lo net. br0 # RC-update add net. br0 default # RC-update del net. eth0 # Remove eth0 boot
4. Restart the network
# rc-service net.br0 restart
Check whether the Network is available, as shown in. Otherwise, the problem may occur.
# ifconfigbr0 Link encap:Ethernet HWaddr 18:03:73:af:66:99 inet addr:10.65.10.80 Bcast:10.65.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:137 errors:0 dropped:44 overruns:0 frame:0 TX packets:53 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:17364 (16.9 KiB) TX bytes:6562 (6.4 KiB)eth0 Link encap:Ethernet HWaddr 18:03:73:af:66:99 UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:41495 errors:0 dropped:0 overruns:0 frame:0 TX packets:13952 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:15108839 (14.4 MiB) TX bytes:2736817 (2.6 MiB) Interrupt:20 Memory:7ea00000-7ea20000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:312 (312.0 B) TX bytes:312 (312.0 B)
5. Configure the bridging Network
# Modprobe Tun
# Tunctl-u <User Name> # create a virtual network card (tapx stands for numbers 0, 1, 2…) for a user (-u parameter is optional... This document uses tap0)
# Brctl addif br0 tap0 # Add the tapx created in the previous step to the bridge br0
# Ifconfig tap0 promisc up # enable tapx and set it to promisc Mode
My execution result is as follows (nehc is the user name ):
nehc ~ # tunctl -u nehcSet 'tap0' persistent and owned by uid 1000nehc ~ # brctl addif br0 tap0nehc ~ # ifconfig tap0 promisc upnehc ~ # ifconfigbr0 Link encap:Ethernet HWaddr 18:03:73:af:66:99 inet addr:10.65.10.80 Bcast:10.65.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1295 errors:0 dropped:400 overruns:0 frame:0 TX packets:156 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:165002 (161.1 KiB) TX bytes:85908 (83.8 KiB)eth0 Link encap:Ethernet HWaddr 18:03:73:af:66:99 UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:42725 errors:0 dropped:0 overruns:0 frame:0 TX packets:14055 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:15291865 (14.5 MiB) TX bytes:2816677 (2.6 MiB) Interrupt:20 Memory:7ea00000-7ea20000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:312 (312.0 B) TX bytes:312 (312.0 B)tap0 Link encap:Ethernet HWaddr 62:65:15:b5:ad:25 UP BROADCAST PROMISC MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
5. Install Guest OS
1. Load the KVM Module
# modprobe kvm_intel
2. Install the system
$ kvm -net nic,macaddr=00:00:00:00:00:00 -net tap,ifname=tap0,script=no,downscript=no -hda gentoo.img -cdrom gentoo_amd64.iso -m 512 -boot d
6. Start the system
The system has been installed, and there is no need to provide so many parameters as in the previous step.
$ kvm -net nic,macaddr=00:00:00:00:00:00 -net tap,ifname=tap0,script=no,downscript=no gentoo.img
In addition, a method for running a virtual machine in the background is provided:
$ kvm -net nic,macaddr=00:00:00:00:00:00 -net tap,ifname=tap0,script=no,downscript=no gentoo.img -vnc 0.0.0.0:0 -daemonize
After the startup, the guest OS runs in the background, and the host OS does not have the guest OS window popped up. It is suitable for running in a system without a graphical interface (this should be the case for servers ).
Although the-VNC parameter is provided here, but the guest OS does not install VNC, I am still used to using SSH remote connection.
My execution results:
Nehc @ nehc ~ /VMS/ELS $ uname-A # Host OS information Linux nehc 3.2.1-gentoo-r2 #2 SMP Tue Mar 13 20:08:39 CST 2012 x86_64 Intel (r) core (TM) i3-2100 CPU @ 3.10 GHz genuineintel GNU/linuxnehc @ nehc ~ /VMS/ELS $ KVM-net Nic, macaddr = 00: 00: 00: 00: 00: 00-net tap, ifname = tap0, script = No, downscript = No els. vmdk-VNC 0.0.0.0: 0-daemonize # Start Guest OS and run nehc @ nehc ~ in the background ~ /VMS/ELS $ SSH root@10.65.30.38 # SSH connection to the virtual machine running in the background password: Last login: Thu Mar 15 11:27:41 CST 2012 from 10.65.10.80 on pts/0xut ~ # Uname-A # virtual machine information Linux xut 3.2.1-gentoo-r2 #1 wed Mar 14 10:08:14 CST 2012 i686 qemu virtual CPU version 0.15.1 genuineintel GNU/linuxxut ~ # Halt # disable the VM broadcast message from root @ xut (pts/0) (Thu Mar 15 11:31:48 2012): The system is going down for system halt now! Xut ~ #
Figure:
Seven No
Reference: http://en.gentoo-wiki.com/wiki/KVM