#!/bin/sh # Copyright (c) 2003 - 2006 - RZ Uni Freiburg # Copyright (c) 2006, 2007 - OpenSLX GmbH # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING # # If you have any feedback please consult http://openslx.org/feedback and # send your feedback to feedback@openslx.org # # General information about OpenSLX can be found under http://openslx.org # # Universal (distro independent) hardware autoconfiguration script for # OpenSLX linux diskless clients, using hwconfig from knoppix as base tool ############################################################################# # local functions used within hwautocfg displaysetup () { # (temporary) configuration file local xfc=$1 # set variables representing the xorg.conf sections (version 6.9.x) # variables might be overwritten via displayvars function local Module='\tLoad\t\t"dbe"\n \tLoad\t\t"extmod"\n \tLoad\t\t"type1"\n \tLoad\t\t"speedo"\n \tLoad\t\t"freetype"\n \tLoad\t\t"v4l"' local ServerFlags='\tOption\t\t"AllowMouseOpenFail"\n \tOption\t\t"blank time"\t\t"5"\n \tOption\t\t"standby time"\t\t"10"\n \tOption\t\t"suspend time"\t\t"15"\n \tOption\t\t"off time"\t\t"20"' # fixme: Do we really need FontPath, RgbPath!?! local Files='\tRgbPath\t\t"/usr/X11R6/lib/X11/rgb"\n \tModulePath\t"/etc/X11/modules"\n \tModulePath\t"/usr/X11R6/lib/modules"\n \tFontPath\t"/usr/X11R6/lib/X11/fonts/misc/:unscaled"\n \tFontPath\t"/usr/X11R6/lib/X11/fonts/75dpi/:unscaled"\n \tFontPath\t"/usr/X11R6/lib/X11/fonts/100dpi/:unscaled"' local InputDevice='\tIdentifier\t"Keyboard1"\n \tDriver\t\t"kbd"\n \tOption\t\t"XkbRules"\t\t"xfree86"\n \tOption\t\t"XkbLayout"\t\t"XKEYBOARD"\n \tOption\t\t"XkbModel"\t\t"pc105"' local InputMouseDef='\tIdentifier "Mouse1"\n \tDriver\t\t"mouse"\n \tOption\t\t"Protocol"\t\t"imps/2"\n \tOption\t\t"Device"\t\t"/dev/input/mice"\n \tOption\t\t"Emulate3Buttons"\n \tOption\t\t"ZAxisMapping"\t\t"4 5"\n \tOption\t\t"Buttons"\t\t"3"' local InputMouseSyn='\tIdentifier "Mouse1"\n \tDriver\t\t"synaptics"\n \tOption\t\t"Protocol"\t\t"explorerps/2"\n \tOption\t\t"Device"\t\t"/dev/input/mice"\n \tOption\t\t"Emulate3Buttons"\t"on"\n \tOption\t\t"Buttons"\t\t"5"\n \tOption\t\t"InputFashion"\t\t"Mouse"\n \tOption\t\t"SHMConfig"\t\t"on"\n \tOption\t\t"ZAxisMapping"\t\t"4 5"' local Monitor='\tIdentifier "Default"\n \tModelName\t"MODEL"\n \tOption\t\t"CalcAlgorithm"\t"CheckDesktopGeometry"\n \tOption\t\t"DPMS"\t\t"true"' local Device='\tIdentifier\t"StdGraphics"\n \tVendorName\t"XDESC"\n \tDriver\t\t"XMODULE"' local Screen='\tIdentifier\t"Screen 1"\n \tDevice\t\t"StdGraphics"\n \tMonitor\t\t"Default"\n \tDefaultColorDepth 24' local ServerLayout='\tIdentifier\t"Simple Layout"\n \tScreen\t\t"Screen 1"\n \tInputDevice\t"Keyboard1"\t"CoreKeyboard"\n \tInputDevice\t"Mouse1"\t"CorePointer"\n \tOption\t\t"BlankTime"\t"5"\n \tOption\t\t"StandbyTime"\t"10"\n \tOption\t\t"SuspendTime"\t"20"\n \tOption\t\t"OffTime"\t"30"' local DRI='\tGroup\t\t"video"\n \tMode\t\t0666' # displayvars may overwrite the above settings and define pathes below e.g. # synapticsdrv displayvars # run localizator and configure X11 keyboard localization "${country}" if [ -z "${XKEYBOARD}" ] ; then error "${hcfg_keyb}" nonfatal XKEYBOARD="de" fi # check if hardware definition variables are set and overwrite autodetected # values if [ -n "${hw_graphic}" ] ; then DRV=${hw_graphic% *} if [ -z "$DRV" ] ; then error "${hcfg_gfxdrv}" nonfatal XMODULE=vesa fi fi # deprecated stuff, needed primarily for CRT displays if [ -n "${hw_monitor}" ] ; then # just cut all starting from k(Hz) ... HS=${hw_monitor%k*} VS=${hw_monitor%Hz*} [ "${hw_monitor}" == "$VS" ] && VS=${hw_monitor%hz*} VS=${VS##* } SCR_MODES="\"${hw_monitor##* }\"" else # gather information about the monitor capabilities screenres > /tmp/screenres VERTSR=`cat /tmp/screenres | sed -n \ '/Vertical Frequency Range/s/[^0-9]* \([0-9-]*\)/\1/p'` HORISR=`cat /tmp/screenres | sed -n \ '/Horizontal Frequency Range/s/[^0-9]* \([0-9-]*\)/\1/p'` HS=$HORISR VS=$VERTSR # compute max resolution SCR_MODES=`cat /tmp/screenres | sed -n \ '/Recommended Screen Modes:/s/[^"]*\(.*\)/\1/p'` fi if [ -z "$HS" ] ; then #error "$hcfg_hfrq" nonfatal HS=${HSYNCRANGE} fi if [ -z "$VS" ] ; then #error "$hcfg_vfrq" nonfatal VS=${VSYNCRANGE} fi if [ -z "$SCR_MODES" ] ; then #error "$hcfg_res" nonfatal SCR_MODES=${DEFAULTMODES} fi monmanual=yes # check for special X driver (fglrx, nvidia, ...) and enable tvout if variable # tvout is not "no" [ -z "$hw_graphic" ] && checkgraphix # finally write config file echo -e "#\n# autogenerated X hardware configuration by $0\n# \ OpenSLX.ORG Project , $date" >$xfc echo -e "# DO NOT EDIT THIS FILE BUT '$0' INSTEAD!\n#" \ >>$xfc for section in Files ServerFlags Module InputDevice Monitor \ Screen Device ServerLayout DRI ; do echo "Section \"$section\"" >>$xfc case "$section" in Files) echo -e ${Files} >>$xfc # check for 64bit CPU/installation (fixme!!) [ -d "/mnt/usr/X11R6/lib64/modules" ] && \ echo -e '\tModulePath\t"/usr/X11R6/lib64/modules"\n' >>$xfc for i in ${D_XFONTPATH} ; do echo -e "\tFontPath\t\"$i/\"" >>$xfc ; done ;; ServerFlags) echo -e ${ServerFlags} >>$xfc ;; Device) echo -e ${Device} | \ sed -e "s,XMODULE,${XMODULE}," -e "s%XDESC%${XDESC}%" >>$xfc # write TV config - no problem, if no TV is connected [ -n "$TVOUT" ] && echo -e $TVOUT >>$xfc [ x$DRV = "xs3virge" ] && \ echo -e "\tOption\t\t\"XVideo\" \"Off\"\n" >>$xfc [ x$DRV = "xnvidia" ] && { echo -e "\tOption\t\t\"NvAGP\" \"3\"" >>$xfc echo -e "\tOption\t\t\"NoLogo\" \"1\"" >>$xfc ; } ;; Module) echo -e ${Module} >>$xfc #[ "x$DRM" = "xyes" ] && \ echo -e "\tLoad\t\t\"dri\"" >>$xfc [ x$GLX != "xno" ] && \ echo -e "\tLoad\t\t\"glx\"" >>$xfc ;; Monitor) echo -e ${Monitor} | \ sed -e "s,HS,${HS},g" -e "s,VS,${VS},g" >>$xfc ;; InputDevice) echo -e ${InputDevice} | sed -e "s,XKEYBOARD,${XKEYBOARD},g" \ >>$xfc [ "${XKEYBOARD}" = "de" ] && \ echo -e '\tOption\t\t"XkbVariant"\t\t"nodeadkeys"' >>$xfc echo -e "EndSection\n\nSection \"$section\"" >>$xfc # if special synaptics touchpad was detected and specific driver # is present if strinfile "synaptics" /tmp/hwsetup.info && \ test -e /mnt/${synapticsdrv} ; then echo -e $InputMouseSyn >>$xfc else echo -e $InputMouseDef >>$xfc fi ;; Screen) echo -e ${Screen} >>$xfc #for BPP in 15 16 24 # do echo -e '\tSubSection "Display"\n\t\tDepth\t'\ # $BPP'\n\t\tModes\t'$SCR_MODES'\n\tEndSubSection' >>$xfc #done ;; ServerLayout) echo -e ${ServerLayout} >>$xfc ;; DRI) echo -e ${DRI} >>$xfc ;; esac echo -e "EndSection\n" >>$xfc done } ############################################################################# # pre part hwpre () { echo "0 0 0 0" >/proc/sys/kernel/printk # start the knoppix hardware autodetection tool driverlist="parport parport_pc " # hack for pseudo modules (not to load) hopefully "usbcore" is present # as a module, might be exchanged with any other existing ... for i in $driverlist ; do echo -e "alias\t$i\tusbcore" >> /etc/modprobe.conf done ( hwsetup -n -v > /tmp/hwsetup.info && echo "hwsetup" > /tmp/hwrun1 ) & ( for mod in usbcore uhci-hcd ohci-hcd usbhid; do modprobe -q $mod 2>/dev/null usleep 10000 done; ) & return 0 } ############################################################################# # network module part nwmod () { [ $DEBUGLEVEL -eq 20 ] && \ echo "** loading all defined network adaptor modules at $(sysup)" for mod in ${NWMODULES}; do modprobe ${MODPRV} $mod || error "$init_errnwad" usleep 50000 done return 0 } ############################################################################# # main part hwmain () { # "drivers" (pseudo, placeholder strings, ...) to exclude from loading # depending on distro more hw modules have to be excluded too. use the # D_HWMODTOIGNORE for that purpose driverlist=" disabled unknown ignore pcspkr synaptics keybdev kanotix \ slamr {D_HWMODTOIGNORE} " # driver blacklist (real modules which fail to load) driverlist=${driverlist}"hw_random genericwheelusb " # hack for pseudo modules (not to load) hopefully "usbcore" is present # as a module, might be exchanged with any other existing ... for i in $driverlist ; do echo -e "alias\t$i\tusbcore" >> /etc/modprobe.conf done # load kernel module for ps2 mice [ -f /lib/modules/${KERNEL}/kernel/drivers/input/mouse/psmouse.ko ] && \ modprobe ${MODPRV} psmouse # and map the mousehandler to /dev/input/mice [ -f /lib/modules/${KERNEL}/kernel/drivers/input/mousedev.ko ] && \ modprobe ${MODPRV} mousedev # wait for /tmp/hwsetup.info to appear waitfor /tmp/hwrun1 50000 || \ error "$hcfg_hwsetup" # in some cases the time to wait for module load is to be increased if [ -n "${SLOWHWSETUP}" ] ; then modwaittime=${SLOWHWSETUP} [ $DEBUGLEVEL -eq 21 ] && echo "** set modwaittime to ${SLOWHWSETUP}ms" else modwaittime=5000 fi [ $DEBUGLEVEL -eq 21 ] && echo "** 1st hwdetection finished at $(sysup)" # load ide drivers first, takes a while to initialize for driver in cmd64x hpt366 piix slc90e66 cs5520 it821x rz1000 \ ahci triflex aec62xx cs5530 cs5535 ns87415 sc1200 trm290 alim15x3 \ cy82c693 opti621 serverworks via82cxxx amd74xx pata_amd \ pdc202xx_new siimage atiixp hpt34x pdc202xx_old sis5513; do strinfile " ${driver}" /tmp/hwsetup.info && { ide="yes" #modwaittime=$((10 + ${modwaittime})) modprobe ${MODPRV} ${driver} & driverlist="${driverlist} ${driver}"; usleep ${modwaittime}; } done # check for IDE/SCSI (SATA); changes in newer kernels prefix pata/sata for driver in ata_piix sata_via sata_mv sata_nv sata_sil sata_sis sata_svw \ sata_sx4 sata_uli sata_vsc sata_qstor sata_promise ahci; do strinfile " ${driver}" /tmp/hwsetup.info && { #SCSIIDE="yes" modprobe ${MODPRV} ${driver} & driverlist="${driverlist} ${driver}"; usleep ${modwaittime}; } done # check for USB2.0 and ieee1394 hardware drivers for driver in ehci-hcd ohci1394; do strinfile " ${driver}" /tmp/hwsetup.info && { USB="yes" modprobe ${MODPRV} ${driver} driverlist="${driverlist} ${driver}"; } done [ -x /bin/mdev ] && mdev -s & # check for pcmcia / cardbus stuff for driver in yenta_socket i82365 pd6729 tcic; do strinfile " ${driver}" /tmp/hwsetup.info && { modprobe ${MODPRV} ${driver} driverlist="${driverlist} ${driver}" pcmcia="yes"; } done # should we check for card reader modules too? # newer kernels support some of the major multicard readers which could # be found in some barebone systems like Pundits or in many laptops if [ -n "${pcmcia}" ] ; then modprobe ${MODPRV} ds fi [ $DEBUGLEVEL -eq 21 ] && echo "** module loading finished at $(sysup)" # rerun the knoppix hardware autodetection tool for USB and ide devices # like dvd or harddisk - wait a few seconds so hopefully the ide driver # is initialized [ -x /bin/mdev ] && mdev -s test -f /proc/bus/usb/devices || \ mount -n -t usbfs usbfs /proc/bus/usb 2>/dev/null [ $DEBUGLEVEL -eq 21 ] && echo "** started 2nd hwdetection at $(sysup)" # remove unneeded network card and USB 1.1 modules for driver in ${NWMODULES} ohci-hcd uhci-hcd ; do strinfile " ${driver}" /tmp/hwsetup.info || { rmmod ${driver} driverlist="${driverlist} ${driver}"; } done # wait depending on time of modules to load a little bit before the next # round of hardware detection usleep ${modwaittime} && hwsetup -v > /tmp/hwsetup.info [ $DEBUGLEVEL -eq 21 ] && echo "** finished 2nd hwdetection at $(sysup)" # load IDE high level drivers if [ -n "$ide" ] ; then # you might want to check /etc/sysconfig/floppy for more info strinfile "ZIP" /tmp/hwsetup.info && modprobe ${MODPRV} ide-floppy strinfile "CDROM" /tmp/hwsetup.info && modprobe ${MODPRV} ide-cd strinfile "HD" /tmp/hwsetup.info && { modprobe ${MODPRV} ide-disk disk=yes; } fi # not rather precise ... if strinfile "SCSI" /tmp/hwsetup.info ; then strinfile "CDROM" /tmp/hwsetup.info && { modprobe ${MODPRV} sr_mod; modprobe ${MODPRV} sg; # just for compatibility to hwsetup (which generates links to scd*) ( waitfor /dev/sr0 1000 && for i in /dev/sr* ; do [ -e /dev/scd${i#/dev/sr} ] || cp -a -f $i /dev/scd${i#/dev/sr} ; done; ) & } strinfile "HD" /tmp/hwsetup.info && { modprobe ${MODPRV} sd_mod disk=yes; } # check if a (scsi) scanner was detected strinfile "SCANNER" /tmp/hwsetup.info && \ echo -e 'KERNEL=="sg*",\t\tNAME="%k", GROUP="disk", MODE="666"' \ >> /tmp/scanner-udev fi [ -x /bin/mdev ] && mdev -s # sound card setup (alsa and oss compatibility drivers) ( if [ -f /etc/sysconfig/sound ] ; then . /etc/sysconfig/sound driver=${DRIVER} else driver="snd-dummy" fi # problem with a specific module not disabled (via above trick) when # busybox is used # rmmod snd_atiixp_modem snd_atiixp modprobe ${MODPRV} ${driver} driverlist="${driverlist} ${driver}" modprobe ${MODPRV} snd-pcm-oss modprobe ${MODPRV} snd-mixer-oss # remaining drivers listed in /tmp/hwsetup.info cat /tmp/hwsetup.info| while read line ; do if strinstr "driver:" "${line}"; then driver=${line##driver: } if ! strinstr " ${driver} " "${driverlist}"; then strinstr "Card:" "${driver}" || strinstr "ps/2" "${driver}" || { modprobe ${MODPRV} ${driver} & usleep 5000; } driverlist="${driverlist} ${driver}" fi fi done ) & [ $DEBUGLEVEL -eq 21 ] && echo "** finished most of module loading at $(sysup)" # get idea of availabe harddisk partitions, put swap partitions into # (/mnt)/etc/fstab and format and mount partitions of type 44 (unknown) [ $DEBUGLEVEL -eq 21 ] && echo "** starting hdd stuff at $(sysup)" if [ "${disk}" = "yes" ] ; then for hd in $(cat /tmp/hwsetup.info|sed -n -e '/HD$/,/device:/p'| \ sed -n -e '/device:/p'|sed -e 's/device: //') ; do /mnt/sbin/fdisk -l /dev/$hd|sed -n "/^\/dev\//p" > /tmp/hd_part for hdpartnr in $(cat /tmp/hd_part | \ sed -n -e "/ 82 /p"|sed -e "s/[[:space:]].*//") ; do echo -e "$hdpartnr\tswap\t\tswap\t\tdefaults\t 0 0" >> /tmp/fstab done # we use special non assigned partition type (id44) for harddisk scratch # space, thus no normal filesystem will be incidentally deleted or # corrupted for hdpartnr in $(cat /tmp/hd_part | \ sed -n -e "/ 44 /p"|sed -e "s/[[:space:]].*//") ; do # check for supported filesystem and formatter ( if diskfm $hdpartnr ; then echo "$hdpartnr is mounted to /mnt/tmp at $(sysup)" > /tmp/tmpready echo -e "$hdpartnr\t/tmp\t\tauto\t\tdefaults\t 0 0" >> /tmp/fstab else echo "formatting failed for some reason ($(sysup))" > /tmp/tmpready fi ) & part44=yes break done # put detected linux partitions into /etc/fstab with "noauto" for hdpartnr in $(cat /tmp/hd_part | \ sed -n -e "/ 83 /p"|sed -e "s/[[:space:]].*//") ; do mkdir -p /mnt/media/${hdpartnr#/dev/*} 2>/dev/null echo -e "$hdpartnr\t/media/${hdpartnr#/dev/*}\tauto\t\tnoauto,\ noexec\t 0 0" >> /tmp/fstab done done # determine if tmp preparation should wait for format/mount or not [ -z "$part44" ] && echo "finished at $(sysup)" > /tmp/tmpready else echo "no disk found ( $(sysup) )" > /tmp/tmpready fi [ $DEBUGLEVEL -eq 21 ] && echo "** finished hdd stuff at $(sysup)" # check if USB mouse and/or keyboard is connected and remove usbhid if # not (does not work properly) #strinfile "genericwheelusb" /tmp/hwsetup.info || \ # (strinfile "keybdev" /tmp/hwsetup.info || rmmod usbhid) # configure some variables from configuration file - wait for dhcp or ldap # confiurator to complete cfgcomplete . /etc/machine-setup [ $DEBUGLEVEL -eq 21 ] && echo "** finished waiting for config at $(sysup)" # run X11 / Xorg configurator if no xorg.conf file was provided by # ConfigTGZ (check for /rootfs/${D_XF86CONFFILE#/mnt}) # set X11 configuration file if [ -n "${D_XF86CONFFILE}" ] ; then D_XF86CONFFILE="/mnt/${D_XF86CONFFILE}" else D_XF86CONFFILE="/mnt/etc/X11/xorg.conf" error "$hcfg_xcfg" nonfatal fi if [ -f /rootfs${D_XF86CONFFILE#/mnt} ] ; then echo "ready" > /tmp/xready else . /etc/sysconfig/xserver >/dev/null 2>&1 || error "${hcfg_hwsetup}" nonfatal ( displaysetup /etc/xorg.conf; echo "ready" > /tmp/xready ) & fi # add entries to initialize keytable and consolefont to boot.slx # postpone some commands into normal bootup environment #echo -e "\t# entries added by $0: $date" >> /mnt/etc/${D_INITDIR}/boot.slx #[ -n "${KEYTABLE}" ] && keytable #[ -n "${CONSOLE_FONT}" ] && consolefont # if any new device appeared up to now if [ -x /bin/mdev ] ; then mdev -s & testmkd /dev/input mknod /dev/input/mice c 13 63 2>/dev/null fi return 0 } ############################################################################# # main script starts here # functions common for all distros . /etc/functions # functions common for all distros, messages contains all error and # info output . /etc/messages # load distro specific configuration variables and functions. distro # specific functions may overwrite functions defined in /etc/functions . /etc/sysconfig/config . /etc/distro-functions # script run timer [ $DEBUGLEVEL -eq 8 -o $DEBUGLEVEL -eq 21 ] && \ echo "** HW $1 setup started at $(sysup)" # heavy debugging output in level 3 and above and specific for 11 [ $DEBUGLEVEL -gt 3 -a $DEBUGLEVEL -lt 8 -o $DEBUGLEVEL -eq 11 ] && \ set -x case $1 in # pre initializsation: loading USB base modules, starting hwsetup pre) hwpre ;; # loading network modules nwmod) nwmod ;; # main part of hardware setup including Xorg main) hwmain # main script run timer or debug information [ $DEBUGLEVEL -eq 8 -o $DEBUGLEVEL -eq 21 ] && \ echo "** HW setup finished at $(sysup)" echo "hwsetup finished at $(sysup)" > /tmp/hwcfg ;; esac