virsh
virsh[1][2] is a command line utility for managing virsh guest domains/virtual machines and the hypervisor[3]. Can be used to operate vm like create, list, start, shutdown or suspend and to manage storage, snapshots and checkpoints[4] among other actions. virt-manager is a graphical alternative to virsh. It supports Xen, QEMU, KVM, LXC, OpenVZ, VirtualBox and VMware ESX.
virsh is include in libvirt-client package in RHEL and Ubuntu and uses libvirt management API. Binaries included:
Contents
Basic Commands[edit]
virshvirsh -r
All Commands[edit]
virsh --connectvirsh -c qemu:///system list
virsh attach-devicevirsh autostart VM_NAMEorvirsh autostart VM_NAME --disable(Related:virsh startandvirsh pool-autostart)virsh blockcommit. Allows Live-disk-backup-with-active-blockcommit [5]virsh blockcopyvirsh blockjobvirsh blockresizevirsh change-mediavirsh create MY_XML_VM_DEFINITION.XML/virsh console YOUR_VMvirsh define MY_XML_VM_DEFINITION.XML(define machine but do not start it)virsh define xmlfile.xml --validatevirsh destroy VM_MACHINE_NAME(Ungraceful Shutdown but do not destroy data or VM but you can corrupt guest file systems)virsh destroy VM_MACHINE_NAME --graceful
virsh domblklist VMNAMEvirsh domblklist --details VM_MACHINE_NAME
virsh domblkstat VMNAMEvirsh domblkinfo VMNAME BLOCK_DEVICE(BLOCK_DEVICE from virsh domblklist command)virsh domdisplayvirsh domfsfreezeQuiesces the guest filesystem in isolation[6]virsh domfsthawQuiesces the guest filesystem in isolation[7]virsh domidvirsh dominfo VMNAME_OR_IDGuess virtual machine information such us state and autostart configuration.virsh dommemstatvirsh domnamevirsh domrename(since 2015)virsh dump --memory-only --verbosevirsh dumpxml VMNAME- domain information in XML (Can be used to move VMs between hosts [8])virsh edit VMNAMEvirsh listvirsh list --name
virsh memtunevirsh migratevirsh pool-autostartvirsh pool-buildvirsh pool-createcreate temporary storage pools from command linevirsh pool-create-ascreate temporary storage pools from XML filevirsh pool-define(create persistent storage from options from XML file)[9]virsh pool-define-as(create persistent storage from options from command line)[10]virsh pool-eventvirsh rebootvirsh restorevirsh resumevirsh savevirsh set-lifecycle-action. Added in November 2017 (v.3.9.0)[11]virsh setmaxmemvirsh setmemvirsh setmem —-config
virsh setvcpusvirsh snapshot-create-asvirsh startvirsh suspendvirsh shutdownvirsh undefinevirsh update-devicevirsh vcpuinfovirsh vncdisplayvirsh backup-beginvirsh checkpoint-createvirsh nodedev-list --treevirsh nodedev-dumpxmlvirsh nodedev-dettach
Getting Information[edit]
- List Running Virtual Machines:
virsh list[12][13]virsh list --namevirsh list --all
virsh dominfo MY_VM_NAMEGuess virtual machine information such us state and autostart configuration.
virsh domstats(show all VMs)virsh domstats --list-persistentvirsh domstats MY_VM_MACHINEvirsh domstats MY_VM_MACHINE --state- --no-wait option https://libvirt.org/news.html
- View configuration:
virsh dumpxml {guest-id, VM_NAME or uuid}> yourfilename.xml[14]- Virtual interfaces:
virsh domiflist VM_NAME
Network info:
Storage info:
virsh pool-listvirsh pool-info <pool>virsh vol-list <pool>(Displays Name and Path)virsh vol-list --details <pool>(Includes also Capacity and Allocation)
virsh vol-info <vol>
virsh vncdisplay VM_NAMEvirsh domdisplay VM_NAME
Guest info:
virsh guestinfov5.7.0 (2019-09-03)[15] (Libvirt Release notes)
virhostuptime(Since August 2019) https://github.com/libvirt/libvirt/commit/8b802f13cb47817706cba101f5d52e2c8957698d#diff-8d027e5576f9d83750bb73c63b12a6e3
Operations[edit]
Changing VM running status operations:
- Start VM:
virsh start VM_MACHINE_NAME - Shutdown VM:
virsh shutdown(stop) Gracefully VM - Reboot VM:
virsh rebootRestart VM - Reset VM:
virsh resetemulates the power reset button on a machine - Resume VM:
virsh resume - Destroy VM:
virsh destroy VM_NAME(Ungraceful Shutdown/stop VM. Actually do not destroy data or VM but you can corrupt guest file systems)virsh destroy VM_MACHINE_NAME --graceful
virsh suspend- Create:
virsh define virsh undefine
virsh console VM_MACHINE_NAME
Snapshots:
virsh snapshot-createvirsh snapshot-create--validate (08/2019) [16]
Migrations:
virsh migrate --live GuestName DestinationURLvirsh migrate --offline[17] (copying non-shared storage or other file based storages (e.g. UEFI variable storage) is not supported during offline migration)
Configuration:
virsh autostart VM_MACHINE_NAME
Virsh Storage commands[edit]
Virsh Storage Information[edit]
virsh domblklist VMNAMEvirsh domblkinfovirsh pool-listvirsh pool-list --all --details
virsh pool-info <pool>virsh vol-info <vol>virsh vol-list <pool>(Displays Name and Path)virsh vol-list --details <pool>(Includes also Capacity and Allocation)
All Storage commands[edit]
virsh domblklist VMNAMEvirsh domblkinfovirsh pool-autostartvirsh pool-buildvirsh pool-createcreate temporary storage pools from command linevirsh pool-create-ascreate temporary storage pools from XML filevirsh pool-define(create persistent storage from options from XML file)[18]virsh pool-define-as(create persistent storage from options from command line)[19]virsh pool-eventvirsh pool-event --listvirsh pool-event --event lifecyclevirsh pool-event --event refresh
virsh pool-listvirsh pool-info <pool>virsh pool-start <pool>virsh vol-clonevirsh vol-create-asvirsh vol-info --pool POOL_NAME VOL_NAMEvirsh vol-list <pool>
Virsh Snapshots[edit]
virsh snapshot-createCreate a snapshot from XML. See also:qemu-imgandqemu-img infovirsh snapshot-create-asCreate a snapshot from a set of args.virsh snapshot-currentGet or set the current snapshotvirsh snapshot-dumpxml VM_MACHINE_NAME SNAPSHOT_NAMEDump XML for a domain snapshotvirsh snapshot-editedit XML for a snapshotvirsh snapshot-infosnapshot information. (virsh snapshot-info --domain DOMAIN_NAME --snapshotname SNAPSHOT_NAME)virsh snapshot-list VM_MACHINE_NAMEList snapshots for a domainvirsh snapshot-parentGet the name of the parent of a snapshotvirsh snapshot-revert(Destructive action) revert a domain to a snapshotvirsh snapshot-deleteDelete a domain snapshot
Virsh CPU Commands[edit]
virsh cpu-models x86_64virsh setvcpus
Virsh Memory Commands[edit]
virsh Memory Commands: virsh setmaxmem, virsh setmem, virsh dommemstat
QEMU[edit]
virsh qemu-attachQEMU Attachvirsh qemu-monitor-commandQEMU Monitor Commandvirsh qemu-monitor-eventQEMU Monitor Eventsvirsh qemu-monitor-event VM_MACHINE_NAME
virsh qemu-agent-commandQEMU Guest Agent Command
Networking[edit]
virsh domifaddrvirsh domiflistvirsh net-autostartautostart a networkvirsh net-createcreate a network from an XML filevirsh net-definedefine an inactive persistent virtual network or modify an existing persistent one from an XML filevirsh net-destroydestroy (stop) a networkvirsh net-dhcp-leasesprint DHCP lease info for a given networkvirsh net-dumpxmlNET_NAME network information in XMLvirsh net-editedit XML configuration for a networkvirsh net-eventNetwork Eventsvirsh net-infonetwork informationvirsh net-listlist networksvirsh net-nameconvert a network UUID to network namevirsh net-startstart a (previously defined) inactive networkvirsh net-undefineundefine a persistent networkvirsh net-updateupdate parts of an existing network's configurationvirsh net-uuidconvert a network name to network UUID
Activities[edit]
- Review virsh command cheatsheet https://computingforgeeks.com/virsh-commands-cheatsheet/
- Read https://github.com/libvirt/libvirt/blob/master/tools/virsh.c source code.
- Enable access to your VM Machines via virsh console command
- Learn difference between
virsh defineandvirsh create - Create Live backups with active virsh blockcommit[20]
- Offline Migrate or move a virtual machine between two KVM servers without shared storage[21]:
virsh dumpxmlandvirsh define
See also[edit]
virtinstpackage[22], includes following python binaries:virt-clone,virt-convert,virt-install[23]- virt-top 'top'-like utility for virtualization stats
- ovirt-RHV module
- virt-admin
- libvirtd:
systemctl status libvirtd,systemctl status libvirt-guests, Libvirt release notes, logs,libvirtd.conf,/etc/libvirt/,/var/log/libvirt/ - KVM, Installation, QEMU,
virsh,virtinst,libguestfs-tools, libvirt, qemu, Red Hat Virtualization (RHV), MacVTap, Virtio, oVirt, KVM services, KVM networking, KVM graphics, CPU, KVM on ARM virsh: Storage information, Connecting, Operations, Memory, Snapshots, Networking, CPU, release notes,virsh nodedev-list
References[edit]
- ↑ http://manpages.ubuntu.com/manpages/xenial/man1/virsh.1.html
- ↑ https://github.com/libvirt/libvirt/blob/master/tools/virsh.c
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/virtualization/chap-virtualization-managing_guests_with_virsh
- ↑ https://github.com/libvirt/libvirt/commit/689beaa47c51fb49fafa992dd468116b8f6b0782#diff-f41fa7374ab97c527387ea4ce48fd04e
- ↑ https://wiki.libvirt.org/page/Live-disk-backup-with-active-blockcommit
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/sect-using_the_qemu_guest_virtual_machine_agent_protocol_cli-libvirt_commands
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/sect-using_the_qemu_guest_virtual_machine_agent_protocol_cli-libvirt_commands
- ↑ https://serverfault.com/questions/434064/correct-way-to-move-kvm-vm
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_and_managing_virtualization/index#creating-storage-for-virtual-machines-using-the-cli_managing-storage-for-virtual-machines-using-the-cli
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_and_managing_virtualization/index#creating-storage-for-virtual-machines-using-the-cli_managing-storage-for-virtual-machines-using-the-cli
- ↑ https://libvirt.org/news.html
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/virtualization/chap-virtualization-managing_guests_with_virsh
- ↑ https://help.ubuntu.com/community/KVM/Managing
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/sect-domain_commands-creating_a_virtual_machine_xml_dump_configuration_file
- ↑ https://fossies.org/linux/libvirt/NEWS
- ↑ https://libvirt.org/news.html
- ↑ https://libvirt.org/migration.html#offline
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_and_managing_virtualization/index#creating-storage-for-virtual-machines-using-the-cli_managing-storage-for-virtual-machines-using-the-cli
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_and_managing_virtualization/index#creating-storage-for-virtual-machines-using-the-cli_managing-storage-for-virtual-machines-using-the-cli
- ↑ https://wiki.libvirt.org/page/Live-disk-backup-with-active-blockcommit
- ↑ https://serverfault.com/questions/434064/correct-way-to-move-kvm-vm
- ↑ https://github.com/virt-manager/virt-manager/tree/master/virtinst
- ↑ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_virtualization/getting-started-with-virtualization-in-rhel-8_configuring-and-managing-virtualization
Script error: No such module "Check for unknown parameters".
Advertising: