QEmu guide - how to install a Linux distribution on EasyOS

Moderator: BarryK

Post Reply
User avatar
Federico
Posts: 142
Joined: Tue Jun 20, 2023 2:40 pm
Has thanked: 1 time
Been thanked: 19 times

QEmu guide - how to install a Linux distribution on EasyOS

Post by Federico »

Installing a Linux distribution on a virtual machine (VM from now on) on EasyOS is for sure less useful for working than installing MS Windows on it, since all the advantages of a powerful Linux distribution are already available on the host. But this is anyway interesting and useful for testing purposes.
Searching for a lightweight distro with a beautiful window manager to be tested with QEmu, my choice landed on MX Linux, with the KDE. Please notice that there is absolutely no connection between me and the development, advertising or sponsorship of MX Linux. The choice has been mostly random. Beautiful is the fact that to run a Linux distribution on QEmu is easyer than running MS Windows on it generally speaking. In this guide we will assume that all data has been placed into /files/other .

1) Needed data / preparation:

In this case, only the installation ISO image of MX Linux KDE is needed, which is only 2.7 GB in size and can be downloaded here.

Your CPU should support the Intel Virtualization Technology or AMD-Virtualization for AMD. So please check in the BIOS that these features are present and active (they are usually active by default).
CPUs without these features should be the vast minority nowadays.
In case you are not sure if your hardware and / or operating system kernel are overall capable of running QEmu, you can download and run the QEmu-ready package from here. Just extract it somewhere and run it and you should see something like this (if you are on Intel):

Screenshot(8).jpg
Screenshot(8).jpg (31.05 KiB) Viewed 130 times

2) Installation:

In order to run QEmu on Easy, you'll obviously need to install it. Please run PKGget and install the package "qemu-6.2.0-r5". Keep in mind that normally the package isn't installed, even if it is shown as
being installed (so click on it to install it). The old version of it (6.2.0-r4) lacks important functionalities. Therefore, if PKGget does not show the latest version, either update the repository (configure packet manager button --> update now) or just update Easy to the latest version. The package "virglrenderer-0.9.1-r3" may also be needed. Also please pay attention not to uninstall other needed packages, like libvulkan for example. Anyway, to check if the software has been installed and works correctly you can issue the command:

Code: Select all

# qemu-system-x86_64 --help

this should show the complete list of possible options and values for the program. It is also adviceable to do the following:

Code: Select all

# export QEMU_AUDIO_DRV=pa

this adds the environment variable QEMU_AUDIO_DRV with value pa to the system.

3) Configuration:

first of all we will have to create the file which will act as the virtual system drive for our VM. This file will grow dynamically in size. Meaning that it will be just a few kilobytes big at the beginning and will be allowed to grow on demand till the size we want to allow. I assume that 20 GB are enough. Otherwise, adjust the command as needed:

Code: Select all

# cd /files/other

# qemu-img create -f qcow2 mxlinuxdisk.qcow2 20G

you can obviously name the qcow2 file as you wish. This is just an example. Once the file has been created and placed on the same folder where the MX Linux ISO is located, we can go on and start our VM for the first time:

Code: Select all

# qemu-system-x86_64 \
-enable-kvm \
-m 2G \
-smp 2 \
-hda [virtual disk filename].qcow2 \
-boot d \
-net nic,model=virtio \
-net user \
-vga virtio \
-device qemu-xhci \
-device ich9-intel-hda,id=sound0 \
-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \
-audiodev pa,id=hda,server=[pulse audio server string] \
-global ICH9-LPC.disable_s3=1 \
-global ICH9-LPC.disable_s4=1 \
-cdrom [MX Linux ISO filename].ISO

let's comment this long command as far as possible:

qemu-system-x86_64 --> we are emulating an x86_64 machine.

-enable-kvm --> this enables the kvm accelerator (https://www.linux-kvm.org/page/Main_Page).

-m 2G --> we assign 2 GB of RAM memory to this VM, because MX Linux seems to be running smoothly even with such a small amount of RAM. Less than 1 GB of RAM is in use when no programs are running. Adjust according to your needs. Remember not to assign more than 50% of the physical memory of the host.

-smp 2 --> with this we say to QEmu that we want to emulate an x86_64 CPU, with 2 threads.

-boot d --> with this we say to QEmu that we want to start the system from the virtual DVD-ROM drive, and not from the virtual HDD.

-net nic,model=virtio --> we want to emulate a "virtio" network card, because usually this driver comes preinstalled.

-vga virtio --> we want to emulate a "virtio" video card, because usually this driver comes preinstalled..

-device ich9-intel-hda,id=sound0
-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0
-audiodev pa,id=hda,server=[pulse audio server string]
-global ICH9-LPC.disable_s3=1
-global ICH9-LPC.disable_s4=1

all these 5 lines are just needed to configure the virtual audio card in such a way that it can be recognized and used without problems by the guest OS.
The pulse audio server string can be retrieved by issueing the command:

Code: Select all

# pactl info

it should be /run/pulse/native --> (but I cannot be 100% sure that it's identical on every version of EasyOS)

-cdrom [MX Linux ISO filename].ISO --> we just say that the MX Linux KDE ISO image file we just downloaded should act as a physical DVD which is inserted into our virtual DVD-ROM drive.

Now theoretically the VM should be running and you should be going through the usual Linux installation process. Start the system from the DVD first, when the system boots up, as usual the first window will give you the possibility of installing the system onto the drive (first button at the top of the page) as well as provide to you credentials for using the system as it is running directly from the DVD. It's up to you if you want to take a look at the system now. You can anyway notice immediately, that the audio and video drivers do work absolutely perfectly here, better than on WIndows 10: the audio has not even the slightest trace of chough; the video has the incredible ability to automatically adapt the resolution exactly to the size of the QEmu window. Basically, the system is able to always output a resolution which matches exactly the size of the QEmu window. So, if you freely resize the QEmu window, you will never get any black stripes on the edges of the QEmu window. This doesn't happen on Windows, which only supports certain reolutions (and the best one has to be chosen every time). The network driver should also work flawlessly.

When you are ready, go on and install the system. As usual. choose username, password, root password, samba workgroup name and domain name. You can also activate / deactivate the auto login.
When the installation routine finishes the system will be rebooted. Everything should work fine. The system should ask to install about 520 MBs of updates. It's up to you if to install them immediately or wait.
The virtual HDD file should have grown till about 11.7 GBs now.
From now on, the installation DVD will not be necessary any more, and the QEmu command will just look like this:

Code: Select all

# qemu-system-x86_64 \
-enable-kvm \
-m 2G \
-smp 2 \
-hda [virtual disk filename].qcow2 \
-net nic,model=virtio \
-net user \
-vga virtio \
-device qemu-xhci \
-device ich9-intel-hda,id=sound0 \
-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \
-audiodev pa,id=hda,server=[pulse audio server string] \
-global ICH9-LPC.disable_s3=1 \
-global ICH9-LPC.disable_s4=1 

4) Finishing touches:

Connecting USB devices from the host to the guest:

It is possible to passthrough to the guest any USB device connected to the host. There are several ways to do that. First of all the lsusb command should be issued:

Code: Select all

# lsusb
Screenshot(9).png
Screenshot(9).png (67.01 KiB) Viewed 1969 times

the output of the lsusb command shows every device connected to the host. Every device is connected to a particular USB bus and is allocated to a particular bus address. More over, every device has a particular vendorid and a particular productid. The vendorid is represented by the 4 digits before the colon, whilst the productid is represented by the 4 digits after the colon.
Now: if the VM is not running we can add lines like these to the QEmu startup command:

Code: Select all

-device usb-host,hostbus=3,hostaddr=3

or:

Code: Select all

-device usb-host,vendorid=0x6ade,productid=0x9582

so that the VM starts with the needed device(s) already attached. If using lines like the first one, for the same USB device the needed command may change every time the device is physically connected to the host. This is due to the fact that USB devices are dynamically allocated to buses and addresses. Therefore, it is better to use vendor and product ids, like in the second line, so that the command never chnges for a given device.

It is even possible to passthrough USB devices on the fly, when the virtual machine is already runnning. To do that, just select the QEmu window and type the key-combination Ctrl + Alt + 2 . This should call the QEmu console, which is called Monitor. Here it is possible to directly type commands for interacting with the VM.

To connect a USB device, of which you know bus number and address, just type, for example:

Code: Select all

device_add usb-host,hostbus=2,hostaddr=3

and hit Enter.

To connect a USB device, of which you know vendor and product IDs, just type for example:

Code: Select all

device_add usb-host,vendorid=0x6ade,productid=0x9582

and hit Enter.

Sharing a folder with the host (requires EasyOS >= 5.4.3):

This is also doable in a relatively easy way. Please notice that there will be anyway no network connection between host and guest. Only the desired folder will be shared.
First of all we need to create a samba share on our Easy host. To do that select Menu --> Network and launch EasyShare. Please if you havn't already done so, click the Samba Setup button and setup the Samba daemon correctly. The writing under the Samba Setup button should be green and should say that the Samba daemon is running. Now in the Samba Setup section it is possible to setup network shares with paths and share names; please share at least one folder. Inside the lower Shared local folders section the shared folder should appear. It's absolutely up to you which folder to share. Notice that this folder will also be accessible by any other PC connected to your own network.

When you are ready, you should start QEmu with the following command:

Code: Select all

# qemu-system-x86_64 \
-enable-kvm \
-m 2G \
-smp 2 \
-hda [virtual disk filename].qcow2 \
-net nic,model=virtio \
-net user \
-vga virtio \
-device qemu-xhci \
-device ich9-intel-hda,id=sound0 \
-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \
-audiodev pa,id=hda,server=[pulse audio server string] \
-global ICH9-LPC.disable_s3=1 \
-global ICH9-LPC.disable_s4=1 \
-fsdev local,security_model=passthrough,id=fsdev0,path=[absolute path to the shared folder] \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare

The last 2 lines of the command basically instruct QEmu to make use of the 9P functionality of the host to share the folder identified by [absolute path to the shared folder] and to create a virtual device on the guest, which will be used for accessing this folder (details can be found here). Please pay attention to the fact that the [absolute path to the shared folder] is not the Samba share name, but just the absolute path to this folder.
When the VM boots up, just open a Konsole shell and do the following:

Code: Select all

# cd /mnt
# sudo mkdir hostshare

type your password, and then issue the following:

Code: Select all

# sudo mount -t 9p -o trans=virtio hostshare /mnt/hostshare -oversion=9p2000.L

type your password

You should be ready to go. You should be able to easily read and modify data on the shared folder by accessing /mnt/hostshare through Dolphin. The mount-point doesn't need to be recreated every time the system starts. You can for sure create a shell script which automatically executes the mount command when the system boots. Or, as an alternative (maybe easyer), you can add a line like the following to the /etc/fstab file:

Code: Select all

hostshare     /mnt/hostshare     9p     trans=virtio,oversion=9p2000.L     0     0

Making easyer to start the VM:

This is obvious. I just add this for completeness. To launch the VM easyer one can create a shell script and place it anywhere, containg the launch command. On the -hda line it is also possible to specify the absolute path to the virtual HDD file, so that the VM can be launched from anywhere. Once this shell script exists somewhere, one can place a new shortcut on the desktop calling it.
A good idea is also to find a Linux icon for it.

Retrieving free space from the virtual drive file:

As already explained, the virtual drive file will grow on demand till the maximum allowed size. If for any reason the space occupation gets smaller on the virtual drive, the file will not be shrinked accordingly.
The procedure to manually shrink the file and retrieve the free space on the host is as follows:

  • launch the VM and create a file somewhere. We will assume that you've created /some/file

  • issue the following command:

Code: Select all

# dd if=/dev/zero of=/some/file

what this will do is to grow this file with zeros till the whole virtual drive is completely full (has grown to its maximum size and there's no more free space).

  • delete /some/file .

  • power off the VM .

  • on the host, cd to the folder where the drive file is located:

Code: Select all

# cd /files/other
  • create a new shrinked drive file:

Code: Select all

# qemu-img convert -O qcow2 mxlinuxdisk.qcow2 new_mxlinuxdisk.qcow2

In this way a new image file will be created and it will be as small as possible for containing the given VM. Please pay attention to the fact that the host file system must have enough free space for containing the new VM drive file. When the process finishes, the old file can be deleted and the new one renamed as needed.

Last edited by Federico on Fri Mar 29, 2024 3:27 pm, edited 19 times in total.

Desktop PC
Case: Sharkoon S25-W MB: Asus Rog Strix B550-A PSU: XFX Pro 750W CPU: AMD Ryzen 5700X @ 4.6 GHz RAM: Corsair 32 GB DDR4 @ 3000 MHz Heatsink: Scythe Mugen 5 rev. B VGA: Asus Tuf RTX 3080 12 GB OC

Laptop PC: Asus Zenbook UX325E

Geek3579
Posts: 245
Joined: Sat Jul 18, 2020 1:07 pm
Has thanked: 68 times
Been thanked: 62 times

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by Geek3579 »

Thanks for all this info @Frederico. Any encouragement to get Puppy users becoming familiar with QEMU is great, as its such a versatile program.

For others reading this, I add the following to the QEMU script to get USB passthrough, which is setup (below) for a USB camera. The vendor and product codes do not change so you only have to determine them once.

# Use lsusb in host to get vendor and product details for all USB devices, in this case its 046d:0825 for the camera
# Then add these variables in at the start of the QEMU script separately,
# so there is a record of what device is accessed by the virtual machine
vend=046d # USB Camera
prod=0825 # USB Camera

# Then add these two lines to the end of the QEMU script, ensuring that what was the last line now has a " \"

-usb -device usb-ehci,id=ehci \
-device usb-host,vendorid=0x$vend,productid=0x$prod

User avatar
BarryK
Posts: 2273
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 93 times
Been thanked: 564 times

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by BarryK »

@Federico
Regarding /etc/libvirt/qemu/qemu.conf that you have recommended to create,
There is a 'libvirt' package that has /etc/libvirt/qemu.conf

http://distro.ibiblio.org/easyos/amd64/ ... -64.tar.xz

EasyOS does not have that installed.
I am wondering whether it is needed.

EDIT:
I did a search packages.debian.org for "qemu.conf", and /etc/libvirt/qemu.conf is the only one found, in the 'libvirt-daemon-system' DEB package (which is part of 'libvirt'):

https://packages.debian.org/bookworm/li ... mon-system

As 'libvirt' is not installed in EasyOS, why is /etc/libvirt/qemu.conf needed?
In anticipation that it might be installed?

User avatar
Federico
Posts: 142
Joined: Tue Jun 20, 2023 2:40 pm
Has thanked: 1 time
Been thanked: 19 times

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by Federico »

BarryK wrote: Mon Jul 17, 2023 1:56 am

@Federico
Regarding /etc/libvirt/qemu/qemu.conf that you have recommended to create,
There is a 'libvirt' package that has /etc/libvirt/qemu.conf

http://distro.ibiblio.org/easyos/amd64/ ... -64.tar.xz

EasyOS does not have that installed.
I am wondering whether it is needed.

EDIT:
I did a search packages.debian.org for "qemu.conf", and /etc/libvirt/qemu.conf is the only one found, in the 'libvirt-daemon-system' DEB package (which is part of 'libvirt'):

https://packages.debian.org/bookworm/li ... mon-system

As 'libvirt' is not installed in EasyOS, why is /etc/libvirt/qemu.conf needed?
In anticipation that it might be installed?

Dear Barry, thank you very much for your attention. Beautiful idea to create a sub-forum for containers and emulation. May I suggest that the name "Containers and Emulation" or "Emulation and containers" or "Containers and Virtual Machines" could be more suitable, since the meaning of the VM acronym is mostly known just by experts and insiders?

Regarding the contents of qemu.conf and the libvirt package, I'm not 100% sure jet but it looks like the file and its contents aren't needed at all. I found this when I was searching for a way to let the sound work on a Windows VM (probably needed on other operating systems).

Desktop PC
Case: Sharkoon S25-W MB: Asus Rog Strix B550-A PSU: XFX Pro 750W CPU: AMD Ryzen 5700X @ 4.6 GHz RAM: Corsair 32 GB DDR4 @ 3000 MHz Heatsink: Scythe Mugen 5 rev. B VGA: Asus Tuf RTX 3080 12 GB OC

Laptop PC: Asus Zenbook UX325E

User avatar
BarryK
Posts: 2273
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 93 times
Been thanked: 564 times

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by BarryK »

Federico wrote: Sat Jul 22, 2023 1:01 pm

Regarding the contents of qemu.conf and the libvirt package, I'm not 100% sure jet but it looks like the file and its contents aren't needed at all. I found this when I was searching for a way to let the sound work on a Windows VM (probably needed on other operating systems).

Yes, it seems that libvirt is a library that some frontends (GUIs) to QEMU use.
The two GUIs that I have now in the menu, AQEMU and QtEmu do not use libvirt.

pamojja
Posts: 31
Joined: Thu Jul 20, 2023 11:34 am
Has thanked: 20 times
Been thanked: 1 time

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by pamojja »

BarryK wrote: Sun Jul 23, 2023 1:26 am

The two GUIs that I have now in the menu, AQEMU and QtEmu do not use libvirt.

For someone never using Qemu, which of the 2 GUIs are better suitable? Is there a difference in functionality?

User avatar
rockedge
Site Admin
Posts: 5720
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1997 times
Been thanked: 2099 times
Contact:

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by rockedge »

I like to use AQEMU. It can handle simple and more complex setups of virtual machines.

pamojja
Posts: 31
Joined: Thu Jul 20, 2023 11:34 am
Has thanked: 20 times
Been thanked: 1 time

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by pamojja »

rockedge wrote: Sun Aug 20, 2023 9:05 pm

I like to use AQEMU. It can handle simple and more complex setups of virtual machines.

I almost get there with Aqemu, as a first trial, trying to virtualize lxle under easyOS. However, despite reading the wiki, I keep getting errors directing it to the lxle ISO:

Image

What I have to do differently?

pamojja
Posts: 31
Joined: Thu Jul 20, 2023 11:34 am
Has thanked: 20 times
Been thanked: 1 time

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by pamojja »

I would never would have found out myself. Here is the help I got on linux.org forum - for other beginners who want to be able to set up a VM with the graphical interface of Aqemu in EasyOS. From this post: https://www.linux.org/threads/lightest- ... ost-203315 it took only 9 further short posts to solve it with a simply audio setting change. As said, I never would have thought such a seemingly unrelated setting being able to hinder the startup of a Linux VM.

pamojja
Posts: 31
Joined: Thu Jul 20, 2023 11:34 am
Has thanked: 20 times
Been thanked: 1 time

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by pamojja »

rockedge wrote: Sun Aug 20, 2023 9:05 pm

I like to use AQEMU. It can handle simple and more complex setups of virtual machines.

Though it was possible to VMs in live mode a explained above, all tried installations as VM failed for me with Aqemu (wattOS, LXLE, Bodhi, Robo..). The Aqemu window just terminated, before the installation completed.

How have you been able to do with Aqemu?

Geek3579
Posts: 245
Joined: Sat Jul 18, 2020 1:07 pm
Has thanked: 68 times
Been thanked: 62 times

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by Geek3579 »

pamojja wrote: Thu Sep 07, 2023 10:32 am
rockedge wrote: Sun Aug 20, 2023 9:05 pm

I like to use AQEMU. It can handle simple and more complex setups of virtual machines.

Though it was possible to VMs in live mode a explained above, all tried installations as VM failed for me with Aqemu (wattOS, LXLE, Bodhi, Robo..). The Aqemu window just terminated, before the installation completed.

How have you been able to do with Aqemu?

A belated reply. QEMU must be installed before AQEMU can run. It finds the QEMU version/location the first time it is run. Were there any error messages when you tried to boot the ISO's ??

User avatar
rockedge
Site Admin
Posts: 5720
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1997 times
Been thanked: 2099 times
Contact:

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by rockedge »

@pamojja Sorry for the late reply! I overlooked the topic.

As mentioned above QEMU needs to be installed. Also there are other packages that need to be installed along with QEMU that has the utilities to create the virtual hard drives for example.

These packages I have installed using the PPM along with the QEMU package:

  1. libqcow-utils

  2. qemu-utils

  3. libqcow1

  4. libvirt-daemon-driver-qemu

Clarity
Posts: 3273
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1349 times
Been thanked: 438 times

Re: QEmu guide - how to install a Linux distribution on EasyOS

Post by Clarity »

I think this post important considering all thing EASY will be moving forward in 2024.

External useful web information

I hope QEMU packaging is upgraded, by now version 8+, for use in EASY for modern Pipewire services

Post Reply

Return to “Containers and VMs”