#!/bin/sh
#
# init script for initramfs (Initial ram filesystem) for LTSP
#
# Copyright (C) 2005 James A. McQuillan <jam@McQuil.Com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# 10/08/2005 -jam- Changed it to use switchroot, instead of pivot_root
# 10/02/2005 -jam- Changed it to make / a ramdisk, and do the nfs-mount to a
# subdirectory.
# 09/25/2005 -jam- Changed from initrd to initramfs
#
# 04/19/2003 -jam- Changed from dhclient to dhcpcd, to work better with w2k
# dhcp servers. This change is thanks to
# Paul Whittaker <paw@si1.dod.gov.au>
#
# 04/11/2003 -jam- Added DPORT as a kernel commandline arg, to cause the
# dhclient program to use an alternate port. Default is 67.
#
# 03/04/2002 -jam- Changed to use modprobe instead of insmod, so that the module
# dependencies would work properly.
# 02/28/2002 -jam- Added IRQ as a kernel cmdline arg, to be passed to the
# NIC module. Also made IO so that it would always be passed
# to the NIC module, even if not required by that module.
# 12/11/2001 -jam- Added loading of 8390.o when using e2100, smc-ultra and wd
# 10/18/2001 -jam- Added support for Linux Progress Patch (LPP
# 09/22/2001 -jam- Added auto-probing to determine what type of NIC
# 09/18/2001 -jam- Added loading of the 8390.o module when either
# 3c503, hp-plus, hp, ne or ne2k-pci are used.
#
# 09/02/2001 -jam- Initial writing of this script
#
echo "==============================================================================="
echo "Running /linuxrc"
echo "Mounting /proc"
mount -t proc /proc /proc
[ "${INITRD_DBG}" = "1" ] && exec /bin/sh
[ "${SLEEP}" -gt 0 ] && sleep ${SLEEP}
if [ -z "${NIC}" ]; then
NIC=`/bin/pci_scan /etc/niclist`
if [ -z "${NIC}" ]; then
echo
echo "ERROR! Could not automatically detect the network card."
echo " PCI cards should be detected automatically."
echo " ISA cards cannot be detected, so they require"
echo " the nic driver to be specified in a 'NIC=' parameter"
echo " to be passed on the kernel command line,"
echo " usually specified in option-129, in the"
echo " /etc/dhcpd.conf file. See the LTSP docs for more info."
echo
exit 1
fi
fi
[ "${INITRD_DBG}" = "2" ] && exec /bin/sh
IOADDR=""
#
# See if we need to pass an IO argument to the driver
#
[ "${INITRD_DBG}" = "3" ] && exec /bin/sh
case ${NIC} in
3c503 | hp_plus | hp | ne | wd)
if [ -z "${IO}" ]; then
echo
echo "ERROR! No IO specified."
echo " The NIC requires an IO=0xNNN entry on the kernel command line."
echo " This is setup in the /etc/dhcpd.conf file using option-129"
echo
exit 1
fi
;;
esac
if [ -n "${IO}" ]; then
IOADDR="io=${IO}"
fi
if [ -n "${IRQ}" ]; then
IRQOPT="irq=${IRQ}"
fi
[ "${SLEEP}" -gt 0 ] && sleep ${SLEEP}
[ "${INITRD_DBG}" = "4" ] && exec /bin/sh
echo "linuxrc: Installing ${NIC} driver"
echo "modprobe ${NIC} ${IOADDR} ${IRQOPT} ${NICOPT}"
modprobe -v ${NIC} ${IOADDR} ${IRQOPT} ${NICOPT}
if [ $? -ne 0 ]; then
echo
echo "ERROR! Failed to install the NIC driver module!"
echo " This could be caused by the wrong module for your particular"
echo " network interface card. Double check the 'option-129' entry"
echo " in your /etc/dhcpd.conf file."
echo
exit 1
fi
#
# dhcpcd runs as a daemon. Once it acquires the info from the
# server, it will automatically configure the interface. A script called
# /etc/dhcpc/dhcpcd.exe is used to perform additional configuration.
#
[ "${INITRD_DBG}" = "6" ] && exec /bin/sh
[ "${SLEEP}" -gt 0 ] && sleep ${SLEEP}
if [ -z "${DPORT}" ]; then
DPORT=67
fi
echo "Running dhcpcd on port ${DPORT}"
/bin/dhcpcd -p ${DPORT} eth0 >/tmp/dhcpcd.out 2>&1
if [ $? -ne 0 ]; then
echo
cat /tmp/dhcpcd.out
echo
echo "ERROR! dhcpcd failed!"
echo
exit 1
fi
#
# The dhcpcd program deposited a bunch of important
# information in the /etc/dhcpc/dhcpcd-eth0.info file.
# Sourcing the file will set a bunch of environment variables.
#
#
# On a slow machine, the dhclient program might fork and return
# control to the /linuxrc script, before the info file gets written.
#
COUNT=5
while [ $COUNT -gt 0 -a ! -f /etc/dhcpc/dhcpcd-eth0.info ]; do
sleep 1
COUNT=`expr $COUNT - 1`
done
if [ ! -f /etc/dhcpc/dhcpcd-eth0.info ]; then
echo
echo "ERROR! No dhcpcd-eth0.info file."
echo " This usually indicates that dhcpcd did not get"
echo " a response from the DHCP server, or the NIC driver"
echo " isn't working properly with the network card"
echo
exit 1
fi
. /etc/dhcpc/dhcpcd-eth0.info
#
# Check for a root-path from the dhcp server
#
[ "${INITRD_DBG}" = "7" ] && exec /bin/sh
if [ -z "${ROOTPATH}" ]; then
echo
echo "ERROR! No 'root-path' received from the DHCP server!"
echo " Possible reasons include:"
echo
echo " 1) Your dhcpd.conf file doesn't include the 'option root-path' entry."
echo
echo " 2) You have multiple DHCP servers on your network, and the client"
echo " received an offer from the wrong one."
echo
exit 1
fi
NFS_IP=` echo ${ROOTPATH} | cut -d : -f 1`
NFS_DIR=`echo ${ROOTPATH} | cut -d : -f 2`
if [ "${NFS_IP}" = "${NFS_DIR}" ]; then
#
# Only the root directory is specified, then we have to use the
# default IP address. For now, we'll use the DHCP server address
#
NFS_IP=${DHCPSERVER}
fi
[ -z "${MOPTS}" ] && MOPTS="nolock,ro"
echo "Creating new ramdisk to hold our root fs..."
mkdir /newroot
mount -n -t ramfs none /newroot
mkdir /newroot/nfsroot
echo "Mounting root filesystem: ${NFS_DIR} from: ${NFS_IP}"
mount -n -o ${MOPTS} ${NFS_IP}:${NFS_DIR} /newroot/nfsroot
if [ $? -ne 0 ]; then
echo
echo "ERROR! Failed to mount the root directory via NFS!"
echo " Possible reasons include:"
echo
echo " 1) NFS services may not be running on the server"
echo
echo " 2) Workstation IP does not map to a hostname, either"
echo " in /etc/hosts, or in DNS"
echo
echo " 3) Wrong address for NFS server in the DHCP config file"
echo
echo " 4) Wrong pathname for root directory in the DHCP config file"
echo
exit 1
fi
[ "${INITRD_DBG}" = "8" ] && exec /bin/sh
echo "Setting up the new root ramdisk area..."
#
# Create the directories on our new root filesystem that should NOT
# come from the NFS filesystem that we mount
#
for i in dev home mnt oldroot proc sys tmp var; do
mkdir /newroot/$i
done
#
# Create symlinks to the items we are need from the NFS mounted filesystem
#
for i in bin etc lib libexec root sbin share usr; do
ln -s /nfsroot/$i /newroot/$i
done
umount /proc
[ "${INITRD_DBG}" = "9" ] && exec /bin/sh
echo "Doing the switchroot"
exec /sbin/switchroot /newroot
echo "Hmm, switchroot must have failed!!!!"
exit