KVM虛擬化學習筆記系列文章列表
----------------------------------------
kvm虛擬化學習筆記(一)之kvm虛擬化環境安裝
http://koumm.blog.51cto.com/703525/1288795
kvm虛擬化學習筆記(二)之linux kvm虛擬機安裝
http://koumm.blog.51cto.com/703525/1289627
kvm虛擬化學習筆記(三)之windows kvm虛擬機安裝
http://koumm.blog.51cto.com/703525/1290191
kvm虛擬化學習筆記(四)之kvm虛擬機平常管理與配置
http://koumm.blog.51cto.com/703525/1290269
kvm虛擬化學習筆記(五)之windows虛擬機性能調整
http://koumm.blog.51cto.com/703525/1290682
kvm虛擬化學習筆記(六)之kvm虛擬機控制檯登陸配置
http://koumm.blog.51cto.com/703525/1290996
kvm虛擬化學習筆記(七)之kvm虛擬機克隆
http://koumm.blog.51cto.com/703525/1291793
kvm虛擬化學習筆記(八)之kvm虛擬機vnc配置
http://koumm.blog.51cto.com/703525/1291803
kvm虛擬化學習筆記(九)之kvm虛擬機時間配置
http://koumm.blog.51cto.com/703525/1291862
kvm虛擬化學習筆記(十)之kvm虛擬機快照備份
http://koumm.blog.51cto.com/703525/1291893
kvm虛擬化學習筆記(十一)之kvm虛擬機擴展磁盤空間
http://koumm.blog.51cto.com/703525/1292146
kvm虛擬化學習筆記(十二)之kvm linux虛擬機在線擴展磁盤
http://koumm.blog.51cto.com/703525/1295296
kvm虛擬化學習筆記(十三)之kvm虛擬機磁盤文件讀取小結
http://koumm.blog.51cto.com/703525/1298845node
kvm虛擬化學習筆記(十四)之kvm虛擬機靜態遷移
http://koumm.blog.51cto.com/703525/1298852
kvm虛擬化學習筆記(十五)之kvm虛擬機動態遷移
http://koumm.blog.51cto.com/703525/1300783linux
kvm虛擬化學習筆記(十六)之kvm虛擬化存儲池配置
http://koumm.blog.51cto.com/703525/1304196
kvm虛擬化學習筆記(十七)之KVM到KVM之v2v遷移windows
http://koumm.blog.51cto.com/703525/1304271api
kvm虛擬化學習筆記(十八)之ESXi到KVM之v2v遷移
http://koumm.blog.51cto.com/703525/1304461app
kvm虛擬化學習筆記(十九)之convirt集中管理平臺搭建
http://koumm.blog.51cto.com/703525/1305553dom
kvm虛擬化學習筆記(二十)之convirt安裝linux系統ssh
http://koumm.blog.51cto.com/703525/1306526ide
kvm虛擬機的克隆分爲兩種狀況,本文也就經過如下兩種狀況進行克隆,克隆虛擬機爲OEL5.8X64。oop
本文出自:http://koumm.blog.51cto.com性能
(1) KVM主機本機虛擬機直接克隆。
(2) 經過複製配置文件與磁盤文件的虛擬機複製克隆(適用於異機的靜態遷移)。
(1) 查看虛擬機配置文件
[root@node1 ~]# cat /etc/libvirt/qemu/oeltest01.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 oeltest01 or other application using the libvirt API. --> <domain type='kvm'> <name>oeltest01</name> <uuid>8f2bb4a7-c7ed-32aa-3676-9fb05923269d</uuid> <memory unit='KiB'>524288</memory> <currentMemory unit='KiB'>524288</currentMemory> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='rhel6.4.0'>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/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/data/test01.img'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='block' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> <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'/> </controller> <interface type='bridge'> <mac address='52:54:00:82:39:01'/> <source bridge='br0'/> <model type='virtio'/> <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='tablet' bus='usb'/> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='5910' autoport='no' listen='0.0.0.0'> <listen type='address' address='0.0.0.0'/> </graphics> <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='0x04' function='0x0'/> </memballoon> </devices> </domain>
虛擬機磁盤文件: /data/test01.img
虛擬機名稱:oeltest01
(2) 開始克隆
# virt-clone -o oeltest01 -n oeltest02 -f /data/test02.img
說明:以oeltest01作爲源,克隆oeltest01虛擬機,並建立名稱爲oeltest02虛擬機,使用磁盤文件/data/test02.img
(3) 啓動虛擬機並配置主機名,IP地址等
[root@node1 data]# virsh console oeltest02
kvm控制檯配置請見kvm虛擬化學習筆記(六)之kvm虛擬機控制檯登陸配置。
鏈接到域 oeltest02 Escape character is ^] Found volume group "vg" using metadata type lvm2 2 logical volume(s) in volume group "vg" now active Welcome to Oracle Linux Oracle Linux Server release 5.8 Press 'I' to enter interactive startup. Starting udev: [ OK ] Loading default keymap (us): [ OK ] Setting hostname test01: [ OK ] Setting up Logical Volume Management: 2 logical volume(s) in volume group "vg" now active [ OK ] Checking filesystems Checking all file systems. [/sbin/fsck.ext3 (1) -- /] fsck.ext3 -a /dev/vg/root /dev/vg/root: clean, 135384/1540096 files, 851398/1540096 blocks [/sbin/fsck.ext3 (1) -- /boot] fsck.ext3 -a /dev/hda1 /boot: clean, 39/26104 files, 26897/104388 blocks [ OK ] Remounting root filesystem in read-write mode: [ OK ] Mounting local filesystems: [ OK ] Enabling local filesystem quotas: [ OK ] Enabling /etc/fstab swaps: [ OK ] INIT: Entering runlevel: 5 Entering non-interactive startup Applying Intel CPU microcode update: [ OK ] Starting background readahead: [ OK ] Checking for hardware changes [ OK ] [ OK ] iSCSI daemon: [ OK ] [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining IP information for eth0... done. [ OK ] Starting auditd: [ OK ] Starting system logger: [ OK ] Starting kernel logger: [ OK ] Starting irqbalance: [ OK ] iscsid (pid 1555) is running... Setting up iSCSI targets: iscsiadm: No records found [ OK ] Starting portmap: [ OK ] Starting NFS statd: [ OK ] Starting RPC idmapd: [ OK ] Starting system message bus: [ OK ] Starting o2cb: [ OK ] [ OK ] Bluetooth services:[ OK ] Mounting other filesystems: [ OK ] Starting PC/SC smart card daemon (pcscd): [ OK ] Starting acpi daemon: [ OK ] Starting HAL daemon: [ OK ] Starting hidd: [ OK ] Starting monitoring for VG vg: 2 logical volume(s) in volume group "vg" monitored [ OK ] Starting autofs: Loading autofs4: [ OK ] Starting automount: [ OK ] [ OK ] Starting hpiod: [ OK ] Starting hpssd: [ OK ] Starting sshd: [ OK ] Starting cups: [ OK ] Starting xinetd: [ OK ] Starting console mouse services: [ OK ] Starting crond: [ OK ] Starting xfs: [ OK ] Starting anacron: [ OK ] [ OK ] atd: [ OK ] Starting background readahead: [ OK ] Starting yum-updatesd: [ OK ] Starting Avahi daemon... [ OK ] Starting smartd: hdc: drive_cmd: status=0x41 { DriveReady Error } hdc: drive_cmd: error=0x04 { AbortedCommand } ide: failed opcode was: 0xec [ OK ] Oracle Linux Server release 5.8 Kernel 2.6.18-308.el5 on an x86_64 test01 login: mtrr: type mismatch for f0000000,100000 old: uncachable new: write-combining mtrr: type mismatch for f0000000,400000 old: uncachable new: write-combining Oracle Linux Server release 5.8 Kernel 2.6.18-308.el5 on an x86_64 test01 login: Oracle Linux Server release 5.8 Kernel 2.6.18-308.el5 on an x86_64 test01 login: root Password: Last login: Sat Sep 7 05:21:11 on ttyS0 [root@test01 ~]# [root@test01 ~]# [root@test01 ~]#
(4) 修改主機名,IP地址等
# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 test02 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=test02
GATEWAY=192.168.233.2
修改IP地址
# vi /etc/sysconfig/network-script/ifcfg-eth0
# Virtio Network Device
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
HWADDR=52:54:00:56:bd:2b
IPADDR=192.168.233.142
NETMASK=255.255.255.0
[root@test01 ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@test01 ~]#
(1) 導入kvm虛擬機配置文件
這裏採用oeltest01作爲模板,進行克隆。
# virsh shutdown oeltest01
# virsh dumpxml oeltest01 > /etc/libvirt/qemu/oeltest03.xml
(2) 複製kvm虛擬機磁盤文件
本系列文章都是採用虛擬磁盤文件進行測試,沒有使用lvm卷。
經過查看配置文件:虛擬磁盤位置<source file='/data/test01.img'/>
(3) 直接編輯修改配置文件
修改name,uuid,disk位置,vnc端口
此時仍是將該配置文件註冊進來,沒法經過virsh edit進行編輯。
[root@node1 data]# vi /etc/libvirt/qemu/oeltest03.xml
<domain type='kvm'>
<name>oeltest03</name>
<uuid>8f2bb4a7-c7ed-32aa-3676-9fb05923260d</uuid>
<memory unit='KiB'>524288</memory>
<currentMemory unit='KiB'>524288</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='rhel6.4.0'>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/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/data/test03.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk>
<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'/>
</controller>
<interface type='bridge'>
<mac address='52:54:00:82:39:01'/>
<source bridge='br0'/>
<model type='virtio'/>
<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='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='5911' autoport='no' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<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='0x04' function='0x0'/>
</memballoon>
</devices>
</domain>
(4) 定義新虛擬機配置文件
[root@node1 data]# virsh define /etc/libvirt/qemu/oeltest03.xml
啓動虛擬機
[root@node1 data]# virsh start oeltest03
域 oeltest03 已開始
(5) 登陸虛擬機進行主機名,IP等修改
[root@node1 data]# virsh console oeltest03
鏈接到域 oeltest03
Escape character is ^]
Oracle Linux Server release 5.8
Kernel 2.6.18-308.el5 on an x86_64
test01 login: mtrr: type mismatch for f0000000,100000 old: uncachable new: write-combining
mtrr: type mismatch for f0000000,400000 old: uncachable new: write-combining
Oracle Linux Server release 5.8
Kernel 2.6.18-308.el5 on an x86_64
test01 login: root
Password:
Last login: Sat Sep 7 05:21:11 on ttyS0
[root@test01 ~]#
[root@test01 ~]#
修改主機名
# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 test03 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=test03
GATEWAY=192.168.233.2
修改IP地址
# vi /etc/sysconfig/network-script/ifcfg-eth0
# Virtio Network Device
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
HWADDR=52:54:00:56:bd:3b
IPADDR=192.168.233.143
NETMASK=255.255.255.0
service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
本文到此經過兩種方式進行kvm虛擬機克隆,其實各有用處。
再次說明:本文克隆的虛擬機是oel5.8,若是克隆的虛擬機是RHEL/CentOS/OEL6.x操做系統,還須要修改/etc/udev/rules.d/70-persistent-net.rules文件。