kvm虚拟机的克隆分为两种情况,本文也就通过以下两种情况进行克隆,克隆虚拟机为OEL5.8X64。

(1) KVM主机本机虚拟机直接克隆。

(2) 通过复制配置文件与磁盘文件的虚拟机复制克隆(适用于异机的静态迁移)。

1.  本机虚拟机直接克隆

(1) 查看虚拟机配置文件

  1. [root@node1 ~]# cat /etc/libvirt/qemu/oeltest01.xml
  2.  
  3. <!--
  4. WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
  5. OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  6. virsh edit oeltest01
  7. or other application using the libvirt API.
  8. -->
  9. <domain type='kvm'>
  10. <name>oeltest01</name>
  11. <uuid>8f2bb4a7-c7ed-32aa--9fb05923269d</uuid>
  12. <memory unit='KiB'></memory>
  13. <currentMemory unit='KiB'></currentMemory>
  14. <vcpu placement='static'></vcpu>
  15. <os>
  16. <type arch='x86_64' machine='rhel6.4.0'>hvm</type>
  17. <boot dev='hd'/>
  18. </os>
  19. <features>
  20. <acpi/>
  21. <apic/>
  22. <pae/>
  23. </features>
  24. <clock offset='utc'/>
  25. <on_poweroff>destroy</on_poweroff>
  26. <on_reboot>restart</on_reboot>
  27. <on_crash>restart</on_crash>
  28. <devices>
  29. <emulator>/usr/libexec/qemu-kvm</emulator>
  30. <disk type='file' device='disk'>
  31. <driver name='qemu' type='raw' cache='none'/>
  32. <source file='/data/test01.img'/>
  33. <target dev='hda' bus='ide'/>
  34. <address type='drive' controller='' bus='' target='' unit=''/>
  35. </disk>
  36. <disk type='block' device='cdrom'>
  37. <driver name='qemu' type='raw'/>
  38. <target dev='hdc' bus='ide'/>
  39. <readonly/>
  40. <address type='drive' controller='' bus='' target='' unit=''/>
  41. </disk>
  42. <controller type='usb' index=''>
  43. <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
  44. </controller>
  45. <controller type='ide' index=''>
  46. <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
  47. </controller>
  48. <interface type='bridge'>
  49. <mac address='52:54:00:82:39:01'/>
  50. <source bridge='br0'/>
  51. <model type='virtio'/>
  52. <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
  53. </interface>
  54. <serial type='pty'>
  55. <target port=''/>
  56. </serial>
  57. <console type='pty'>
  58. <target type='serial' port=''/>
  59. </console>
  60. <input type='tablet' bus='usb'/>
  61. <input type='mouse' bus='ps2'/>
  62. <graphics type='vnc' port='' autoport='no' listen='0.0.0.0'>
  63. <listen type='address' address='0.0.0.0'/>
  64. </graphics>
  65. <video>
  66. <model type='cirrus' vram='' heads=''/>
  67. <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
  68. </video>
  69. <memballoon model='virtio'>
  70. <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
  71. </memballoon>
  72. </devices>
  73. </domain>

虚拟机磁盘文件: /data/test01.img

虚拟机名称:oeltest01

(2) 开始克隆

  1. # virt-clone -o oeltest01 -n oeltest02 -f /data/test02.img

说明:以oeltest01做为源,克隆oeltest01虚拟机,并创建名称为oeltest02虚拟机,使用磁盘文件/data/test02.img

(3) 启动虚拟机并配置主机名,IP地址等

[root@node1 data]# virsh console oeltest02

  1. 连接到域 oeltest02
  2.  
  3. Escape character is ^]
  4. Found volume group "vg" using metadata type lvm2
  5. logical volume(s) in volume group "vg" now active
  6. Welcome to Oracle Linux Oracle Linux Server release 5.8
  7. Press 'I' to enter interactive startup.
  8. Starting udev: [ OK ]
  9. Loading default keymap (us): [ OK ]
  10. Setting hostname test01: [ OK ]
  11. Setting up Logical Volume Management: logical volume(s) in volume group "vg" now active
  12. [ OK ]
  13. Checking filesystems
  14. Checking all file systems.
  15. [/sbin/fsck.ext3 () -- /] fsck.ext3 -a /dev/vg/root
  16. /dev/vg/root: clean, / files, / blocks
  17. [/sbin/fsck.ext3 () -- /boot] fsck.ext3 -a /dev/hda1
  18. /boot: clean, / files, / blocks
  19. [ OK ]
  20. Remounting root filesystem in read-write mode: [ OK ]
  21. Mounting local filesystems: [ OK ]
  22. Enabling local filesystem quotas: [ OK ]
  23. Enabling /etc/fstab swaps: [ OK ]
  24. INIT: Entering runlevel:
  25. Entering non-interactive startup
  26. Applying Intel CPU microcode update: [ OK ]
  27. Starting background readahead: [ OK ]
  28. Checking for hardware changes [ OK ]
  29. [ OK ] iSCSI daemon: [ OK ]
  30. [ OK ]
  31. Bringing up loopback interface: [ OK ]
  32. Bringing up interface eth0:
  33. Determining IP information for eth0... done.
  34. [ OK ]
  35. Starting auditd: [ OK ]
  36. Starting system logger: [ OK ]
  37. Starting kernel logger: [ OK ]
  38. Starting irqbalance: [ OK ]
  39. iscsid (pid ) is running...
  40. Setting up iSCSI targets: iscsiadm: No records found
  41. [ OK ]
  42. Starting portmap: [ OK ]
  43. Starting NFS statd: [ OK ]
  44. Starting RPC idmapd: [ OK ]
  45. Starting system message bus: [ OK ]
  46. Starting o2cb: [ OK ]
  47. [ OK ] Bluetooth services:[ OK ]
  48. Mounting other filesystems: [ OK ]
  49. Starting PC/SC smart card daemon (pcscd): [ OK ]
  50. Starting acpi daemon: [ OK ]
  51. Starting HAL daemon: [ OK ]
  52. Starting hidd: [ OK ]
  53. Starting monitoring for VG vg: logical volume(s) in volume group "vg" monitored
  54. [ OK ]
  55. Starting autofs: Loading autofs4: [ OK ]
  56. Starting automount: [ OK ]
  57. [ OK ]
  58. Starting hpiod: [ OK ]
  59. Starting hpssd: [ OK ]
  60. Starting sshd: [ OK ]
  61. Starting cups: [ OK ]
  62. Starting xinetd: [ OK ]
  63. Starting console mouse services: [ OK ]
  64. Starting crond: [ OK ]
  65. Starting xfs: [ OK ]
  66. Starting anacron: [ OK ]
  67. [ OK ] atd: [ OK ]
  68. Starting background readahead: [ OK ]
  69. Starting yum-updatesd: [ OK ]
  70. Starting Avahi daemon... [ OK ]
  71. Starting smartd: hdc: drive_cmd: status=0x41 { DriveReady Error }
  72. hdc: drive_cmd: error=0x04 { AbortedCommand }
  73. ide: failed opcode was: 0xec
  74. [ OK ]
  75. Oracle Linux Server release 5.8
  76. Kernel 2.6.-.el5 on an x86_64
  77. test01 login: mtrr: type mismatch for f0000000, old: uncachable new: write-combining
  78. mtrr: type mismatch for f0000000, old: uncachable new: write-combining
  79. Oracle Linux Server release 5.8
  80. Kernel 2.6.-.el5 on an x86_64
  81. test01 login:
  82. Oracle Linux Server release 5.8
  83. Kernel 2.6.-.el5 on an x86_64
  84. test01 login: root
  85. Password:
  86. Last login: Sat Sep :: on ttyS0
  87. [root@test01 ~]#
  88. [root@test01 ~]#
  89. [root@test01 ~]#
  90.  
  91. () 修改主机名,IP地址等
  92.  
  93. # vi /etc/hosts
  94.  
  95. # Do not remove the following line, or various programs
  96. # that require network functionality will fail.
  97. 127.0.0.1 test02 localhost.localdomain localhost
  98. :: localhost6.localdomain6 localhost6
  99.  
  100. # vi /etc/sysconfig/network
  101.  
  102. NETWORKING=yes
  103. NETWORKING_IPV6=no
  104. HOSTNAME=test02
  105. GATEWAY=192.168.233.2
  106.  
  107. 修改IP地址
  108.  
  109. # vi /etc/sysconfig/network-script/ifcfg-eth0
  110.  
  111. # Virtio Network Device
  112. DEVICE=eth0
  113. BOOTPROTO=static
  114. ONBOOT=yes
  115. HWADDR=::::bd:2b
  116. IPADDR=192.168.233.142
  117. NETMASK=255.255.255.0
  118.  
  119. [root@test01 ~]# service network restart
  120. Shutting down interface eth0: [ OK ]
  121. Shutting down loopback interface: [ OK ]
  122. Bringing up loopback interface: [ OK ]
  123. Bringing up interface eth0: [ OK ]
  124. [root@test01 ~]#

2.  复制配置文件与磁盘文件克隆

(1) 导入kvm虚拟机配置文件

这里采用oeltest01做为模板,进行克隆。

  1. # virsh shutdown oeltest01

  1. # virsh dumpxml oeltest01 > /etc/libvirt/qemu/oeltest03.xml

(2) 复制kvm虚拟机磁盘文件

本系列文章都是采用虚拟磁盘文件进行测试,没有使用lvm卷。

通过查看配置文件:虚拟磁盘位置<source file='/data/test01.img'/>

(3) 直接编辑修改配置文件

修改name,uuid,disk位置,vnc端口

此时还是将该配置文件注册进来,无法通过virsh edit进行编辑。

  1. [root@node1 data]# vi /etc/libvirt/qemu/oeltest03.xml
  2. <domain type='kvm'>
  3. <name>oeltest03</name>
  4. <uuid>8f2bb4a7-c7ed-32aa--9fb05923260d</uuid>
  5. <memory unit='KiB'></memory>
  6. <currentMemory unit='KiB'></currentMemory>
  7. <vcpu placement='static'></vcpu>
  8. <os>
  9. <type arch='x86_64' machine='rhel6.4.0'>hvm</type>
  10. <boot dev='hd'/>
  11. </os>
  12. <features>
  13. <acpi/>
  14. <apic/>
  15. <pae/>
  16. </features>
  17. <clock offset='utc'/>
  18. <on_poweroff>destroy</on_poweroff>
  19. <on_reboot>restart</on_reboot>
  20. <on_crash>restart</on_crash>
  21. <devices>
  22. <emulator>/usr/libexec/qemu-kvm</emulator>
  23. <disk type='file' device='disk'>
  24. <driver name='qemu' type='raw' cache='none'/>
  25. <source file='/data/test03.img'/>
  26. <target dev='hda' bus='ide'/>
  27. <address type='drive' controller='' bus='' target='' unit=''/>
  28. </disk>
  29. <disk type='block' device='cdrom'>
  30. <driver name='qemu' type='raw'/>
  31. <target dev='hdc' bus='ide'/>
  32. <readonly/>
  33. <address type='drive' controller='' bus='' target='' unit=''/>
  34. </disk>
  35. <controller type='usb' index=''>
  36. <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
  37. </controller>
  38. <controller type='ide' index=''>
  39. <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
  40. </controller>
  41. <interface type='bridge'>
  42. <mac address='52:54:00:82:39:01'/>
  43. <source bridge='br0'/>
  44. <model type='virtio'/>
  45. <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
  46. </interface>
  47. <serial type='pty'>
  48. <target port=''/>
  49. </serial>
  50. <console type='pty'>
  51. <target type='serial' port=''/>
  52. </console>
  53. <input type='tablet' bus='usb'/>
  54. <input type='mouse' bus='ps2'/>
  55. <graphics type='vnc' port='' autoport='no' listen='0.0.0.0'>
  56. <listen type='address' address='0.0.0.0'/>
  57. </graphics>
  58. <video>
  59. <model type='cirrus' vram='' heads=''/>
  60. <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
  61. </video>
  62. <memballoon model='virtio'>
  63. <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
  64. </memballoon>
  65. </devices>
  66. </domain>

(4) 定义新虚拟机配置文件

  1. [root@node1 data]# virsh define /etc/libvirt/qemu/oeltest03.xml

启动虚拟机

  1. [root@node1 data]# virsh start oeltest03
  2. oeltest03 已开始

(5) 登录虚拟机进行主机名,IP等修改

  1. [root@node1 data]# virsh console oeltest03
  2. 连接到域 oeltest03
  3. Escape character is ^]
  4.  
  5. Oracle Linux Server release 5.8
  6. Kernel 2.6.-.el5 on an x86_64
  7.  
  8. test01 login: mtrr: type mismatch for f0000000, old: uncachable new: write-combining
  9. mtrr: type mismatch for f0000000, old: uncachable new: write-combining
  10.  
  11. Oracle Linux Server release 5.8
  12. Kernel 2.6.-.el5 on an x86_64
  13.  
  14. test01 login: root
  15. Password:
  16. Last login: Sat Sep :: on ttyS0
  17.  
  18. [root@test01 ~]#
  19. [root@test01 ~]#
  20.  
  21. 修改主机名
  22.  
  23. # vi /etc/hosts
  24.  
  25. # Do not remove the following line, or various programs
  26. # that require network functionality will fail.
  27. 127.0.0.1 test03 localhost.localdomain localhost
  28. :: localhost6.localdomain6 localhost6
  29.  
  30. # vi /etc/sysconfig/network
  31.  
  32. NETWORKING=yes
  33. NETWORKING_IPV6=no
  34. HOSTNAME=test03
  35. GATEWAY=192.168.233.2
  36.  
  37. 修改IP地址
  38.  
  39. # vi /etc/sysconfig/network-script/ifcfg-eth0
  40.  
  41. # Virtio Network Device
  42. DEVICE=eth0
  43. BOOTPROTO=static
  44. ONBOOT=yes
  45. HWADDR=::::bd:3b
  46. IPADDR=192.168.233.143
  47. NETMASK=255.255.255.0
  48.  
  49. service network restart
  50. Shutting down interface eth0: [ OK ]
  51. Shutting down loopback interface: [ OK ]
  52. Bringing up loopback interface: [ OK ]
  53. Bringing up interface eth0: [ OK ]

本文到此通过两种方式进行kvm虚拟机克隆,其实各有用处。

再次说明:本文克隆的虚拟机是oel5.8,如果克隆的虚拟机是RHEL/CentOS/OEL6.x操作系统,还需要修改/etc/udev/rules.d/70-persistent-net.rules文件。

kvm虚拟化之kvm虚拟机克隆的更多相关文章

  1. kvm虚拟化之kvm虚拟机快照备份

    kvm虚拟机默认使用raw格式的镜像格式,性能最好,速度最快,它的缺点就是不支持一些新的功能,如支持镜像,zlib磁盘压缩,AES加密等.   要使用镜像功能,磁盘格式必须为qcow2.下面开始kvm ...

  2. kvm虚拟化之kvm虚拟机vnc配置

    本文是通过vnc方式访问虚拟主机上的KVM虚拟机.    这里的通过vnc方式访问虚拟机不是在kvm虚拟机安装配置vnc服务器,通过虚拟主机的IP地址与端口进行访问,kvm虚拟化对vnc的支持相对来说 ...

  3. KVM虚拟化之windows虚拟机性能调整

    通过KVM安装WindowsXP/2003/7/2008操作系统后,由于默认的磁盘驱动(IDE)性能与网卡驱动(RTL8139100M)的性能都极其低下,需要调整,通过加载Redhatvirtio驱动 ...

  4. kvm虚拟化安装及虚拟机创建

    1.开启虚拟化(VMware虚拟机为例),安装centos7操作系统. 2.查看CPU是否开启虚拟化 #zgrep  "vmx" /proc/cpuinfo 3.配置yum源,通过 ...

  5. KVM虚拟化(KVM简介和KVM安装)

    KVM 虚拟化架构分类 寄居虚拟化架构:指在宿主操作系统之上安装和运行虚拟化程序,依赖于宿主操作系统对设备的支持和物理资源的管理. 裸金属虚拟化架构:指直接在硬件上面安装虚拟化软件,再在其上安装操作系 ...

  6. CentOS7.1 KVM虚拟化之linux虚拟机安装(2)

    一.上传ISO文件到/data/iso下 这里使用CentOS-5.5-i386-bin-DVD.iso 二.安装CentOS5.5 CentOS7.1 安装KVM虚拟机默认磁盘格式为qcow2(推荐 ...

  7. Kvm虚拟化安装与虚拟机创建

    1. 验证CPU是否支持KVM:如果结果中有vmx(Intel)或svm(AMD)字样,就说明CPU的支持的. egrep '(vmx|svm)' /proc/cpuinfo 2. 关闭SELinux ...

  8. kvm虚拟化之kvm虚拟机控制台登陆

    vm虚拟机能否像xen虚拟机一样通过virsh console 一样采用字符界面进行linux虚拟机控制台呢,答案是肯定的,默认情况下该命令是不起作用的,需要修改相关文件才能实现. 1. 配置方法如下 ...

  9. kvm虚拟化学习笔记(三)之windows kvm虚拟机安装

    KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...

随机推荐

  1. Differences Between 3 Types Of Proxy Servers: Normal, Transparent And Reverse Proxy

    What is a Proxy Server? A Proxy server is an intermediary machine, between a client and the actual s ...

  2. XPath在python中的高级应用

    XPath在python的爬虫学习中,起着举足轻重的地位,对比正则表达式 re两者可以完成同样的工作,实现的功能也差不多,但XPath明显比re具有优势,在网页分析上使re退居二线. XPath介绍: ...

  3. Echarts主题颜色

    Echarts主题颜色搜集: 直接覆盖默认颜色即可 例如在 echarts.setOption({ '#2ec7c9','#b6a2de','#5ab1ef','#ffb980','#d87a80', ...

  4. ubuntu如何安装samba

    1.samba安装sudo apt-get install samba2.修改smb.confsudo gedit /etc/samba/smb.conf 文件最后增加如下代码:[share] pat ...

  5. 实践作业4:Web测试实践(小组作业)每日任务记录3

    会议时间:2017年12月23日 会议地点:东九教学楼自习区 主  持  人:王晨懿 参会人员:王晨懿.余晨晨.郑锦波.杨潇.侯欢.汪元 记  录  人:王晨懿 会议议题:小组作业第二阶段 下面是今天 ...

  6. Auth模块

    文本目录 1 扩展默认的auth_user表 2 auth模块是什么 3 auth模块的常用方法 1 扩展默认的auth_user 表 在开始写项目之前,我们要创建表,同事内置的认证系统又很好用,但是 ...

  7. C#通过Redis实现分布式锁

    Redis有三个最基本属性来保证分布式锁的有效实现: 安全性: 互斥,在任何时候,只有一个客户端能持有锁. 活跃性A:没有死锁,即使客户端在持有锁的时候崩溃,最后也会有其他客户端能获得锁,超时机制. ...

  8. C#6.0特性(快来围观)(转)

    出处:http://www.cnblogs.com/HJL-Blog/p/4457632.html 说明一下,很多博友一进来就认为仅仅是语法糖,C#语法的更新,代表着它的进步,语法糖是为了让我们更好的 ...

  9. 【转】彻底理解ThreadLocal

    ThreadLocal是什么 早在JDK 1.2的版本中就提供Java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地 ...

  10. aspnetcore的那些actionresult们

    比MVC5多了n个actionresult,傻傻分不清,整理了下,妈妈再也不用担心了 https://docs.asp.net/projects/api/en/latest/autoapi/Micro ...