Reprinted from
Http://forum.ubuntu.org.cn/viewtopic.php? F = 65 & t = 154792 & SID = 591087b7c7a8b9dcef3c39f297d78946
After studying KVM for a long time, I feel like I have used the fastest virtual machine. Compared with common virtual machines, VMWare has comprehensive functions and simple settings, but its speed is not very good. Although virtualbox is more efficient than VMWare, it has many disadvantages, it seems that the CPU is occupied during running. Now virtualbox supports SMP and virtualization technology, but the overall efficiency is not as high as KVM (but the graphic efficiency is good ); kernel-based Virtual Machine (KVM) is the fastest virtual machine I have ever used. It requires the CPU to support virtualization technology and enable virtualization options in the BIOS, the efficiency can reach 80% of the physical machine's
. Therefore, KVM is strongly recommended for sputation.
(Please note that the disk is updated !!!)
No nonsense. The following is a 64-bit Ubuntu 804.4 method.
Obtain KVM:
KVM Website: http://sourceforge.net/projects/kvm/files/
Download the latest qemu-kvm-0.12.4.tar.gz
Decompress:
-
Code:
Select All
-
tar -xzvf qemu-kvm-0.12.4.tar.gz
Required packages:
-
Code:
Select All
-
sudo apt-get install gcc libsdl1.2-dev zlib1g-dev libasound2-dev linux-kernel-headers pkg-config libgnutls-dev libpci1 pciutils-dev
In ubuntu 10.04, you can use
-
Code:
Select All
-
sudo apt-get build-dep qemu-kvm
To solve the dependency.
Three steps:
-
Code:
Select All
-
cd qemu-kvm-0.12.4
./configure --prefix=/usr/local/kvm
make
sudo make install
Load the KVM module after installation
-
Code:
Select All
-
Sudo modprobe KVM
Sudo modprobe KVM-Intel // if you are using an Intel processor, use this
Sudo modprobe KVM-AMD // if you are using an AMD processor, use this
In this way, it is installed.
The following describes how to configure the KVM bridging Network: \ pay special attention to the fact that most wireless network adapters cannot be bridges... Only PCI NICs can be Bridge ....
Install the bridge tool:
-
Code:
Select All
-
sudo apt-get install bridge-utils
Install the tool for creating the tap interface:
-
Code:
Select All
-
sudo apt-get install uml-utilities
Edit the network interface configuration file (
-
Code:
Select All
-
sudo vi /etc/network/interfaces
According to your situation, add the following content:
-
Code:
Select All
-
Auto eth0
Iface eth0 Inet ManualAuto tap0
Iface tap0 Inet Manual
Up ifconfig $ iface 0.0.0.0 up
Down ifconfig $ iface down
Tunctl_user lm \ lm is my user name. Here, replace it with your user name.
Auto br0
Iface br0 Inet static \ can also be allocated using DHCP.
Bridge_ports eth0 tap0
Address 192.168.1.3
Netmask 255.255.255.0
Gateway 192.168.1.1
Activate tap0 and br0: // sometimes it will not work, but it will work after restart.
-
Code:
Select All
-
sudo /sbin/ifup tap0
sudo /sbin/ifup br0
Now, you can check ifconfig. If you have an additional tap0 and br0, the IP address on br0 is the IP address of your local machine.
KVM usage:
For details about how to use KVM, refer
-
Code:
Select All
-
/usr/local/kvm/bin/qemu-system-x86_64 --help
The following are examples:
Create a virtual disk (use the qemu-IMG command ):
-
Code:
Select All
-
mkdir kvm
cd kvm
/usr/local/kvm/bin/qemu-img create -f qcow2 winxp.img 10G
Create a virtual machine:
-
Code:
Select All
-
sudo /usr/local/kvm/bin/qemu-system-x86_64 -m 512 -drive file=/home/lm/kvm/winxp.img,cache=writeback -localtime -net nic,vlan=0,macaddr=52-54-00-12-34-01 -net tap,vlan=0,ifname=tap0,script=no -boot d -cdrom /home/lm/iso/winxp.iso -smp 2 -soundhw es1370
The parameters are described as follows:
-
Code:
Select All
-
-m 512
Allocate MB of memory to guest OS
-
Code:
Select All
-
-drive file=/home/lm/kvm/winxp.img,cache=writeback
Use the file and path of the Virtual Disk and enable writeback cache.
-
Code:
Select All
-
-localtime
Use local time (this parameter must be added, or the VM time may be faulty)
-
Code:
Select All
-
-net nic,vlan=0,macaddr=52-54-00-12-34-01 -net tap,vlan=0,df=h,ifname=tapo,script=no
Use the network and connect to an existing network device, such as tap0. Note that you must compile your MAC address. If you have virtualized multiple systems and want to run them simultaneously, otherwise Mac conflicts, remove df = H in the KVM-87
-
Code:
Select All
-
-boot d
Boot from the CD (boot c from the hard disk)
-
Code:
Select All
-
-cdrom /home/lm/iso/winxp.iso
The disk image used. If you want to use a physical optical drive, it is-CDROM/dev/CDROM.
-
Code:
Select All
-
-smp 2
The number of SMP processors is 2. If you are a 4-core processor, the following number is 4 (if you do not enable this option, you can only run in Single-core Mode)
Have you started the installation system? Is it very fast? If your machine can, install XP in about 15 minutes.
Start the installed Virtual Machine (very simple, just change the above command to two parameters ):
-
Code:
Select All
-
sudo /usr/local/kvm/bin/qemu-system-x86_64 -m 512 -drive file=/home/lm/kvm/winxp.img,cache=writeback -localtime -net nic,vlan=0,macaddr=52-54-00-12-34-01 -net tap,vlan=0,ifname=tap0,script=no -boot c -smp 2 -soundhw es1370
Then you can use the IP address in the client, but the KVM video card cannot be used. You can use rdesktop for remote connection.
-
Code:
Select All
-
Rdesktop 192.168.1.4: 3389-u administrator-P ******-G 1280x750-d-r sound: Local \ resolution can be set by yourself, is it better than virtualbox's seamless connection mode ??
Supplement:
If multiple Guest OS are running at the same time, you need to modify the network settings and add several tap interfaces to/etc/Network/interfaces. Each guest OS uses a single tap, for example, if you want to run three guest OS at the same time, the configuration file is as follows:
-
Code:
Select All
-
Auto tap0
Iface tap0 Inet Manual
Up ifconfig $ iface 0.0.0.0 up
Down ifconfig $ iface down
Tunctl_user lm \ lm is my user name. Here, replace it with your user name.Auto tap1
Iface tap1 Inet Manual
Up ifconfig $ iface 0.0.0.0 up
Down ifconfig $ iface down
Tunctl_user lm \ lm is my user name. Here, replace it with your user name.
Auto tap2
Iface tap2 Inet Manual
Up ifconfig $ iface 0.0.0.0 up
Down ifconfig $ iface down
Tunctl_user lm \ lm is my user name. Here, replace it with your user name.
Auto br0
Iface br0 Inet static \ can also be allocated using DHCP.
Bridge_ports eth0 tap0 tap1 tap2
Address 192.168.1.3
Netmask 255.255.255.0
Gateway 192.168.1.1
Start Guest OS
-
Code:
Select All
-
sudo /usr/local/kvm/bin/qemu-system-x86_64 -m 512-drive file=/home/lm/kvm/winxp.img,cache=writeback -localtime -net nic,vlan=0,macaddr=52-54-00-12-34-01 -net tap,vlan=0,ifname=tap0,script=no -boot c -smp 2 -clock rtc -soundhw es1370
Change ifname = tap0 to tap1 or tap2, and change Mac ..
Note that the KVM kernel module must be reloaded after the system is restarted:
-
Code:
Select All
-
Sudo modprobe KVM
Sudo modprobe KVM-AMD // if you use an AMD processor
Sudo modprobe KVM-Intel // if it is an Intel processor
Of course, you can also modify the system settings to automatically load the module at startup.
Similarly, you can use this method to install Linux. After the installation, we can compare it. Is it much better than VB and Vm?
For other problems such as USB connection, refer to the posts in the Forum.
I have run four centos 4.8 and one WINXP SP3 and one win2003 SP2 and five FreeBSD 8.0 in my system at the same time.
The speed is too fast, incredible.
The system configuration is: Ubuntu 8.04.4 64bit running at athlon X2 5000 + 8g RAM.
In fact, KVM is easy to install and use. You need to understand the meaning of each KVM parameter. The most important thing is the KVM network bridging settings. Here, you need to read the documents of the software, which will be of great help.
The above is the most basic implementation method of KVM. We hope you can read more documents to learn more and more flexible functions.
BTW:
The reason for the poor performance of the original disk has been found. The previous method is to use-hda disk. IMG method to use the virtual disk. Now, after the version is updated,-drive file =/home/lm/KVM/WINXP. IMG, cache = writeback to use virtual disks. Pay attention to the changes here when using KVM.
-Hda/HDB parameters are used by a partition on a physical hard disk.
Note: The Installation Method for Ubuntu 10.04 lts (qemu-KVM 0.12.3 ):
Direct
-
Code:
Select All
-
sudo apt-get install qemu-kvm
The network configuration is the same as above.
Please note that if you are virtualizing win2003, do not use model = e1000 in the-net parameter; otherwise, Ping between host and guest is not allowed.