unix:virtualization:virtlib:quickreference
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
unix:virtualization:virtlib:quickreference [2021/04/21 23:18] – rodolico | unix:virtualization:virtlib:quickreference [2022/10/31 23:12] – c/libvirt/ rodolico | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== virt-lib Quick Reference ====== | ====== virt-lib Quick Reference ====== | ||
+ | |||
+ | virtlib stores its configuration for each //domain// (virtual) in / | ||
+ | |||
+ | The xml files are, well, xml. The format is documented at https:// | ||
===== virt-top ===== | ===== virt-top ===== | ||
Line 14: | Line 18: | ||
* **dommemstat //name//** - show allocated RAM | * **dommemstat //name//** - show allocated RAM | ||
* **domstats //name// | grep vcpu.current** - displays number of virtual cpu's assigned | * **domstats //name// | grep vcpu.current** - displays number of virtual cpu's assigned | ||
+ | * **domblklist //name//** - show attached block devices | ||
+ | * **domiflist //name//** - list all domain interfaces | ||
* **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 23: | Line 29: | ||
* **console domain** - attaches to the serial console of domain assuming the port has been set up. | * **console domain** - attaches to the serial console of domain assuming the port has been set up. | ||
* Attach/ | * Attach/ | ||
- | * attach-interface | + | * attach-interface |
- | * detach-interface | + | * This will attach a new bridge to domain //domain//, using //bridge// defined on hypervisor, called vnet3 on the virtual, with the mac address set to whatever you use. |
+ | * detach-interface | ||
* Remove virtual image (config file only)< | * Remove virtual image (config file only)< | ||
+ | * **change-media //name// //drive//** - Insert or Eject a CDROM | ||
+ | * change-media //name// //drive// --eject | ||
+ | * change-media //name// //drive// // | ||
+ | |||
+ | ==== Boot from CD ROM ==== | ||
+ | |||
+ | This is actually not intuitive. I'm going to describe how to do this from a pretty complex setup with no GUI; adjust as needed. In this case, we need to boot the virtual myvirt from a gparted cdrom image located in / | ||
+ | |||
+ | Both assume the virtual has been turned off <code bash> | ||
+ | |||
+ | Some people do not want to manually edit the XML used to configure the virtuals, others prefer it. Some things, like setting a boot menu with a realistic timeout appear to require it; I have not found a way to do it through the virsh command. | ||
+ | |||
+ | I use the --config flag a lot. If you use this flag, any changes you make are written to the config file and will persist across boots. | ||
+ | |||
+ | === without manually editing configuration === | ||
+ | - First, see if there is a cdrom installed. One simple way is to dump the xml and grep for cdrom< | ||
+ | - Once this is done and you have a cdrom, you should be able to tell which one it is with< | ||
+ | - Mount your image on the CDROM | ||
+ | - If you have one and you know which drive it is<code bash> | ||
+ | - If you do not have a CDROM, use<code bash> | ||
+ | |||
+ | === I'm not afraid to edit the config === | ||
+ | - Edit the config file with <code bash> | ||
+ | - Look for something like //<disk type=' | ||
+ | - If it exists, add <code xml>< | ||
+ | - Look for the section //< | ||
+ | - <code xml>< | ||
+ | - This will enable the boot menu, and have a wait of 5 seconds (5000 milliseconds) for you to choose. | ||
+ | - If you want, change the boot order by adding <code xml>< | ||
+ | |||
+ | === Starting the virtual === | ||
+ | - Start the virtual with <code bash> | ||
+ | - Immediately make the VNC connection (if you followed the manual edit, you have 5 seconds) | ||
+ | - When prompted, press ESC to choose the CDROM drive (assuming you didn't set it as the default) | ||
+ | === Cleanup === | ||
+ | Do the following if you want to remove the CDROM when you're done. Note: this is likely required if you set the CDROM as the primary boot device. | ||
+ | <code bash> | ||
+ | |||
+ | |||
==== Remove a network from the entire system ==== | ==== Remove a network from the entire system ==== | ||
Line 45: | Line 91: | ||
// | // | ||
]] will do the trick with only one extra step. | ]] will do the trick with only one extra step. | ||
+ | |||
+ | **Note**: You may have to manually start the virtual several times during the installation. Windows reboots 2-3 times during an installation, | ||
- Add the --print-xml flag to virt-install, | - Add the --print-xml flag to virt-install, | ||
Line 50: | Line 98: | ||
- Change the drive letter | - Change the drive letter | ||
- Change the target to point to virtio-win.iso | - Change the target to point to virtio-win.iso | ||
- | - run virsh create name_of_xml_file to begin the installation | + | - run <code bash>virsh create name_of_xml_file</ |
+ | - After installation is complete, install the remainder of the virtio drivers for maximum efficiency | ||
+ | - To permanently define after installation | ||
+ | - Edit XML and remove the second CDROM (if desired) | ||
+ | - <code bash> | ||
Line 98: | Line 150: | ||
==== Problems shutting down with //virsh// ==== | ==== Problems shutting down with //virsh// ==== | ||
- | After installing the win-virtio package, you can use qemu-guest-agent to manage shutdown and reboot. This is much more reliable than using ACPI. | + | 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 | Edit the guest | ||
Line 114: | Line 168: | ||
</ | </ | ||
- | You will need to restart | + | Start the virtual |
<code bash> | <code bash> | ||
virsh shutdown DOMAIN | virsh shutdown DOMAIN | ||
virsh reboot DOMAIN | virsh reboot DOMAIN | ||
+ | </ | ||
+ | |||
+ | This also allows you to execute // | ||
+ | |||
+ | ==== Using save/ | ||
+ | |||
+ | An alternative is to use //virsh save// to shut down and //virsh restore// to recover. In this case, use | ||
+ | <code bash> | ||
+ | virsh save domainname / | ||
+ | </ | ||
+ | to save the image. It will suspend the virtual, then save processor/ | ||
+ | |||
+ | Once this is done, you can do whatever you needed to do, then use the following command to restore it. | ||
+ | <code bash> | ||
+ | virsh restore / | ||
</ | </ | ||
Line 124: | Line 193: | ||
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. | 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 | ||
+ | </ | ||
+ | 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 / | ||
+ | |||
+ | I call this every 5 minutes from cron, thus, the max downtime will be 10 minutes, with an average of 5. | ||
+ | |||
+ | **WARNING: | ||
+ | |||
+ | <code perl checkVirtuals> | ||
+ | #! / | ||
+ | |||
+ | use strict; | ||
+ | use warnings; | ||
+ | |||
+ | my @servers = ( | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | |||
+ | my $virsh = '/ | ||
+ | |||
+ | my $output = `virsh list`; | ||
+ | |||
+ | foreach my $server ( @servers ) { | ||
+ | if ( $output =~ m/$server/ ) { | ||
+ | unlink "/ | ||
+ | } else { | ||
+ | if ( -e "/ | ||
+ | print " | ||
+ | | ||
+ | | ||
+ | } else { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | 1; | ||
+ | |||
+ | </ | ||
===== Replacing Network Interfaces ===== | ===== Replacing Network Interfaces ===== | ||
Line 135: | Line 248: | ||
virsh detach-interface domain --type bridge --mac ##:##:##:##:##:## | virsh detach-interface domain --type bridge --mac ##:##:##:##:##:## | ||
# redefine it. Use values from above command, or change as needed | # redefine it. Use values from above command, or change as needed | ||
- | virsh attach-interface domain --type bridge --source br_private --mac ##:##:##:##:##:## | + | virsh attach-interface domain --type bridge |
</ | </ | ||
Line 141: | Line 254: | ||
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. | 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 ==== | + | |
+ | ===== Naming Network | ||
+ | |||
+ | to give a domain interface a static name when it is run, you can add the following to the interface definition. | ||
+ | <code xml>< | ||
+ | NOTE: the name must not begin with ' | ||
+ | https:// | ||
+ | <code xml> | ||
+ | < | ||
+ | <mac address=' | ||
+ | <source bridge=' | ||
+ | <target dev=' | ||
+ | <model type=' | ||
+ | <address type=' | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | You can now do things like <code bash> | ||
+ | |||
+ | ===== Links ===== | ||
* https:// | * https:// | ||
Line 148: | Line 280: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
+ |
unix/virtualization/virtlib/quickreference.txt · Last modified: 2023/02/26 17:12 by rodolico