# # 2003-03-18 # http://homex.subnet.at/~max/diskless/ # # Description: # - ask for the client screen's resolution # and check for the file "lowres" (which results in an 'automatic' 800x600) # - determine the client's IP address # - creates /tmp-indivs/$MYIP/ # - copies /etc and /var to it, creates /tmp there # - make sure a "swap" file exists in /tmp-indivs/$MYIP/ # - creates a 1MB ramdisk and mounts it as /mnt/ramdisk # thus hiding the server's standard /etc, /var, /tmp # - creates symlink /mnt/ramdisk/my-indiv/ -> /tmp-indivs/$MYIP # thus having the symlinks /etc, /var and /tmp pointing to # valid directories again # - initialize the swap-file and do some tricks to mount it # via NFS # - use the corresponding XF86Config-4 and do a little clean-up # - set the hostname to the last octet of $MYIP with the prefix "dls" # (results in hostnames "dls1" through "dls127") # # This way, each client has its own /etc, /var and /tmp with # read-write. Instead of wasting local RAM, we have these directories # mounted via NFS, thus the consume server-disk-space (and once # at boot time lot's of time copying everything over the network) # instead of precious local RAM. # # This script is started by the link /etc/rcS.d/S11diskless and thus # after(!!) S10checkroot.sh as "/" is mounted "rw" then. # # This script needs Bash-2.05a or similar. It will not run with # Debian Potato's Bash, as this script uses the new Bash's read command # with "timeouts" and similar options. # # default resolution: # possible values: 1024x768, 800x600 RES=1024x768 /bin/echo /bin/echo Diskless setup starts ... /bin/echo MYIP=`/sbin/ifconfig eth0 | grep inet | awk '{print $2}' | sed 's/^addr://g'` echo my ip: $MYIP VALIDANSWER=n while [ $VALIDANSWER == "n" ]; do read -r -t 10 -n 1 -p "Does this client support 1024x768? [y|n] " XReply if [ -z "${XReply}" ]; then # no answer given, check if the file "lowres" exists (800x600), # else use default resolution if [ -f /tmp-indivs/$MYIP/lowres ]; then /bin/echo No answer chosen, file \"lowres\" exists, using 800x600. RES=800x600 else /bin/echo No answer chosen, using $RES. fi VALIDANSWER=y else if [ $XReply == "y" ] || [ $XReply == "Y" ]; then /bin/echo /bin/echo Using resolution 1024x768. /bin/rm -f /tmp-indivs/$MYIP/lowres RES=1024x768 VALIDANSWER=y elif [ $XReply == "n" ] || [ $XReply == "N" ]; then /bin/echo /bin/echo Using resolution 800x600. /usr/bin/touch /tmp-indivs/$MYIP/lowres RES=800x600 VALIDANSWER=y else /bin/echo /bin/echo You gave an invalid answer, try again... fi fi done /bin/echo Re-creating /tmp-indivs/$MYIP ... if [ -f /tmp-indivs/$MYIP/swap ]; then /bin/echo swap-file exists, re-using it /bin/mv /tmp-indivs/$MYIP/swap /tmp-indivs/swap_$MYIP else /bin/echo swap-file doesnt exist yet, need to copy it later fi if [ -f /tmp-indivs/$MYIP/lowres ]; then /bin/echo lowres-file exists, handling it /bin/mv /tmp-indivs/$MYIP/lowres /tmp-indivs/lowres_$MYIP fi /bin/rm -rf /tmp-indivs/$MYIP/ /bin/mkdir /tmp-indivs/$MYIP/ if [ -f /tmp-indivs/lowres_$MYIP ]; then /bin/mv /tmp-indivs/lowres_$MYIP /tmp-indivs/$MYIP/lowres fi if [ -f /tmp-indivs/swap_$MYIP ]; then /bin/mv /tmp-indivs/swap_$MYIP /tmp-indivs/$MYIP/swap fi /bin/echo Re-creating /tmp-indivs/$MYIP done. /bin/echo Creating and populating tmp, etc, var and perhaps swap in /tmp-indivs/$MYIP/ ... /bin/mkdir /tmp-indivs/$MYIP/tmp/ /bin/chmod 1777 /tmp-indivs/$MYIP/tmp/ /bin/cp -aL /etc /tmp-indivs/$MYIP/ /bin/cp -aL /var /tmp-indivs/$MYIP/ if [ ! -f /tmp-indivs/$MYIP/swap ]; then /bin/echo Copying swap-file cp -aL /swap-template /tmp-indivs/$MYIP/swap else echo swap-file already exists fi /bin/echo tmp, etc, var, swap done. /bin/echo Creating 1MB ramdisk /dev/ram0 ... /bin/dd if=/dev/zero of=/dev/ram0 bs=1k count=1024 /bin/echo Creating 1MB ramdisk done. /bin/echo Creating EXT2-filesystem on ramdisk /dev/ram0 ... /sbin/mke2fs -q -i 1024 -m0 /dev/ram0 1024 /bin/echo Creating EXT2-filesystem done. /bin/echo Mounting /dev/ram0 to /mnt/ramdisk ... /bin/mount -n -t ext2 -o rw,suid,dev,exec,async,nocheck /dev/ram0 /mnt/ramdisk /bin/echo Mounting ramdisk done. /bin/echo Creating symlink /mnt/ramdisk/my-indiv/ -> /tmp-indivs/$MYIP/ ... /bin/ln -ivs /tmp-indivs/$MYIP/ /mnt/ramdisk/my-indiv /bin/echo Creating symlink done. /bin/echo Initializing and activating swap-file ... /sbin/mkswap /tmp-indivs/$MYIP/swap /sbin/losetup /dev/loop0 /tmp-indivs/$MYIP/swap /sbin/swapon /dev/loop0 /bin/echo Initializing swap-file done. /bin/echo Correcting /etc/X11/X, make it a symlink again ... # otherwise, X won't start up /bin/rm -f /etc/X11/X /bin/ln -ivs /usr/bin/X11/XFree86 /etc/X11/X /bin/echo Correcting /etc/X11/X done. /bin/echo Setting XF86Config-4 according to screen resolution ... if [ $RES == "1024x768" ]; then /bin/cp -f /etc/X11/XF86Config-4_1024x768 /etc/X11/XF86Config-4 elif [ $RES == "800x600" ]; then /bin/cp -f /etc/X11/XF86Config-4_800x600 /etc/X11/XF86Config-4 else /bin/echo WARNING: RES has no valid value, using 1024x768 /bin/cp -f /etc/X11/XF86Config-4_1024x768 /etc/X11/XF86Config-4 /bin/sleep 5 fi /bin/echo Setting XF86Config-4 done. /bin/echo Setting the hostname ... /bin/echo -n "dlc" > /etc/hostname /bin/echo $MYIP | sed s/\\./' '/g | awk '{print $4}' >> /etc/hostname /bin/echo Setting hostname `/bin/cat /etc/hostname` done. /bin/echo /bin/echo Diskless setup done. /bin/echo