Split up scripts to reuse parts for other initramfs systems
This commit is contained in:
parent
9ab572032d
commit
898e1f7347
4 changed files with 103 additions and 52 deletions
|
@ -48,50 +48,8 @@ function set_INITRAMFSTOOLS () {
|
||||||
insert_INITRAMFSTOOLS 4 "$SCRIPTDIR/$ETCMODULES"
|
insert_INITRAMFSTOOLS 4 "$SCRIPTDIR/$ETCMODULES"
|
||||||
insert_INITRAMFSTOOLS 11 "$SCRIPTDIR/$INITRAMFS/modules"
|
insert_INITRAMFSTOOLS 11 "$SCRIPTDIR/$INITRAMFS/modules"
|
||||||
|
|
||||||
# Assign the GPU device ids to a variable
|
"$SCRIPTDIR/lib/set_VFIO.sh" "$1"
|
||||||
GPU_DEVID="$1"
|
"$SCRIPTDIR/lib/set_MODPROBE.sh" "$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"
|
|
||||||
|
|
||||||
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
|
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
|
||||||
}
|
}
|
||||||
|
|
37
lib/set_MODPROBE.sh
Executable file
37
lib/set_MODPROBE.sh
Executable 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
45
lib/set_VFIO.sh
Executable 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"
|
27
vfio-setup
27
vfio-setup
|
@ -91,35 +91,46 @@ fi
|
||||||
|
|
||||||
# Make the directories
|
# Make the directories
|
||||||
mkdir -p "$SCRIPTDIR/$MODPROBE"
|
mkdir -p "$SCRIPTDIR/$MODPROBE"
|
||||||
mkdir -p "$SCRIPTDIR/$DEFAULT"
|
|
||||||
mkdir -p "$SCRIPTDIR/$INITRAMFS"
|
|
||||||
mkdir -p "$SCRIPTDIR/$QUICKEMU"
|
mkdir -p "$SCRIPTDIR/$QUICKEMU"
|
||||||
|
|
||||||
# Write the cmdline file
|
# Write the cmdline file
|
||||||
echo "$CMDLINE" > "$SCRIPTDIR/config/kernel_args"
|
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" ];
|
if [ -f "/etc/modules" ];
|
||||||
then
|
then
|
||||||
# This copies /etc/modules without the vfio module lines
|
# This copies /etc/modules without the vfio module lines
|
||||||
grep -v "vfio" "/etc/modules" > "$SCRIPTDIR/$ETCMODULES"
|
grep -v "vfio" "/etc/modules" > "$SCRIPTDIR/$ETCMODULES"
|
||||||
else
|
|
||||||
touch "$SCRIPTDIR/$ETCMODULES"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "/etc/default/grub" ];
|
if [ -f "/etc/default/grub" ];
|
||||||
then
|
then
|
||||||
|
# Create the default folder
|
||||||
|
mkdir -p "$SCRIPTDIR/$DEFAULT"
|
||||||
|
|
||||||
# Copy grub config
|
# Copy grub config
|
||||||
cp "/etc/default/grub" "$SCRIPTDIR/$DEFAULT/grub"
|
cp "/etc/default/grub" "$SCRIPTDIR/$DEFAULT/grub"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "/etc/initramfs-tools/modules" ];
|
if [ -f "/etc/initramfs-tools/modules" ];
|
||||||
then
|
then
|
||||||
|
# Create the initramfs folder
|
||||||
|
mkdir -p "$SCRIPTDIR/$INITRAMFS"
|
||||||
|
|
||||||
# This copies /etc/initramfs-tools/modules without the vfio modules
|
# This copies /etc/initramfs-tools/modules without the vfio modules
|
||||||
grep -v "vfio" "/etc/initramfs-tools/modules" > "$SCRIPTDIR/$INITRAMFS/modules"
|
grep -v "vfio" "/etc/initramfs-tools/modules" > "$SCRIPTDIR/$INITRAMFS/modules"
|
||||||
else
|
fi
|
||||||
touch "$SCRIPTDIR/$INITRAMFS"
|
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
# Run ls-iommu so we can verify that IOMMU properly working
|
# Run ls-iommu so we can verify that IOMMU properly working
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue