User Tools

Site Tools


Sidebar

unix:virtualization:virtlib:quickreference

This is an old revision of the document!


virt-lib Quick Reference

virt-top

This is not always installed by default. When run, it will bring up a full console window that shows all virtuals running on a system, similar to the top command.

virsh

The main controller for virt-lib. The basic format of the command is

virsh command parameters

. man virsh or simply virsh –help are your friends.

Some common commands are:

  • list –all - list all domains virt-lib knows about and show their state (running, off, whatever)
  • vncdisplay name - show vnc display number (not port) assigned
  • dommemstat name - show allocated RAM
  • domstats name | grep vcpu.current - displays number of virtual cpu's assigned
  • start name - starts the domain named name (name from list –all)
  • reboot name
  • shutdown name
  • dumpxml name dumps the config to STDOUT
  • list –autostart - list all domains which will autostart
  • autostart domain - set domain to be autostarted in the future
  • autostart –disable domain - unset autostart flag for domain
  • console domain - attaches to the serial console of domain assuming the port has been set up.
    • attach-interface –domain pxe –type bridge –source br1 –model virtio –config –live
    • detach-interface –domain pxe –type bridge –mac 52:54:00:47:2f:eb –config

Remove a network from the entire system

virsh net-list --all
virsh net-destroy br1
virsh net-undefine br1
virsh net-list --all

convert config file to native

virsh -c xen:/// domxml-to-native --format xen-xl \
    /path/to/libvirt/vm.domxml.cfg > vm.xenxl.cfg

New Install of Windows with virtio

virt-install does not allow you to use two ISO's as cdrom images by default. This can be a problem when you want to do a new install, but want to use virtio on Windows (which requires a second ISO. You may be able to do a change-media, but the following, taken from https://superuser.com/questions/147419/using-virt-install-to-mount-multiple-cdrom-drives-images will do the trick with only one extra step.

  1. Add the –print-xml flag to virt-install, and pipe the output to a file.
  2. Manually edit the resulting xml file, adding a second cdrom drive (copy/paste)
    1. Change the drive letter
    2. Change the target to point to virtio-win.iso
  3. run virsh create name_of_xml_file to begin the installation

Upgrading a disk to virtio (Unix)

I messed up and did not use virtio as the bus for one of my setups, which resulted in horrible disk I/O. I could have rebuilt the virtual (it was a simple install and I had not gone very far), but I decided to learn how to do it the “right way”. The trick here is to detach the disk, then re-attach it with the proper parameters.

Warning Linux (and FreeBSD) have the virtio drivers built in, but Microsoft products do not. Read the section on Microsoft products if you are trying to do this with Windows.

In my case, I wanted to reconfigure the boot drive, so I needed the machine down. It was running under the scsi bus, and I wanted virtio. Note that his is using LVM2 as the back end.

# get a list of all the block devices
virsh domblklist router
# detach the first drive (sda) from the domain router
virsh detach-disk router sda --config
# reattach it using the virtio bus.
virsh attach-disk router /dev/vg/lvname sda --config --targetbus=virtio

Normally, you attach/detach disks from a running system. The –config parameter allows you to do it on an inactive domain; it just erases the entry, then rebuilds it.

Upgrading a disk to virtio (Windows)

For Windows, you need to have the correct device drivers installed before you change the disk. This assumes the domain is running

  1. Get a copy of the Windows VirtIO-win in iso onto your machine, someplace virsh can access, and mount the ISO
    1. Download ISO
      cd /media/virtstorage && wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
    2. Mount it on a running system
      virsh attach-disk domainname /media/virtstorage/stable-virtio/virtio-win.iso hdc --type cdrom --mode readonly
  2. Create a temporary disk and attach it. Use virtio for the format of it.
    1. virsh attach-disk domainname /path/to/disk/image sdb --targetbus=virtio
  3. Open your console to the windows domain
    1. Find the new diskdisk (sdb). It will have a yellow triangle, indicating it can not be read because there is no device driver. Right click and say “Update Driver”, then go find the drivers from the CD.
    2. Shut down your Windows guest
  4. Detach, then attach the primary drive.
    # get a list of all the block devices
    virsh domblklist router
    # detach the first drive (sda) from the domain router
    virsh detach-disk domainname sda --config
    # reattach it using the virtio bus.
    virsh attach-disk domainname /dev/vg/lvname sda --config --targetbus=virtio
  5. Start the Windows guest back up. Since the drivers are already installed, it should come back up.

I did this with a Windows 10 installation on my workstation. Prior to using virtio, it would take, literally, 5-7 minutes after boot before I could do anything, and it was very sluggish after that. Once I used virtio, it was almost bare hardware speeds.

Replacing Network Interfaces

Sometimes you need to undefine and redefine a network interface. This is actually fairly simple to do.

# get a list of all network interfaces in domain
virsh domiflist domain
# remove the one you want. Use values (type, mac) from above command
virsh detach-interface domain --type bridge --mac ##:##:##:##:##:## --config
# redefine it. Use values from above command, or change as needed
virsh attach-interface domain --type bridge --source br_private --mac ##:##:##:##:##:## --model virtio --config

In this example, domain is the name of the domain to be worked on. I use domiflist to get information about the network interfaces as I need the type and mac. The –config makes it permanent, writing it to the config file.

In my case, I had built a Windows domain without using virtio, and I wanted to change it. This was actually the simplest way I found to do it.

unix/virtualization/virtlib/quickreference.1615185190.txt.gz · Last modified: 2021/03/08 00:33 by rodolico