kvm虚拟机的克隆分为两种情况

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

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

1.  本机虚拟机直接克隆

(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

 

连接到域 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 ~]#

  

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

(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:11'/>
<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

(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 ]

  

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

 

转自:https://blog.51cto.com/koumm/1291793

 

 

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

  1. 关于kvm虚拟机的克隆方法总结

    kvm虚拟机的克隆分为两种情况,第一种kvm宿主机上对虚拟机直接克隆 第二种通过复制配置文件与磁盘文件的虚拟机复制克隆(适用于异机的静态迁移). 现笔者将分别两种kvm虚拟机克隆的的详细操作过程都记录 ...

  2. 转:KVM 虚拟机的克隆

    KVM 虚拟机的克隆 首先把需要克隆的源虚拟机先关闭,然后使用以下命令来进行克隆,注意我这里使用的是相对路径.   virsh shutdown VM02 virt-clone -o VM02 -n ...

  3. kvm虚拟机的克隆以及快照

    克隆(常见有3种方法) 1 直接克隆(克隆虚拟机使用自己的磁盘) virt-clone -o vm-01 -n vm-02 -f /kvm/os/vm-02.qcow2 virsh start vm- ...

  4. 烂泥:KVM虚拟机克隆

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 上一篇文章介绍了有关KVM虚拟机快照的创建与恢复,这篇文章我们来介绍有关KVM虚拟机克隆. KVM虚拟机的克隆,我们可以分以下几步: 1. 使用virt ...

  5. Linux中如何克隆KVM虚拟机

    转载:https://yq.aliyun.com/articles/64860 作者 digoal 日期 2016-11-11 标签 Linux , KVM , 虚拟化 , 克隆 背景 当需要批量部署 ...

  6. kvm虚拟化之kvm虚拟机克隆

    kvm虚拟机的克隆分为两种情况,本文也就通过以下两种情况进行克隆,克隆虚拟机为OEL5.8X64. (1) KVM主机本机虚拟机直接克隆. (2) 通过复制配置文件与磁盘文件的虚拟机复制克隆(适用于异 ...

  7. CentOS 6.9下KVM虚拟机通过virt-clone克隆虚拟机(转)

    一.virt-clone概述 1.virt-clone作用简介 virt-clone主要是用来克隆kvm虚拟机,并且通过Options.General Option.Storage Configura ...

  8. 如何克隆kvm虚拟机

    关于如何使用kvm虚拟化技术创建虚拟机,这里有一系列博客讲的已经非常清楚了,这里不再赘述,不过其中有些小坑可能需要大家注意: 0. 写在创建虚拟机之前(即教程的系列三之前) 1. 确认防火墙是否关闭, ...

  9. KVM虚拟机管理——虚拟机克隆

    1. 概述2. 部署基本操作系统虚拟机3. 配置虚拟机3.1 修改/etc/sysconfig/network3.2 删除/etc/sysconfig/network-scripts/ifcfg-et ...

随机推荐

  1. iOS - 常用宏定义和PCH文件知识点整理

    (一)PCH文件操作步骤演示: 第一步:图文所示: 第二步:图文所示: (二)常用宏定义整理: (1)常用Log日志宏(输出日志详细可定位某个类.某个函数.某一行) //=============== ...

  2. Spring Cloud Eureka的自我保护模式与实例下线剔除

    之前我说明了Eureka注册中心的保护模式,由于在该模式下不能剔除失效节点,故按原有配置在实际中不剔除总感觉不是太好,所以深入研究了一下.当然,这里重申一下,不管实例是否有效剔除,消费端实现Ribbo ...

  3. 微信支付H5支付开发文档

    参考文档如下:https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=4_2

  4. python 的三元操作符

    条件表达式(三元操作符)    1.有了这个三元操作符的条件表达式,你可以使用一条语句来完成下面的条件判断和赋值操作: x,y=4,5 if x<y: temp = x else: temp = ...

  5. kubernetes CRI 前世今生

    在学习kubernetes的过程中,我们会遇到CRI.CNI.CSI.OCI 等术语,本文试图先通过分析k8s目前默认的一种容器运行时架构,来帮助我们更好理解k8s 运行时背后设计逻辑.进而引出CRI ...

  6. Mysql 数据库部署(解压免安装)

    下载压缩包,解压. 在根目录下添加my.ini, 复制一下内容,保存. [mysqld] skip-grant-tables #绑定IPv4和3306端口 bind-address = 0.0.0.0 ...

  7. mysql中的case when then 的用法

    将立立饭饭的性别变更为女 ,烦烦 嗯嗯 问我的性别变更为男 update `table` set sex = ( case when sname in('立立','饭饭') then '女' else ...

  8. HttpWatch功能详细介绍

    来源:https://www.cnblogs.com/Chilam007/p/6947235.html HttpWatch是功能强大的网页数据分析工具,集成在IE工具栏,主要功能有网页摘要.cooki ...

  9. CF1256(div3 java题解)

    A: 题意:给定A个N元,B个一元,问是否可以凑成S元. 思路:A*i+j=S 即 A*I<=S<=A*I+B 即min(S/N,A)+B>=S: /* @author nimphy ...

  10. Eclipse IDE for java EE Developers下载和安装

    1.登录 http://www.eclipse.org/home/index.php ,下载Eclipse IDE for java EE Developers 2.解压缩压缩包到任意路径(推荐:G: ...