Restore a virtual machine using an existing virtual disk (copy modifies an existing profile)

Source: Internet
Author: User

Restore a virtual machine using an existing virtual disk (copy modifies an existing profile)


Note: Here, using an existing disk, restart the virtual machine by copying the configuration file, and if the virtual machine's disk file is deleted, the virtual machine cannot be restored


First, build the test environment, shut down the virtual machine daixuan2, delete the configuration file, only the disk

[Email protected] ~]# Virsh list--all

Id Name Status

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

Daixuan4 Running

Daixuan2 Running

Daixuan1 Running

-Daixuan3 off

-Daixuan5 off


[Email protected] ~]# Virsh destroy Daixuan2

Domain daixuan2 is deleted


[Email protected] ~]# Virsh undefine daixuan2

Domain daixuan2 has been undefined


[Email protected] ~]# Virsh list--all

Id Name Status

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

Daixuan4 Running

Daixuan1 Running

-Daixuan3 off

-Daixuan5 off

[[email protected] ~]# ls/etc/libvirt/qemu///virtual machine daixuan2 configuration file Daixuan2.xml has been deleted

Autostart daixuan1.xml daixuan3.xml daixuan4.xml daixuan5.xml Networks


[[email protected] ~]# ls/data///Virtual Disk file Daixuan2.qcow2 exists, restore virtual machine through this file

Daixuan1_2.qcow2 daixuan2.qcow2 daixuan4.qcow2

Daixuan1.qcow2 Daixuan3.qcow2 Daixuan5.qcow2


Second, copy the configuration file and modify


1. Copy the configuration file

Method One, enter the virtual machine configuration file directory copy daixuan1 configuration file renamed to 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


Method Two, use the Dumpxml command to copy the virtual machine daixuan1 configuration file to the/etc/libvirt/qemu/directory and rename

[Email protected] ~]# Virsh dumpxml daixuan1 >/etc/libvirt/qemu/daixuan2.xml


2. Modify the configuration file

[Email protected] ~]# Cd/etc/libvirt/qemu

[Email protected] qemu]# VI daixuan2.xml

<name>daixuan1</name> virtual machine name Daixuan1 modified to daixuan2

<name>daixuan2</name>


<UUID>82C8EDA7-C875-18BB-34E3-3478C038CD30</uuid> modified to: 0->8 UUID cannot be duplicated

<UUID>82C8EDA7-C875-18BB-34E3-3478C038CD38</uuid>


<driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/>

<source file= '/data/daixuan1.qcow2 '/> file to daixuan2, note qcow2 or img format

<driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/>

<source file= '/data/daixuan2. Qcow2 '/>

[Email protected] qemu]# Virsh list--all

Id Name Status

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

Daixuan4 Running

Daixuan1 Running

-Daixuan3 off

-Daixuan5 off


3. Redefine the daixuan2 configuration file

[Email protected] qemu]# Virsh define/etc/libvirt/qemu/daixuan2.xml

Define domain daixuan2 (from/etc/libvirt/qemu/daixuan2.xml)


[Email protected] qemu]# Virsh list--all

Id Name Status

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

Daixuan4 Running

Daixuan1 Running

-Daixuan2 off

-Daixuan3 off

-Daixuan5 off

[Email protected] qemu]# Virsh start daixuan2

Domain Daixuan2 has started


4, do not restart the virtual machine online increase network card

[[email protected] qemu]# Virsh domiflist daixuan2//View the list of network cards for the DAIXUAN2 sub-machine

Interface Type Source Model MAC

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

Vnet2 Bridge br1 virtio 52:54:00:3a:2a:71


Add a network card to the command line:

[Email protected] qemu]# Virsh attach-interface daixuan2--type bridge--source BR1

Successful Attach interface


The network card added by the command line is only stored in memory, and the reboot is invalidated, so it needs to be saved to the configuration file, where/etc/libvirsh/qemu/daixuan2.xml is the configuration file of the Daixuan2 sub-machine

[Email protected] qemu]# Virsh dumpxml daixuan2 >/etc/libvirt/qemu/daixuan2.xml

[Email protected] qemu]# Virsh console daixuan2

Connect to the domain daixuan2

Escape character is ^]


ETH3 network card is added online.

[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)



This article is from the "Daixuan" blog, make sure to keep this source http://daixuan.blog.51cto.com/5426657/1743336

Restore a virtual machine using an existing virtual disk (copy modifies an existing profile)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.