Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use KVM basic commands

Shulou Source: shulou.com Published: 2022-05-31 18:23:57 10月02日 Update

This article introduces the relevant knowledge of "how to use KVM basic commands". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

KVM (Kernel-based Virtual Machine) is a full-featured virtualization solution on x86 hardware platforms under Linux, consisting of a loadable kernel module kvm.ko providing and virtualizing core architecture and processor specification modules.

KVM allows multiple virtual machines, including Linux and Windows, to have their own hardware, including network cards, disks, and graphics adapters.

KVM VM related commands:

Start: virsh start test1

virsh shutdown test1

Forced shutdown: virsh destroy test1

reboot: virsh reboot test1

Start the host via the configuration file: virsh create/etc/libvirt/qemu/test1.xml

View host status: virsh list --all

Stop/hang virtual machine: virsh suspend test1

Save virtual machine: virsh save test1

Restore virtual machine: virsh resume test1

Create a new virtual machine from an existing device profile:

virsh dumpxml test1 >/etc/libvirt/qemu/test2.xmlqemu-img create -f qcow2 test2.img 20G Initialize installation of a Centos system using virt-install

# virt-install --connect qemu:///system \ #If you install using kvm and use root, default to this, based on xen or other, refer to man virt-install

--n test1 \ #Specifies the display name of the virtual machine

--c/mnt/centos6.4-x86_64.iso #Specify the installation image, you can also specify cdrom direct installation, such as:-c /dev/sr0

--r 2048 \ #Specifies memory, MB by default

--arch=x86_64 \ #Specify arch model

--vcpus=2 --check-cpu --cpuset=0-1 \ #Specify cpu0,1 as the CPU of the virtual machine, where CPU is bound

--os-type=linux --os-variant= rhel6\ #Specify system type and version

--disk path=/var/lib/libvirt/p_w_picpaths/test1.img,device=disk,bus=virtio,spare=true -s 10 \ #Specify disk information, load with virtio driver

--network bridge= br0\ #Specify bridge mode and bridge through br0 NIC

--noautoconsol --autostart \ #does not automatically open the console, and starts automatically with the host

--vnc #provides vnc port access, where you can set a password or not

--force

Modify Memory/CPU:

Modify memory size: virsh setmem test1 4G #Default unit is KB

Set maximum memory: virsh setmaxmem test1 8G

Increase the number of VCPUs: virsh setvcpus test1 8

Backup/Restore:

Backup: virsh save --bypass-cache test1 /var/lib/libvirt/save/test1_1.save --running

virsh restore/var/lib/libvirt/save/test1_1.save--bypass-cache --running

Snapshot Management:

If you want to use the snapshot function of kvm, you must use the disk format of qcow2, while raw only supports memory snapshots. If not, please refer to Section 3 for modifications.

View snapshot: virsh snapshot-list test1

Create snapshot: virsh snapshot-create test1 test1.snap1

Restore to snapshot: virsh snapshot-revert test1 test1.snap1

Delete snapshot: virsh snapshot-delete test1 test1.snap1

KVM virtual machine migration virsh migrate --live test1 qemu+tcp//destnationip/system tcp://destnationip"How to use KVM basic command" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Snapshot memory command host content disk foundation function backup more module knowledge hardware system network card reference configuration to this end learn something next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Linux MySQL Shulou Tech Info