home *** CD-ROM | disk | FTP | other *** search
Neil Brown's ash script | 2001-08-14 | 9.4 KB | 402 lines |
- #!/bin/ash
-
- # BBC init shell script
- # Copyright (C) 1999-2001 Linuxcare, Inc.
- # Copyright (C) 2001 Seth Schoen
-
- # This must run under ash. Also, it should run with almost no external
- # binaries available. If you need a particular binary here, you need to
- # build it in BusyBox and replace the BusyBox in the root filesystem.
-
- # Further caveat: the old static ash version 2 I'm currently using does
- # not support a lot of standard shell features. For example, the standard
- # "if ! command", the test [ -e ], and shell arithmetic like $((1+1)).
-
- PATH="/bin:/usr/bin"
- TERM=linux
- ignoreeof=10
- export PATH DISPLAY TERM ignoreeof
- umask 022
-
- mount /proc/ /proc -n -t proc
-
- # some people have USB and might be able to benefit from this
- # (if it's not in the kernel, it will give an error)
- mount -t usbdevfs none /proc/bus/usb
-
- # Don't try to probe hardware during boot process (since modprobe is
- # not yet available and all usable modules are compiled into kernel)
- echo /bin/true > /proc/sys/kernel/modprobe
-
- # Are we going to do a Debian install?
-
- set `cat /proc/cmdline`
-
- DEBINST=false
- QUICK=false
-
- while [ $# -gt 0 ]
- do
- [ x"$1" = xdebinst ] && DEBINST=true
- [ x"$1" = xquick ] && QUICK=true
- [ x"$1" = xdebug ] && set -x
- [ x"$1" = xinteractive ] && exec sh
- shift
- done
-
- if $DEBINST
- then
- echo Loading Debian installer...
- echo Sorry, Debian installer not supported in this version.
- fi
-
- partition=0
-
- for drive in `echo /dev/hd? /dev/scd? /dev/sd?`
- do
- echo "Attempting to mount $drive as CD-ROM"
- if ! mount -r -t iso9660 $drive /mnt/tmp 2>/dev/null
- then continue
- elif [ -f /mnt/tmp/singularity ]
- then
-
- # Debian installer code
- if $DEBINST
- then
- echo "Found the LNX CD-ROM on $drive, mounting under /debinst/cd"
- mkdir /debinst
- mkdir /debinst/cd
- umount /mnt/tmp
- mount -r -t iso9660 $drive /debinst/cd
- echo "Copying rescue image files..."
-
- cd /debinst
- ln -s cd/debian debian
-
- # We do this this way because we are still using the minimalist
- # utilities in busybox, which can't do cp -r right.
-
- cat cd/debian/resc1440.tar.gz | zcat | star
-
- echo "Transferring control to Debian installer..."
- umount /proc
-
- # debchroot.lnx is a static binary which does chroot("/debinst")
- # and then exec("/sbin/init")
-
- exec debchroot.lnx
- echo "exec of Debian rescue system failed!"
- exec ash
- echo "exec of ash failed!"
- exit 1
- fi
-
-
- # Normal LNX rescue system code
-
- echo "Found the LNX CD-ROM on $drive, mounting under /mnt/cdrom-real"
- umount /mnt/tmp
- mount -r -t iso9660 $drive /mnt/cdrom-real 2>/dev/null
-
- # cloop mount happens here!
-
- if [ -f /mnt/cdrom-real/singularity ]
- then
- echo "Found compressed ext2 filesystem in /mnt/cdrom-real, loading cloop driver"
- cd /mnt/cdrom-real
-
-
- # Uses Klaus's cloop-0.6
- ./insmod cloop.o file=/mnt/cdrom-real/singularity
- echo "Mounting compressed blockdevice /dev/cloop under /mnt/cdrom"
- mount -o ro -t ext2 /dev/cloop /mnt/cdrom
-
- else
- echo "Uh-oh, can't find compressed ext2 filesystem!"
- fi
-
- # cloop mount done
-
- else echo "Found a CD-ROM here, but it's not LNX!"
- echo "Mounting under /mnt/$partition"
- umount /mnt/tmp
- mkdir /mnt/$partition
- mount -r -t iso9660 $drive /mnt/$partition 2>/dev/null
- partition=$(expr $partition + 2)
- fi
- done
-
- if [ ! -d /mnt/cdrom/etc ]
- then
- cat <<ALAS
-
- Sorry, I could not mount the compressed loopback filesystem. Thus, you will
- not have access to most of the software on this CD-ROM.
-
- The most likely explanations for this are:
-
- - You have too little RAM (less than about 16 MB).
- - You have an unusual or non-standard CD-ROM drive (especially on certain
- laptops, which require you to pass parameters to the kernel at boot time).
- - You have a corrupt or damaged CD-ROM image.
-
- If you know what you are doing, you can try to fix the problem from this
- shell prompt. When you are done, reboot by pressing Ctrl-Alt-Delete.
-
- If you believe that your system should be supported and you do not
- understand why you are seeing this message, you may report the problem
- to the lnx-bbc mailing list. Please see
-
- http://zork.net/mailman/listinfo/lnx-bbc/
-
- for more information.
-
- ALAS
- exec /bin/ash
- fi
-
-
- # So far, so good
-
-
- # Get the dynamic linker in place in /lib, where dynamic binaries are
- # hard-coded to look for it. All other shared libraries will be in
- # /usr/lib, which is the same as /mnt/cdrom/usr/lib because /usr in the
- # RAM disk is a link to /mnt/cdrom/usr.
-
- cp /mnt/cdrom/lib/ld-linux.so.2 /lib/
-
- # Running ldconfig (a static binary in /usr/bin) updates the dynamic
- # linker cache, to make all of the shared libraries (like glibc) visible
- # when we run dynamic libraries from now on.
- ldconfig
- hostname lnx-bbc
-
- # The /usr/bin here runs the version in /usr/bin instead of the version in
- # /bin. This was needed when /bin/mv used to be dynamically linked (I
- # think /bin/mv would have stopped working after the ldconfig command or
- # something like that).
- /usr/bin/mv /bin /bin.defunct
- /usr/bin/mv /sbin /sbin.defunct
-
- ln -s /mnt/cdrom/bin /bin
- ln -s /bin /sbin
-
- if ! $QUICK
- then
-
-
-
- #########
- ######### Old "find partions" stanza
- #########
-
- # Try to mount found partitions.
-
- for drive in $(cat /proc/partitions | awk '/[0-9]$/ {print $4}')
- do
- echo "Attempting to mount $drive as an ext2 partition"
- if ! mount -r -t ext2 /dev/$drive /mnt/tmp 2>/dev/null
- then continue
- else
- echo "Found an ext2fs on /dev/$drive, mounting under /mnt/$partition"
- umount /mnt/tmp
- mkdir /mnt/$partition
- mount -r -t ext2 /dev/$drive /mnt/$partition 2>/dev/null
- partition=$(expr $partition + 1)
- fi
- done
-
- # begin Klaus's partitions.sh
- # Scan partitions with
- # if [ -f /proc/partitions ]; then
- # partitions=""
- # while read a b c p; do
- # case $p in
- # hd?|sd?) partitions="$partitions /dev/$p"
- # *) ;;
- # esac
- # done < /proc/partitions
- #
- # if [ -n "$partitions" ]
- # then
- #
- # foundp="$(fdisk -l $partitions 2>/dev/null)"
- # for p in `echo "$foundp" | awk '/^\/dev\//{if($NF!~/[Ss]wap/&&$NF!~/[Ee]xtended/
- # ){print $1}}'`
- # do
- # #d="/mnt/${p##*/}"
- # # - or -
- # d="/mnt/$(basename $p)"
- # [ -d "$d" ] || mkdir -p $d
- # new="$p $d auto user,auto,exec,ro 0 0"
- # grep -q "$new" /etc/fstab || echo "$new" >> /etc/fstab
- # done
- #
- # fi
- # fi
- #
- #
- #
- # end Klaus's partitions.sh
-
- # this fi is needed from far above
- fi
-
- cp -a /mnt/cdrom/etc/* /etc
-
- # Let's make a fresh ssh host key, so that it will be safe for the user
- # to run sshd later on. This requires availability of /dev/random.
- # Also requires /etc/passwd to avoid "you don't exist, go away" error.
-
- host-key &
-
- # Convention that _all and only_ documentation text files in /mnt/cdrom at
- # top level inside cloop have names starting with capital letters. These
- # should appear in / because people may not look for them in /mnt/cdrom.
-
- # This convention is violated by System.map
- cp -a /mnt/cdrom/[A-R]* /
-
- # mkdir /bin
- # ln -s /usr/bin/sh /bin/sh
- # ln -s /usr/bin/sh /bin/bash
- # ln -s /usr/bin/login /bin/login
- # ln -s /bin.defunct/reboot /bin/reboot
-
- export PATH="/usr/bin:/bin"
-
- # Add loopback route
-
- ifconfig lo inet 127.0.0.1
- route add -host 127.0.0.1 lo
-
- # Now allow modprobing again
- echo /sbin/modprobe > /proc/sys/kernel/modprobe
-
- # Get /dev/pts filesytem
-
- mount /dev/pts /dev/pts -t devpts
-
- # eepro100 was taken out of our kernel, but we don't want to confuse people
- # who expect it to be automatically present (you can rmmod if you need
- # to pass options)
-
- # This has been moved into trivial-net-setup
- #modprobe eepro100
-
-
- # While that's going on, make the file-list.gz for "locate" script and start
- # appending files to it.
-
- touch /var/cache/file-list.gz
-
- (find / -xdev; find /mnt/cdrom -xdev; find /mnt/cdrom-real -xdev; echo /etc/ssh_host_dsa_key; echo /etc/ssh_host_dsa_key.pub; echo /etc/ssh_host_key; echo /etc/ssh_host_key.pub) | gzip -9 -c >> /var/cache/file-list.gz
-
- # wait for host-key to finish
-
- wait
-
- # Optionally run a script on the CD to complete boot-time configuration
- # (useful for people making customized bootable CDs based on our BBC).
-
- [ -x /mnt/cdrom-real/auto/config ] && /mnt/cdrom-real/auto/config
-
- # Optionally run a script on the CD _INSTEAD OF_ completing normal init
- # (useful for people making customized bootable CDs based on our BBC).
-
- [ -x /mnt/cdrom-real/auto/init ] && exec /mnt/cdrom-real/auto/init
-
- # Get ready for the X
- echo
- echo
-
- if ! $QUICK
- then
-
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
- echo
-
- # VGA splash screen has been REMOVED due to conflicts with some video cards
- # (it was linuxcare.vga)
-
- # ANSI text splash screen
- cat /etc/lnx.spl
-
- # Let the glory of the lnX-bbc sink in
- sleep 5
-
- fi
-
- export PS1='\u@\h:\w# '
-
- rm -rf /bin.defunct
-
- ## Begin respawning of gettys
- AGETTY="/usr/bin/agetty 57600"
-
- # This is a silly way of doing respawning, but we _are_ in a shell script
- # here, so doing it the right way is a little inconvenient. This way works
- # and we avoid excessive system load by sleeping three seconds in between
- # checks for whether something should be respawned.
- A=/fake
- B=/oh
- C=/well
- D=/whatever
- E=/nevermind
-
- while :
- do
- if [ ! -d $A ]
- then
- $AGETTY tty1 &
- A=/proc/$!
- fi
- if [ ! -d $B ]
- then
- $AGETTY tty2 &
- B=/proc/$!
- fi
- if [ ! -d $C ]
- then
- $AGETTY tty3 &
- C=/proc/$!
- fi
- if [ ! -d $D ]
- then
- $AGETTY tty4 &
- D=/proc/$!
- fi
- if [ ! -d $E ]
- then
- /usr/bin/agetty -L ttyS0 9600 linux &
- E=/proc/$!
- fi
-
- while [ -d $A -a -d $B -a -d $C -a -d $D ]
- do
- sleep3 # i.e. "sleep 3"
- done
- done
-
- # NOTREACHED
- exec /bin/ash
-