From 0677328054a51160b79af3fb982b852294c5e175 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Wed, 20 Aug 2008 12:20:07 +0000 Subject: * merged branch 'initramfs-ng' back intro trunk - requires careful testing ... git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@2055 95ad53e4-c205-0410-b2fa-d234c58c8868 --- initramfs/stage3-stuff/bin/dhcpmkconfig | 31 ++++ initramfs/stage3-stuff/bin/hwautocfg | 185 +++++++++++++++++++ initramfs/stage3-stuff/bin/servconfig | 304 ++++++++++++++++++++++++++++++++ 3 files changed, 520 insertions(+) create mode 100755 initramfs/stage3-stuff/bin/dhcpmkconfig create mode 100755 initramfs/stage3-stuff/bin/hwautocfg create mode 100755 initramfs/stage3-stuff/bin/servconfig (limited to 'initramfs/stage3-stuff/bin') diff --git a/initramfs/stage3-stuff/bin/dhcpmkconfig b/initramfs/stage3-stuff/bin/dhcpmkconfig new file mode 100755 index 00000000..66f16371 --- /dev/null +++ b/initramfs/stage3-stuff/bin/dhcpmkconfig @@ -0,0 +1,31 @@ +#!/bin/ash +# Copyright (c) 2003..2006 - RZ Uni Freiburg +# Copyright (c) 2006..2008 - 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) IP configuration writer for busybox udhcpc +# applet used within OpenSLX initramfs. The result is written to the +# /etc/initramfs-setup file + +# heavy debugging output in level 3 and above ... and on 13 +#FIXME: DEBUGLEVEL is not propagated to this file (at least for Ubuntu) +[ -z "$DEBUGLEVEL" ] && DEBUGLEVEL=0 +[ $DEBUGLEVEL -gt 3 -a $DEBUGLEVEL -lt 8 -o $DEBUGLEVEL -eq 13 ] && \ + set -x + +echo -e "# network configuration written by $0:" >/tmp/confviadhcp +unset infomsg HOME IFS mask lease interface cfgmsg cfgfile DEBUGLEVEL +set | sed \ + -e "s,^P.*,,;s,ntpsrv,ntp_servers,;s,ip,clientip," \ + -e "s,serverid,serverip,;s,subnet,subnet_mask," \ + -e "s,router,gateway,;s,hostname,host_name," \ + -e "s,domain,domain_name,;s,dns,domain_name_servers," \ + -e "s,broadcast,broadcast_address,;s,dhc.*,,;/^$/d" \ + -e "/OPTIND.*/d" >>/tmp/confviadhcp diff --git a/initramfs/stage3-stuff/bin/hwautocfg b/initramfs/stage3-stuff/bin/hwautocfg new file mode 100755 index 00000000..c83f17ac --- /dev/null +++ b/initramfs/stage3-stuff/bin/hwautocfg @@ -0,0 +1,185 @@ +#!/bin/ash +# Copyright (c) 2003..2006 - RZ Uni Freiburg +# Copyright (c) 2006..2008 - 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 stateless clients, using SuSE hwinfo for configuration + +############################################################################# +# pre part, load USB modules and start hardware detection pci +base () { +# avoid annoying error messages because of missing scripts +for tool in /usr/sbin/acpidump \ + /usr/bin/udevinfo \ + /sbin/dmraid ; do + testmkd ${tool%/*} + echo -e "#!/bin/ash" >${tool} + chmod u+x ${tool} +done +# no kernel messages +echo "0 0 0 0" >/proc/sys/kernel/printk +modprobe ${MODPRV} usbhid & +nwcardlist=$(echo ${slxconf_listnwmod}|sed "s/\ /|/g") +hwinfo --netcard --usb-ctrl | grep modprobe | grep -E "$nwcardlist|hcd" | \ + grep -v ehci | sed 's/.* Cmd: "//;s/"//' | sort -u >/etc/modprobe.base +ash /etc/modprobe.base; mdev -s +# optimization possible: exclude network and usb base drivers from the +# following list (bios detection for non-hwautocfg component) +( hwinfo --pci >/etc/hwinfo.data; hwinfo --bios >/etc/hwinfo.bios ) & +return 0 +} + +############################################################################# +# main part +hwmain () { +# activate the previously detected devices +[ $DEBUGLEVEL -ge 2 ] || modloadbg=" >/dev/null 2>\&1" +sed '/Driver Info #1/,/Config Status:/d' \ + /etc/hwinfo.data | grep modprobe | sed "s|.* Cmd: \"||;s|\"|$modloadbg|" \ + | sort -u >/etc/modprobe.pci +ash /etc/modprobe.pci +mdev -s + +# bluetooth setup (start it later if present, depends on firmware availa- +# bility, interpreted by servconfig) +#( hwinfo --bluetooth >/etc/hwinfo.bt ) & + +# load harddisk driver and check for harddisk +( grep -q -E "IDE|SCSI" /etc/hwinfo.data && modprobe ${MODPRV} sd_mod + hwinfo --disk | sed -n "/Device File: /p" | sed "s|.*Device File: /dev/||" \ + >/etc/hwinfo.disk; ) & +[ $DEBUGLEVEL -eq 21 ] && echo "** finished 2nd hwdetection at $(sysup)" + +# load disk/optical high level drivers +modprobe ${MODPRV} ide-cd +modprobe ${MODPRV} sr_mod +modprobe ${MODPRV} ide-floppy +mdev -s + +# load kernel module for ps2 mice and map the mousehandler to /dev/input/mice +( [ -f /lib/modules/${KERNEL}/kernel/drivers/input/mouse/psmouse.ko ] && \ + modprobe ${MODPRV} psmouse + [ -f /lib/modules/${KERNEL}/kernel/drivers/input/mousedev.ko ] && \ + modprobe ${MODPRV} mousedev + testmkd /dev/input + mknod /dev/input/mice c 13 63 2>/dev/null + hwinfo --mouse >/etc/hwinfo.mouse ) & + +# complete the audio configuration and load the dummy module if no audio +# hardware is present in the machine +grep -q -E "Audio|sound" /etc/hwinfo.data || modprobe snd-dummy +modprobe ${MODPRV} snd-pcm-oss +modprobe ${MODPRV} snd-mixer-oss + +[ $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)" +waitfor /etc/hwinfo.disk 10000 +if [ -s /etc/hwinfo.disk ] ; then +for hd in $(cat /etc/hwinfo.disk) ; do + fdisk -l /dev/$hd|sed -n "/^\/dev\//p" >/etc/disk.partition + for hdpartnr in $(cat /etc/disk.partition | \ + 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 /etc/disk.partition | \ + 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 /etc/disk.partition | \ + 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)" + +# scanner setup (fixme: to be checked) +hwinfo --scanner >/etc/hwinfo.scanner +[ -f /tmp/scanner-udev ] && cat /tmp/scanner-udev \ + >>/mnt/etc/udev/rules.d/04-scanner.rules + +# if any new device appeared up to now +mdev -s +return 0 +} + +############################################################################# +# cleanup/finishing part +finish () { +# remove unneeded disk and mouse drivers +[ ! -s /etc/hwinfo.disk ] && rmmod sd_mod 2>/dev/null +grep -q -i "/dev/psaux" || rmmod psmouse 2>/dev/null +# more sophistication possible :) +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/distro-functions +# source general slx settings +. /etc/slxsystem.conf + +# 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 initialization: loading USB base and network adaptor modules, + # detection of other pci bus modules + base) + base + ;; + # 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 + ;; + # remove unneeded kernel modules + finish) + finish + ;; +esac diff --git a/initramfs/stage3-stuff/bin/servconfig b/initramfs/stage3-stuff/bin/servconfig new file mode 100755 index 00000000..6885e687 --- /dev/null +++ b/initramfs/stage3-stuff/bin/servconfig @@ -0,0 +1,304 @@ +#!/bin/ash +# Copyright (c) 2003..2006 - RZ Uni Freiburg +# Copyright (c) 2006..2008 - 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) configuration script for OpenSLX linux +# diskless clients (executed in stage3 within initial ramfs). The file- +# system setup is completed when servconfig starts + +############################################################################# +# check for configuration files to source + +# functions common for all distros, messages contains all error and +# info output +. /etc/messages +. /etc/functions +# load distro specific configuration functions. Distro specific functions may +# overwrite functions defined in /etc/functions +. /etc/distro-functions +. /etc/slxsystem.conf + +# script run timer +[ $DEBUGLEVEL -eq 8 ] && echo "** SW setup started at $(sysup)" + +# heavy debugging output in level 3 and below 8 ... +[ $DEBUGLEVEL -gt 3 -a $DEBUGLEVEL -lt 8 -o $DEBUGLEVEL -eq 12 ] && \ + set -x + +############################################################################# +# read and unify configuration options - default configuration file, from +# dhcp, ldap ... +# wait for the appearance of configuration from several sources +cfgcomplete +. /etc/initramfs-setup +[ $DEBUGLEVEL -eq 8 ] && echo "** Config info is complete at $(sysup)" + +# copy additional configuration and var files and directories +# admins can place there files in /var/lib/openslx/config/... +# to be packed during stage2 into (/srv/dxs)/tftpboot/client-config...) +cp -a /rootfs/* /mnt 2>/dev/null + +# copy passwd file for temporarily (within stage3 configuration) use by chown +cp /mnt/etc/passwd /etc + +# set greeting and add information on booted system +len=$(expr length ${SLXVERSION}${SYSTEM_NAME}) +if [ $len -le 28 ] ; then + vdstr="Stateless Workstation (V${SLXVERSION}/${SYSTEM_NAME})" + smax=28 +else + vdstr="V${SLXVERSION}/${SYSTEM_NAME}" + smax=52 +fi +while [ $len -le $smax ] ; do + vdstr="$vdstr " + len=$(($len + 1)) +done +len=$(expr length ${host_name}) +while [ $len -le 30 ] ; do + space="$space " + len=$(($len + 1)) +done +echo " + WELCOME TO $space \n (\l) + _____ ______ ______ __ __ _______ __ __ __ + / _ | _ | ___| | | | | ____| | | | | | + | | | | |_| | |_ | | | | |___ | | / / + | | | | ___/| _| | | ____ | | | | + | |_| | | | |___| | | | ____| | |___ / / + _____/|__| |______|__| |__| |_______|______|__| |__| + + $vdstr (c) +" >/mnt/etc/issue + +############################################################################# +# set localization and add entries to initialize keytable and consolefont to +# boot.slx +if [ -z "${country}" ] ; then + error "$scfg_country" nonfatal + country="us" +fi +# do localization (this functions starts a distro specific setup) +localization "${country}" + +############################################################################# +# setup passwd and shadow for local system users like root, bin, daemon and +# nobody if no user/admin provided passwd exists ... fixme: see #206 +basepasswd $(sed "/+::0/d;s/root://;s/:.*//" /rootfs/etc/shadow) + +############################################################################# +# dns and ip configuration +# hostname of the machine +echo "$host_name" >/proc/sys/kernel/hostname +echo -e "# /etc/hosts - file generated by $0 during OpenSLX stage3\ +\n#\n# IP-Address Full-Qualified-Hostname Short-Hostname\n#\n\ +127.0.0.1\tlocalhost\n::1\t\tlocalhost ipv6-localhost ipv6-loopback\n\ +fe00::0\t\tipv6-localnet\nff00::0\t\tipv6-mcastprefix\nff02::1\ +\t\tipv6-allnodes\nff02::2\t\tipv6-allrouters\nff02::3\t\t\ +ipv6-allhosts\n" >/mnt/etc/hosts +if [ -n "$domain_name" ]; then + echo -en "$clientip\t" >>/mnt/etc/hosts + for name in $domain_name; do + echo -en "$host_name.$name " >>/mnt/etc/hosts + done + echo -e "$host_name" >>/mnt/etc/hosts +else + echo -e "$clientip\t$host_name" >>/mnt/etc/hosts +fi +# set up domainname and resolving +rm -rf /mnt/etc/resolv.conf +test -n "$domain_name" && \ + echo -e "# /etc/resolv.conf - file generated by\n#\t$0:\n\ +#\t$date\n#options timeout:1 attempts:1 rotate\n\ +search "$domain_name >/mnt/etc/resolv.conf +test -n "$domain_name_servers" && { + for name in $domain_name_servers; do + echo nameserver $name >>/mnt/etc/resolv.conf; + done; } + +############################################################################# +# run distro specific configuration function +config_distro + +############################################################################# +# basic (non network) services + +# at daemon - calling distro specific function config_atd +config_atd + +# configuration of cron services - calling distro specific function +# config_cron (runlevel links, directories, ...) +config_cron +[ "x$crontab_entries" != "x" ] && \ + echo -e "$crontab_entries" >> /mnt/etc/crontab + +# setup system log services - distro dependent function config_syslog +config_syslog + +# acpi and powersave - distro dependent function config_acpi, these daemons +# might require dbus +config_acpi + +# configure dbus - distro dependent function config_dreshal - handle +# all stuff regarding dependent services like dbus, resmgr, hal ... +# (check for runlevel scripts, passwd entries, directories ...) +config_dreshal + +# configure automounter (should be moved to plugin) +if [ "x$automnt" != "xno" ] ; then + # check if there is some user provided configuration (only auto.master is + # important) and skip automatic setup + if [ ! -f /rootfs/etc/auto.master ] ; then + if [ -d /mnt/misc ] ; then + echo -e "# /etc/auto.master - file generated by $0:\n\ +/misc\t/etc/auto.misc" >/mnt/etc/auto.master + echo -e "# /etc/auto.misc - file generated by $0:" >/mnt/etc/auto.misc + else + echo -e "# /etc/auto.master - file generated by $0:\n\ +/misc\t#/etc/auto.misc" >/mnt/etc/auto.master + echo -e "# /etc/auto.misc - file generated by $0:\nautomount for \ +removable devices is mostly deprecated, so /misc is not\nactivated in \ +auto.master." >/mnt/etc/auto.misc + fi + if [ -n "${automnt_src}" ] ; then + # local directory and home directory server from initialramfs-setup + [ -z "${automnt_dir}" ] && automnt_dir="/home" + # remove leading and trailing slash + automnt_dir=${automnt_dir#/} + automnt_dir=${automnt_dir%/} + test -d /${automnt_dir} || error "$scfg_erradir" nonfatal + strinstr "/" ${automnt_dir} && error "$scfg_erratpld" nonfatal + amserv=$(uri_token $automnt_src server) + ampath=$(uri_token $automnt_src path) + echo -e "/${automnt_dir}\t/etc/auto.${automnt_dir}\n" \ + >> /mnt/etc/auto.master + echo -e "# /etc/auto.${automnt_dir} created by $0:\n" \ + > /mnt/etc/auto.${automnt_dir} + echo -e "*\t-rsize=32768,wsize=32768,rw\t${amserv}:${ampath}/&" \ + >> /mnt/etc/auto.${automnt_dir} + # no tempfs needed if automounter operates on /home + [ "${automnt_dir}" = "home" ] && umount -t tmpfs /mnt/home 2>/dev/null + # portmapper is needed for remote NFS sources and local nfs directories + testmkd /mnt/var/lib/nfs/state + config_portmap + fi + fi + config_automount +fi + +# configure print services / start requested printer daemon +config_printer + +# configure bluetooth services +#[ -s /etc/hwinfo.bt ] if existance of bt devices should play any role +config_bt + +############################################################################# +# network(ed) services + +# network time service (ntp) configuration file +if [ -n "$ntp_servers" -a ! -f /rootfs/etc/ntp.conf ]; then + echo -e "# /etc/ntp.conf - file generated by $0: \ +$date\n" >/mnt/etc/ntp.conf + for name in $ntp_servers; do + echo server $name >>/mnt/etc/ntp.conf + done +fi +# copy timezone file defined with language settings +[ -z "$TZ" ] && TZ="$timezone" +ln -snf /usr/share/zoneinfo/${TZ} /mnt/etc/localtime || \ + error "$scfg_ntptz" nonfatal +config_ntp + +# secure shell server - at the moment all clients share one "secret" +# key or the key has to be regenerated on every bootup or fetched on +# every bootup from somewhere +config_sshd + +# simple network management protocol agent +config_snmp + +# setup afs client stuff +config_afs + +# setup nfsv4/krb stuff +config_nfsv4 + +# configure samba service +config_samba + +############################################################################# +# NIS +# setup nis configuration if needed +if [ "x$nis_domain" != "x" ] && [ "x$nis_servers" != "x" ] ; then + echo $nis_domain >/mnt/etc/defaultdomain + echo -e "# /etc/yp.conf - file generated by $0:\n#\t\ +$date\n\nypserver "$nis_servers >/mnt/etc/yp.conf + config_nis +fi + +############################################################################# +# name service caching daemon if networked user database +config_nscd + +############################################################################# +# preparation of /tmp directory (partition 44, nfs scratch, ramdisk). there +# might be the chance that we have a disk partition available, so wait for +# completion of detection, setup process +[ $DEBUGLEVEL -eq 8 ] && echo "** Waiting for /tmp completion at $(sysup)" +waitfor /tmp/tmpready 40000 +[ $DEBUGLEVEL -eq 8 ] && echo "** Setup of /tmp completed at $(sysup)" +# create some directories and correct permissions +tmpisdisk=$(sed -n '/\/tmp/p' /tmp/fstab 2>/dev/null) +# if there is no local disk partition for /tmp then try to mount a rw +# scratch space (if defined in $scratch) and prepared on server +if [ -n "$scratch" -a -z "$tmpisdisk" ] ; then + scrproto=$(uri_token $FILESRC prot) + scrpath=$(uri_token $FILESRC path) + testmkd /tmp/scratch + # exports have to be per client!! + case "$scrproto" in + nbd) + : + ;; + *) + tmpserv=$(uri_token $scratch server) + tmppath=$(uri_token $scratch path) + # check that nfs is available + nfsmod + # hanging mount processes might stop further setup - timeout + # should be configured ... it is possible to mount "nolock" only + mount -t nfs -o rw,tcp,nolock,intr,nodev,soft,timeo=2,nosuid \ + ${tmpserv}:${tmppath} /tmp/scratch >/dev/null 2>&1 && { + testmkd /tmp/scratch/${clientip} + umount /tmp/scratch + # no need for tempfs there ... + umount /mnt/tmp >/dev/null 2>&1 + mount -t nfs -o rw,tcp,nolock,intr,nodev,soft,timeo=2,nosuid \ + ${tmpserv}:${tmppath}/${clientip} /mnt/tmp >/dev/null 2>&1 + # somehow we need to move it to the vmware plugin. Any ideas + # how to handle the dependencies? + # create an empty container file for vmware *.vmem, it does not + # like to live on NFS exports + if [ "x$vmware" != "x" -a "x$vmware" != "xno" ] ; then + dd if=/dev/zero of=/mnt/tmp/vm-container count=1 seek=2048000 + diskfm /mnt/tmp/vm-container /mnt/tmp/vmware + chmod a+rwxt /mnt/tmp/vmware + fi; } + ;; + esac +fi + +# script run timer +[ $DEBUGLEVEL -eq 8 ] && echo "** SW setup finished at $(sysup)" + +# servconfig finished successfully +echo "servconfig finished at $(sysup)" > /tmp/svcfg -- cgit v1.2.3-55-g7522