installation and administration Vms on centos

來源:互聯網
上載者:User

標籤:qemu linux

                         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 that the name of disk is ubuntu12.04.img.

I suggest you rather use raw format for virtual disk as a template image file.I think "qemu-img" also is a good tool to create an 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 do 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 is in.


8.define VM via virsh command

virsh define ubuntu2.xml

virsh start ubuntu2

attention:if you 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 have already been able to create new Vms quickly now.


本文出自 “技術為王” 部落格,轉載請與作者聯絡!

installation and administration Vms on centos

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.