From f76c5c56961f6a1952558604e284781110af6e9b Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 11:32:56 +0100
Subject: [PATCH 01/34] added paths for dracut and mkinitcpio
---
lib/paths.sh | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/paths.sh b/lib/paths.sh
index 745426f..6d287ce 100755
--- a/lib/paths.sh
+++ b/lib/paths.sh
@@ -3,4 +3,6 @@ MODPROBE="config/etc/modprobe.d"
INITRAMFS="config/etc/initramfs-tools"
ETCMODULES="config/etc/modules"
DEFAULT="config/etc/default"
-QUICKEMU="config/quickemu"
\ No newline at end of file
+QUICKEMU="config/quickemu"
+DRACUT="config/etc/dracut.conf.d/10-vfio.conf"
+MKINITCPIO="config/etc/mkinitcpio.conf"
\ No newline at end of file
From 12d7c957de5da125820a237e1eee36a6ed40278e Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 11:35:10 +0100
Subject: [PATCH 02/34] mention making pull requests to the dev branch
(cherry picked from commit db70581045375cd6012b61b02372299a5c22a52b)
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index f918ca0..d5becd9 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ cd quickpassthrough
I know my bash skills are not great, so help is always welcome! And help is wanted here.
-If you know bash well, you will be able to help! Just make a pull request with your changes!
+If you know bash well, you will be able to help! Just make a pull request to the [dev branch](https://github.com/HikariKnight/quickpassthrough/tree/dev) with your changes!
Just remember to add comments to document the work and explain it for people who are less familiar with the bash syntax or anything else you use. 😄
Also if you know English, you can help by just proof reading. English is not my native language, plus I have dyslexia so I often make spelling mistakes.
From 2cd4ceb2e5125a5f44e7f441ef9754c9b86fbf93 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 12:14:47 +0100
Subject: [PATCH 03/34] fix broken variables
(cherry picked from commit ddb37dc738480a81d3e5b181e9033b34ddb08374)
---
lib/set_MODULES.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/set_MODULES.sh b/lib/set_MODULES.sh
index 0675edd..1a839ae 100755
--- a/lib/set_MODULES.sh
+++ b/lib/set_MODULES.sh
@@ -16,7 +16,7 @@ function insert_MODULES() {
fi
# Write header
- echo "$ETCMODULES_HEADER" > "$2"
+ echo "$MODULES_HEADER" > "$2"
# If vendor-reset existed from before
if [ $VENDOR_RESET == 1 ];
@@ -36,7 +36,7 @@ vfio_virqfd
" >> "$2"
# Write the previously enabled modules under vfio in the load order
- echo "$ETCMODULES_ENABLED" >> "$2"
+ echo "$MODULES_ENABLED" >> "$2"
}
function set_MODULES () {
From 22f6786977da9b620f194c7ce6aef47e0231b359 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 12:19:48 +0100
Subject: [PATCH 04/34] Rename set_MODULES to set_INITRAMFSTOOLS to start work
with other initramfs systems
---
lib/get_GPU_GROUP.sh | 2 +-
lib/{set_MODULES.sh => set_INITRAMFSTOOLS.sh} | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
rename lib/{set_MODULES.sh => set_INITRAMFSTOOLS.sh} (93%)
diff --git a/lib/get_GPU_GROUP.sh b/lib/get_GPU_GROUP.sh
index 917a6c5..c5f017d 100755
--- a/lib/get_GPU_GROUP.sh
+++ b/lib/get_GPU_GROUP.sh
@@ -49,7 +49,7 @@ USB_CTL_ID=()
"$SCRIPTDIR/lib/get_GPU_ROM.sh" "$ROM_PCI_ID"
# Start setting up modules
- exec "$SCRIPTDIR/lib/set_MODULES.sh" $GPU_DEVID
+ exec "$SCRIPTDIR/lib/set_INITRAMFSTOOLS.sh" $GPU_DEVID
;;
*)
exec "$SCRIPTDIR/lib/get_GPU.sh"
diff --git a/lib/set_MODULES.sh b/lib/set_INITRAMFSTOOLS.sh
similarity index 93%
rename from lib/set_MODULES.sh
rename to lib/set_INITRAMFSTOOLS.sh
index 1a839ae..fa68934 100755
--- a/lib/set_MODULES.sh
+++ b/lib/set_INITRAMFSTOOLS.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-function insert_MODULES() {
+function insert_INITRAMFSTOOLS() {
# Get the header and enabled modules separately from the /etc/modules file
local MODULES_HEADER
local MODULES_ENABLED
@@ -39,14 +39,14 @@ vfio_virqfd
echo "$MODULES_ENABLED" >> "$2"
}
-function set_MODULES () {
+function set_INITRAMFSTOOLS () {
# Get the config paths
source "$SCRIPTDIR/lib/paths.sh"
# Insert modules in the correct locations as early as possible without
# conflicting with vendor-reset module if it is enabled
- insert_MODULES 4 "$SCRIPTDIR/$ETCMODULES"
- insert_MODULES 11 "$SCRIPTDIR/$INITRAMFS/modules"
+ insert_INITRAMFSTOOLS 4 "$SCRIPTDIR/$ETCMODULES"
+ insert_INITRAMFSTOOLS 11 "$SCRIPTDIR/$INITRAMFS/modules"
# Assign the GPU device ids to a variable
GPU_DEVID="$1"
@@ -100,7 +100,7 @@ softdep radeon pre: vfio vfio_pci
function main () {
SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
- set_MODULES "$1"
+ set_INITRAMFSTOOLS "$1"
}
main "$1"
From 96809da530d9eda5af5513b9d49570421ab8b346 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 12:39:53 +0100
Subject: [PATCH 05/34] use the right variable for the modified grub file
---
lib/set_CMDLINE.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh
index 3497532..6eae808 100755
--- a/lib/set_CMDLINE.sh
+++ b/lib/set_CMDLINE.sh
@@ -48,17 +48,17 @@ function set_GRUB () {
local GRUB_CMDLINE_LINUX
# Check if there is a GRUB_CMDLINE_LINUX_DEFAULT line in grub config
- if grep -q "GRUB_CMDLINE_LINUX_DEFAULT=" "$SCRIPTDIR/config/etc/default/grub" ;
+ if grep -q "GRUB_CMDLINE_LINUX_DEFAULT=" "$SCRIPTDIR/$DEFAULT/grub" ;
then
# Update the GRUB_CMDLINE_LINUX_DEFAULT line
GRUB_CMDLINE=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX_DEFAULT" | perl -pe "s/GRUB_CMDLINE_LINUX_DEFAULT=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g")
GRUB_CMDLINE_LINUX=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX_DEFAULT")
- perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/config/etc/default/grub"
+ perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/$DEFAULT/grub"
else
# Update the GRUB_CMDLINE_LINUX line
GRUB_CMDLINE=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX" | perl -pe "s/GRUB_CMDLINE_LINUX=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g")
GRUB_CMDLINE_LINUX=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX")
- perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/config/etc/default/grub"
+ perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/$DEFAULT/grub"
fi
@@ -69,7 +69,7 @@ $SCRIPTDIR/backup/etc/default/grub
"
read -r -p "Press ENTER to continue"
- sudo cp -v "$SCRIPTDIR/config/etc/default/grub" "/etc/default/grub"
+ sudo cp -v "$SCRIPTDIR/$DEFAULT/grub" "/etc/default/grub"
# Generate grub.cfg
if [ -d "/boot/grub" ];
From 0bf8e320625afe25af55ea0ea4ae5fcfc30dda8c Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 14:14:56 +0100
Subject: [PATCH 06/34] Cleanup
---
lib/get_GPU_ROM.sh | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/lib/get_GPU_ROM.sh b/lib/get_GPU_ROM.sh
index f4e6672..4869daa 100755
--- a/lib/get_GPU_ROM.sh
+++ b/lib/get_GPU_ROM.sh
@@ -6,7 +6,7 @@ function get_GPU_ROM () {
source "$SCRIPTDIR/lib/paths.sh"
VBIOS_PATH=$(find /sys/devices -name rom | grep "$1")
- printf "We will now attempt to dump the vbios of your selected GPU.
+ echo "We will now attempt to dump the vbios of your selected GPU.
Passing a VBIOS rom to the card used for passthrough is required for some cards, but not all.
Some cards also requires you to patch your VBIOS romfile, check online if this is neccessary for your card.
The VBIOS will be read from $VBIOS_PATH
@@ -17,15 +17,17 @@ sudo cat $VBIOS_PATH > $SCRIPTDIR/$QUICKEMU/vfio_card.rom
echo 0 | sudo tee $VBIOS_PATH
"
- read -p "Do you want to dump the VBIOS, choosing N will skip this step [y/N]: " YESNO
+ read -r -p "Do you want to dump the VBIOS, choosing N will skip this step [y/N]: " YESNO
case "${YESNO}" in
[Yy]*)
echo 1 | sudo tee "$VBIOS_PATH"
sudo cat "$VBIOS_PATH" > "$SCRIPTDIR/$QUICKEMU/vfio_card.rom"
sudo md5sum "$VBIOS_PATH" | cut -d " " -f 1 > "$SCRIPTDIR/$QUICKEMU/vfio_card.rom.md5"
- local ROM_MD5=$(sudo md5sum "$VBIOS_PATH" | cut -d " " -f 1)
+ local ROM_MD5
+ ROM_MD5=$(sudo md5sum "$VBIOS_PATH" | cut -d " " -f 1)
echo 0 | sudo tee "$VBIOS_PATH"
- local ROMFILE_MD5=$(md5sum "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" | cut -d " " -f 1)
+ local ROMFILE_MD5
+ ROMFILE_MD5=$(md5sum "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" | cut -d " " -f 1)
if [ -f "$SCRIPTDIR"/$QUICKEMU/vfio_card.rom ];
then
@@ -35,14 +37,14 @@ echo 0 | sudo tee $VBIOS_PATH
echo "Dumping of VBIOS successful!"
echo 'GPU_ROMFILE="vfio_card.rom"' >> "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
- read -p "Press ENTER to continue." ENTER
+ read -r -p "Press ENTER to continue."
else
echo "Checksums does not match!"
echo "Dumping of VBIOS failed, skipping romfile"
mv "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" "$SCRIPTDIR/$QUICKEMU/vfio_card.rom.fail"
echo 'GPU_ROMFILE=""' >> "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
- read -p "Press ENTER to continue." ENTER
+ read -r -p "Press ENTER to continue."
fi
else
echo 'GPU_ROMFILE=""' >> "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
@@ -61,7 +63,7 @@ echo 0 | sudo tee $VBIOS_PATH
function main () {
SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
- get_GPU_ROM $1
+ get_GPU_ROM "$1"
}
-main $1
\ No newline at end of file
+main "$1"
\ No newline at end of file
From 0cfea988e594981c023992a0d93c21447e937381 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 14:22:30 +0100
Subject: [PATCH 07/34] Move a quote
---
lib/get_GPU_ROM.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/get_GPU_ROM.sh b/lib/get_GPU_ROM.sh
index 4869daa..519c355 100755
--- a/lib/get_GPU_ROM.sh
+++ b/lib/get_GPU_ROM.sh
@@ -29,7 +29,7 @@ echo 0 | sudo tee $VBIOS_PATH
local ROMFILE_MD5
ROMFILE_MD5=$(md5sum "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" | cut -d " " -f 1)
- if [ -f "$SCRIPTDIR"/$QUICKEMU/vfio_card.rom ];
+ if [ -f "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" ];
then
if [ "$ROM_MD5" == "$ROMFILE_MD5" ];
then
From 8668c738c5faa08ed4255a500e4d9b1f9c54c4e0 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 14:25:55 +0100
Subject: [PATCH 08/34] General cleanup and add missing quotes
---
lib/get_GPU_GROUP.sh | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/get_GPU_GROUP.sh b/lib/get_GPU_GROUP.sh
index c5f017d..bd8bebc 100755
--- a/lib/get_GPU_GROUP.sh
+++ b/lib/get_GPU_GROUP.sh
@@ -24,32 +24,32 @@ To use any of these devices for passthrough ALL of them has to be passed through
To return to the previous page just press ENTER without typing in anything.
"
- read -p "Do you want to use these devices for passthrough? [y/N]: " YESNO
+ read -r -p "Do you want to use these devices for passthrough? [y/N]: " YESNO
case "${YESNO}" in
[Yy]*)
# Get the hardware ids from the selected group
local GPU_DEVID
- GPU_DEVID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | perl -pe "s/.+\[([0-9a-f]{4}:[0-9a-f]{4})\].+/\1/" | perl -pe "s/\n/,/" | perl -pe "s/,$/\n/")
+ GPU_DEVID=$("$SCRIPTDIR/utils/ls-iommu" | grep -i "group $1" | perl -pe "s/.+\[([0-9a-f]{4}:[0-9a-f]{4})\].+/\1/" | perl -pe "s/\n/,/" | perl -pe "s/,$/\n/")
# Get the PCI ids
local PCI_ID
- PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4 | perl -pe "s/([0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]{1})\n/\"\1\" /" | perl -pe "s/\s$//")
+ PCI_ID=$("$SCRIPTDIR/utils/ls-iommu" | grep -i "group $1" | cut -d " " -f 4 | perl -pe "s/([0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]{1})\n/\"\1\" /" | perl -pe "s/\s$//")
# Write the GPU_PCI_IDs to the config that quickemu might make use of in the future
- printf "GPU_PCI_ID=($PCI_ID)
+ echo "GPU_PCI_ID=($PCI_ID)
USB_CTL_ID=()
" > "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
# Get the rom PCI_ID
local ROM_PCI_ID
- ROM_PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "vga" | grep -i "group $1" | cut -d " " -f 4)
+ ROM_PCI_ID=$("$SCRIPTDIR/utils/ls-iommu" | grep -i "vga" | grep -i "group $1" | cut -d " " -f 4)
# Get the GPU ROM
"$SCRIPTDIR/lib/get_GPU_ROM.sh" "$ROM_PCI_ID"
# Start setting up modules
- exec "$SCRIPTDIR/lib/set_INITRAMFSTOOLS.sh" $GPU_DEVID
+ exec "$SCRIPTDIR/lib/set_INITRAMFSTOOLS.sh" "$GPU_DEVID"
;;
*)
exec "$SCRIPTDIR/lib/get_GPU.sh"
@@ -60,7 +60,7 @@ USB_CTL_ID=()
function main () {
SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
- get_GROUP $1
+ get_GROUP "$1"
}
-main $1
+main "$1"
From 9ab572032d22f6b71de40b6a0c5f789bc04f1cb1 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 14:32:25 +0100
Subject: [PATCH 09/34] add newline to make output nicer
---
lib/set_CMDLINE.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh
index 6eae808..d66db03 100755
--- a/lib/set_CMDLINE.sh
+++ b/lib/set_CMDLINE.sh
@@ -139,7 +139,8 @@ NOTE: Some AMD GPUs will require the vendor-reset kernel module from https://git
echo "* $dev"
done
- echo "For performance tuning and advanced configuration look at:
+ echo "
+For performance tuning and advanced configuration look at:
https://github.com/HikariKnight/vfio-setup-docs/wiki"
}
From 898e1f7347179ff260fe8ca1501bc55b5f85bb74 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 14:39:05 +0100
Subject: [PATCH 10/34] Split up scripts to reuse parts for other initramfs
systems
---
lib/set_INITRAMFSTOOLS.sh | 46 ++-------------------------------------
lib/set_MODPROBE.sh | 37 +++++++++++++++++++++++++++++++
lib/set_VFIO.sh | 45 ++++++++++++++++++++++++++++++++++++++
vfio-setup | 27 ++++++++++++++++-------
4 files changed, 103 insertions(+), 52 deletions(-)
create mode 100755 lib/set_MODPROBE.sh
create mode 100755 lib/set_VFIO.sh
diff --git a/lib/set_INITRAMFSTOOLS.sh b/lib/set_INITRAMFSTOOLS.sh
index fa68934..03fb5ff 100755
--- a/lib/set_INITRAMFSTOOLS.sh
+++ b/lib/set_INITRAMFSTOOLS.sh
@@ -48,50 +48,8 @@ function set_INITRAMFSTOOLS () {
insert_INITRAMFSTOOLS 4 "$SCRIPTDIR/$ETCMODULES"
insert_INITRAMFSTOOLS 11 "$SCRIPTDIR/$INITRAMFS/modules"
- # Assign the GPU device ids to a variable
- GPU_DEVID="$1"
-
- # Get the kernel_args file content
- CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
-
- # Ask if we shall disable video output on this card
- echo "
-Disabling video output in Linux for the card you want to use in a VM
-will make it easier to successfully do the passthrough without issues."
- read -p "Do you want to force disable video output in linux on this card? [Y/n]: " DISABLE_VGA
- case "${DISABLE_VGA}" in
- [Yy]*)
- # Update kernel_args file
- echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID} vfio_pci.disable_vga=1" > "$SCRIPTDIR/config/kernel_args"
-
- # Update GPU_DEVID
- GPU_DEVID="$GPU_DEVID disable_vga=1"
- ;;
- [Nn]*)
- echo ""
- ;;
- *)
- # Update kernel_args file
- echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID} vfio_pci.disable_vga=1" > "$SCRIPTDIR/config/kernel_args"
-
- # Update GPU_DEVID
- GPU_DEVID="$GPU_DEVID disable_vga=1"
- ;;
- esac
-
- # Write the vfio modprobe config
- printf "## This is an autogenerated file that stubs your graphic card for use with vfio
-## This file should be placed inside /etc/modprobe.d/
-# Uncomment the line below to \"hardcode\" your graphic card to be bound to the vfio-pci driver.
-# In most cases this should not be neccessary, it will also prevent you from turning off vfio in the bootloader.
-#options vfio_pci ids=%s
-
-# Make sure vfio_pci is loaded before these modules: nvidia, nouveau, amdgpu and radeon
-softdep nvidia pre: vfio vfio_pci
-softdep nouveau pre: vfio vfio_pci
-softdep amdgpu pre: vfio vfio_pci
-softdep radeon pre: vfio vfio_pci
-" "${GPU_DEVID}" > "$SCRIPTDIR/$MODPROBE/vfio.conf"
+ "$SCRIPTDIR/lib/set_VFIO.sh" "$1"
+ "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
}
diff --git a/lib/set_MODPROBE.sh b/lib/set_MODPROBE.sh
new file mode 100755
index 0000000..1bb5f4b
--- /dev/null
+++ b/lib/set_MODPROBE.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+function set_MODPROBE () {
+ # Get the config paths
+ source "$SCRIPTDIR/lib/paths.sh"
+
+ # Assign the GPU device ids to a variable
+ GPU_DEVID="$1"
+
+ # If VGA is disabled
+ if grep -q "vfio_pci.disable_vga=1" "$SCRIPTDIR/config/kernel_args" ;
+ then
+ # Modify our GPU_DEVID line to containe disable_vga=1
+ GPU_DEVID="${GPU_DEVID} disable_vga=1"
+ fi
+
+ # Write the vfio modprobe config
+ printf "## This is an autogenerated file that stubs your graphic card for use with vfio
+## This file should be placed inside /etc/modprobe.d/
+# Uncomment the line below to \"hardcode\" your graphic card to be bound to the vfio-pci driver.
+# In most cases this should not be neccessary, it will also prevent you from turning off vfio in the bootloader.
+#options vfio_pci ids=%s
+
+# Make sure vfio_pci is loaded before these modules: nvidia, nouveau, amdgpu and radeon
+softdep nvidia pre: vfio vfio_pci
+softdep nouveau pre: vfio vfio_pci
+softdep amdgpu pre: vfio vfio_pci
+softdep radeon pre: vfio vfio_pci
+" "${GPU_DEVID}" > "$SCRIPTDIR/$MODPROBE/vfio.conf"
+}
+
+function main () {
+ SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+
+ set_MODPROBE "$1"
+}
+
+main "$1"
\ No newline at end of file
diff --git a/lib/set_VFIO.sh b/lib/set_VFIO.sh
new file mode 100755
index 0000000..142a54e
--- /dev/null
+++ b/lib/set_VFIO.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+function set_VFIO () {
+ # Get the config paths
+ source "$SCRIPTDIR/lib/paths.sh"
+
+ # Assign the GPU device ids to a variable
+ GPU_DEVID="$1"
+
+ # Get the kernel_args file content
+ CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
+
+ # Ask if we shall disable video output on this card
+ echo "
+Disabling video output in Linux for the card you want to use in a VM
+will make it easier to successfully do the passthrough without issues."
+ read -p "Do you want to force disable video output in linux on this card? [Y/n]: " DISABLE_VGA
+ case "${DISABLE_VGA}" in
+ [Yy]*)
+ # Update kernel_args file
+ echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID} vfio_pci.disable_vga=1" > "$SCRIPTDIR/config/kernel_args"
+
+ # Update GPU_DEVID
+ GPU_DEVID="$GPU_DEVID disable_vga=1"
+ ;;
+ [Nn]*)
+ # Update kernel_args file
+ echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID}" > "$SCRIPTDIR/config/kernel_args"
+ ;;
+ *)
+ # Update kernel_args file
+ echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID} vfio_pci.disable_vga=1" > "$SCRIPTDIR/config/kernel_args"
+
+ # Update GPU_DEVID
+ GPU_DEVID="$GPU_DEVID disable_vga=1"
+ ;;
+ esac
+}
+
+function main () {
+ SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+
+ set_VFIO "$1"
+}
+
+main "$1"
\ No newline at end of file
diff --git a/vfio-setup b/vfio-setup
index e1c625f..9461d14 100755
--- a/vfio-setup
+++ b/vfio-setup
@@ -91,35 +91,46 @@ fi
# Make the directories
mkdir -p "$SCRIPTDIR/$MODPROBE"
-mkdir -p "$SCRIPTDIR/$DEFAULT"
-mkdir -p "$SCRIPTDIR/$INITRAMFS"
mkdir -p "$SCRIPTDIR/$QUICKEMU"
# Write the cmdline file
echo "$CMDLINE" > "$SCRIPTDIR/config/kernel_args"
-# Copy system configs into our config folder so we can safely edit them
-
+# Copy system configs that exists into our config folder so we can safely edit them
if [ -f "/etc/modules" ];
then
# This copies /etc/modules without the vfio module lines
grep -v "vfio" "/etc/modules" > "$SCRIPTDIR/$ETCMODULES"
-else
- touch "$SCRIPTDIR/$ETCMODULES"
fi
if [ -f "/etc/default/grub" ];
then
+ # Create the default folder
+ mkdir -p "$SCRIPTDIR/$DEFAULT"
+
# Copy grub config
cp "/etc/default/grub" "$SCRIPTDIR/$DEFAULT/grub"
fi
if [ -f "/etc/initramfs-tools/modules" ];
then
+ # Create the initramfs folder
+ mkdir -p "$SCRIPTDIR/$INITRAMFS"
+
# This copies /etc/initramfs-tools/modules without the vfio modules
grep -v "vfio" "/etc/initramfs-tools/modules" > "$SCRIPTDIR/$INITRAMFS/modules"
-else
- touch "$SCRIPTDIR/$INITRAMFS"
+fi
+
+if [ -f "/etc/mkinitcpio.conf" ];
+then
+ # Copy mkinitcpio.conf to our config folder
+ cp "/etc/mkinitcpio.conf" "$SCRIPTDIR/$MKINITCPIO"
+fi
+
+if [ -f "/etc/dracut.conf" ];
+then
+ # Create a dracut.conf.d file
+ touch "$SCRIPTDIR/$DRACUT"
fi
# Run ls-iommu so we can verify that IOMMU properly working
From cd7b7a989a765035bcaa6a56fb22d4126c8994d1 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 14:50:07 +0100
Subject: [PATCH 11/34] Add more comments
---
lib/set_INITRAMFSTOOLS.sh | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/set_INITRAMFSTOOLS.sh b/lib/set_INITRAMFSTOOLS.sh
index 03fb5ff..d77f377 100755
--- a/lib/set_INITRAMFSTOOLS.sh
+++ b/lib/set_INITRAMFSTOOLS.sh
@@ -48,7 +48,10 @@ function set_INITRAMFSTOOLS () {
insert_INITRAMFSTOOLS 4 "$SCRIPTDIR/$ETCMODULES"
insert_INITRAMFSTOOLS 11 "$SCRIPTDIR/$INITRAMFS/modules"
+ # Bind GPU to VFIO
"$SCRIPTDIR/lib/set_VFIO.sh" "$1"
+
+ # Configure modprobe
"$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
From 4fc07b97f2982575b4da387fa0004d10b1a2d913 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 15:28:44 +0100
Subject: [PATCH 12/34] use realpath with dirname to get the scriptdir
---
lib/apply_CHANGES.sh | 2 +-
lib/get_GPU.sh | 2 +-
lib/get_GPU_GROUP.sh | 2 +-
lib/get_GPU_ROM.sh | 2 +-
lib/get_USB_CTL.sh | 2 +-
lib/get_USB_CTL_GROUP.sh | 2 +-
lib/set_CMDLINE.sh | 3 ++-
lib/set_INITRAMFSTOOLS.sh | 2 +-
lib/set_MODPROBE.sh | 2 +-
lib/set_VFIO.sh | 2 +-
vfio-setup | 2 +-
11 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index 0bd5b0e..009d997 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -74,7 +74,7 @@ to build your new initrd image (all of this will require sudo permissions!)"
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
apply_CHANGES
}
diff --git a/lib/get_GPU.sh b/lib/get_GPU.sh
index cf8772c..ef2dead 100755
--- a/lib/get_GPU.sh
+++ b/lib/get_GPU.sh
@@ -33,7 +33,7 @@ DO NOT use any of the files from $SCRIPTDIR/config !
}
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_GPU
}
diff --git a/lib/get_GPU_GROUP.sh b/lib/get_GPU_GROUP.sh
index bd8bebc..86b851a 100755
--- a/lib/get_GPU_GROUP.sh
+++ b/lib/get_GPU_GROUP.sh
@@ -58,7 +58,7 @@ USB_CTL_ID=()
}
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_GROUP "$1"
}
diff --git a/lib/get_GPU_ROM.sh b/lib/get_GPU_ROM.sh
index 519c355..82180e5 100755
--- a/lib/get_GPU_ROM.sh
+++ b/lib/get_GPU_ROM.sh
@@ -61,7 +61,7 @@ echo 0 | sudo tee $VBIOS_PATH
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_GPU_ROM "$1"
}
diff --git a/lib/get_USB_CTL.sh b/lib/get_USB_CTL.sh
index 9346c35..4fcc00a 100755
--- a/lib/get_USB_CTL.sh
+++ b/lib/get_USB_CTL.sh
@@ -31,7 +31,7 @@ Press q to quit
}
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_USB_CTL
}
diff --git a/lib/get_USB_CTL_GROUP.sh b/lib/get_USB_CTL_GROUP.sh
index 6dcfedb..ea9de2f 100755
--- a/lib/get_USB_CTL_GROUP.sh
+++ b/lib/get_USB_CTL_GROUP.sh
@@ -39,7 +39,7 @@ To return to the previous page just press ENTER.
}
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_USB_CTL_GROUP $1
}
diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh
index d66db03..5a8e763 100755
--- a/lib/set_CMDLINE.sh
+++ b/lib/set_CMDLINE.sh
@@ -170,7 +170,8 @@ function set_CMDLINE () {
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+
set_CMDLINE
}
diff --git a/lib/set_INITRAMFSTOOLS.sh b/lib/set_INITRAMFSTOOLS.sh
index d77f377..6a06a80 100755
--- a/lib/set_INITRAMFSTOOLS.sh
+++ b/lib/set_INITRAMFSTOOLS.sh
@@ -59,7 +59,7 @@ function set_INITRAMFSTOOLS () {
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_INITRAMFSTOOLS "$1"
}
diff --git a/lib/set_MODPROBE.sh b/lib/set_MODPROBE.sh
index 1bb5f4b..5f66ebe 100755
--- a/lib/set_MODPROBE.sh
+++ b/lib/set_MODPROBE.sh
@@ -29,7 +29,7 @@ softdep radeon pre: vfio vfio_pci
}
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_MODPROBE "$1"
}
diff --git a/lib/set_VFIO.sh b/lib/set_VFIO.sh
index 142a54e..3a9f4b6 100755
--- a/lib/set_VFIO.sh
+++ b/lib/set_VFIO.sh
@@ -37,7 +37,7 @@ will make it easier to successfully do the passthrough without issues."
}
function main () {
- SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_VFIO "$1"
}
diff --git a/vfio-setup b/vfio-setup
index 9461d14..6d07d62 100755
--- a/vfio-setup
+++ b/vfio-setup
@@ -1,7 +1,7 @@
#!/bin/bash
# Get the scripts directory
-SCRIPTDIR=$(dirname "$(which $0)")
+SCRIPTDIR=$(dirname "$(realpath "$0")")
cd "$SCRIPTDIR"
# Get the config paths
From 901096604c077c7e92c3fe00122e739143ef1856 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 15:34:40 +0100
Subject: [PATCH 13/34] Make shellcheck happier
---
lib/apply_CHANGES.sh | 3 ++-
lib/get_GPU.sh | 8 ++++----
lib/get_GPU_GROUP.sh | 6 +++---
lib/get_GPU_ROM.sh | 2 +-
lib/get_USB_CTL.sh | 6 +++---
lib/get_USB_CTL_GROUP.sh | 4 ++--
lib/set_CMDLINE.sh | 2 +-
lib/set_INITRAMFSTOOLS.sh | 2 +-
lib/set_MODPROBE.sh | 2 +-
lib/set_VFIO.sh | 4 ++--
10 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index 009d997..92502a3 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -74,7 +74,8 @@ to build your new initrd image (all of this will require sudo permissions!)"
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+
apply_CHANGES
}
diff --git a/lib/get_GPU.sh b/lib/get_GPU.sh
index ef2dead..e8a7633 100755
--- a/lib/get_GPU.sh
+++ b/lib/get_GPU.sh
@@ -15,14 +15,14 @@ does not belong to itself. Both cards must also have unique hardware ids [xxxx:y
Press q to quit
"
- read -p "Which group number do you want to check?: " IOMMU_GROUP
+ read -r -p "Which group number do you want to check?: " IOMMU_GROUP
case "${IOMMU_GROUP}" in
[1-9]*)
- exec "$SCRIPTDIR/lib/get_GPU_GROUP.sh" $IOMMU_GROUP
+ exec "$SCRIPTDIR/lib/get_GPU_GROUP.sh" "$IOMMU_GROUP"
;;
[Qq]*)
- printf "Aborted, your setup is incomplete!
+ echo "Aborted, your setup is incomplete!
DO NOT use any of the files from $SCRIPTDIR/config !
"
;;
@@ -33,7 +33,7 @@ DO NOT use any of the files from $SCRIPTDIR/config !
}
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_GPU
}
diff --git a/lib/get_GPU_GROUP.sh b/lib/get_GPU_GROUP.sh
index 86b851a..f0c1309 100755
--- a/lib/get_GPU_GROUP.sh
+++ b/lib/get_GPU_GROUP.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-function get_GROUP () {
+function get_GPU_GROUP () {
clear
# Get the config paths
source "$SCRIPTDIR/lib/paths.sh"
@@ -58,9 +58,9 @@ USB_CTL_ID=()
}
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
- get_GROUP "$1"
+ get_GPU_GROUP "$1"
}
main "$1"
diff --git a/lib/get_GPU_ROM.sh b/lib/get_GPU_ROM.sh
index 82180e5..568d2af 100755
--- a/lib/get_GPU_ROM.sh
+++ b/lib/get_GPU_ROM.sh
@@ -61,7 +61,7 @@ echo 0 | sudo tee $VBIOS_PATH
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_GPU_ROM "$1"
}
diff --git a/lib/get_USB_CTL.sh b/lib/get_USB_CTL.sh
index 4fcc00a..ccda58c 100755
--- a/lib/get_USB_CTL.sh
+++ b/lib/get_USB_CTL.sh
@@ -15,11 +15,11 @@ is only needed if you intend to use other devices than just mouse and keyboard w
Press q to quit
"
- read -p "Which group number do you want to check?: " IOMMU_GROUP
+ read -r -p "Which group number do you want to check?: " IOMMU_GROUP
case "${IOMMU_GROUP}" in
[1-9]*)
- exec "$SCRIPTDIR/lib/get_USB_CTL_GROUP.sh" $IOMMU_GROUP
+ exec "$SCRIPTDIR/lib/get_USB_CTL_GROUP.sh" "$IOMMU_GROUP"
;;
[Qq]*)
exec "$SCRIPTDIR/lib/apply_CHANGES.sh"
@@ -31,7 +31,7 @@ Press q to quit
}
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_USB_CTL
}
diff --git a/lib/get_USB_CTL_GROUP.sh b/lib/get_USB_CTL_GROUP.sh
index ea9de2f..956e9bb 100755
--- a/lib/get_USB_CTL_GROUP.sh
+++ b/lib/get_USB_CTL_GROUP.sh
@@ -20,7 +20,7 @@ To use any of the devices shown for passthrough, all of them have to be passed t
To return to the previous page just press ENTER.
"
- read -p "Do you want to use the displayed devices for passthrough? [y/N]: " YESNO
+ read -r -p "Do you want to use the displayed devices for passthrough? [y/N]: " YESNO
case "${YESNO}" in
[Yy]*)
@@ -39,7 +39,7 @@ To return to the previous page just press ENTER.
}
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
get_USB_CTL_GROUP $1
}
diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh
index 5a8e763..9a53365 100755
--- a/lib/set_CMDLINE.sh
+++ b/lib/set_CMDLINE.sh
@@ -170,7 +170,7 @@ function set_CMDLINE () {
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_CMDLINE
}
diff --git a/lib/set_INITRAMFSTOOLS.sh b/lib/set_INITRAMFSTOOLS.sh
index 6a06a80..288875d 100755
--- a/lib/set_INITRAMFSTOOLS.sh
+++ b/lib/set_INITRAMFSTOOLS.sh
@@ -59,7 +59,7 @@ function set_INITRAMFSTOOLS () {
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_INITRAMFSTOOLS "$1"
}
diff --git a/lib/set_MODPROBE.sh b/lib/set_MODPROBE.sh
index 5f66ebe..c87495c 100755
--- a/lib/set_MODPROBE.sh
+++ b/lib/set_MODPROBE.sh
@@ -29,7 +29,7 @@ softdep radeon pre: vfio vfio_pci
}
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_MODPROBE "$1"
}
diff --git a/lib/set_VFIO.sh b/lib/set_VFIO.sh
index 3a9f4b6..18da794 100755
--- a/lib/set_VFIO.sh
+++ b/lib/set_VFIO.sh
@@ -13,7 +13,7 @@ function set_VFIO () {
echo "
Disabling video output in Linux for the card you want to use in a VM
will make it easier to successfully do the passthrough without issues."
- read -p "Do you want to force disable video output in linux on this card? [Y/n]: " DISABLE_VGA
+ read -r -p "Do you want to force disable video output in linux on this card? [Y/n]: " DISABLE_VGA
case "${DISABLE_VGA}" in
[Yy]*)
# Update kernel_args file
@@ -37,7 +37,7 @@ will make it easier to successfully do the passthrough without issues."
}
function main () {
- SCRIPTDIR=$(dirname "$(realpath $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_VFIO "$1"
}
From 371fdb3edd7b3d3b04809cf142c31e863ee4f275 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 15:39:09 +0100
Subject: [PATCH 14/34] Update information
---
lib/apply_CHANGES.sh | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index 92502a3..5bab923 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -55,10 +55,10 @@ By proceeding, a backup of your system's version of these files will be placed i
$SCRIPTDIR/backup
unless a backup already exist.
-Then the files above will be copied to your system followed by running \"update-initramfs -u\"
-to build your new initrd image (all of this will require sudo permissions!)"
+Then the files above will be copied to your system followed by running followed by updating your
+initramfs and then attempt adding new kernel arguments to your bootloader."
- read -p "Do you want to proceed with the installation of the files? (no=skip) [Y/n]: " YESNO
+ read -p "Do you want to proceed with the installation of the files? (no=quit) [Y/n]: " YESNO
case "${YESNO}" in
[Yy]*)
@@ -67,7 +67,7 @@ to build your new initrd image (all of this will require sudo permissions!)"
exec "$SCRIPTDIR/lib/set_CMDLINE.sh"
;;
*)
- exec "$SCRIPTDIR/lib/set_CMDLINE.sh"
+ exit 1
;;
esac
}
@@ -75,7 +75,7 @@ to build your new initrd image (all of this will require sudo permissions!)"
function main () {
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
-
+
apply_CHANGES
}
From d0d972cf9fe82d108731b0f147771c5d3c2a6cd7 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 15:40:56 +0100
Subject: [PATCH 15/34] Script to configure dracut modules
---
lib/set_DRACUT.sh | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100755 lib/set_DRACUT.sh
diff --git a/lib/set_DRACUT.sh b/lib/set_DRACUT.sh
new file mode 100755
index 0000000..76b6b8c
--- /dev/null
+++ b/lib/set_DRACUT.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+function set_DRACUT () {
+ # Get the config paths
+ source "$SCRIPTDIR/lib/paths.sh"
+
+ # Write the dracut config
+ echo "add_drivers+=\" vfio_pci vfio vfio_iommu_type1 vfio_virqfd \"" > "$SCRIPTDIR/$DRACUT"
+
+ # Get the kernel_args file content
+ CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
+
+ # Update kernel_args to load the vfio_pci module early in dracut (as dracut uses kernel arguments for early loading)
+ echo "$CMDLINE rd.driver.pre=vfio_pci" > "$SCRIPTDIR/config/kernel_args"
+
+ # Bind GPU to VFIO
+ "$SCRIPTDIR/lib/set_VFIO.sh" "$1"
+
+ # Configure modprobe
+ "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
+
+ exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
+}
+
+function main () {
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+
+ set_DRACUT "$1"
+}
+
+main "$1"
\ No newline at end of file
From eb3d9986aca69372f3ade8679725af7ba8ebc087 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 15:48:58 +0100
Subject: [PATCH 16/34] fix unable to create 10-vfio.conf for dracut
---
lib/paths.sh | 2 +-
lib/set_DRACUT.sh | 2 +-
vfio-setup | 4 +++-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/paths.sh b/lib/paths.sh
index 6d287ce..fb632ea 100755
--- a/lib/paths.sh
+++ b/lib/paths.sh
@@ -4,5 +4,5 @@ INITRAMFS="config/etc/initramfs-tools"
ETCMODULES="config/etc/modules"
DEFAULT="config/etc/default"
QUICKEMU="config/quickemu"
-DRACUT="config/etc/dracut.conf.d/10-vfio.conf"
+DRACUT="config/etc/dracut.conf.d"
MKINITCPIO="config/etc/mkinitcpio.conf"
\ No newline at end of file
diff --git a/lib/set_DRACUT.sh b/lib/set_DRACUT.sh
index 76b6b8c..d41169b 100755
--- a/lib/set_DRACUT.sh
+++ b/lib/set_DRACUT.sh
@@ -4,7 +4,7 @@ function set_DRACUT () {
source "$SCRIPTDIR/lib/paths.sh"
# Write the dracut config
- echo "add_drivers+=\" vfio_pci vfio vfio_iommu_type1 vfio_virqfd \"" > "$SCRIPTDIR/$DRACUT"
+ echo "add_drivers+=\" vfio_pci vfio vfio_iommu_type1 vfio_virqfd \"" > "$SCRIPTDIR/$DRACUT/10-vfio.conf"
# Get the kernel_args file content
CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
diff --git a/vfio-setup b/vfio-setup
index 6d07d62..1c085dc 100755
--- a/vfio-setup
+++ b/vfio-setup
@@ -129,8 +129,10 @@ fi
if [ -f "/etc/dracut.conf" ];
then
+ # Create the dracut folder
+ mkdir -p "$SCRIPTDIR/$DRACUT"
# Create a dracut.conf.d file
- touch "$SCRIPTDIR/$DRACUT"
+ touch "$SCRIPTDIR/$DRACUT/10-vfio.conf"
fi
# Run ls-iommu so we can verify that IOMMU properly working
From b848efafbf223da6d33092708c1821ed71cb2c83 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 17:34:00 +0100
Subject: [PATCH 17/34] remove chmod for all scripts in lib
---
vfio-setup | 3 ---
1 file changed, 3 deletions(-)
diff --git a/vfio-setup b/vfio-setup
index 1c085dc..7217262 100755
--- a/vfio-setup
+++ b/vfio-setup
@@ -7,9 +7,6 @@ cd "$SCRIPTDIR"
# Get the config paths
source "$SCRIPTDIR/lib/paths.sh"
-# Make sure all the scripts are executable
-chmod +x "$SCRIPTDIR/lib/*"
-
# Get the CPU Vendor
CPU_VENDOR=$(cat /proc/cpuinfo | grep vendor | head -1 | cut -f 2 | cut -d " " -f 2)
CMDLINE="iommu=pt"
From d8c42d382a98db59a758672c1aa7ead5d1b5054c Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 17:41:03 +0100
Subject: [PATCH 18/34] prepare for multiple initramfs infrastructures
---
lib/apply_CHANGES.sh | 85 +++++++++++++++++++++++++++++++++++---------
1 file changed, 68 insertions(+), 17 deletions(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index 5bab923..9372ed7 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -6,39 +6,90 @@ function make_BACKUP () {
if [ ! -d "$BACKUPDIR" ];
then
- # Make the backup directories
- mkdir -p "$BACKUPDIR/etc/initramfs-tools"
- mkdir -p "$BACKUPDIR/etc/modprobe.d"
- mkdir -p "$BACKUPDIR/etc/default"
+ # Make the backup directories and backup the files
+ if [ -d "/etc/initramfs-tools" ];
+ then
+ mkdir -p "$BACKUPDIR/etc/initramfs-tools"
+ cp -v "/etc/initramfs-tools/modules" "$BACKUPDIR/etc/initramfs-tools/modules"
+ cp -v "/etc/modules" "$BACKUPDIR/etc/modules"
- # Backup system files
- sudo cp -v "/etc/modules" "$BACKUPDIR/etc/modules"
- sudo cp -v "/etc/initramfs-tools/modules" "$BACKUPDIR/etc/initramfs-tools/modules"
- sudp cp -v "/etc/default/grub" "$BACKUPDIR/etc/default/grub"
+ elif [ -d "/etc/dracut.conf.d" ];
+ then
+ mkdir -p "$BACKUPDIR/etc/dracut.conf.d"
+ if [ -f "/etc/dracut.conf.d/10-vfio.conf" ];
+ then
+ cp -v "/etc/dracut.conf.d/10-vfio.conf" "$BACKUPDIR/etc/dracut.conf.d/10-vfio.conf"
+
+ fi
+
+ elif [ -f "/etc/mkinitcpio.conf" ];
+ then
+ mkdir -p "$BACKUPDIR/etc"
+ cp -v "/etc/mkinitcpio.conf" "$BACKUPDIR/etc/mkinitcpio.conf"
+
+ fi
+
+ if [ -f "/etc/default/grub" ];
+ then
+ mkdir -p "$BACKUPDIR/etc/default"
+ cp -v "/etc/default/grub" "$BACKUPDIR/etc/default/grub"
+
+ fi
+
+ mkdir -p "$BACKUPDIR/etc/modprobe.d"
# If a vfio.conf file exists, backup that too
if [ -f "/etc/modprobe.d/vfio.conf" ];
then
- sudo cp -v "/etc/modprobe.d/vfio.conf" "$BACKUPDIR/etc/modprobe.d/vfio.conf"
+ cp -v "/etc/modprobe.d/vfio.conf" "$BACKUPDIR/etc/modprobe.d/vfio.conf"
+
fi
- echo "Backup completed!"
+ printf "Backup completed!\n"
else
- echo "A backup already exists!
-backup skipped."
+ echo "
+A backup already exists!
+backup skipped.
+"
fi
}
function copy_FILES () {
echo "Starting copying files to the system!"
- sudo cp -v "$SCRIPTDIR/$ETCMODULES" "/etc/modules"
- sudo cp -v "$SCRIPTDIR/$INITRAMFS/modules" "/etc/initramfs-tools/modules"
+
sudo cp -v "$SCRIPTDIR/$MODPROBE/vfio.conf" "/etc/modprobe.d/vfio.conf"
- echo ""
- echo "Rebuilding initramfs"
- sudo update-initramfs -u
+ if [ -d "/etc/initramfs-tools" ];
+ then
+ sudo cp -v "$SCRIPTDIR/$ETCMODULES" "/etc/modules"
+ sudo cp -v "$SCRIPTDIR/$INITRAMFS/modules" "/etc/initramfs-tools/modules"
+ echo "
+Rebuilding initramfs"
+ sudo update-initramfs -u
+
+ elif [ -d "/etc/dracut.conf.d" ];
+ then
+ cp -v "$SCRIPTDIR/$DRACUT/10-vfio.conf" "/etc/dracut.conf.d/10-vfio.conf"
+ echo "
+Rebuilding initramfs"
+ sudo dracut -f -kver "$(uname -r)"
+
+ else
+ echo "
+Unsupported initramfs infrastructure
+In order to make vfio work, please add these modules to your
+initramfs and make them load early, then rebuild initramfs.
+
+vfio
+vfio_iommu_type1
+vfio_pci
+vfio_virqfd
+"
+
+ fi
+
+
}
function apply_CHANGES () {
From 81f392fb43f905d2b40b8a9ec76f4d3590071659 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 17:49:08 +0100
Subject: [PATCH 19/34] look for an actual dracut.conf and not the
dracut.conf.d folder
---
lib/apply_CHANGES.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index 9372ed7..7b47700 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -13,7 +13,7 @@ function make_BACKUP () {
cp -v "/etc/initramfs-tools/modules" "$BACKUPDIR/etc/initramfs-tools/modules"
cp -v "/etc/modules" "$BACKUPDIR/etc/modules"
- elif [ -d "/etc/dracut.conf.d" ];
+ elif [ -d "/etc/dracut.conf" ];
then
mkdir -p "$BACKUPDIR/etc/dracut.conf.d"
if [ -f "/etc/dracut.conf.d/10-vfio.conf" ];
@@ -68,7 +68,7 @@ function copy_FILES () {
Rebuilding initramfs"
sudo update-initramfs -u
- elif [ -d "/etc/dracut.conf.d" ];
+ elif [ -d "/etc/dracut.conf" ];
then
cp -v "$SCRIPTDIR/$DRACUT/10-vfio.conf" "/etc/dracut.conf.d/10-vfio.conf"
echo "
From fcadf14b2ace79275647d0169561c819c1a139a8 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 17:52:20 +0100
Subject: [PATCH 20/34] add a pause if we detect an unsupported initramfs
infrastructure
---
lib/apply_CHANGES.sh | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index 7b47700..ddf5c2e 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -85,7 +85,10 @@ vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
-"
+
+
+Press ENTER to continue once you have done the above."
+ read -r
fi
From cac6eee5e81166b0befaa9254c89be05082163a2 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 17:53:46 +0100
Subject: [PATCH 21/34] send the if conditions for "which kernelstub" and
"which grub-mkconfig" to null
---
lib/set_CMDLINE.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh
index 9a53365..24604cb 100755
--- a/lib/set_CMDLINE.sh
+++ b/lib/set_CMDLINE.sh
@@ -150,7 +150,7 @@ function set_CMDLINE () {
BOOTLOADER_AUTOCONFIG=0
# If kernelstub is detected (program to manage systemd-boot)
- if which kernelstub ;
+ if which kernelstub > /dev/null ;
then
# Configure kernelstub
set_KERNELSTUB
@@ -158,7 +158,7 @@ function set_CMDLINE () {
fi
# If grub exists
- if which grub-mkconfig ;
+ if which grub-mkconfig > /dev/null ;
then
# Configure grub
set_GRUB
From 55434fb26d000314fb785527d396a8e2a40446bb Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 17:56:23 +0100
Subject: [PATCH 22/34] send all the output of which to null
---
lib/set_CMDLINE.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh
index 24604cb..cd929a3 100755
--- a/lib/set_CMDLINE.sh
+++ b/lib/set_CMDLINE.sh
@@ -150,7 +150,7 @@ function set_CMDLINE () {
BOOTLOADER_AUTOCONFIG=0
# If kernelstub is detected (program to manage systemd-boot)
- if which kernelstub > /dev/null ;
+ if which kernelstub > /dev/null 2>&1 ;
then
# Configure kernelstub
set_KERNELSTUB
@@ -158,7 +158,7 @@ function set_CMDLINE () {
fi
# If grub exists
- if which grub-mkconfig > /dev/null ;
+ if which grub-mkconfig > /dev/null 2>&1 ;
then
# Configure grub
set_GRUB
From dde49a43c88b2c201f9d1345c91a311ae2b8965e Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 18:00:41 +0100
Subject: [PATCH 23/34] Copy modprobe file to system only if modprobe.d folder
exists
---
lib/apply_CHANGES.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index ddf5c2e..bf2bf26 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -58,7 +58,11 @@ backup skipped.
function copy_FILES () {
echo "Starting copying files to the system!"
- sudo cp -v "$SCRIPTDIR/$MODPROBE/vfio.conf" "/etc/modprobe.d/vfio.conf"
+ if [ -d "/etc/modprobe.d" ];
+ then
+ sudo cp -v "$SCRIPTDIR/$MODPROBE/vfio.conf" "/etc/modprobe.d/vfio.conf"
+
+ fi
if [ -d "/etc/initramfs-tools" ];
then
From 8c11b69f6da1abcee2ebc3a910f9871d78d31690 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 18:04:26 +0100
Subject: [PATCH 24/34] make yes the default option for apply
---
lib/apply_CHANGES.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index bf2bf26..b551015 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -119,14 +119,14 @@ initramfs and then attempt adding new kernel arguments to your bootloader."
read -p "Do you want to proceed with the installation of the files? (no=quit) [Y/n]: " YESNO
case "${YESNO}" in
- [Yy]*)
+ [Nn]*)
+ exit 1
+ ;;
+ *)
make_BACKUP
copy_FILES
exec "$SCRIPTDIR/lib/set_CMDLINE.sh"
;;
- *)
- exit 1
- ;;
esac
}
From 9870b51c268d6c10d7f263426c8e54480ffd7192 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 18:30:59 +0100
Subject: [PATCH 25/34] Testing support for mkinitcpio
---
lib/set_MKINITCPIO.sh | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100755 lib/set_MKINITCPIO.sh
diff --git a/lib/set_MKINITCPIO.sh b/lib/set_MKINITCPIO.sh
new file mode 100755
index 0000000..f4c1f82
--- /dev/null
+++ b/lib/set_MKINITCPIO.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+function set_MKINITCPIO () {
+ # Get the config paths
+ source "$SCRIPTDIR/lib/paths.sh"
+
+ # Grab the current modules but exclude vfio and vendor-reset
+ CURRENTMODULES=$(grep -P "^MODULES" /etc/mkinitcpio.conf | perl -pe "s/MODULES=\((.+)\)/\1/")
+ MODULES="$(grep -P "^MODULES" /etc/mkinitcpio.conf | perl -pe "s/MODULES=\((.+)\)/\1/" | perl -pe "s/\s?(vfio_iommu_type1|vfio_pci|vfio_virqfd|vfio|vendor-reset)\s?//g")"
+
+ if [[ $CURRENTMODULES =~ "vendor-reset" ]];
+ then
+ perl -pi -e "s/MODULES=\(${CURRENTMODULES}\)/MODULES=\(vendor-reset vfio vfio_iommu_type1 vfio_pci vfio_virqfd ${MODULES}\)/" "$SCRIPTDIR/$MKINITCPIO"
+ else
+ perl -pi -e "s/MODULES=\(${CURRENTMODULES}\)/MODULES=\(vfio vfio_iommu_type1 vfio_pci vfio_virqfd ${MODULES}\)/" "$SCRIPTDIR/$MKINITCPIO"
+ fi
+
+}
+
+function main () {
+ SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
+
+ set_MKINITCPIO "$1"
+}
+
+main "$1"
\ No newline at end of file
From b4a45b422809a4781438f748b369cbc70a3ce240 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 18:37:06 +0100
Subject: [PATCH 26/34] get current modules and modules from our config folder
---
lib/set_MKINITCPIO.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/set_MKINITCPIO.sh b/lib/set_MKINITCPIO.sh
index f4c1f82..945aa2c 100755
--- a/lib/set_MKINITCPIO.sh
+++ b/lib/set_MKINITCPIO.sh
@@ -4,8 +4,8 @@ function set_MKINITCPIO () {
source "$SCRIPTDIR/lib/paths.sh"
# Grab the current modules but exclude vfio and vendor-reset
- CURRENTMODULES=$(grep -P "^MODULES" /etc/mkinitcpio.conf | perl -pe "s/MODULES=\((.+)\)/\1/")
- MODULES="$(grep -P "^MODULES" /etc/mkinitcpio.conf | perl -pe "s/MODULES=\((.+)\)/\1/" | perl -pe "s/\s?(vfio_iommu_type1|vfio_pci|vfio_virqfd|vfio|vendor-reset)\s?//g")"
+ CURRENTMODULES=$(grep -P "^MODULES" "$SCRIPTDIR/$MKINITCPIO" | perl -pe "s/MODULES=\((.+)\)/\1/")
+ MODULES="$(grep -P "^MODULES" "$SCRIPTDIR/$MKINITCPIO" | perl -pe "s/MODULES=\((.+)\)/\1/" | perl -pe "s/\s?(vfio_iommu_type1|vfio_pci|vfio_virqfd|vfio|vendor-reset)\s?//g")"
if [[ $CURRENTMODULES =~ "vendor-reset" ]];
then
From ed0d400c2f1eceb71edd6855ac3fe9bc717bc661 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 19:22:01 +0100
Subject: [PATCH 27/34] Support for mkinitcpio
---
lib/set_MKINITCPIO.sh | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/set_MKINITCPIO.sh b/lib/set_MKINITCPIO.sh
index 945aa2c..abf0022 100755
--- a/lib/set_MKINITCPIO.sh
+++ b/lib/set_MKINITCPIO.sh
@@ -7,10 +7,13 @@ function set_MKINITCPIO () {
CURRENTMODULES=$(grep -P "^MODULES" "$SCRIPTDIR/$MKINITCPIO" | perl -pe "s/MODULES=\((.+)\)/\1/")
MODULES="$(grep -P "^MODULES" "$SCRIPTDIR/$MKINITCPIO" | perl -pe "s/MODULES=\((.+)\)/\1/" | perl -pe "s/\s?(vfio_iommu_type1|vfio_pci|vfio_virqfd|vfio|vendor-reset)\s?//g")"
+ # Check if vendor-reset is present
if [[ $CURRENTMODULES =~ "vendor-reset" ]];
then
+ # Inject vfio modules with vendor-reset
perl -pi -e "s/MODULES=\(${CURRENTMODULES}\)/MODULES=\(vendor-reset vfio vfio_iommu_type1 vfio_pci vfio_virqfd ${MODULES}\)/" "$SCRIPTDIR/$MKINITCPIO"
else
+ # Inject vfio modules
perl -pi -e "s/MODULES=\(${CURRENTMODULES}\)/MODULES=\(vfio vfio_iommu_type1 vfio_pci vfio_virqfd ${MODULES}\)/" "$SCRIPTDIR/$MKINITCPIO"
fi
From f3391a622e1d5acee7a8361fb80ffc62059320e7 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 20:04:25 +0100
Subject: [PATCH 28/34] Print raw qemu command to do the gpu passthrough
---
lib/set_CMDLINE.sh | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh
index cd929a3..29f00f0 100755
--- a/lib/set_CMDLINE.sh
+++ b/lib/set_CMDLINE.sh
@@ -125,7 +125,7 @@ to disable/unbind the graphic card from the vfio driver on boot.
The files inside \"$SCRIPTDIR/$QUICKEMU\" are currently unused files, however they provide
the required information that the QuickEMU project can hook into and use to add support for VFIO enabled VMs.
-The PCI Devices with these IDs are what you should add to your VMs:
+The PCI Devices with these IDs are what you should add to your VMs using Virt Manager:
NOTE: Some AMD GPUs will require the vendor-reset kernel module from https://github.com/gnif/vendor-reset to be installed!"
source "${SCRIPTDIR}/config/quickemu/qemu-vfio_vars.conf"
@@ -139,6 +139,15 @@ NOTE: Some AMD GPUs will require the vendor-reset kernel module from https://git
echo "* $dev"
done
+echo "
+To add the graphic card to your VM using qemu directly, use the following arguments:"
+ for dev in "${GPU_PCI_ID[@]}"
+ do
+
+ echo -n "-device vfio-pci,host=$dev "
+ done
+ printf "\n"
+
echo "
For performance tuning and advanced configuration look at:
https://github.com/HikariKnight/vfio-setup-docs/wiki"
From f196052c279b3d7405744d79e8a74aa0cd08b082 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 20:29:58 +0100
Subject: [PATCH 29/34] enable test support for mkinitcpio and dracut
---
lib/apply_CHANGES.sh | 23 +++++++++++++++++------
lib/get_GPU_GROUP.sh | 19 ++++++++++++++++++-
lib/set_DRACUT.sh | 4 +---
lib/set_INITRAMFSTOOLS.sh | 4 +---
lib/set_MKINITCPIO.sh | 5 +++++
lib/set_MODPROBE.sh | 2 ++
6 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index b551015..000d67d 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -36,15 +36,19 @@ function make_BACKUP () {
fi
- mkdir -p "$BACKUPDIR/etc/modprobe.d"
-
- # If a vfio.conf file exists, backup that too
- if [ -f "/etc/modprobe.d/vfio.conf" ];
+ if [ -d "/etc/modprobe.d" ];
then
- cp -v "/etc/modprobe.d/vfio.conf" "$BACKUPDIR/etc/modprobe.d/vfio.conf"
+ mkdir -p "$BACKUPDIR/etc/modprobe.d"
+
+ # If a vfio.conf file exists, backup that too
+ if [ -f "/etc/modprobe.d/vfio.conf" ];
+ then
+ cp -v "/etc/modprobe.d/vfio.conf" "$BACKUPDIR/etc/modprobe.d/vfio.conf"
+
+ fi
fi
-
+
printf "Backup completed!\n"
else
@@ -79,6 +83,13 @@ Rebuilding initramfs"
Rebuilding initramfs"
sudo dracut -f -kver "$(uname -r)"
+ elif [ -f "/etc/mkinitcpio.conf" ];
+ then
+ cp -v "$SCRIPTDIR/$MKINITCPIO" "/etc/mkinitcpio.conf"
+ echo "
+Rebuilding initramfs"
+ sudo mkinitcpio -P
+
else
echo "
Unsupported initramfs infrastructure
diff --git a/lib/get_GPU_GROUP.sh b/lib/get_GPU_GROUP.sh
index f0c1309..208408a 100755
--- a/lib/get_GPU_GROUP.sh
+++ b/lib/get_GPU_GROUP.sh
@@ -49,7 +49,24 @@ USB_CTL_ID=()
"$SCRIPTDIR/lib/get_GPU_ROM.sh" "$ROM_PCI_ID"
# Start setting up modules
- exec "$SCRIPTDIR/lib/set_INITRAMFSTOOLS.sh" "$GPU_DEVID"
+ if [ -d "/etc/initramfs-tools" ];
+ then
+ exec "$SCRIPTDIR/lib/set_INITRAMFSTOOLS.sh" "$GPU_DEVID"
+
+ elif [ -d "/etc/dracut.conf" ];
+ then
+ exec "$SCRIPTDIR/lib/set_DRACUT.sh" "$GPU_DEVID"
+
+ elif [ -f "/etc/mkinitcpio.conf" ];
+ then
+ exec "$SCRIPTDIR/lib/set_MKINITCPIO.sh" "$GPU_DEVID"
+ else
+ # Bind GPU to VFIO
+ "$SCRIPTDIR/lib/set_VFIO.sh" "$1"
+
+ # Configure modprobe
+ "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
+ fi
;;
*)
exec "$SCRIPTDIR/lib/get_GPU.sh"
diff --git a/lib/set_DRACUT.sh b/lib/set_DRACUT.sh
index d41169b..4989f9a 100755
--- a/lib/set_DRACUT.sh
+++ b/lib/set_DRACUT.sh
@@ -16,9 +16,7 @@ function set_DRACUT () {
"$SCRIPTDIR/lib/set_VFIO.sh" "$1"
# Configure modprobe
- "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
-
- exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
+ exec "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
}
function main () {
diff --git a/lib/set_INITRAMFSTOOLS.sh b/lib/set_INITRAMFSTOOLS.sh
index 288875d..6210112 100755
--- a/lib/set_INITRAMFSTOOLS.sh
+++ b/lib/set_INITRAMFSTOOLS.sh
@@ -52,9 +52,7 @@ function set_INITRAMFSTOOLS () {
"$SCRIPTDIR/lib/set_VFIO.sh" "$1"
# Configure modprobe
- "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
-
- exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
+ exec "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
}
diff --git a/lib/set_MKINITCPIO.sh b/lib/set_MKINITCPIO.sh
index abf0022..2a584ec 100755
--- a/lib/set_MKINITCPIO.sh
+++ b/lib/set_MKINITCPIO.sh
@@ -17,6 +17,11 @@ function set_MKINITCPIO () {
perl -pi -e "s/MODULES=\(${CURRENTMODULES}\)/MODULES=\(vfio vfio_iommu_type1 vfio_pci vfio_virqfd ${MODULES}\)/" "$SCRIPTDIR/$MKINITCPIO"
fi
+ # Bind GPU to VFIO
+ "$SCRIPTDIR/lib/set_VFIO.sh" "$1"
+
+ # Configure modprobe
+ exec "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
}
function main () {
diff --git a/lib/set_MODPROBE.sh b/lib/set_MODPROBE.sh
index c87495c..1c54229 100755
--- a/lib/set_MODPROBE.sh
+++ b/lib/set_MODPROBE.sh
@@ -26,6 +26,8 @@ softdep nouveau pre: vfio vfio_pci
softdep amdgpu pre: vfio vfio_pci
softdep radeon pre: vfio vfio_pci
" "${GPU_DEVID}" > "$SCRIPTDIR/$MODPROBE/vfio.conf"
+
+ exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
}
function main () {
From ec85ba08fa4a6d3f35e6d468a8ac9f779f0fb69e Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 20:50:53 +0100
Subject: [PATCH 30/34] check for dracut config directly
---
lib/apply_CHANGES.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index 000d67d..b64f323 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -76,7 +76,7 @@ function copy_FILES () {
Rebuilding initramfs"
sudo update-initramfs -u
- elif [ -d "/etc/dracut.conf" ];
+ elif [ -f "/etc/dracut.conf" ];
then
cp -v "$SCRIPTDIR/$DRACUT/10-vfio.conf" "/etc/dracut.conf.d/10-vfio.conf"
echo "
From c8cab6a17deca5c0d90869c766fad511f7324c13 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 20:51:47 +0100
Subject: [PATCH 31/34] fix the dracut command
---
lib/apply_CHANGES.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index b64f323..8c42de0 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -81,7 +81,7 @@ Rebuilding initramfs"
cp -v "$SCRIPTDIR/$DRACUT/10-vfio.conf" "/etc/dracut.conf.d/10-vfio.conf"
echo "
Rebuilding initramfs"
- sudo dracut -f -kver "$(uname -r)"
+ sudo dracut -f --kver "$(uname -r)"
elif [ -f "/etc/mkinitcpio.conf" ];
then
From a20bc548fc8d7b1ada095da3b8223a3542a2302c Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 20:52:42 +0100
Subject: [PATCH 32/34] be verbose when running dracut
---
lib/apply_CHANGES.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh
index 8c42de0..14f01e1 100755
--- a/lib/apply_CHANGES.sh
+++ b/lib/apply_CHANGES.sh
@@ -81,7 +81,7 @@ Rebuilding initramfs"
cp -v "$SCRIPTDIR/$DRACUT/10-vfio.conf" "/etc/dracut.conf.d/10-vfio.conf"
echo "
Rebuilding initramfs"
- sudo dracut -f --kver "$(uname -r)"
+ sudo dracut -f -v --kver "$(uname -r)"
elif [ -f "/etc/mkinitcpio.conf" ];
then
From 29f716954906b7cc1600263c4e0d5b7466276715 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 20:55:29 +0100
Subject: [PATCH 33/34] remove mention of update-initramfs -u
---
lib/set_CMDLINE.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh
index 29f00f0..0a3ef0b 100755
--- a/lib/set_CMDLINE.sh
+++ b/lib/set_CMDLINE.sh
@@ -116,8 +116,8 @@ proceed to add it to your virtual machines.
A backup the files we replaced on your system can be found inside
$SCRIPTDIR/backup/
-In order to restore these files just copy them back to your system and run
-\"sudo update-initramfs -u\"
+In order to restore these files just copy them back to your system and
+rebuild your initramfs image.
You can remove the the vfio_pci kernel arguments from the linux line in your bootloader
to disable/unbind the graphic card from the vfio driver on boot.
From 1e05143a5bd38ef6b34d0393054018992497ba48 Mon Sep 17 00:00:00 2001
From: HikariKnight <2557889+HikariKnight@users.noreply.github.com>
Date: Sat, 12 Mar 2022 21:03:24 +0100
Subject: [PATCH 34/34] update readme
---
README.md | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index d5becd9..bc95497 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,6 @@
A project to simplify setting up GPU passthrough on your Linux host for [QuickEMU](https://github.com/quickemu-project/quickemu)(vfio support not developed yet) and libvirt/virt-manager
-Currently this project works with systems using initramfs-tools, if you want support for systems using other initrd image builders like dracut, consider contributing!
-
You can use it by simply running
```bash
@@ -18,7 +16,7 @@ cd quickpassthrough
* Enable and configure vfio modules
* Configure 2nd GPU for GPU Passthrough
* Dump the selected GPU rom (as some cards require a romfile for passthrough to work), however no rom patching support planned.
-* Enable and configure the correct kernel modules and load them early (initramfs-tools only for now)
+* Enable and configure the correct kernel modules and load them early (initramfs-tools, dracut and mkinitcpio)
* Configure kernel arguments for systemd-boot (using kernelstub)
* Configure kernel arguments for grub2
* Provides you with the correct kernel arguments to add to your bootloader entry if a supported bootloader is not found
@@ -28,7 +26,7 @@ cd quickpassthrough
I know my bash skills are not great, so help is always welcome! And help is wanted here.
-If you know bash well, you will be able to help! Just make a pull request to the [dev branch](https://github.com/HikariKnight/quickpassthrough/tree/dev) with your changes!
+If you know bash well, you will be able to help! Just make a pull request with your changes!
Just remember to add comments to document the work and explain it for people who are less familiar with the bash syntax or anything else you use. 😄
Also if you know English, you can help by just proof reading. English is not my native language, plus I have dyslexia so I often make spelling mistakes.