使用现有的虚拟磁盘恢复虚拟机(拷贝修改现有配置文件)

使用现有的虚拟磁盘恢复虚拟机(拷贝修改现有配置文件)


注:这里使用现有的磁盘,通过拷贝修改配置文件重新启动虚拟机,如果该虚拟机的磁盘文件被删除,则虚拟机就无法恢复了

一、搭建测试环境,关闭虚拟机daixuan2,删除配置文件,只剩下磁盘

[[email protected] ~]# virsh list --all

Id    名称                         状态

----------------------------------------------------

22    daixuan4                       running

26    daixuan2                       running

27    daixuan1                       running

-     daixuan3                       关闭

-     daixuan5                       关闭

[[email protected] ~]# virsh destroy daixuan2

域 daixuan2 被删除

[[email protected] ~]# virsh undefine daixuan2

域 daixuan2 已经被取消定义

[[email protected] ~]# virsh list --all

Id    名称                         状态

----------------------------------------------------

22    daixuan4                       running

27    daixuan1                       running

-     daixuan3                       关闭

-     daixuan5                       关闭

[[email protected] ~]# ls /etc/libvirt/qemu/  //虚拟机daixuan2的配置文件daixuan2.xml已经被删除

autostart  daixuan1.xml  daixuan3.xml  daixuan4.xml  daixuan5.xml  networks

[[email protected] ~]# ls /data/  //虚拟磁盘文件daixuan2.qcow2存在,通过该文件恢复虚拟机

daixuan1_2.qcow2  daixuan2.qcow2  daixuan4.qcow2

daixuan1.qcow2    daixuan3.qcow2  daixuan5.qcow2


二、拷贝配置文件并修改

1、拷贝配置文件

方法一、进入虚拟机的配置文件目录拷贝daixuan1的配置文件改名为daixuan2.xml

[[email protected] ~]# cd /etc/libvirt/qemu

[[email protected] qemu]# ls

autostart  daixuan1.xml  daixuan3.xml  daixuan4.xml  daixuan5.xml  networks

[[email protected] qemu]# cp daixuan1.xml daixuan2.xml

方法二、使用dumpxml命令拷贝虚拟机daixuan1的配置文件到/etc/libvirt/qemu/目录并重命名

[[email protected] ~]# virsh dumpxml daixuan1 > /etc/libvirt/qemu/daixuan2.xml

2、修改配置文件

[[email protected] ~]# cd /etc/libvirt/qemu

[[email protected] qemu]# vi daixuan2.xml

<name>daixuan1</name>  虚拟机名称daixuan1修改为daixuan2

<name>daixuan2</name>

<uuid>82c8eda7-c875-18bb-34e3-3478c038cd30</uuid>  修改为:0->8 UUID不能重复

<uuid>82c8eda7-c875-18bb-34e3-3478c038cd38</uuid>

<driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/>

<source file=‘/data/daixuan1.qcow2‘/>  文件改为daixuan2,注意是qcow2还是img格式

<driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/>

<source file=‘/data/daixuan2.qcow2‘/>

[[email protected] qemu]# virsh list --all

Id    名称                         状态

----------------------------------------------------

22    daixuan4                       running

27    daixuan1                       running

-     daixuan3                       关闭

-     daixuan5                       关闭

3、重新定义daixuan2的配置文件

[[email protected] qemu]# virsh define /etc/libvirt/qemu/daixuan2.xml

定义域 daixuan2(从 /etc/libvirt/qemu/daixuan2.xml)

[[email protected] qemu]# virsh list --all

Id    名称                         状态

----------------------------------------------------

22    daixuan4                       running

27    daixuan1                       running

-     daixuan2                       关闭

-     daixuan3                       关闭

-     daixuan5                       关闭

[[email protected] qemu]# virsh start daixuan2

域 daixuan2 已开始

4、不重启虚拟机在线增加网卡

[[email protected] qemu]# virsh domiflist daixuan2  //查看daixuan2子机的网卡列表

Interface  Type       Source     Model       MAC

-------------------------------------------------------

vnet2      bridge     br1        virtio      52:54:00:3a:2a:71

命令行增加一块网卡:

[[email protected] qemu]# virsh attach-interface daixuan2 --type bridge --source br1

成功附加接口

命令行增加的网卡只保存在内存中,重启就失效,所以需要保存到配置文件中,其中 /etc/libvirsh/qemu/daixuan2.xml 为daixuan2子机的配置文件

[[email protected] qemu]# virsh dumpxml daixuan2 > /etc/libvirt/qemu/daixuan2.xml

[[email protected] qemu]# virsh console daixuan2

连接到域 daixuan2

Escape character is ^]

在线增加了eth3网卡

[[email protected] ~]# ifconfig -a

eth3      Link encap:Ethernet  HWaddr 52:54:00:3A:2A:71

BROADCAST MULTICAST  MTU:1500  Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

eth4      Link encap:Ethernet  HWaddr 52:54:00:A6:C7:6A

BROADCAST MULTICAST  MTU:1500  Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Interrupt:11 Base address:0x8000

lo        Link encap:Local Loopback

inet addr:127.0.0.1  Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING  MTU:65536  Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

时间: 2025-01-06 14:05:50

使用现有的虚拟磁盘恢复虚拟机(拷贝修改现有配置文件)的相关文章

虚拟磁盘恢复虚拟机

虚拟机配置文件路径:/etc/libvirt/qemu 先copy一份虚拟机配置文件: virsh dumpxml  xrc2 > /etc/libvirt/qemu/xrc1.xml vi xrc1.xml  ,修改name,uid,以及disk路径 virsh define  /etc/libvirt/qemu/xrc1.xml  重新定义域

KVM ---- 通过虚拟磁盘恢复虚拟机

1.查看  必须先关闭子机 也就是不能running [[email protected] qemu]# virsh list --allId    Name                           State-----------------------------------------------------     caimz1                         shut off-     caimz2                         shut

2.4-虚拟磁盘恢复虚拟机

如果要彻底删除虚拟机,需要3条命令 1.virsh destroy wyp1           #首先从列表中删除 2.virsh undefine wyp1          #删除虚拟机的配置文件. 3.rm -rf /data/wyp1.img        #最后删除虚拟机的文件 如果此时想在恢复虚拟机wyp1,必须要有img文件,否则首先复制一份wyp2.img文件为wyp1.img 在复制一份虚拟机配置文件. 1.cp /data/wyp2.img /data/wyp1.img  

解决克隆 centos虚拟机后修改克隆后的机器的ip、mac、uuid失败的问题

解决办法: So here’s how we fix it: Remove the kernel’s networking interface rules file so that it can be regenerated # rm -f /etc/udev/rules.d/70-persistent-net.rules Restart the VM # reboot UPDATE your interface configuration file # vi /etc/sysconfig/ne

linux(Centos)修改现有用户名

对现有的用户名不满意,如拼写错误,用户名过长等,可使用系统管理命令 System Management Commands 进行修改. man出来看看 vipw, vigr - edit the password, group, shadow-password or shadow-group file vipw,vigr用于修改系统中 password,group,sheadow-password ,shadow-group 这些设计权限管理的文件. 当仅修改现有用户的文件名时,如下: vipw 

openstack宿主机故障时从云硬盘恢复虚拟机

1.在web界面找到要恢复的虚拟机 2.查看虚拟机的云硬盘ID 3.列如:云硬盘的ID是 49a426c8-6a9c-4047-a100-8ad07885952c 4.从数据库cinder库中,卸载云硬盘和虚拟机的挂载 1).查看此云硬盘的信息 mysql> select * from volumes where id="49a426c8-6a9c-4047-a100-8ad07885952c"; +---------------------+------------------

使用Veeam Backup &amp; Replication 9.5 U3备份恢复虚拟机

对于VMware vSphere虚拟化架构虚拟机备份来说,有多种方式,比较常用的是使用官方发布的VDP备份工具以及第三方工具,本文介绍如何使用Veeam Backup & Replication 9.5 U3备份恢复虚拟机. 第1步,准备好WINDOWS虚拟机(也支持在物理服务器运行),运行Veeam Backup & Replication 9.5 U3安装程序. 第2步,部署Veeam Backup & Replication 9.5 U3需要.NET支持. 第3步,接受许可协

Docker Toolbox虚拟机文件地址修改 以及镜像加速

Docker Toolbox虚拟机文件地址修改  默认情况下,docker-machine创建的虚拟机文件,是保存在C盘的C:\Users\用户名\.docker\machine\machines\default 目录下的,如果下载和使用的镜像过多,那么必然导致该文件夹膨胀过大,如果C盘比较吃紧,那么我们就得考虑把该虚拟机移到另一个盘上.具体操作如下 powershell输入docker-machine stop default 停止虚拟机 打开VirtualBox,选择"管理"菜单下

虚拟机怎么修改IP地址

今天要说的是在虚拟机里面修改IP地址,无线是Windows系统还是luix系统里面设置方法都大同小异,今天介绍的更是简单,一个软件就可以了. 虚拟机换IP后可以脱离母机的IP,各持不同IP,只需要在虚拟机中下载一个<深度IP转换器>软件,需要哪里的IP连接之后IP就改变了,非常简单. 原文地址:https://blog.51cto.com/12983014/2383617