-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vfio and kvmfr module support to dx images
- Loading branch information
1 parent
d7c60c3
commit b91abff
Showing
4 changed files
with
216 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/bash | ||
|
||
set -ouex pipefail | ||
|
||
sed -i 's@enabled=0@enabled=1@g' /etc/yum.repos.d/_copr_ublue-os-akmods.repo | ||
if [[ "${FEDORA_MAJOR_VERSION}" -ge "39" ]]; then | ||
rpm-ostree install \ | ||
/tmp/akmods-rpms/kmods/*kvmfr*.rpm | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env bash | ||
source /usr/lib/ujust/ujust.sh | ||
|
||
# Required disclaimer and where to report issues first | ||
echo "$(Urllink "https://looking-glass.io/docs/rc/ivshmem_kvmfr/#libvirt" "This module") along with $(Urllink "https://looking-glass.io" "Looking Glass") is very experimental and not recommended for production use!" | ||
echo "The ublue team packages the kvmfr module only because it has to be supplied with the system image while using an atomic desktop." | ||
echo "If you do plan to use Looking Glass, please $(Urllink "https://universal-blue.discourse.group/docs?topic=956" "follow the guide here") on how to compile it for your system." | ||
echo "To use the kvmfr module after enabling it, just add and edit the xml for libvirt from the documentation in the first link." | ||
echo "Since we package the kvmfr module please open kvmfr related issues you have on Bluefin or Aurora and tag me" | ||
echo "in the $(Urllink "https://discord.gg/WEu6BdFEtp" "Universal Blue Discord") or the $(Urllink "https://github.com/ublue-os/bluefin/issues" "Bluefin Github issue tracker")." | ||
echo "~ @HikariKnight" | ||
|
||
CONFIRM=$(Choose Ok Cancel) | ||
if [ "$CONFIRM" == "Cancel" ]; then | ||
exit 0 | ||
fi | ||
|
||
# Add kvmfr to dracut so that it's modprobe file can be used | ||
echo "" | ||
echo "Setting up kvmfr module so it loads next boot" | ||
sudo bash -c 'cat << KVMFR_DRACUT > /etc/dracut.conf.d/kvmfr.conf | ||
install_items+=" /etc/modprobe.d/kvmfr.conf " | ||
KVMFR_DRACUT' | ||
|
||
# Add kvmfr modprobe file following upstream documentation | ||
sudo bash -c "cat << KVMFR_MODPROBE > /etc/modprobe.d/kvmfr.conf | ||
options kvmfr static_size_mb=128 | ||
KVMFR_MODPROBE" | ||
|
||
# Add upstream udev rule for kvmfr, adjusted for fedora systems | ||
echo "Adding udev rule for /dev/kvmfr0" | ||
sudo bash -c 'cat << KVMFR_UDEV > /etc/udev/rules.d/99-kvmfr.rules | ||
SUBSYSTEM=="kvmfr", OWNER="'$USER'", GROUP="qemu", MODE="0660" | ||
KVMFR_UDEV' | ||
|
||
# Add /dev/kvmfr0 to qemu cgroup device acl list | ||
echo "Adding /dev/kvmfr0 to qemu cgroup_device_acl" | ||
# This is not ideal and if someone has a better way to do this without perl, you are welcome to change it | ||
sudo perl -0777 -pi -e 's/ | ||
#cgroup_device_acl = \[ | ||
# "\/dev\/null", "\/dev\/full", "\/dev\/zero", | ||
# "\/dev\/random", "\/dev\/urandom", | ||
# "\/dev\/ptmx", "\/dev\/kvm", | ||
# "\/dev\/userfaultfd" | ||
#\] | ||
/ | ||
cgroup_device_acl = \[ | ||
"\/dev\/null", "\/dev\/full", "\/dev\/zero", | ||
"\/dev\/random", "\/dev\/urandom", | ||
"\/dev\/ptmx", "\/dev\/kvm", | ||
"\/dev\/userfaultfd", "\/dev\/kvmfr0" | ||
\] | ||
/' /etc/libvirt/qemu.conf | ||
|
||
# Add SELinux context record for /dev/kvmfr0 (for simplicity we use the same one that was used for the shm) | ||
echo "Adding SELinux context record for /dev/kvmfr0" | ||
sudo semanage fcontext -a -t svirt_tmpfs_t /dev/kvmfr0 | ||
|
||
# Create type enforcement for /dev/kvmfr0 as there is no existing way to access kvmfr using virt context | ||
echo "Adding SELinux access rules for /dev/kvmfr0" | ||
if [ ! -d "$HOME/.config/selinux_te/mod" ]; then | ||
mkdir -p "$HOME/.config/selinux_te/mod" | ||
fi | ||
if [ ! -d "$HOME/.config/selinux_te/pp" ]; then | ||
mkdir -p "$HOME/.config/selinux_te/pp" | ||
fi | ||
bash -c "cat << KVMFR_SELINUX > $HOME/.config/selinux_te/kvmfr.te | ||
module kvmfr 1.0; | ||
require { | ||
type device_t; | ||
type svirt_t; | ||
class chr_file { open read write map }; | ||
} | ||
#============= svirt_t ============== | ||
allow svirt_t device_t:chr_file { open read write map }; | ||
KVMFR_SELINUX" | ||
|
||
# Tell user what type enforcement we made and how it looks like | ||
echo "This is the type enforcement we wrote for SELinux and you can find it in $HOME/.config/selinux_te/kvmfr.te" | ||
echo "#======= start of kvmfr.te =======" | ||
cat "$HOME/.config/selinux_te/kvmfr.te" | ||
echo "#======== end of kvmfr.te ========" | ||
checkmodule -M -m -o "$HOME/.config/selinux_te/mod/kvmfr.mod" "$HOME/.config/selinux_te/kvmfr.te" | ||
semodule_package -o "$HOME/.config/selinux_te/pp/kvmfr.pp" -m "$HOME/.config/selinux_te/mod/kvmfr.mod" | ||
sudo semodule -i "$HOME/.config/selinux_te/pp/kvmfr.pp" | ||
|
||
# Load kvmfr module into currently booted system | ||
echo "Loading kvmfr module so you do not have to reboot to use it the first time" | ||
sudo modprobe kvmfr static_size_mb=128 | ||
sudo chown $USER:qemu /dev/kvmfr0 | ||
|
||
# Final message and regenerate initramfs so kvmfr loads next boot | ||
echo "" | ||
echo "Kvmfr0 $(Urllink "https://looking-glass.io/docs/rc/install_libvirt/#determining-memory" "static size is set to 128mb by default")" | ||
echo "this will work with up to 4K SDR resolutiion, as most dummy plugs go up to 4K" | ||
echo "some games will try use the adapters max resolution on first boot and cause issues if the value is too low." | ||
echo "Most ghost display adapters max out at 4k, hence the default value of 128mb." | ||
echo "" | ||
echo "If you need to change it to a different value" | ||
echo "you can do that in /etc/modprobe.d/kvmfr.conf" | ||
echo "$(Urllink "https://looking-glass.io/docs/rc/ivshmem_kvmfr/#libvirt" "Please read official documentation for kvmfr for how to use it")" | ||
echo "" | ||
echo "Press OK to start the process of regenerating your initramfs, this will take a long time" | ||
echo "and there is no good way to track progress for it, if anything is wrong it will error out." | ||
echo "${b}NOTE: You can start using kvmfr right now without rebooting, but you will need to regenerate initramfs for it to auto load next boot.${n}" | ||
|
||
CONFIRM=$(Choose OK) | ||
rpm-ostree initramfs --enable |