#!/bin/sh # # Simple init script that should handle both # livecd/livedisk, thinclient and hdd boot # PATH=/usr/sbin:/usr/bin:/sbin:/bin ROOT_LINKS="bin sbin lib boot usr opt" ROOT_TREES="etc root home var" TMPFS_DIRS="dev mnt mnt/cdrom mnt/livecd mnt/thin tmp sys proc media" LOOP="pardus.img" CDROOT=0 NFSROOT=0 QUIET=0 RAID=0 ROOT_DEVICE="" ROOT_LABEL="" FS_TYPE="" RESUME_DEVICE="" IMG_DEVICES="hd[a-z] sr[0-9]* scd[a-z]" MNTDIR="" fall2sh() { echo "--> $*" /bin/sh } probe_devices() { /bin/coolplug 1> /dev/null 2>&1 } probe_raid() { /bin/modprobe dm-mod /bin/modprobe raid0 /bin/modprobe raid1 /bin/modprobe raid10 /bin/modprobe raid456 /bin/mdadm --examine --scan > /etc/mdadm.conf /bin/mdadm -As } resume_from_hibernate() { if [ -f "/sys/power/resume" ] then if [ -f "/bin/resume" ] then # char device needed by static resume binary /bin/mknod /dev/snapshot c 10 231 /bin/resume fi fi } parse_cmdline() { for x in `cat /proc/cmdline`; do case "${x}" in [0123456Ss]) LEVEL=${x} ;; mudur=*livecd*) CDROOT=1 ;; mudur=*livedisk*) CDROOT=1 IMG_DEVICES="hd[a-z][0-9]* sd[a-z][0-9]*" ;; mudur=*raid*) RAID=1 ;; mudur=*thin*) NFSROOT=1 ;; root=*) ROOT_DEVICE=`echo ${x}|cut -f2 -d=` if [ "${ROOT_DEVICE}" == "LABEL" ] then ROOT_LABEL=`echo ${x}|cut -f3 -d=` fi ;; resume=*) RESUME_DEVICE=`echo ${x}|cut -f2 -d=` ;; init=*) INIT=`echo ${x}|cut -f2 -d=` ;; quiet) QUIET=1 ;; esac done } findcdmount() { if [ "$#" -gt "0" ] then for x in $* do mount -r ${x} /newroot/mnt/cdrom > /dev/null 2>&1 if [ "$?" = "0" ] then # Check for cdroot image if [ -e /newroot/mnt/cdrom/${LOOP} ] then ROOT_DEVICE="${x}" break else umount /newroot/mnt/cdrom fi fi done fi } manage_tmpfs() { mount -t tmpfs tmpfs /newroot for d in ${TMPFS_DIRS} do mkdir -p "/newroot/${d}" done mv /dev/* /newroot/dev/ # coolplug may continue making nodes mount -o bind /newroot/dev /dev # just to make sure, may not be necessary [ ! -e /newroot/dev/console ] && mknod /newroot/dev/console c 5 1 } run_dhcpc() { # FIXME: built in kernel? modprobe af_packet udhcpc -i eth0 -s /etc/udhcpc.script } mount_nfs() { cd /newroot # FIXME: busybox mount does not load automatically modprobe nfs # mount nfs if [ -z "/etc/udhcpc.info" ] then fall2sh "/etc/udhcpc.info not found" fi . /etc/udhcpc.info if [ -z "${ROOTPATH}" ] then fall2sh "NFS rootpath not found" fi echo "Mounting NFS from $ROOTPATH" mount -o tcp,nolock,ro $ROOTPATH /newroot/mnt/thin if [ "$?" != '0' ] then fall2sh "Could not nfs root" fi FS_LOCATION='mnt/thin' for x in ${ROOT_LINKS} do ln -s "${FS_LOCATION}/${x}" "${x}" done chmod 1777 tmp (cd /newroot/${FS_LOCATION}; cp -a ${ROOT_TREES} /newroot) # Needed for ltspfs mechanism echo "$IP $HOSTNAME" >> /newroot/etc/hosts } mount_cdroot() { # These are not loaded automatically modprobe loop modprobe squashfs cd /newroot # Loop type squashfs mount -t squashfs -o loop,ro /newroot/mnt/cdrom/${LOOP} /newroot/mnt/livecd if [ "$?" != "0" ] then fall2sh "Could not mount root image" fi FS_LOCATION="mnt/livecd" umount /dev for x in ${ROOT_LINKS} do ln -s "${FS_LOCATION}/${x}" "${x}" done chmod 1777 tmp (cd /newroot/${FS_LOCATION}; cp -a ${ROOT_TREES} /newroot) # this is needed for yali MNTDIR=`grep \/mnt\/cdrom\ /proc/mounts|sed 's/\/newroot//g'` echo "$MNTDIR" >> /newroot/etc/fstab } # ----- main ------- mount -n -t proc proc /proc > /dev/null 2>&1 mount -n -t sysfs sys /sys > /dev/null 2>&1 parse_cmdline if [ "${ROOT_DEVICE}" == "shellnoprobe" ] then fall2sh "Starting up a shell without probing, as commanded" elif [ "${ROOT_DEVICE}" == "shell" ] then probe_devices fall2sh "Starting up a shell, as commanded" fi # Minimizing kernel noise [ -n "$QUIET" ] && echo "1" > /proc/sys/kernel/printk probe_devices if [ "${RAID}" -eq "1" ] then probe_raid fi if [ "${RESUME_DEVICE}" != "" ] then # Write resume device to /sys/power/resume for SATA disks /bin/stat -c%t:%T $RESUME_DEVICE > /sys/power/resume # If we suspend2disk resume it from here resume_from_hibernate fi echo 0x0100 > /proc/sys/kernel/real-root-dev if [ "${CDROOT}" -eq "1" ] then ROOT_DEVICE="" manage_tmpfs # modprobe filesystems that are not in kernel, for live disks for i in nls_cp857 nls_utf8 vfat jbd mbcache ext2 ext3 do modprobe ${i} 1> /dev/null 2>&1 done for i in `seq 10` do for t in ${IMG_DEVICES} do findcdmount "/newroot/dev/$t" if [ "${ROOT_DEVICE}" != "" ] then break fi done if [ "${ROOT_DEVICE}" != "" ] then break else probe_devices sleep 1 fi done if [ "${ROOT_DEVICE}" == "" ] then fall2sh "Could not find mount media" fi mount_cdroot elif [ "${NFSROOT}" -eq '1' ] then run_dhcpc manage_tmpfs mount_nfs # set hostname for mudur hostname $HOSTNAME else # mount real root for i in `seq 10` do if [ "${ROOT_LABEL}" != "" ] then ROOT_DEVICE=`findfs LABEL=${ROOT_LABEL}` fi if [ ! -b "${ROOT_DEVICE}" ] then probe_devices sleep 1 else break fi done if [ ! -b "${ROOT_DEVICE}" ] then fall2sh "Could not find boot device" else FS_TYPE=`disktype $ROOT_DEVICE | grep KERNELMODULE | awk '{print $2}'` # We probably won't need this, but keeping for a while in case something pops up #if [ "${FS_TYPE}" == "vfat" ] #then # modprobe nls_cp857 1> /dev/null 2>&1 # modprobe nls_utf8 1> /dev/null 2>&1 #fi modprobe ${FS_TYPE} 1> /dev/null 2>&1 mount -t auto -n -o ro $ROOT_DEVICE /newroot fi fi umount -n /sys umount -n /proc [ "${INIT}" == "" ] && INIT="/sbin/init"; # and we start exec /bin/switch_root -c /dev/console /newroot ${INIT} ${LEVEL}