Part 3 - Using QEMU/KVM on Arch Linux

All things related to software and development.
Windows, Linux and Mac.
User avatar
UraharaUlquiorra
Game Development Club Leader
Posts: 10
Joined: Wed Feb 24, 2016 7:43 pm
Country: South Africa
Firstname: Alano

Part 3 - Using QEMU/KVM on Arch Linux

Postby UraharaUlquiorra » Mon Nov 21, 2016 12:46 am

Hi all,

This should be the final part of the project. Hopefully everything went well up to this point.

Synopsis
Installing Windows 10 on a Virtual machine.
(For some reason windows 7 doesn't work. Also custom windows iso's have issues with UEFI boot. I'm still running a bunch of tests trying to get windows 7 to run.)
EDIT: Windows 7 not installing was due to the Intel Skylake range CPU's. If you are running an old gen Intel or AMD processor, windows 7 should work.

Installing Qemu
First we need Qemu on arch linux.
Run:

Code: Select all

sudo pacman -S qemu


Additional Package:

Code: Select all

sudo pacman -S libvirt


Ovmf-git:
-Source

Code: Select all

cd Downloads/
mkdir ovmf-git
wget https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=ovmf-git
mv PKGBUILD?h=ovmf-git PKGBUILD
wget https://aur.archlinux.org/cgit/aur.git/plain/gcc-6.0.patch?h=ovmf-git
mv gcc-6.0.patch?h=ovmf-git gcc-6.0.patch
wget https://aur.archlinux.org/cgit/aur.git/plain/ovmf.install?h=ovmf-git
mv ovmf.install?h=ovmf-git ovmf.install
wget http://pastebin.com/raw/c4LHdKux
patch < c4LHdKux
makepkg -s


The terminal will now download all of the needed packages. Once downloaded you will need to navigate to 'Downloads/ovmf-git/' and look at what your ovmf-git package is called. Mine for instance is called "ovmf-git-20130.4dd8787-1-x86_64.pkg.tar.xz".

Code: Select all

pacman -U ovmf-git-20130.4dd8787-1-x86_64.pkg.tar.xz
pacman -Ql ovmf-git


Now I prefer using the GUI as it is so much faster to create a VM. Here is the gui I use.

Code: Select all

sudo pacman -S virt-manager

We now have to make sure our virt-manager uses ovmf firmware image.

Code: Select all

sudo nano /etc/libvirt/qemu.conf

(in nano you can search through a document by using ctrl+w)
Add this

Code: Select all

nvram = [
 "/usr/share/ovmf/x64/ovmf_x64.bin:/usr/share/ovmf/x64/ovmf_vars_x64.bin"
]


restart libvirtd.service

Code: Select all

sytemctl restart libvirtd.service


Using Qemu
Enable libvirtd

Code: Select all

systemctl enable --now libvirtd
systemctl enable virtlogd.socket


Fire up virt-manager and go to the create New VM.
Select Local Install (ISO) and architecture x86_64.
Image

After that select the windows 10 ISO.
Then select OS Type: Windows
Version: Microsoft Windows 10
Image

When asked for the amount of RAM and CPU's I would advise not giving less than 4GB of RAM if you are going to be gaming. AS for CPU's, this depends on the current CPU you have. For now you can leave it to 1 as we will be editing this later with more detail.

The next step is for creating the Hard Drive. Use your own discretion when creating this. Just remember that Windows needs atleast 20GB for a good long term setup (provision for updates ect).

The last step if will ask for the VM name. You can make the name whatever you want. The most important part is to select "Customize configuration before install". As for the network configuration - I use NAT.

You will now be presented with a settings screen. In this screen there will be a heading "Overview". Here change "Firmware" to "UEFI x86_64:/usr/share/ovmf/x64/ovmf_x64.bin"
Remeber to hit apply first before switching to the other tabs.

Note if this section is grayed out, go back and edit /etc/libvirt/qemu.conf and make sure the path is correct.
Also remember to restart libvirtd.service

In the "Processor section" change your CPU model to "host-passthrough". Type it in by hand if it is not an option.
Now go to "Add Hardware" and add a Controller for SCSI of the "VirtIO SCSI" model. Change the default IDE disk to SCSI - which will now bind to the VirtIO controller.

Download the virtio-win-0.1.126.iso

Add this ISO to the virtual machine as a SCSI CD/DVD drive. Start the virtual machine when you are satisfied with all the settings.
For now we are only going to run a virtual environment inside of linux and not to the dedicated GPU. Once the installation has started, windows will ask for the device drivers. Select the virt iso as a driver source and navigate to the directory "/vioscsi/w10/".

The installation should add the driver and an empty disk should show up. Complete the installation, once done shutdown the VM.
We will now increase some performance and add sound to the VM as well as change over to the GPU.
Have a set of secondary peripherals at hand as you will need to control the host as well as the VM.

Inside virt-manager go to "Add hardware" and select the GPU you want to passthrough, as well as the GPU audio. If you are planning on using the screen as an audio source from your graphics card, then you are set for audio. For those that need to pass it to their host system you will need to edit some config files.
Also passthrough your secondary keyboard and mouse for use inside the VM.

Because we are using virt-manager we need to run this command to edit it's configurations.

Code: Select all

sudo EDITOR=nano virsh edit [VM NAME]

Just replace whatever you called your VM with VM NAME

My output file looks like this:

Code: Select all

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>windows</name>
<uuid>60338d1b-973c-4d30-be61-8fef69063091</uuid>
<memory unit='KiB'>4096000</memory>
<currentMemory unit='KiB'>4096000</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
  <type arch='x86_64' machine='pc-i440fx-2.7>hvm</type>.....


Copy domain type and vcpu placement.

The xmlns:qemu in domain is to ensure we can use qemu:commandline in the configurations. As for vcpu pinning: Here, for instance, the guest cores 0, 1, 2 and 3 are mapped to the host cores 5, 6, 7 and 8 respectively.

Code: Select all

<vcpu placement='static'>4</vcpu>
<cputune>
    <vcpupin vcpu='0' cpuset='4'/>
    <vcpupin vcpu='1' cpuset='5'/>
    <vcpupin vcpu='2' cpuset='6'/>
    <vcpupin vcpu='3' cpuset='7'/>
</cputune>


vcpu sets the amount of processors we want our VM to have. I have an 4 core cpu, with 8 threads.

Depending on what you want change the <topology> settings:
For instance:

Code: Select all

 <cpu mode='custom' match='exact'>
    ...
    <topology sockets='1' cores='4' threads='1'/>
    ...
   

This will ensure that the VM is utilising the CPU as much as possible, if you want to do nothing on the host while the VM is active.

Another example:

Code: Select all

<cpu mode='custom' match='exact'>
    ...
    <topology sockets='1' cores='2' threads='2'/>
    ...
</cpu>

This will ensure that both the VM and Host are sharing the CPU efficiently, so you can still work on the host while the VM is active.

For Nvidia drivers on host machines add this to the config:

Code: Select all

<hyperv>
           <vendor_id state='on' value='whatever'/>
           </hyperv>
     


For extra performance and to make it hidden to applications that they are running on a VM:

Code: Select all

           <kvm>
            <hidden state='on'/>
            </kvm>


For sound add this at the end of the file before </domain>:

Code: Select all

 <qemu:commandline>
   <qemu:env name='QEMU_PA_SAMPLES' value='1024'/>
   <qemu:env name='QEMU_AUDIO_DRV' value='pa'/>
   <qemu:env name='QEMU_PA_SERVER' value='/run/user/1000/pulse/native'/>
  </qemu:commandline>
 


[EDIT]
So I ran into some troubles with sound when I redid my arch install. I fixed it by editing /etc/libvirt/qemu.conf
and adding my userid to the user field. Output

Code: Select all

user = '1000'
as well as adding my groupid to group. Output

Code: Select all

group='100'


I then followed this guide and it sorted out my pulseaudio server on arch.
[End of edit]

If you have anymore sound issues go to this page: here

Sources
Arch Packagebuilder: here
QEMU/libvirt/virt-manager: here & here
OVMF-git: here
Setting up OVMF-based VM: here

Final Words
Well that should do it. I hope this guide helped, I spent hours reading through everything again, making sure that I am compiling something of worth. If I made a mistake, please point it out so I can fix it. If you are struggeling, just ask in the comments below - chances are I have come across it.

Kind Regards,
Alano (benehiko)
Summoner Name: Arki Benehiko
:D
Image

Return to “Software”

Who is online

Users browsing this forum: No registered users and 1 guest