Installation and administration Vms on CentOS

Source: Internet
Author: User

Installation and administration Vms on CentOS

1.Compile QEMU

wget http://wiki.qemu.org/download/qemu-0.15.1.tar.gz
Tar zxf qemu-0.15.1.tar.gz
CD qemu-0.15.1
./configure--prefix=/opt/qemu-0.15.1
Make
Make install

Ln-s/opt/qemu-0.15.1/bin/qemu-nbd/usr/local/bin/

2.Installvirtualization Tools

Yum Install Libvirt

Yum Install Virt-manger

3.Install template OS (using "virt-manage" seems easy)

I don ' t decribe it.you can install any OS step by step by Virt-manager.

We assume the name of disk is ubuntu12.04.img.

I suggest you rather the use of raw format for virtual disk as a template image file. I think "qemu-img" also is a good tool to create a image,like this:

Qemu-img create-f Raw Ubuntu12.04.img 20G

4.dump VMs and create new

Virsh Dumpxml ubuntu12.04 >ubuntu2.xml

Virsh undefine ubuntu12.04

Create a new disk image for the other OS

Qemu-img create-f qcow2-o\ cluster_size=2m,backing_file=ubuntu12.04.img ubuntu2.qcow2 30G

5. Mount Ubuntu2.qcow2 to change OS settings

Yum Install KMOD-NBD

Qemu-nbd-c/dev/nbd0 Ubuntu2.qcow2

Partprobe/dev/nbd0
Fdisk-l/dev/nbd0

650) this.width=650; "Src=" https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F% 2f2.bp.blogspot.com%2f-vx4sattkcd0%2fvha8lnejb6i%2faaaaaaaaafi%2fbxta76lokfi%2fs1600%2fnbd.jpg&container= blogger&gadget=a&rewritemime=image%2f* "height=" 212 "border=" 0 "width=" 640 "alt=" proxy?url=http%3A%2F% 2f2.bp.blogspot.com "/>

mount/dev/nbd0p1/mnt

Now you should does some work for the new OS

1) Change hostname

Sed-i "s,127.0.1.1.*,127.0.1.1 ubuntu2,g"/mnt/etc/hosts

Sed-i "S,ubuntu,ubuntu2,g"/mnt/etc/hostname

mac="52:54:$ (dd if=/dev/urandom count=1 2>/dev/null \


| md5sum | sed 's/^\ (.. \)\(.. \)\(.. \)\(.. \). *$/\1:\2:\3:\4/')"


Vim/mnt/etc/udev/rules.d/70-persistent-net.rules

subsystem== "NET", action== "Add", drivers== "? *", attr{address}== "%mac%", attr{type}== "1", kernel== "eth*", name= " Eth0"

Remember:please use MAC to REPLACE%mac%

2) Set Network

Vim/mnt/etc/network/interfaces

Auto Lo

Iface Lo inet Loopback

Auto Eth0

Iface eth0 inet Static

Address 192.168.122.222

Netmask 255.255.255.0

Broadcast 192.168.122.255

Gateway 192.168.122.1

6.umount NBD Device

Umount/mnt

Qemu-nbd-d/dev/nbd0

7.create VM ' s XML file

CP Template.xml Ubuntu2.xml

Modify "%vm_name", "%uuid%", "%mac%", "%image_path%"

Sed-i "S,%vm_name,ubuntu2,g" Ubuntu2.xml

Uuid= ' Uuidgen '

Sed-i "s,%uuid%, $UUID, G" ubuntu2.xml

Ok,please Refer Section 5 to modify Mac.change "%image_path%" to the PATH where your IMAGE was in.


8.define VM via Virsh command

Virsh Define Ubuntu2.xml

Virsh Start UBUNTU2

Attention:if installed KVM by yum,the emulator path is "/USR/LIBEXEC/QEMU-KVM" not "/USR/BIN/KVM" in Ubuntu2.xml file.

Check the VNC port

Virsh Vncdisplay UBUNTU2


Ok,that ' s all.you has already been able to the create new Vms quickly now.


This article from "Technology for the King" blog, reproduced please contact the author!

Installation and administration Vms on CentOS

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.