Installation (Installation)
Here, for example, Ubuntu Linux 10.04, install KVM.
First, install the KVM-related basic kit:
- Libvirt-bin: Provides LIBVIRTD to manage QEMU and KVM.
- QEMU-KVM: The main virtual engine.
- Ubuntu-vm-builder: A powerful virtual machine tool.
- Bridge-utils: Used to build a bridge used by virtual machines.
Install with apt:
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
Alternatively, you can install Virt-viewer to see the virtual machine:
sudo apt-get install virt-viewer
After the installation is complete, the system will automatically add your username to the LIBVIRTD group, and users in this group will be able to use KVM, and if you want to make the setting effective, you must log out and log in again. In addition, the system will add a more KVM group, but the general user does not need to join this group, so do not care about it.
After re-entry, first check that the installation is correct and execute:
virsh -c qemu:///system list
If you see
Id Name State
----------------------------------
That means no problem, if you see this:
Libvir:remote Error:permission denied
error:failed to connect
to the hypervisor
Please check to see if there is a problem with the installation process, or if you have forgotten to log out and log in again.
Also, check the sock file's permissions:
sudo ls -la /var/run/libvirt/libvirt-sock
Should be like this
srwxrwx---1 root libvirtd 0 2012-02-04 13:38/var/run/libvirt/libvirt-sock
It's no problem.
In addition, if you use the Ubuntu Desktop version, you can also install the graphical interface management program:
sudo apt-get install virt-manager
Network Setting (Networking)
To set up a KVM network, it is common to say that the network is set up in two ways:
- UserMode Networking: The virtual machine connects to the Internet via NAT, which is a preset.
- Bridged Networking: Connected to the Internet through bridge mode, the outside of the machine can also directly connect to this virtual machine, so you can provide Web services, such as a Web site.
With UserMode Networking, the virtual machine can obtain an IP address from 192.168.122.0/24, and the IP address of the real machine is 192.168.122.1, and if the file is to be transferred, it can be communicated using SCP. If you want to use the UserMode Networking method, you do not need any extra settings to skip directly over here.
Bridged Networking way can be connected to the network through the physical network, so that the outside user can connect to the virtual machine, which because the pen is not available, so it is not studied at a time.
Here the pen wants to lock the virtual machine inside, allowing only the inside connection, so make a slight change to the preset network, first look at the current setting:
virsh net-list
Outputs
Name State Autostart
-----------------------------------------
Default Active Yes
The current network setup is the default setting, so we can modify it directly? ㄌㄜ Okay, well, first of all, pour out the Setup files:
virsh net-dumpxml default > default.xml
This content should look like this:
<network>
<name>default</name>
<uuid>45f1405b-791a-06e4-d8e8-8bcfffc4c90f</uuid>
<forward mode=‘nat‘/>
<bridge name=‘virbr0‘ stp=‘on‘ delay=‘0‘ />
<ip address=‘192.168.122.1‘ netmask=‘255.255.255.0‘>
<dhcp>
<range start=‘192.168.122.2‘ end=‘192.168.122.254‘ />
</dhcp>
</ip>
</network>
One of the <forward mode= ' Nat '/> is to set the network as a NAT mode in which the packets above the virtual machine are automatically connected to the outside via the IP forward, but this is not what the pen needs, so just take this line off, This virtual machine can only connect with host.
Then feed back to the Virsh in the setting of the editing good:
virsh define default.xml
This completes the setup. The default setting is then set to auto-activate and the default setting is activated:
virsh net-autostart default
virsh net-start default
This way, the modification of the setup dump can actually be replaced by an instruction:
virsh net-edit default
This way of editing is to use the VI editor, if you do not want to use this way VI, you can also change the editor environment to specify the editor you are accustomed to.
Create Virtual machine
To build a virtual machine, use the Vmbuilder tool, and he has a lot of options to start by listing all the options to see what can be used:
vmbuilder kvm ubuntu --help
Many of the options are to be adjusted for individual situations, first in order to place the image:
cd /var/lib/libvirt/images
Then build the virtual machine:
vmbuilder kvm ubuntu \
--domain=kvm \
--dest=vm01 \
--arch=amd64 \
--hostname=vm01 \
--mem=8192 \
--cpus=16 \
--user=seal \
--pass=my_pass \
--ip=192.168.122.10 \
--mask=255.255.255.0 \
--net=192.168.122.0 \
--bcast=192.168.122.255 \
--gw=192.168.122.1 \
--iso=/home/seal/LinuxISO/ubuntu-10.04.3-server-amd64.iso \
--suite=lucid \
--components=‘main,universe,restricted‘ \
--addpkg=acpid \
--addpkg=vim \
--addpkg=build-essential \
--addpkg=openssh-server \
--addpkg=avahi-daemon \
--libvirt=qemu:///system
Installing KVM under Ubuntu