KVM/oVirt Commands

KVM and oVirt CLI commands for open-source virtualization.

Host Startup Procedure

Step 1: Power on KVM host

Boot the physical server

Step 2: Wait for host boot

Wait for Linux OS to fully boot

systemctl status libvirtd

Verify libvirt service is running

systemctl start libvirtd

Start libvirt service if stopped

Step 3: VMs auto-start

VMs with autostart enabled will boot automatically

virsh list --all

List all VMs and their states

systemctl status vdsmd

Verify VDSM service on oVirt host

Step 4: Check oVirt Engine

Verify oVirt Engine is accessible

systemctl status ovirt-engine

Check Engine service status

Host Shutdown Procedure

Step 1: Shutdown all VMs (KVM)

Gracefully shutdown all VMs

virsh list --state-running

List running VMs

virsh shutdown <vm-name>

Gracefully shutdown each VM

Step 2: Put host in maintenance (oVirt)

Move VMs to other hosts first

action host <host> deactivate

Put host in maintenance mode

Step 3: Stop services

Stop virtualization services

systemctl stop libvirtd

Stop libvirt service

systemctl stop vdsmd

Stop VDSM service

Step 4: Shutdown host

Gracefully shutdown the host

shutdown -h now

Shutdown the host immediately

reboot

Reboot the host (alternative)

VM Management - KVM/libvirt

virsh list --all

List all VMs

virsh dominfo <vm-name>

Display VM information

virsh start <vm-name>

Start VM

virsh shutdown <vm-name>

Graceful shutdown VM

virsh destroy <vm-name>

Force stop VM

virsh reboot <vm-name>

Reboot VM

virsh suspend <vm-name>

Pause VM

virsh resume <vm-name>

Resume paused VM

virsh autostart <vm-name>

Enable VM autostart

virsh autostart --disable <vm-name>

Disable VM autostart

virsh undefine <vm-name>

Delete VM definition

virsh undefine <vm-name> --remove-all-storage

Delete VM and storage

virt-install --name <name> --memory <MB> --vcpus <num> --disk path=<path>,size=<GB>

Create new VM

virsh setvcpus <vm-name> <count> --config --maximum

Set max vCPU count

virsh setmem <vm-name> <size-KB> --config

Set VM memory

VM Management - oVirt CLI

ovirt-shell

Start oVirt shell

list vms

List all VMs in oVirt shell

show vm <vm-name>

Display VM details

action vm <vm-name> start

Start VM

action vm <vm-name> stop

Stop VM

action vm <vm-name> shutdown

Graceful shutdown

action vm <vm-name> suspend

Suspend VM

add vm --name <name> --cluster-name <cluster> --template-name Blank

Create VM

update vm <vm-name> --memory <bytes>

Update VM memory

update vm <vm-name> --cpu-topology-cores <num>

Update CPU cores

Storage Management - KVM

virsh pool-list --all

List storage pools

virsh pool-define-as <name> dir --target <path>

Create directory pool

virsh pool-start <pool-name>

Start storage pool

virsh pool-autostart <pool-name>

Enable pool autostart

virsh pool-destroy <pool-name>

Stop storage pool

virsh vol-list <pool-name>

List volumes in pool

virsh vol-create-as <pool> <name> <size>G

Create volume

virsh vol-delete <volume> --pool <pool>

Delete volume

virsh vol-resize <volume> --pool <pool> <size>G

Resize volume

qemu-img create -f qcow2 <file> <size>G

Create qcow2 disk image

qemu-img info <file>

Display image information

qemu-img convert -f qcow2 -O raw <source> <dest>

Convert image format

qemu-img resize <file> +<size>G

Resize disk image

Storage Management - oVirt

list storagedo mains

List storage domains

show storagedomain <name>

Display storage domain details

list disks

List all disks

show disk <disk-id>

Display disk details

add disk --name <name> --size <GB> --storage-domain-name <domain>

Create disk

action disk <disk-id> attach --vm-name <vm>

Attach disk to VM

action disk <disk-id> detach

Detach disk from VM

Network Management - KVM

virsh net-list --all

List all networks

virsh net-info <network>

Display network information

virsh net-start <network>

Start network

virsh net-autostart <network>

Enable network autostart

virsh net-define <xml-file>

Define network from XML

virsh net-destroy <network>

Stop network

virsh net-undefine <network>

Delete network definition

virsh domiflist <vm-name>

List VM network interfaces

virsh attach-interface <vm> network <network> --model virtio --config

Add network interface to VM

virsh detach-interface <vm> network --mac <mac>

Remove network interface

ip link add <bridge> type bridge

Create Linux bridge

ip link set <interface> master <bridge>

Add interface to bridge

Network Management - oVirt

list networks

List all networks

show network <name>

Display network details

add network --name <name> --data_center-name <dc>

Create network

list nics --vm-name <vm>

List VM NICs

add nic --vm-name <vm> --network-name <network> --name <nic>

Add NIC to VM

delete nic <nic-id> --vm-name <vm>

Remove NIC from VM

Snapshot Management

virsh snapshot-create-as <vm> <snapshot-name>

Create snapshot

virsh snapshot-list <vm>

List VM snapshots

virsh snapshot-info <vm> <snapshot>

Display snapshot info

virsh snapshot-revert <vm> <snapshot>

Revert to snapshot

virsh snapshot-delete <vm> <snapshot>

Delete snapshot

action vm <vm> snapshot --description <desc>

Create VM snapshot

list snapshots --vm-name <vm>

List snapshots

action vm <vm> preview_snapshot --snapshot-id <id>

Preview snapshot

action vm <vm> undo_snapshot

Undo snapshot preview

delete snapshot <id> --vm-name <vm>

Delete snapshot

Migration & HA - oVirt

action vm <vm> migrate --host-name <target-host>

Migrate VM to another host

update vm <vm> --high_availability-enabled true

Enable HA for VM

update vm <vm> --high_availability-priority <num>

Set HA priority

list hosts

List all hosts in cluster

action host <host> fence

Fence (power manage) host

action host <host> activate

Activate host

action host <host> deactivate

Put host in maintenance

Monitoring & Troubleshooting

virsh nodeinfo

Display host node information

virsh nodecpustats

Display host CPU stats

virsh nodememstats

Display host memory stats

virsh domstats <vm>

Display VM statistics

virsh vcpuinfo <vm>

Display VM vCPU information

virsh console <vm>

Connect to VM console

virsh edit <vm>

Edit VM XML configuration

virsh dumpxml <vm>

Display VM XML definition

virt-top

Monitor VM resource usage (top-like)

journalctl -u libvirtd -f

Monitor libvirt logs

tail -f /var/log/libvirt/qemu/<vm>.log

Monitor VM QEMU logs

systemctl status vdsmd

Check VDSM status

vdsm-client Host getStats

Get host statistics

tail -f /var/log/vdsm/vdsm.log

Monitor VDSM logs