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):
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 if you are using EasyOS Kirkstone or qemu-8.2.1-r1 if you are using EasyOS Scarthgap. 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 correct procedure for the installation is to update the packages database by pressing the Configure package manager button and update database --> update now. Afterwards, when installing the QEmu package PKGget should automatically ask if to also download and install all its required dependencies (which should be particular versions of virglrenderer and libvulkan). Let PKGget download and install them. Please do not install any foreign package for any reason.
To check if the software has been installed properly 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.
To ascertain which version of the software is installed and being used:
Code: Select all
# qemu-system-x86_64 --version
QEMU emulator version 8.2.1
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
#
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. In case you want your virtual system drive file to grow beyond the limit you had set in the past (let's say from 20 to 50 GB), you can simply use the following command:
Code: Select all
# cd /files/other
# qemu-img resize winvirtualdisk.qcow2 50G
Image resized.
#
and, of course, the partition will need to be manually expanded afterwards (you can use any partition resizing utility - Gparted for 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:
For QEmu 6 on EasyOS Kirkstone:
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
For QEmu 8 on EasyOS Scarthgap:
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 \
-audio 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.
-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] // or "-audio pa,id=hda,server=[pulse audio server string]" for QEmu 8
-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 its window. This doesn't happen on MS Windows, which only supports certain reolutions (and the best one has to be chosen every time). Not only that: on QEmu 8 you will also be able to move the mouse cursor from the guest to the host without the need of pressing the Ctrl+Alt+G key-combination and the clock will be in sync with the host (without the need of further command-lines); 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:
For QEmu 6 on EasyOS Kirkstone:
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
For QEmu 8 on EasyOS Scarthgap:
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 \
-audio 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
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:
For QEmu 6 on EasyOS Kirkstone:
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
For QEmu 8 on EasyOS Scarthgap:
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 \
-audio 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.