Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are KVM clones and snapshots

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The cloning and snapshots of KVM are clich é s, and there are a lot of data. Here are only records of personal experiments, which are easy to consult later.

Virtual machine cloning

The clone operation of the virtual machine is very frequent. After the first virtual machine is installed, the basic settings can be made. The virtual machine is already used as a template, and it can be cloned directly later, without the need for repeated system installation.

Cloning a virtual machine first requires shutting down or suspending the virtual machine.

[root@kvm7 vps] virsh shutdown vm01

Clone vm01 virtual machine to vm02

Virt-clone-o vm01-n vm02-f / home/vps/vm02.img

Cloning will take up a lot of disk IO, and if you are doing experiments in a virtual machine and a mechanical hard disk, the local computer will be very stuck.

If the virtual machine vm01 created earlier is configured with a fixed VNC port, then you need to modify the configuration file of vm02 to change the VNC port to something else to avoid conflicts, but there is no need to adjust if the state is autoport='yes'.

Virtual machine snapshot

Kvm snapshots can be created in two ways:

Qemu-img snapshot commands to generate snapshots virsh snapshot related commands to generate snapshots

After querying the qemu-img to generate a snapshot, the computer needs to be turned off, and many netizens reported that the data was lost. Relatively speaking, everyone recommends virsh snapshot to create a snapshot.

Https://www.51cto.com/it/news/2019/1125/16914.html

Https://article.pchome.net/content-2104480.html

Disk conversion

If the disk in raw format does not support snapshots, if it is in raw format, it needs to be converted to qcow2.

[root@kvm7 vps] qemu-img info vm01.imgimage: vm01.imgfile format: rawvirtual size: 10G (10737418240 bytes) disk size: 2.5G [root@kvm7 vps] qemu-img convert-f raw-O qcow2 vm01.img vm01.qcow2 # is copied and converted to qcow2 format in the virtual machine disk file directory [root@kvm7 vps] qemu-img info vm01.qcow2 image: vm01.qcow2file format: qcow2virtual size: 10G (10737418240 bytes) disk size: 2.3Gcluster_size: 65536

Create a snapshot

Create a snapshot of the virtual machine vm01:

[root@localhost vps] virsh snapshot-create vm01

View snapshots:

[root@kvm7 vps] virsh snapshot-list vm01 name Creation Time status-1481193249 2016-12-08 18:34:09 + 0800 running

The snapshot corresponding to the current virtual machine is stored in the / var/lib/libvirt/qemu/snapshot/vm01 directory, that is, a xml file. You can use the command to view the snapshot configuration:

[root@kvm7 vps] virsh snapshot-current vm01

Restore snapshot

Generate a few files in vm01 and then restore the snapshot for a simple test:

To restore a snapshot, you need to shut down the virtual machine, so shut down the vm01 host first:

[root@kvm7 vps] virsh shutdown vm01

Domain vm01 is closed

View the status of the virtual machine:

[root@kvm7 vps] virsh domstate vm01

Close

Perform restore snapshot: view to vm01 snapshot time is 1481193249

[root@kvm7 vps] virsh snapshot-revert vm01 1481193249

Compared with the three files created before, they are gone, and the snapshot has been restored successfully.

It is also easy to check whether a snapshot exists on the corresponding disk. The disk that created the snapshot will display the snapshot information through the info view:

[root@kvm7 vps] qemu-img info vm01.img image: vm01.imgfile format: qcow2virtual size: 8.0G (8589934592 bytes) disk size: 2.7Gcluster_size: 65536Snapshot list:ID TAG VM SIZE DATE VM CLOCK1 1481193249 212m 2016-12-08 18:34:09 0015 0015 25.775

Delete snapshot

[root@kvm7 vps] virsh snapshot-delete vm01 1481193249

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report