Install KVM on Ubuntu and build a virtual environment

Source: Internet
Author: User
Tags virtual environment xming

Install KVM on Ubuntu and build a virtual environment

Install KVM on Ubuntu and build a virtual environment. There are four chapters:

1. Prepare the environment
2. Install KVM Software
3. configure a bridge Nic
4. Create a Virtual Machine (Ubuntu, winxp)

1. Prepare the environment

1) two computers, one for the Client and the other for the Server

Client: Laptop, Win7 flagship edition, 64-bit, Intranet ip: 192.168.1.101

Server (Host): Server, Ubuntu 12.04LTS 64-bit, 2-core CPU, 4G memory, Intranet ip Address: 192.168.1.10,

2) Enable CPU Virtualization in the BIOS when the server is started.

Go to BIOS and choose config> CPU.
Intel (R) Virtualization Technology (Enabled)
Intel (R) VT-d Feature (Enabled)

Different BIOS menus are slightly different.

3) install Openssh-Server on the server before the Client can connect

~ Sudo apt-get install openssh-server

Clinet uses Putty to connect to the Server.

Note: All of the following operations are performed through SSH.

4) Server System Environment

~ Uname-
Linux conan 3.5.0-23-generic #35 ~ Precise1-Ubuntu SMP Fri Jan 25 17:13:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
~ Cat/etc/issue
Ubuntu 12.04.2 LTS \ n \ l

5) view CPU virtualization support

~ Egrep 'svm | vmx'/proc/cpuinfo
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat limit 36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm limit pebs bts nopl limit pni limit monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm ida dtherm tpr_shadow vnmi flexpriority
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat limit 36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm limit pebs bts nopl limit pni limit monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm ida dtherm tpr_shadow vnmi flexpriority


My machine is an intel CPU. You can view the vmx ID.

 

6) on the Server, configure the ubuntu download source sources. list. I use the sohu source.

~ Sudo vi/etc/apt/sources. list
Deb http://mirrors.sohu.com/ubuntu/ precise main restricted
Deb-src http://mirrors.sohu.com/ubuntu/ precise main restricted
Deb http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
Deb-src http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
Deb http://mirrors.sohu.com/ubuntu/ precise universe
Deb-src http://mirrors.sohu.com/ubuntu/ precise universe
Deb http://mirrors.sohu.com/ubuntu/ precise-updates universe
Deb-src http://mirrors.sohu.com/ubuntu/ precise-updates universe
Deb http://mirrors.sohu.com/ubuntu/ precise multiverse
Deb-src http://mirrors.sohu.com/ubuntu/ precise multiverse
Deb http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
Deb-src http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
Deb http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
Deb-src http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
Deb http://mirrors.sohu.com/ubuntu/ precise-security main restricted
Deb-src http://mirrors.sohu.com/ubuntu/ precise-security main restricted
Deb http://mirrors.sohu.com/ubuntu/ precise-security universe
Deb-src http://mirrors.sohu.com/ubuntu/ precise-security universe
Deb http://mirrors.sohu.com/ubuntu/ precise-security multiverse
Deb-src http://mirrors.sohu.com/ubuntu/ precise-security multiverse
Deb http://extras.ubuntu.com/ubuntu precise main
Deb-src http://extras.ubuntu.com/ubuntu precise main

# Update source
~ Sudo apt-get update

2. Install KVM Software

1) install KVM and virt management software on the Server

~ Sudo apt-get install kvm qemu
~ Sudo apt-get install stronginst python-libvirt virt-viewer virt-manager

Installing on ubuntu is really simple.

3. configure a bridge Nic

1) Here we use the NIC bridging method

~ Sudo apt-get install bridge-utils

2) view Nic settings

~ Ifconfig
Eth0 Link encap: Ethernet HWaddr 00: 1c: 25: a1: 99: fc
Inet addr: 192.168.1.10 Bcast: 192.168.1.255 Mask: 255.255.255.0
Inet6 addr: fe80: 21c: 25ff: fea1: 99fc/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 736674 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 1098750 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 63783787 (63.7 MB) TX bytes: 1540374899 (1.5 GB)
Interrupt: 20 Memory: fc200000-fc220000

Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopback running mtu: 16436 Metric: 1
RX packets: 1156 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 1156 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 114090 (114.0 KB) TX bytes: 114090 (114.0 KB)

Virbr0 Link encap: Ethernet HWaddr be: 65: ec: 88: 86: 3d
Inet addr: 192.168.122.1 Bcast: 192.168.122.255 Mask: 255.255.255.0
Up broadcast 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: 0
RX bytes: 0 (0.0 B) TX bytes: 0 (0.0 B)

3) Existing NICs
Eth0 is the ethernet card directly inserted into the network cable,
Lo is a local network with local resources
Virbr0 is the virtual network card that we generated after installing KVM.

4) Nic bridging
We add a virtual network card named br0 to enable this network card to bridge with the network card of eth0 Ethernet.

~ Sudo vi/etc/network/interfaces
Auto lo
Iface lo inet loopback
Auto eth0
Iface eth0 inet manual
Auto br0
Iface br0 inet static
Address 192.168.1.10
Netmask 255.255.255.0
Gateway 192.168.1.1
Bridge_ports eth0

Save and restart Nic settings

~ Sudo/etc/init. d/networking restart

View Nic settings

~ Ifconfig
Br0 Link encap: Ethernet HWaddr 00: 1c: 25: a1: 99: fc
Inet addr: 192.168.1.10 Bcast: 192.168.1.255 Mask: 255.255.255.0
Inet6 addr: fe80: 21c: 25ff: fea1: 99fc/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 91 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 100 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 6260 (6.2 KB) TX bytes: 15470 (15.4 KB)

Eth0 Link encap: Ethernet HWaddr 00: 1c: 25: a1: 99: fc
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 605 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 425 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 112441 (112.4 KB) TX bytes: 61529 (61.5 KB)
Interrupt: 20 Memory: fc200000-fc220000

Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopback running mtu: 16436 Metric: 1
RX packets: 36 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 36 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 2100 (2.1 KB) TX bytes: 2100 (2.1 KB)

Virbr0 Link encap: Ethernet HWaddr 2a: b8: 36: cf: cc: c6
Inet addr: 192.168.122.1 Bcast: 192.168.122.255 Mask: 255.255.255.0
Up broadcast 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: 0
RX bytes: 0 (0.0 B) TX bytes: 0 (0.0 B)

At this time, eth0 has no specific IP address. The IP address is on the virtual network of br0.

Ping the public ip address to see if it is accessible.

~ Ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56 (84) bytes of data.
64 bytes from 8.8.8.8: icmp_req = 1 ttl = 46 time = 51.7 MS
64 bytes from 8.8.8.8: icmp_req = 2 ttl = 46 time = 50.8 MS

4. Create a virtual machine

Create a Virtual Machine (Guest) through virt Virtual Machine management software ).

Upload two installation images to the Server: u1204.iso, xp. iso

In the/home/conan/OS directory.

1) Create Guest1 and Ubuntu 64-bit LTS 12.04 (command line, no visual interface)

Mount the u1204.iso file to a directory

~ Sudo mount-o loop/home/conan/OS/u1204.iso/home/conan/OS/ubuntu
~ Ls/home/conan/OS/ubuntu
Boot dists EFI isolinux pics preseed ubuntu
Cdromupgrade doc install md5sum.txt pool README. diskdefines

Create a virtual machine

~ Sudo virt-install -- connect = qemu: // system \
-- Name g1 \
-- Ram 2048 \
-- Vcpus = 2 \
-- OS-type = linux \
-- OS-variant = ubuntuprecise \
-- Accelerate \
-- Hvm \
-- Disk path =/home/conan/OS/g1.img, size = 6, bus = virtio \
-- Location/home/conan/OS/ubuntu \
-- Extra-args = 'console = tty0 console = ttys0 '\
-- Network bridge = br0, model = virtio \
-- Graphics none

Go to the installation page

Lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [!] Select a language tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
X
X Choose the language to be used for the installation process. The x
X selected language will also be the default language for the installed x
X system. x
X
X Language: x
X
X C x
X English x
X
X <Go Back> x
X
Mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
<Tab> moves; <Space> selects; <Enter> activates buttons

Install the system

Lqqqqqqqqqqqqqqqqqqqqqqqqqu [!] Configure the network tqqqqqqqqqqqqqqqqqqqqqqqqqk
X
X Please enter the hostname for this system. x
X
X The hostname is a single word that identifies your system to the x
X network. If you don't know what your hostname shocould be, consult your x
X network administrator. If you are setting up your own home network, x
X you can make something up here. x
X
X Hostname: x
X
X localhost ____________________________________________________________________ x
X
X <Go Back> <Continue> x
X
Mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
<Tab> moves; <Space> selects; <Enter> activates buttons

Installation Complete

2). Create Guest2 and Ubuntu 64-bit LTS 12.04 (through VNC, with visualization)

On the server side, I want to enable port support for vnc_listen.

~ Vi/etc/libvirt/qemu. conf
# Open comments
Vnc_listen = "0.0.0.0"

Restart virt software

~ Sudo/etc/init. d/libvirt-bin restart
~ Netstat-nlt | grep 5900
Tcp 0 0 0.0.0.0: 5900 0.0.0.0: * LISTEN


We need to use Xming and putty together to display the VNC signal remotely transmitted by putty through Xming.

In putty, we need to modify the configuration.

Start Xming Software

Execute Command

~ Sudo virt-install -- connect = qemu: // system \
-- Name g2 \
-- Ram 2048 \
-- Vcpus = 2 \
-- OS-type = linux \
-- OS-variant = ubuntuprecise \
-- Accelerate \
-- Hvm \
-- Disk path =/home/conan/OS/g2.img, size = 6, bus = virtio \
-- Cdrom/home/conan/OS/u1204.iso \
-- Network bridge = br0, model = virtio \
-- Graphics vnc

The VNC interface is displayed through Xming, And the ubuntu installation screen is displayed.

Installation Complete

3. Create Guest3 and Winxp (through VNC, there is a visual interface)

Note 1: winxp must be installed, but ghost cannot.

NOTE 2: For windows installation, you must use the VNC interface mode and install it directly without commands.

Execute Command

Sudo virt-install -- connect = qemu: // system \
-- Name g3 \
-- Ram 1024 \
-- Vcpus = 1 \
-- OS-type = windows \
-- OS-variant = winxp \
-- Accelerate \
-- Hvm \
-- Disk path =/home/conan/OS/g3.img, size = 4 \
-- Cdrom/home/conan/OS/xp. iso \
-- Network bridge = br0, model = ne2k_pci \
-- Graphics vnc

The VNC interface is displayed through Xming, And the WinXP installation screen is displayed.

Installation Complete

Virtual machines communicate with each other

We started Guest1 (ubuntu) and Guest3 (winxp ).
Client: ip: 192.168.1.101
Server: ip: 192.168.1.10
Guest1: ip: 192.168.1.11
Guest3: ip: 192.168.1.12

They are all in the same network segment. They can ping each other or call each other.

If your experiment results are the same as mine, congratulations, you have already implemented the VPS process through KVM.

 

Error Solution

1. Error code:

LibvirtError: internal error Process exited while reading console log output: char device redirected to/dev/pts/4
Cocould not access KVM kernel module: Permission denied
Failed to initialize KVM: Permission denied
No accelerator found!


Solution:

~ Sudo rmmod kvm_intel
~ Sudo modprobe-r kvm_intel
~ Sudo modprobe kvm_intel nested = 1

-------------------------------------- Split line --------------------------------------

How to add a hard disk for a Linux Virtual Machine in KVM

Getting started with Linux: KVM for Virtual Machine experience

RHEL6 KVM virtualization creates a bridge NIC-Bridge

RedHat Linux KVM Virtual Machine bridging

Installation/bridging settings of KVM in CentOS 5.6/virtual machine creation and operation

The/bin/qemu-KVM problem cannot be found when the kvm virtual machine is installed with libvirt In Ubuntu.

Install and configure the KVM Virtual Machine in RedHat6.5

-------------------------------------- Split line --------------------------------------

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.