Reformat code, fix typos, use apt instead of apt-get, improve consistency

This commit is contained in:
Kazevic
2024-07-02 03:44:09 -03:00
parent 47596d6dde
commit 45bbdf87ee
42 changed files with 423 additions and 315 deletions

View File

@@ -1,21 +1,30 @@
# Creating a Virtual Machine in KVM
This step-by-step guide will take you through setting up a CPU and memory efficient virtual machine to use with WinApps leveraging KVM, an open-source virtualization software contained in most linux distributions.
This step-by-step guide will take you through setting up a CPU and memory efficient virtual machine
to use with WinApps leveraging KVM, an open-source virtualization software contained in most Linux distributions.
## Install KVM
First up, you must install KVM and the Virtual Machine Manager. By installing `virt-manager`, you will get everything you need for your distribution:
```bash
sudo apt-get install -y virt-manager
sudo apt install -y virt-manager
```
## Download the Windows Professional and KVM VirtIO drivers
You will need Windows 10 Professional (or Enterprise or Server) to run RDP apps, Windows 10 Home will not suffice. You will also need drivers for VirtIO to ensure the best performance and lowest overhead for your system. You can download these at the following links.
You will need Windows 10 Professional (or Enterprise or Server) to run RDP apps, Windows 10 Home will not suffice.
You will also need drivers for VirtIO to ensure the best performance and the lowest overhead for your system.
You can download these at the following links:
Windows 10 ISO: https://www.microsoft.com/en-us/software-download/windows10ISO
KVM VirtIO drivers (for all distros): https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
## Create your virtual machine
The following guide will take you through the setup. If you are an expert user, you may wish to:
The following guide will take you through the setup. If you're an expert user, you may wish to:
- [Define a VM from XML (may not work on all systems)](#define-a-vm-from-xml)
- [Run KVM in user mode](#run-kvm-in-user-mode)
@@ -39,11 +48,13 @@ Now select the location of your Windows 10 ISO, and `Automatically detect` the i
![](kvm/04.png)
Set your memory and CPUs. We recommend `2` CPUs and `4096MB` for memory. We will be using a Memory Ballooning service, meaning 4096 is the maximum amount of memory the VM will ever use, but will not use this amount except when it is needed.
Set your memory and CPUs. We recommend `2` CPUs and `4096MB` for memory. We will be using a Memory Ballooning service,
meaning 4096 is the maximum amount of memory the VM will ever use, but will not use this amount except when it is needed.
![](kvm/05.png)
Choose your virtual disk size, keep in mind this is the maximum size the disk will grow to, but it will not take up this space until it needs it.
Choose your virtual disk size, keep in mind this is the maximum size the disk will grow to,
but it will not take up this space until it needs it.
![](kvm/06.png)
@@ -58,12 +69,14 @@ After clicking `Finish`, ensure under CPU that `Copy host CPU configuration` is
![](kvm/08.png)
Next, go to the `XML` tab, and edit the `<clock>` section to contain:
```xml
<clock offset='localtime'>
<timer name='hpet' present='yes'/>
<timer name='hypervclock' present='yes'/>
</clock>
```
Then `Apply`. This will drastically reduce idle CPU usage (from ~25% to ~3%).
![](kvm/09.png)
@@ -84,30 +97,35 @@ For the NIC, set the `Device model` to `virtio`.
![](kvm/13.png)
Click the `Add Hardware` button in the lower right, and choose `Storage`. For `Device type`, select `CDROM device` and choose the VirtIO driver ISO you downloaded earlier. This will give the Windows 10 Installer access to drivers during the install process. Now click `Finish` to add the new CDROM device.
Click the `Add Hardware` button in the lower right, and choose `Storage`. For `Device type`, select `CDROM device`
and choose the VirtIO driver ISO you downloaded earlier. This will give the Windows 10 Installer access
to drivers during the installation process. Now click `Finish` to add the new CD-ROM device.
![](kvm/14.png)
You are now ready to click `Begin Installation`
You're now ready to click `Begin Installation`
![](kvm/15.png)
Now move on to installing the virtual machine.
## Install the virtual machine
From here out you will install Windows 10 Professional as you would on any other machine.
![](kvm/16.png)
Once you get to the point of selecting the location for installation, you will see there are no disks available. This is because we need to load the VirtIO driver. Select `Load driver`.
Once you get to the point of selecting the location for installation, you will see there are no disks available.
This is because we need to load the VirtIO driver. Select `Load driver`.
![](kvm/17.png)
The installer will then ask you to specify where the driver is located. Select the `E:\` drive or whichever drive the VirtIO driver ISO is located on.
The installer will then ask you to specify where the driver is located. Select the `E:\` drive
or whichever drive the VirtIO driver ISO is located on.
![](kvm/18.png)
Choose the appropriate driver for the OS you have selected, which is most likely the `w10` driver for Windows 10.
Choose the appropriate driver for the OS you've selected, which is most likely the `w10` driver for Windows 10.
![](kvm/19.png)
@@ -115,11 +133,12 @@ You will now see a disk you can select for the installation.
![](kvm/20.png)
Windows will begin to install, and you will likely need to reboot the VM a number times during this process.
Windows will begin to install, and you will likely need to reboot the VM a number of times during this process.
![](kvm/21.png)
At some point, you will come to a network screen. This is because the VirtIO drivers for the network have not yet been loaded. Simply click `I don't have internet`.
At some point, you will come to a network screen. This is because the VirtIO drivers
for the network haven't yet been loaded. Simply click `I don't have internet`.
![](kvm/22.png)
@@ -127,31 +146,37 @@ It will confirm your choice, so just choose `Continue with limited setup`.
![](kvm/23.png)
After you get into Windows and login with the user you created during the install. Open up `Explorer` and navigate the `E:\` drive or wherever the VirtIO driver ISO is mounted. Double click the `virt-win-gt-64.exe` file to launch the VirtIO driver installer.
After you get into Windows and login with the user you created during the installation. Open `Explorer`
and navigate the `E:\` drive or wherever the VirtIO driver ISO is mounted. Double-click the `virt-win-gt-64.exe` file
to launch the VirtIO driver installer.
![](kvm/24.png)
Leave everything as default and click `Next` through the installer. This will install device drivers as well as the Memory Ballooning service.
Leave everything as default and click `Next` through the installer. This will install device drivers as well as
the Memory Ballooning service.
![](kvm/25.png)
Once you finish the driver install, you will need to make some registry changes to enable RDP Applications to run on the system. Start by downloading the [RDPApps.reg](/install/RDPApps.reg) file, right clicking on the `Raw` button, and clicking on `Save target as`.
Once you finish the driver install, you will need to make some registry changes to enable RDP Applications
to run on the system. Start by downloading the [RDPApps.reg](/install/RDPApps.reg) file,
right-clicking on the `Raw` button, and clicking on `Save target as`.
![](kvm/26.png)
Once you have downloaded the registry file, right click on it, and choose `Merge`, then accept any confirmations along the way.
Once you've downloaded the registry file, right-click on it, and choose `Merge`, then accept any confirmations along the way.
![](kvm/27.png)
Next up, we need to rename the VM so that WinApps can locate it. Go to the start menu and type `About` to bring up the `About your PC` settings.
Next up, we need to rename the VM so that WinApps can locate it. Go to the start menu and type `About`
to bring up the `About your PC` settings.
![](kvm/28.png)
Scroll down and click on `Rename this PC`
Scroll down and click on `Rename this PC`.
![](kvm/29.png)
Rename to `RDPWindows`, and then `Next`, but **do not** restart.
Rename to `RDPWindows`, and then `Next`, but **don't** restart.
![](kvm/30.png)
@@ -159,36 +184,49 @@ Lastly, scroll down to `Remote Desktop`, and toggle `Enable Remote Desktop` on,
![](kvm/31.png)
At this point you will need to restart and you have completed your setup.
At this point, you will need to restart, and you've completed your setup.
Rather than restart you can go right ahead and install other applications like Microsoft Office or Adobe CC that could be used through WinApps.
Rather than restart, you can go right ahead and install other applications like Microsoft Office or Adobe CC
that could be used through WinApps.
You may also wish to install the [Spice Guest Tools](https://www.spice-space.org/download/windows/spice-guest-tools/spice-guest-tools-latest.exe) inside the VM which enables features like auto-desktop resize and cut-and-paste when using `virt-manager`. As WinApps uses RDP, this is not necessary if you do not plan to access the machine via `virt-manager`.
You may also wish to install
the [Spice Guest Tools](https://www.spice-space.org/download/windows/spice-guest-tools/spice-guest-tools-latest.exe)
inside the VM which enables features like auto-desktop resize and cut-and-paste when using `virt-manager`.
As WinApps uses RDP, this is unnecessary if you don't plan to access the machine via `virt-manager`.
Once you are finished, restart the VM, but do not log in. Simply close the VM viewer, and close the Virtual Machine Manager.
Once you're finished, restart the VM, but don't log in. Simply close the VM viewer, and close the Virtual Machine Manager.
## Expert installs
### Define a VM from XML
This expert guide for XML imports is specific to Ubuntu 20.04 and may not work on all hardware platforms.
You can refer to the [KVM](https://www.linux-kvm.org) documentation for specifics, but the first thing you need to do is set up a Virtual Machine running Windows 10 Professional (or any version that supports RDP). First, install KVM:
You can refer to the [KVM](https://www.linux-kvm.org) documentation for specifics, but the first thing you need to do is
set up a Virtual Machine running Windows 10 Professional (or any version that supports RDP). First, install KVM:
``` bash
sudo apt-get install -y virt-manager
sudo apt install -y virt-manager
```
Now, copy your Windows ISO and VirtIO iso (links to download in the main guide) into the folder and update the `kvm/RDPWindows.xml` appropriately.
Now, copy your Windows ISO and VirtIO iso (links to download in the main guide) into the folder
and update the `kvm/RDPWindows.xml` appropriately.
Next, define a VM called RDPWindows from the sample XML file with:
``` bash
virsh define kvm/RDPWindows.xml
virsh autostart RDPWindows
```
You should then open the VMs properties in `virt-manager` and ensure that under CPU `Copy host CPU configuration` is selected.
Boot it up, install windows, and then [Install the virtual machine](#install-the-virtual-machine).
Boot it up, install Windows, and then [Install the virtual machine](#install-the-virtual-machine).
### Run KVM in user mode
Now set up KVM to run as your user instead of root and allow it through AppArmor (for Ubuntu 20.04 and above):
``` bash
sudo sed -i "s/#user = "root"/user = "$(id -un)"/g" /etc/libvirt/qemu.conf
sudo sed -i "s/#group = "root"/group = "$(id -gn)"/g" /etc/libvirt/qemu.conf
@@ -197,4 +235,5 @@ sudo usermod -a -G libvirt $(id -un)
sudo systemctl restart libvirtd
sudo ln -s /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/
```
You will likely need to reboot to ensure your current shell is added to the group.

View File

@@ -1,26 +1,32 @@
# Docker
# Creating a Virtual Machine in Docker
## Why docker?
## Why Docker?
While working with `virsh` is completely fine for winapps, you have to set up and optimize you vm manually. Docker on the other hand sets up most of the stuff automatically and also makes the VM highly portable between Linux distros.
While working with `virsh` is completely fine for WinApps, you have to set up and optimize your VM manually.
Docker, on the other hand, sets up most of the stuff automatically and makes the VM highly portable between Linux distros.
# Requirements
Since Docker manages the dependencies of the container automatically you only need to install Docker itself.
Since Docker manages the dependencies of the container automatically, you only need to install Docker itself.
You can try using Podman too because of their faster container startup times, but note that Podman and Docker are not always fully interchangeable. In case you want to follow this guide using podman, you will have to install the `docker` CLI to be able to run `docker compose` commands. You'll also have to enable the Podman socket. Refer to the podman docs for how to do that.
You can try using Podman too because of their faster container startup times,
but note that Podman and Docker aren't always fully interchangeable. In case you want to follow this guide using Podman,
you will have to install the `docker` CLI to be able to run `docker compose` commands.
You will also have to enable the Podman socket. Refer to the Podman docs for how to do that.
See:
- [Podman installation docs](https://podman.io/docs/installation)
- [Docker installation docs](https://docs.docker.com/engine/install)
- [Using `docker compose` with Podman](https://www.redhat.com/sysadmin/podman-docker-compose) (slightly outdated)
> [!NOTE]
> This will only work on Linux systems since some kernel interfaces (like KVM) are needed by the VM. Because of this performance can vary depending on kernel version (newer will likely perform better).
> This will only work on Linux systems since the VM needs some kernel interfaces (like KVM). Because of this,
> performance can vary depending on kernel version (newer will likely perform better).
# Setup docker container
# Setup Docker Container
The easiest way to set up a Windows VM is by using docker compose. A compose file that looks like this is already shipped with winapps:
The easiest way to set up a Windows VM is by using docker compose. A compose file that looks like this is already shipped with WinApps:
```yaml
name: "winapps"
@@ -47,35 +53,42 @@ services:
- data:/storage
```
Now you can tune the ram/usage by changing `RAM_SIZE` & `CPU_CORES`. You can also specify the windows versions you want to use. You might also want to take a look at the [repo of the Docker image](https://github.com/dockur/windows) for further information.
Now you can tune the RAM/usage by changing `RAM_SIZE` & `CPU_CORES`. You can also specify
the Windows versions you want to use. You might also want to take a look at the [repo of the Docker image](https://github.com/dockur/windows) for further information.
This compose file uses Windows 11 by default. You can use Windows 10 by changing the `VERSION` to `tiny10`.
> [!NOTE]
> We use a stripped-down Windows installation by default. This is recommended, but you can still opt for stock windows by changing the version to one of the versions listed in the README of the images repository linked above.
> We use a stripped-down Windows installation by default. This is recommended,
> but you can still opt for stock Windows by changing the version to one of the versions listed in
> the README of the images repository linked above.
> [!NOTE]
> Older versions than Windows 10 are not officially supported by us. However they might still work with some additional tuning.
> We don't officially support older versions than Windows 10. However, they might still work with some additional tuning.
You can now just run:
```shell
docker compose up -d
```
to run the VM in the background.
After this just open http://127.0.0.1:8006 in your web browser and wait for the Windows installation to finish.
After this, just open http://127.0.0.1:8006 in your web browser and wait for the Windows installation to finish.
> [!WARNING]
> Make sure to change the `RDP_IP` in your winapps config to `127.0.0.1`.
> Make sure to change the `RDP_IP` in your WinApps config to `127.0.0.1`.
Now you should be ready to go and try to connect to your VM with winapps.
Now you should be ready to go and try to connect to your VM with WinApps.
For stopping the VM, just use:
For stopping the VM just use:
```shell
docker compose stop
```
For starting again afterwards use:
For starting again afterward, use:
```shell
docker compose start
```