User Tools

Site Tools


unix:virtualization:virtlib:quickreference

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
unix:virtualization:virtlib:quickreference [2020/10/31 03:04] rodolicounix:virtualization:virtlib:quickreference [2021/04/22 21:04] rodolico
Line 11: Line 11:
 Some common commands are: Some common commands are:
   * **list --all** - list all domains virt-lib knows about and show their state (running, off, whatever)   * **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)   * **start //name//** - starts the domain named **name** (name from list --all)
   * **reboot //name//**   * **reboot //name//**
Line 22: Line 25:
     * attach-interface --domain pxe --type bridge --source br1 --model virtio --config --live     * 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     * detach-interface --domain pxe --type bridge --mac 52:54:00:47:2f:eb --config
 +  * Remove virtual image (config file only)<code bash> virsh undefine domainname</code>
  
 ==== Remove a network from the entire system ==== ==== Remove a network from the entire system ====
Line 36: Line 40:
     /path/to/libvirt/vm.domxml.cfg > vm.xenxl.cfg     /path/to/libvirt/vm.domxml.cfg > vm.xenxl.cfg
 </code> </code>
 +
 +==== 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.
 +
 +  - Add the --print-xml flag to virt-install, and pipe the output to a file.
 +  - Manually edit the resulting xml file, adding a second cdrom drive (copy/paste)
 +    - Change the drive letter
 +    - Change the target to point to virtio-win.iso
 +  - run virsh create name_of_xml_file to begin the installation
 +
  
 ==== Upgrading a disk to virtio (Unix) ==== ==== Upgrading a disk to virtio (Unix) ====
Line 46: Line 62:
  
 <code bash> <code bash>
 +# get a list of all the block devices
 +virsh domblklist router
 # detach the first drive (sda) from the domain router # detach the first drive (sda) from the domain router
 virsh detach-disk router sda --config virsh detach-disk router sda --config
Line 66: Line 84:
     - Shut down your Windows guest     - Shut down your Windows guest
   - Detach, then attach the primary drive.<code bash>   - Detach, then attach the primary drive.<code bash>
 +# get a list of all the block devices
 +virsh domblklist router
 # detach the first drive (sda) from the domain router # detach the first drive (sda) from the domain router
 virsh detach-disk domainname sda --config virsh detach-disk domainname sda --config
Line 75: Line 95:
 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. 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.
  
 +===== Shutdown and restart of Windows guests =====
 +
 +==== Problems shutting down with //virsh// ====
 +After installing the win-virtio package, you should see QEMU Guest Agent running as a service. With this running, you can use qemu-guest-agent to manage shutdown and reboot. This is much more reliable than using ACPI.
 +
 +**Important** Shut down the virtual before doing the following.
 +
 +Edit the guest
 +<code bash>
 +virsh edit DOMAIN
 +</code>
 +
 +Place the following block under the <devices> section. I usually put it after the <console> sections, but just so long as it is in the <devices> section of the config. Virsh will rearrainge it for you anyway.
 +
 +<code xml>
 +<channel type="unix">
 +  <source mode="bind"/>
 +  <target type="virtio" name="org.qemu.guest_agent.0"/>
 +</channel>
 +</code>
 +
 +Start the virtual back up. Once that is done you can use the following commands much more reliably.
 +<code bash>
 +virsh shutdown DOMAIN
 +virsh reboot DOMAIN
 +</code>
 +
 +This also allows you to execute //qemu-agent-command// from within //virsh//, but this is strongly discouraged unless you have researched what is going on. Any changes you make can cause instability in libvirt, since they are bypassing virsh. Kind of like using hdparm, where you can do Really Bad Things to your hard disk if you don't know for sure what you are doing. Do what you want, but be careful.
 +
 +==== Windows servers will not restart ====
 +
 +I'm having a problem with Windows virtuals not rebooting. When you issue the restart command, they shut off and don't come back up. As a band aid, I have a script running on the hypervisor with a cron job, every 5 minutes.
 +
 +This script has been tested on our machines, but I'm sure there are some issues with it. Just do a 
 +<code bash>
 +virsh list --all
 +</code>
 +and select the domains you want to ensure are running all the time. Place them in the array that has DOMAIN1 and DOMAIN2 (ie, replace DOMAIN1 with your first choice, etc...).
 +
 +When called, checkVirtuals will look for each of the domains and see if they are running (using //virsh list//). If they are not running, it will place a flag file in /tmp/DOMAIN.down. The next time it is run, it will note the domain is still not down, and the flag file exists, so it will start the domain (using //virsh start DOMAIN// and delete the flag file.
 +
 +I call this every 5 minutes from cron, thus, the max downtime will be 10 minutes, with an average of 5.
 +
 +**WARNING:** Remember this is running. If you need to take a virtual down for some reason, as long as this script is running, it will blindly go ahead and restart it.
 +
 +<code perl checkVirtuals>
 +#! /usr/bin/env perl
 +
 +use strict;
 +use warnings;
 +
 +my @servers = ( 
 +   'DOMAIN1',
 +   'DOMAIN2'
 +   );
 +   
 +my $virsh = '/usr/bin/virsh start ';
 +
 +my $output = `virsh list`;
 +
 +foreach my $server ( @servers ) {
 +   if ( $output =~ m/$server/ ) {
 +      unlink "/tmp/$server.down" if  -e "/tmp/$server.down";
 +   } else {
 +      if ( -e "/tmp/$server.down" ) {
 +         print "$server has been down for a while, starting back up\n";
 +         `$virsh $server`; 
 +         unlink "/tmp/$server.down";
 +      } else {
 +         `touch /tmp/$server.down`;
 +      }
 +   }
 +}
 +
 +1;
 +
 +</code>
 +
 +===== Replacing Network Interfaces =====
 +
 +Sometimes you need to undefine and redefine a network interface. This is actually fairly simple to do.
 +
 +<code bash>
 +# 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
 +</code>
 +
 +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.
 ==== Links ==== ==== Links ====
  
Line 80: Line 194:
   * https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/   * https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/
   * https://linuxhint.com/install_virtio_drivers_kvm_qemu_windows_vm/   * https://linuxhint.com/install_virtio_drivers_kvm_qemu_windows_vm/
 +  * https://serverfault.com/questions/672253/how-to-configure-and-use-qemu-guest-agent-in-ubuntu-12-04-my-main-aim-is-to-get#691616
 +  * https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/virtualization_administration_guide/sect-qemu_guest_agent-running_the_qemu_guest_agent_on_a_windows_guest
unix/virtualization/virtlib/quickreference.txt · Last modified: 2023/02/26 17:12 by rodolico