由于使用的是ubuntu13.04平台,接下來就在ubuntu中做相關的LVM快照。在redhat平台也是類似,就是使用root身份做如下操作。
在安裝虛拟機的過程當中我們使用lvm邏輯卷作為kvm虛拟機的硬碟,這樣才能使用LVM的快照功能:
建立LVM邏輯卷:sudo fdisk /dev/sda3(分區,這裡就不在詳細介紹)
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x25c225c1
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 391167 194560 83 Linux
/dev/sda2 393214 117268479 58437633 5 Extended
/dev/sda3 117268480 312581807 97656664 83 Linux
/dev/sda4 391168 393213 1023 83 Linux
/dev/sda5 393216 16392191 7999488 82 Linux swap / Solaris
/dev/sda6 16394240 117268479 50437120 8e Linux LVM
sudo partprobe
sudo pvcreate /dev/sda3
sudo vgcreate vg00 /dev/sda3
sudo lvcreate -L 20G -n lv01 vg00 (建立一個centos的邏輯卷給裝系統使用)
安裝kvm虛拟機:
使用virt-manager來管理kvm虛拟機。
<a href="http://s3.51cto.com/wyfs02/M00/22/BD/wKioL1MlfJTDZavkAADnvSG6fgk848.jpg" target="_blank"></a>
<a href="http://s3.51cto.com/wyfs02/M01/22/BD/wKioL1MlfQCRq28QAAEw9-hDys8095.jpg" target="_blank"></a>
<a href="http://s3.51cto.com/wyfs02/M01/22/BD/wKioL1MlfQCRq28QAAEw9-hDys8095.jpg" target="_blank">在安裝Redhot建立Redhot邏輯卷的快照:</a>
lvcreate -L 2G -s -n lv02 /dev/vg00/lv01
(一般快照大小隻要為被快照的邏輯卷的15~20%就可以了)
zym@zym-TOP2:~$ ls /dev/vg00/lv0
lv01 lv02 lv03 lv04 lv05 lv06 lv07 lv08
zym@zym-TOP2:~$ ls /etc/libvirt/qemu/
networks/ Rnode1.xml Rnode3.xml Rnode5.xml Rnode7.xml
node1.xml Rnode2.xml Rnode4.xml Rnode6.xml Rnode8.xml
最後修改kvm的配置檔案: vim /etc/libvirt/qemu/Rnode2.xml
zym@zym-TOP2:~$ sudo cat /etc/libvirt/qemu/Rnode2.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit Rnode2
or other application using the libvirt API.
-->
<domain type='kvm'>
<name>Rnode2</name> 改檔案名
<uuid>569634c8-4d1e-9623-32fe-3553399f062d</uuid> 改uuid 随便改一個數字或字母
<memory unit='KiB'>224288</memory> 改記憶體 小一點 虛拟機多了放記憶體不夠
<currentMemory unit='KiB'>224288</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='i686' machine='pc-i440fx-1.4'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/vg00/lv02'/>
修改成快照名 就是lvcreate -L 2G -s -n lv02 /dev/vg00/lv01
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='cdrom'>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
<interface type='network'>
<mac address='52:54:20:6e:41:ea'/> 改mac位址 随便改一數字
<source network='default'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'/>
<sound model='ich6'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</memballoon>
</devices>
</domain>
修改檔案完畢
zym@zym-TOP2:~$ sudo virsh define /etc/libvirt/qemu/Rnode2.xml
虛拟機中就會有 Rnode2 這個了
二、快速制造多台虛拟機
1、為原虛拟機所在的lv做一個快照。
lvcreate -L 2G -s -n lv02 /dev/vg00/lv01 (一般快照大小是宿主的15-20%)
2、複制/etc/libvirt/qemu/虛拟機名.xml并改名為/etc/libvirt/qemu/虛拟機名1.xml
cp /etc/libvirt/qemu/虛拟機名.xml /etc/libvirt/qemu/虛拟機名1.xml
3、修改 /etc/libvirt/qemu/虛拟機名1.xml
vim /etc/libvirt/qemu/虛拟機1.xml (修改一下幾項,随便改隻要與原來不一樣就可以了。)比如:
<name>Rnode1</name>
<uuid>395ae05e-c118-e460-4de4-7f58e08f8aa1</uuid>
<source dev=‘虛拟機快照名’>
<mac address='52:54:00:a7:11:cb'/>
4、virsh define 虛拟機名1.xml (定義虛拟機)
5、virsh start 虛拟機名1 (新的虛拟機就可以使用啦。呵呵)
<a href="http://s3.51cto.com/wyfs02/M01/22/BD/wKioL1MlghPzSJEZAAIN026pJnU665.jpg" target="_blank"></a>
<a href="http://s3.51cto.com/wyfs02/M02/22/BD/wKioL1MlgxiAHOp-AAJ2Jlu2XU8194.jpg" target="_blank"></a>
我建立了8個虛拟機 都能用 可同時打開
本文轉自zhang25yun51CTO部落格,原文連結:http://blog.51cto.com/1585654/1377636 ,如需轉載請自行聯系原作者