WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Check VGA card and load respective driver.  (Read 1591 times)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Check VGA card and load respective driver.
« on: November 16, 2015, 01:52:09 PM »
For my USB install of Tiny Core I'm not using the default xvesa but xorg which needs a graphics driver depending on the graphics card. Not always knowing the hardware of the boxes, I came up with this code which resides in  /op/bootsync.sh .

Depends on  pci-utils.tcz .

Code: [Select]
## Check VGA card and load respective driver.
[ -d /etc/X11 ] || mkdir -p /etc/X11
if [ $(which lspci) ]; then
echo -en "\033[1;30m:: \033[1;34mVGA\033[1;30m: "

VGA="$(lspci | grep -m1 -E "VGA|3D")"
VGA_VENDOR="$(echo "$VGA" | grep -m1 -i -o -E "intel|nvidia|radeon" )"
if [ -n "$VGA_VENDOR" ]; then
VGA_MODEL="$(lspci | grep -m1 -e VGA -e 3D | sed 's/^.*VGA compatible controller: //;s/ Corporation//;s/ Mobile//;s/ Express//;s/ Integrated Graphics Controller//;s/ (rev .*//' | sed "s:$VGA_VENDOR ::I")"
echo -en "\033[1;33m$VGA_VENDOR \033[1;32m$VGA_MODEL\033[1;30m ...\033[1;33m"
TCUSER="$(cat /etc/sysconfig/tcuser)"
KERNEL="$(uname -r)"
VGA_VENDOR="$(echo "$VGA_VENDOR" | tr '[:upper:]' '[:lower:]')"
case $VGA_VENDOR in
intel)
su "$TCUSER" -c "tce-load -i xf86-video-intel" >/dev/null &
rotdash $!
echo -e "\033[1;30mDone\033[0;39m"
;;
nvidia)
if [ -e "/etc/sysconfig/tcedir/optional/nvidia-304.125-$KERNEL.tcz" ]; then
su "$TCUSER" -c "tce-load -i nvidia-304.125-$KERNEL" >/dev/null &
rotdash $!
[ -e /etc/X11/xorg.conf ] || nvidia-xconfig >/dev/null 2>&1
else
su "$TCUSER" -c "tce-load -i xf86-video-nouveau" >/dev/null &
rotdash $!
fi
echo -e "\033[1;30mDone\033[0;39m"
;;
radeon)
su "$TCUSER" -c "tce-load -i firmware-radeon xf86-video-ati" >/dev/null &
rotdash $!
echo -e "\033[1;30mDone\033[0;39m"
;;
*) echo -e "\033[1;30mUnknown\033[0;39m" ;;
esac
else
echo -e "\033[1;31mFailed\033[1;34m to determine driver\033[1;30m.\033[0;39m"
fi

#VGA_PCI="$(echo "$VGA" | awk '{printf "%s" $1}')"
#VGA_RAM="$(sudo lspci -v -s "$VGA_PCI" | grep -m1 ", prefetchable)" | awk '{printf "%s" $6}' | awk 'BEGIN {FS = "="} {if ($1 == "[size") { RAM = $2 }} END {print RAM}' | sed 's:]$:B:')"
#echo "Video RAM: $VGA_RAM"
fi

Works for Intel and NVidia cards as long as the extensions are available on the boot media.
ATI cards have not been tested.
Download a copy and keep it handy: Core book ;)

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10240
Re: Check VGA card and load respective driver.
« Reply #1 on: November 17, 2015, 01:40:49 AM »
Nice, the lazy user would just load them all and have Xorg detect it based on the PCI id.
The only barriers that can stop you are the ones you create yourself.

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Check VGA card and load respective driver.
« Reply #2 on: November 17, 2015, 02:07:29 AM »
The proprietary nvidia drivers, compared to other drivers, seem to need a lot of RAM even if unused. Not sure if it would make much of a difference since it's just cached or buffered stuff that would probably get unloaded if more RAM is needed. But anyway, loading less is always good I think and speeds up boot time.

Added check for  Xorg .
Added displaying of Video RAM because reasons.
Moved creation of  /etc/X11  directory.
Code: [Select]
## Check VGA card and load respective driver.
if [ $(which lspci) ] && [ $(which Xorg) ]; then
echo -en "\033[1;30m:: \033[1;34mVGA\033[1;30m: "

VGA="$(lspci | grep -m1 -E "VGA|3D")"
VGA_VENDOR="$(echo "$VGA" | grep -m1 -i -o -E "intel|nvidia|radeon" )"
if [ -n "$VGA_VENDOR" ]; then
[ -d /etc/X11 ] || mkdir -p /etc/X11
VGA_MODEL="$(lspci | grep -m1 -e VGA -e 3D | sed 's/^.*VGA compatible controller: //;s/ Corporation//;s/ Mobile//;s/ Express//;s/ Integrated Graphics Controller//;s/ (rev .*//' | sed "s:$VGA_VENDOR ::I")"
VGA_PCI="$(echo "$VGA" | awk '{printf "%s" $1}')"
VGA_RAM="$(lspci -v -s "$VGA_PCI" | grep -m1 ", prefetchable)" | awk '{printf "%s" $6}' | awk 'BEGIN {FS = "="} {if ($1 == "[size") { RAM = $2 }} END {print RAM}' | sed 's:]$:B:')"
echo -en "\033[1;33m$VGA_VENDOR \033[1;32m$VGA_MODEL \033[0;32m($VGA_RAM)\033[1;30m ...\033[1;33m"
TCUSER="$(cat /etc/sysconfig/tcuser)"
KERNEL="$(uname -r)"
VGA_VENDOR="$(echo "$VGA_VENDOR" | tr '[:upper:]' '[:lower:]')"
case $VGA_VENDOR in
intel)
su "$TCUSER" -c "tce-load -i xf86-video-intel" >/dev/null &
rotdash $!
echo -e "\033[1;30mDone\033[0;39m"
;;
nvidia)
if [ -e "/etc/sysconfig/tcedir/optional/nvidia-304.125-$KERNEL.tcz" ]; then
su "$TCUSER" -c "tce-load -i nvidia-304.125-$KERNEL" >/dev/null &
rotdash $!
[ -e /etc/X11/xorg.conf ] || nvidia-xconfig >/dev/null 2>&1
else
su "$TCUSER" -c "tce-load -i xf86-video-nouveau" >/dev/null &
rotdash $!
fi
echo -e "\033[1;30mDone\033[0;39m"
;;
radeon)
su "$TCUSER" -c "tce-load -i firmware-radeon xf86-video-ati" >/dev/null &
rotdash $!
echo -e "\033[1;30mDone\033[0;39m"
;;
*) echo -e "\033[1;30mUnknown\033[0;39m" ;;
esac
else
echo -e "\033[1;31mFailed\033[1;34m to determine driver\033[1;30m.\033[0;39m"
fi
fi
Download a copy and keep it handy: Core book ;)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Check VGA card and load respective driver.
« Reply #3 on: November 17, 2015, 05:19:18 AM »
Well, checking the VRAM via lspci seems to be relatively useless as it cannot see more than 256 MB.
So I removed it. Also removed one redundant lspci.

Code: [Select]
## Check VGA card and load respective driver.
if [ $(which lspci) ] && [ $(which Xorg) ]; then
echo -en "\033[1;30m:: \033[1;34mVGA\033[1;30m: "

VGA="$(lspci | grep -m1 -E "VGA|3D")"
VGA_VENDOR="$(echo "$VGA" | grep -m1 -i -o -E "intel|nvidia|radeon" )"
if [ -n "$VGA_VENDOR" ]; then
[ -d /etc/X11 ] || mkdir -p /etc/X11
VGA_MODEL="$(echo "$VGA" | sed 's/^.*VGA compatible controller: //;s/ Corporation//;s/ Mobile//;s/ Express//;s/ Integrated Graphics Controller//;s/ (rev .*//' | sed "s:$VGA_VENDOR ::I")"
echo -en "\033[1;33m$VGA_VENDOR \033[1;32m$VGA_MODEL\033[1;30m ...\033[1;33m"
TCUSER="$(cat /etc/sysconfig/tcuser)"
KERNEL="$(uname -r)"
VGA_VENDOR="$(echo "$VGA_VENDOR" | tr '[:upper:]' '[:lower:]')"
case $VGA_VENDOR in
intel)
su "$TCUSER" -c "tce-load -i xf86-video-intel" >/dev/null &
rotdash $!
echo -e "\033[1;30mDone\033[0;39m"
;;
nvidia)
if [ -e "/etc/sysconfig/tcedir/optional/nvidia-304.125-$KERNEL.tcz" ]; then
su "$TCUSER" -c "tce-load -i nvidia-304.125-$KERNEL" >/dev/null &
rotdash $!
[ -e /etc/X11/xorg.conf ] || nvidia-xconfig >/dev/null 2>&1
else
su "$TCUSER" -c "tce-load -i xf86-video-nouveau" >/dev/null &
rotdash $!
fi
echo -e "\033[1;30mDone\033[0;39m"
;;
radeon)
su "$TCUSER" -c "tce-load -i firmware-radeon xf86-video-ati" >/dev/null &
rotdash $!
echo -e "\033[1;30mDone\033[0;39m"
;;
*) echo -e "\033[1;30mUnknown\033[0;39m" ;;
esac
else
echo -e "\033[1;31mFailed\033[1;34m to determine driver\033[1;30m.\033[0;39m"
fi
fi

If anyone with an ATI / Radeon card would like to try this code in  /opt/bootsync.sh , I'd like to hear if it works or if additional extensions are needed.
Also I have no idea about  geode , mach64 , neomagic , openchrome  and  vmware .
Feel free to feed me with the output of
Code: [Select]
lspci | grep -m1 -E "VGA|3D"
Download a copy and keep it handy: Core book ;)