Manjaro Difference between revisions of "Virt-manager"

Difference between revisions of "Virt-manager"

From Manjaro
m (removed outdated)
(Update the information and more usage tips)
Line 14: Line 14:


<!--T:4-->
<!--T:4-->
'''[https://virt-manager.org/ Virt-manager]''' uses '''[http://libvirt.org/ libvirt]''' and it's a manager of many hypervisors, including the one that we want to use here: QEMU/KVM.  
'''[https://virt-manager.org/ Virt-manager]''' uses '''[http://libvirt.org/ libvirt]''' and it's a manager of many '''[https://libvirt.org/drivers.html hypervisors]''', including the one that we want to use here: QEMU/KVM.  


<!--T:5-->
<!--T:5-->
----
----


<!--T:6-->
<!--T:6-->
{{note|Now from 1.2.1 release switch to spice-gtk3 '''so you need to have: Cinnamon/Gnome (Mate-gtk3/Xfce-gtk3 > not yet)'''}}
<br clear="all" />


<!--T:7-->
<!--T:7-->
<br clear="all" />
'''Why do I need to virtualize?'''


<!--T:8-->
<!--T:8-->
'''Why do I need to virtualize?'''
* To learn about a new O.S.


<!--T:9-->
<!--T:9-->
* To learn about a new O.S.
* To configure a hardware that has a setup only for that operating system


<!--T:10-->
<!--T:10-->
* To configure a hardware that has a setup only for that operating system
<!--T:11-->
* To use a software that only works on another
* To use a software that only works on another


= I want to know more = <!--T:12-->
= I want to know more = <!--T:11-->


<!--T:13-->
<!--T:12-->
[[file:Hypervisor_1.png|left]]
[[file:Hypervisor_1.png|left]]
<br clear="all" />
<br clear="all" />
Line 50: Line 46:
<br clear="all" />
<br clear="all" />


= What we absolutely must know = <!--T:14-->
= What we absolutely must know = <!--T:13-->
<br clear="all" />
<br clear="all" />
1. What is my CPU. Identify it and make sure it's at least a quad core. '''TAKE A LOOK AT''' '''[http://www.cpu-world.com/CPUs/CPU.html CPU-World]'''
1. What is my CPU. Identify it and make sure it's at least a quad core. '''TAKE A LOOK AT''' '''[http://www.cpu-world.com/CPUs/CPU.html CPU-World]'''
<br clear="all" />
<br clear="all" />
2. Check if the 'virtualization parameters' are enabled on BIOS
2. Check if the 'virtualization parameters' are enabled on BIOS using
<br clear="all" />
LC_ALL=C lscpu | grep Virtualization
3. How much memory I have. Check the RAM and verify that is at least 4GB.
3. How much memory I have. Check the RAM and verify that is at least 4GB.
<br clear="all" />
<br clear="all" />
4. The amount of free space on my HDD.Launch gparted and make sure you have a partition with at least 20GB free. While you're there add a label to the partitions to better recognize them even by name.
4. The amount of free space on my hard drive. The virtual machine can use a disk image file so extra partitions are not necessary.
<br clear="all" />
{{note|You can also use raw partition specific for virtual machines. See [https://wiki.archlinux.org/title/Partitioning partitioning] for more information}}
5. The minimum hardware requirements of the operating system you want to install as a virtual machine.
5. The minimum hardware requirements of the operating system you want to install as a virtual machine.
<br clear="all" />
<br clear="all" />


<!--T:15-->
= Install virt-manager, qemu and all dependencies= <!--T:16-->
From terminal:
sudo pacman -S inxi dmidecode gparted && sudo inxi -Fxm
 
<!--T:16-->
[[File:Inxi_1.png|thumb|left|375px]] [[File:Gparted_1.png|thumb|center|375px]]
<br clear="all" />
 
= Install virt-manager, qemu and all dependencies= <!--T:17-->
<br clear="all" />
<br clear="all" />
From terminal:
From terminal:
  sudo pacman -S virt-manager qemu vde2 iptables-nft dnsmasq bridge-utils openbsd-netcat
  sudo pacman -S virt-manager qemu vde2 iptables-nft dnsmasq bridge-utils openbsd-netcat edk2-ovmf swtpm
Enable and start service
Enable and start service
  sudo systemctl enable libvirtd.service
  sudo systemctl enable libvirtd.service
  sudo systemctl start libvirtd.service
  sudo systemctl start libvirtd.service
Add user to ''libvirt'' group to use the '''system'''-level virtual machines (qemu:///system)
sudo usermod -a G libvirt $USER
{{note|
# You don't need this step to run system-level virtual machines. However, virt-manager will prompt for sudoer's password when launch if the user is not in the ''libvirt'' group 
# You can also create '''user'''-level virtual machines (qemu:///session) and use without sudoer's privelige. However, some features such as [https://libvirt.org/kbase/virtiofs.html VirtioFS file sharing] may be unavailable in qemu:///session}}
= Using Virt-Manager for guest creation= <!--T:17-->
<br clear="all" />
<br clear="all" />
 
0. Prepare installation image. If you're going to install Windows, prepare the [https://www.linux-kvm.org/page/WindowsGuestDrivers/Download_Drivers Virtio driver] image too.
= Using Virt-Manager= <!--T:18-->
{{tip|You can also find the [https://aur.archlinux.org/packages/virtio-win virtio-win] package in AUR. The image is located in '''/var/lib/libvirt/images''', which is the default [https://libvirt.org/storage.html#StorageBackendDir directory pool] of qemu:///system}}
<br clear="all" />
<br clear="all" />
1. Launch menu Virtual Machine Manager,  check that it is connected.
1. Launch menu Virtual Machine Manager. It should already have a [https://libvirt.org/drvlxc.html LXC] connection. You can disconnect and remove it if you don't use LXC.
<br clear="all" />
<br clear="all" />
2. Go to File, choose Add Connection and choose hypervisor QEMU/KVM user session. Click on connect.From the screen select the first qemu / kvm, Right click, disconnect and delete it.
2. Go to File, choose Add Connection and choose hypervisor QEMU/KVM, or QEMU/KVM user session if you don't want '''system'''-level virtual machines. Click on connect.
<br clear="all" />
<br clear="all" />
3. You need the HDD space in which to create the virtual machine and copy the ISO file of the operating system (but you can also use a burned cd/dvd ). Double click qemu/kvm, go on storage and add by clicking + the path to the folder where you have the iso and the folder where create the virtual machine.
3. You need directory pools to store the disk images of virtual machines or the ISO file of CD/DVD. Double click qemu/kvm, go on storage and add by clicking + the path to the folder where you have the iso and the folder where create the virtual machine.
<br clear="all" />
<br clear="all" />
{{tip|My advice: use a different partition than the root. If you can, make a new one with gparted or recover new space with a resize. In case you need to reinstall your operating system you don't lose the VM that already ready-to-start.}}
{{tip|My advice: use a different partition than the root. In case you need to reinstall your operating system you don't lose the VM that already ready-to-start.}}
4. Click on create a new virtual machine: select cdrom or iso (first path maked to put the iso file)
4. Click on create a new virtual machine: select '''Local install media (ISO image or CDROM)''', and select the installation ISO image and OS type (if not detected).
<br clear="all" />
<br clear="all" />
5. How many CPU assign and how much memory? (check the recommended requirements of O.S. that you are installing)
5. How many CPU assign and how much memory? (check the recommended requirements of O.S. that you are installing)
<br clear="all" />
<br clear="all" />
6. Create the file system of the virtual machine by selecting managed or other storage and create the volume of the virtual machine.  How many GB? Check the recommended requirements O.S. you install.
6. Create the file system of the virtual machine by selecting '''Select or create custom storage''' and click '''Manage...'''. Under your desired directory pool, create the volume of the virtual machine (default in qcow2 format).  How many GB? Check the recommended requirements O.S. you install.
<br clear="all" />
7.Assign a name to the machine and flag '''customize configuration before install'''. You have access to the screen with all the hardware that will be virtualized, do a check if there is all that is needed to initialize and launch the installer.
<br clear="all" />
8. In ''Overview'', change the firmware to UEFI for future-proof capacity.
<br clear="all" />
9. Change the type of SATA Disk 1 (the disk image of the creating virtual machine) to ''virtio'' for better performance. Change discard mode to ''unmap'', and then apply the change. You should notice the device name would change from SATA Disk 1 to VirtIO Disk 1.
{{warning| If you're installing Windows, make sure to create a new SATA CDROM device and select the '''virtio-win''' image as the media, so that the Windows Installer can load the driver to recognize the disk. The virtio storage driver should be located at somewhere like ''E:\viostor\w10\amd64''}}
10. Set the NIC type to virtio too for better network performance.
{{note| If you're installing Windows, once the system if ready, make sure to install all the virtio drivers so that your virtIO network can work normally}}
11. Add TPM chip, select '''TIS''' model through '''Emulated device''' backend.
<br clear="all" />
12. Add a watchdog to reboot the guest when it hangs. Leave the settings as default.
<br clear="all" />
<br clear="all" />
7.Assign a name to the machine and flag customize before installing. You have access to the screen with all the hardware that will be virtualized, do a check if there is all that is needed to initialize and launch the installer.
13. And a hardware RNG, to get entropy from the host.
<br clear="all" />
<br clear="all" />
8. Click on the top to start.
14. Click on the top to start installation.
<br clear="all" />
<br clear="all" />
{{warning|'''All these steps are visible on youtube.''' '''[https://youtu.be/DiUG_hlLk3c >>> PLAY THIS] [[File:YouTube_1.png|thumb|center|300px]]'''}}
{{warning|'''All these steps are visible on youtube.''' '''[https://youtu.be/DiUG_hlLk3c >>> PLAY THIS] [[File:YouTube_1.png|thumb|center|300px]]'''}}
==Install guest additions==
==Install guest additions==
Once the VM is started and running you have to install the guest spice tools.
Once the VM is started and running you have to install the [https://www.spice-space.org/download.html spice guest tools].
<br clear="all" />
<br clear="all" />
For Windows is a single package: spice-guest-tools-xxxx.exe
For Windows is a single package: spice-guest-tools-xxxx.exe
Line 109: Line 117:
Visit: '''[http://www.spice-space.org/download.html Spice download]'''
Visit: '''[http://www.spice-space.org/download.html Spice download]'''


= References = <!--T:19-->
==Tune the display settings==
The default model of display card is QXL. If your virtual machine is Linux system, you can change it to virtio and enable 3D acceleration for better graphic performance.
<br clear="all" />
Windows virtual machine, however doesn't support virtio display yet. Nevertheless, we can increase its VGA memory from the default 16 MB to 64 MB to allow higher display resolution and slightly better 2D graphical performance.
<br clear="all" />
To do so, we need to edit the XML file of the virtual machine.
# In virt-manager, go to edit > preference, and check '''Enable XML edit'''.
# In virtual machine details, go to display card. Under the XML tab, change the value of '''vgamem''' to 65536, then apply the change.
<br clear="all" />
 
==File sharing between host and guest==
For Linux guests, Virtio-FS and 9p are available for file sharing. See [https://wiki.archlinux.org/title/Libvirt#Sharing_data_between_host_and_guest ArchWiki] for more information.
<br clear="all" />
For Windows guest, the easiest way to share file between host and guest is through [https://wiki.manjaro.org/index.php/Using_Samba_in_your_File_Manager SAMBA].
# Create a SAMBA usershare
# In Windows guest, enter '''\\192.168.122.1''' in the file explorer, and you should be able to see the usershare on your host.
# Map that SAMBA usershare to a new drive, and connect to it with the appropriate credential. That's it.
<br clear="all" />
 
= References = <!--T:18-->


<!--T:20-->
<!--T:19-->
'''[https://virt-manager.org/ Virt-manager]'''
'''[https://virt-manager.org/ Virt-manager]'''
<br clear="all" />
<br clear="all" />

Revision as of 21:10, 10 October 2021

Other languages:
English • ‎Türkçe • ‎русский

Overview

Topbar logo.png



Tip
Have you heard about Virtualbox to virtualize operating systems like Linux and Windows or Mac? It 'a good software, but not the only one! Don't forget VMware, Gnome Boxes and ...virt-manager.



Virt-manager uses libvirt and it's a manager of many hypervisors, including the one that we want to use here: QEMU/KVM.



Why do I need to virtualize?

  • To learn about a new O.S.
  • To configure a hardware that has a setup only for that operating system
  • To use a software that only works on another

I want to know more

Hypervisor 1.png


1. Virtualization
2. Hypervisor
3. Virtual machine

What we absolutely must know


1. What is my CPU. Identify it and make sure it's at least a quad core. TAKE A LOOK AT CPU-World
2. Check if the 'virtualization parameters' are enabled on BIOS using

LC_ALL=C lscpu | grep Virtualization

3. How much memory I have. Check the RAM and verify that is at least 4GB.
4. The amount of free space on my hard drive. The virtual machine can use a disk image file so extra partitions are not necessary.

Note
You can also use raw partition specific for virtual machines. See partitioning for more information

5. The minimum hardware requirements of the operating system you want to install as a virtual machine.

Install virt-manager, qemu and all dependencies


From terminal:

sudo pacman -S virt-manager qemu vde2 iptables-nft dnsmasq bridge-utils openbsd-netcat edk2-ovmf swtpm

Enable and start service

sudo systemctl enable libvirtd.service
sudo systemctl start libvirtd.service

Add user to libvirt group to use the system-level virtual machines (qemu:///system)

sudo usermod -a G libvirt $USER
Note
  1. You don't need this step to run system-level virtual machines. However, virt-manager will prompt for sudoer's password when launch if the user is not in the libvirt group
  2. You can also create user-level virtual machines (qemu:///session) and use without sudoer's privelige. However, some features such as VirtioFS file sharing may be unavailable in qemu:///session

Using Virt-Manager for guest creation


0. Prepare installation image. If you're going to install Windows, prepare the Virtio driver image too.


Tip
You can also find the virtio-win package in AUR. The image is located in /var/lib/libvirt/images, which is the default directory pool of qemu:///system


1. Launch menu Virtual Machine Manager. It should already have a LXC connection. You can disconnect and remove it if you don't use LXC.
2. Go to File, choose Add Connection and choose hypervisor QEMU/KVM, or QEMU/KVM user session if you don't want system-level virtual machines. Click on connect.
3. You need directory pools to store the disk images of virtual machines or the ISO file of CD/DVD. Double click qemu/kvm, go on storage and add by clicking + the path to the folder where you have the iso and the folder where create the virtual machine.


Tip
My advice: use a different partition than the root. In case you need to reinstall your operating system you don't lose the VM that already ready-to-start.

4. Click on create a new virtual machine: select Local install media (ISO image or CDROM), and select the installation ISO image and OS type (if not detected).
5. How many CPU assign and how much memory? (check the recommended requirements of O.S. that you are installing)
6. Create the file system of the virtual machine by selecting Select or create custom storage and click Manage.... Under your desired directory pool, create the volume of the virtual machine (default in qcow2 format). How many GB? Check the recommended requirements O.S. you install.
7.Assign a name to the machine and flag customize configuration before install. You have access to the screen with all the hardware that will be virtualized, do a check if there is all that is needed to initialize and launch the installer.
8. In Overview, change the firmware to UEFI for future-proof capacity.
9. Change the type of SATA Disk 1 (the disk image of the creating virtual machine) to virtio for better performance. Change discard mode to unmap, and then apply the change. You should notice the device name would change from SATA Disk 1 to VirtIO Disk 1.

Warning
If you're installing Windows, make sure to create a new SATA CDROM device and select the virtio-win image as the media, so that the Windows Installer can load the driver to recognize the disk. The virtio storage driver should be located at somewhere like E:\viostor\w10\amd64

10. Set the NIC type to virtio too for better network performance.

Note
If you're installing Windows, once the system if ready, make sure to install all the virtio drivers so that your virtIO network can work normally

11. Add TPM chip, select TIS model through Emulated device backend.
12. Add a watchdog to reboot the guest when it hangs. Leave the settings as default.
13. And a hardware RNG, to get entropy from the host.
14. Click on the top to start installation.

Warning
All these steps are visible on youtube. >>> PLAY THIS
YouTube 1.png

Install guest additions

Once the VM is started and running you have to install the spice guest tools.
For Windows is a single package: spice-guest-tools-xxxx.exe
For linux are: spice-vdagent and xf86-video-qxl. If you visrtualize a linux distro you can install them with their package manager
Visit: Spice download

Tune the display settings

The default model of display card is QXL. If your virtual machine is Linux system, you can change it to virtio and enable 3D acceleration for better graphic performance.
Windows virtual machine, however doesn't support virtio display yet. Nevertheless, we can increase its VGA memory from the default 16 MB to 64 MB to allow higher display resolution and slightly better 2D graphical performance.
To do so, we need to edit the XML file of the virtual machine.

  1. In virt-manager, go to edit > preference, and check Enable XML edit.
  2. In virtual machine details, go to display card. Under the XML tab, change the value of vgamem to 65536, then apply the change.


File sharing between host and guest

For Linux guests, Virtio-FS and 9p are available for file sharing. See ArchWiki for more information.
For Windows guest, the easiest way to share file between host and guest is through SAMBA.

  1. Create a SAMBA usershare
  2. In Windows guest, enter \\192.168.122.1 in the file explorer, and you should be able to see the usershare on your host.
  3. Map that SAMBA usershare to a new drive, and connect to it with the appropriate credential. That's it.


References

Virt-manager
Libvirt
Qemu
x86 virtualization
Intel-vt
Amd-v

Cookies help us deliver our services. By using our services, you agree to our use of cookies.