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
unix:virtualization:virtlib:quickreference [2022/03/05 14:58] rodolicounix:virtualization:virtlib:quickreference [2023/02/26 17:12] (current) rodolico
Line 1: Line 1:
 ====== virt-lib Quick Reference ====== ====== virt-lib Quick Reference ======
 +
 +virtlib stores its configuration for each //domain// (virtual) in /etc/libvirt/qemu*.xml. You should not manually modify anything in this directory, but you can safely do any read-only operation. To edit/export/whatever, the //virsh// command has several options that will help you out.
 +
 +The xml files are, well, xml. The format is documented at https://libvirt.org/formatdomain.html which is guaranteed to either help you, or put you to sleep.
  
 ===== virt-top ===== ===== virt-top =====
Line 15: Line 19:
   * **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   * **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 24: 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/Detach network interfaces (https://computingforgeeks.com/managing-kvm-network-interfaces-in-linux/)   * Attach/Detach network interfaces (https://computingforgeeks.com/managing-kvm-network-interfaces-in-linux/)
-    * attach-interface --domain pxe --type bridge --source br1 --model virtio --config --live +    * attach-interface //domain// bridge //bridge// --config --target vnet3 --mac 00:16:3e:xx:xx:xx --model virtio 
-    * detach-interface --domain pxe --type bridge --mac 52:54:00:47:2f:eb --config+      * 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 //domain// --type bridge --mac 00:16:3e:xx:xx:xx --config
   * Remove virtual image (config file only)<code bash> virsh undefine domainname</code>   * Remove virtual image (config file only)<code bash> virsh undefine domainname</code>
   * **change-media //name// //drive//** - Insert or Eject a CDROM   * **change-media //name// //drive//** - Insert or Eject a CDROM
     * change-media //name// //drive// --eject     * change-media //name// //drive// --eject
     * change-media //name// //drive// //path/to/image// --insert     * change-media //name// //drive// //path/to/image// --insert
 +
 +==== 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 /media/isos/gparted-live-1.3.0-1-amd64.iso so we can modify the partitions. However, we did not have a cdrom image for the installation, so one has not been created.
 +
 +Both assume the virtual has been turned off <code bash>virsh shutdown myvirt</code>
 +
 +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<code bash>virsh dumpxml myvirt | grep cdrom</code>
 +  - Once this is done and you have a cdrom, you should be able to tell which one it is with<code bash>virsh domblklist myvirt</code> which shows the block devices attached to myvirt.
 +  - Mount your image on the CDROM
 +    - If you have one and you know which drive it is<code bash>virsh change-media dd-113-virt hdb /media/xen-store/isos/gparted-live-1.3.0-1-amd64.iso --insert --config</code>This is assuming the drive was hdb
 +    - If you do not have a CDROM, use<code bash>virsh attach-disk myvirt /media/xen-store/isos/gparted-live-1.3.0-1-amd64.iso hdb --driver file --type cdrom --mode readonly --config</code>This assumes hdb did not show up as used in your domblklist above.
 +
 +=== I'm not afraid to edit the config ===
 +  - Edit the config file with <code bash>virsh edit myvirt</code>
 +  - Look for something like //<disk type='file' device='cdrom'>//
 +  - If it exists, add <code xml><source file='/media/isos/gparted-live-1.3.0-1-amd64.iso'/></code>
 +  - Look for the section //<os>//, generally near the top and add lines if necessary
 +    - <code xml><bootmenu enable='yes' timeout='5000'/></code>
 +    - 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><boot dev='cdrom'/></code> //above// the boot entry if it is not already set.
 +
 +=== Starting the virtual ===
 +  - Start the virtual with <code bash>virsh start myvirt</code>
 +  - 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>virsh change-media myvirt hdb --eject --config</code>
 +
 +
  
 ==== Remove a network from the entire system ==== ==== Remove a network from the entire system ====
Line 49: Line 91:
 //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 //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. ]] 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, and sometimes this is not handled well by virsh.
  
   - Add the --print-xml flag to virt-install, and pipe the output to a file.   - Add the --print-xml flag to virt-install, and pipe the output to a file.
Line 54: 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</code> to begin the installation 
 +  - 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>virsh define name_of_xml_file</code>
  
  
Line 206: 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 Links ===== 
 + 
 +to give a domain interface a static name when it is run, you can add the following to the interface definition. 
 +<code xml><target dev='dom113'/></code> 
 +NOTE: the name must not begin with 'vnet', 'vif', 'macvtap', or 'macvlan', which are prefixes reserved by libvirt and certain hypervisors. See 
 +https://libvirt.org/formatdomain.html#overriding-the-target-element 
 +<code xml> 
 +   <interface type='bridge'> 
 +      <mac address='00:16:3e:6b:f4:da'/> 
 +      <source bridge='br_lan'/> 
 +      <target dev='dom113'/> 
 +      <model type='virtio'/> 
 +      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> 
 +    </interface> 
 +</code> 
 + 
 +You can now do things like <code bash>ifconfig dom113</code> or <code bash>ip a show dom113</code> 
 + 
 +===== Adding USB Drive Image ===== 
 + 
 +Building and using a USB Thumbdrive image is a little weird, but it can be done. See [[software:multibootusb|]] for an example of one way I did it. 
 + 
 +===== Links =====
  
   * https://www.caretech.io/2017/10/18/converting-windows-vm-hard-disk-interface-to-virtio-with-proxmox-ve-5/   * https://www.caretech.io/2017/10/18/converting-windows-vm-hard-disk-interface-to-virtio-with-proxmox-ve-5/
Line 213: Line 284:
   * 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://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   * 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
 +  * https://libvirt.org/formatdomain.html
 +
unix/virtualization/virtlib/quickreference.1646513902.txt.gz · Last modified: 2022/03/05 14:58 by rodolico