Split up scripts to reuse parts for other initramfs systems

This commit is contained in:
HikariKnight 2022-03-12 14:39:05 +01:00
parent 9ab572032d
commit 898e1f7347
No known key found for this signature in database
GPG key ID: E8B239063B022F5A
4 changed files with 103 additions and 52 deletions

View file

@ -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"
}

37
lib/set_MODPROBE.sh Executable file
View file

@ -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"

45
lib/set_VFIO.sh Executable file
View file

@ -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"

View file

@ -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