Unbinding vtconsoles

Hello,

I wrote a script to change the modules my gpu uses (unloads vfio modules and loads amdgpu modules) so I can use my more powerful gpu on linux aswell.

The problem is when I unbind the vtconsoles (echo 0 > /sys/class/vtconsoles/vtcon0/bind), most of the time when I boot and run my script, the vtcon0 gets unbound but then the script stops. After that I am left with the tty because lightdm got stopped because of my script.

When I now look at the vtconsole directory, there is a vtcon1 directory aswell. When I run the script a second time (I wrote a loop so that it unbinds all the consoles in the vtconsole directory) it works and all vtconsoles get unbound and the script works.

My question:

Why, after unbinding the first vtcon, a second one is generated? And how do I stop this from happening? Its pretty annoying having to run a script twice for it to work…

Btw I use Manjaro and heres my script:

#! /bin/sh

systemctl stop lightdm

for i in /sys/class/vtconsole/*
do
   echo 0 > $i/bind
done

sleep 2

modprobe -r nouveau
modprobe -r vfio_pci
modprobe -r vfio_iommu_type1
modprobe -r vfio

sleep 2

modprobe amdgpu
sleep 1
cp /etc/X11/xorg.conf.d/10-nv.conf /home/sabo/.tmp
rm /etc/X11/xorg.conf.d/10-nv.conf

for i in /sys/class/vtconsole/*
do
   echo 1 > $i/bind
done

systemctl start lightdm

sleep 1 

cp /home/sabo/.tmp/10-nv.conf /etc/X11/xorg.conf.d/

Like I said, the script stops working after unbinding the first vtconsole, so the vfio and nouveau drivers aren’t touched.

Help would be really appreciated!

PS: everytime I start lightdm since yesterday, after logging in, there is a bash shell open? Why tf is there a terminal open everytime I log in. Feels weird. As I said, it happened randomly since yesterday