Linux-Single-GPU-Passthrough/hooks/vfio-startup.sh

75 lines
1.9 KiB
Bash
Raw Normal View History

2020-04-25 04:32:07 +00:00
#!/bin/bash
# Helpful to read output when debugging
set -x
long_delay=10
medium_delay=5
short_delay=1
echo "Beginning of startup!"
2020-04-25 04:32:07 +00:00
2020-10-04 01:05:49 +00:00
function stop_display_manager_if_running {
2020-12-22 03:14:44 +00:00
# Stop dm using systemd
if command -v systemctl; then
if systemctl is-active --quiet "$1.service" ; then
echo $1 >> /tmp/vfio-store-display-manager
systemctl stop "$1.service"
fi
while systemctl is-active --quiet "$1.service" ; do
sleep "${short_delay}"
done
return
2020-10-04 01:05:49 +00:00
fi
2020-12-22 03:14:44 +00:00
# Stop dm using runit
if command -v sv; then
if sv status $1 ; then
echo $1 >> /tmp/vfio-store-display-manager
sv stop $1
fi
2020-10-04 01:05:49 +00:00
fi
}
2020-10-09 00:30:22 +00:00
# Stop currently running display manager
if test -e "/tmp/vfio-store-display-manager" ; then
rm -f /tmp/vfio-store-display-manager
fi
2020-12-22 03:14:44 +00:00
stop_display_manager_if_running sddm
stop_display_manager_if_running gdm
stop_display_manager_if_running lightdm
stop_display_manager_if_running lxdm
stop_display_manager_if_running xdm
stop_display_manager_if_running mdm
stop_display_manager_if_running display-manager
2020-04-25 04:32:07 +00:00
2020-10-09 00:30:22 +00:00
# Unbind VTconsoles if currently bound (adapted from https://www.kernel.org/doc/Documentation/fb/fbcon.txt)
if test -e "/tmp/vfio-bound-consoles" ; then
rm -f /tmp/vfio-bound-consoles
fi
2020-10-09 00:30:22 +00:00
for (( i = 0; i < 16; i++))
do
if test -x /sys/class/vtconsole/vtcon${i}; then
if [ `cat /sys/class/vtconsole/vtcon${i}/name | grep -c "frame buffer"` \
= 1 ]; then
echo 0 > /sys/class/vtconsole/vtcon${i}/bind
echo "Unbinding console ${i}"
echo $i >> /tmp/vfio-bound-consoles
fi
fi
done
2020-12-22 03:14:44 +00:00
# Unbind EFI-Framebuffer
if test -e "/tmp/vfio-is-nvidia" ; then
rm -f /tmp/vfio-is-nvidia
fi
2020-10-04 01:05:49 +00:00
if lsmod | grep "nvidia" &> /dev/null ; then
2020-12-22 03:14:44 +00:00
echo "true" >> /tmp/vfio-is-nvidia
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
2020-10-09 00:30:22 +00:00
fi
echo "End of startup!"