1# /etc/rc.minix - MINIX system startup script 2 3PATH=/sbin:/usr/sbin:/bin:/usr/bin 4 5# The normal system boot situation is that init(8) invokes the ramdisk RC 6# script, which invokes the NetBSD rc infrastructure, which in turn calls this 7# script through /etc/rc.d/minixrc. With a boot ramdisk (x86_ramimage), the 8# ramdisk RC is bypassed altogether, but stored as /etc/rc.ramdisk. We then 9# have to invoke it here (for startup only!) to let it perform its tasks first. 10if sysenv bootramdisk >/dev/null 11then 12 [ "$1" = "start" ] && sh /etc/rc.ramdisk "$@" 13fi 14 15# Same settings as in the default /etc/profile. We do not source this file 16# as the system administrator may decide to change those values for his users. 17RC_TZ=/etc/rc.timezone 18 19# Are we booting from CD? 20bootcd="`/bin/sysenv bootcd`" 21 22# Set TERM to minix if not present. 23TERM="${TERM-minix}" 24 25export TERM PATH 26 27# Local variables 28ARCH="`sysenv arch`" 29 30usage() 31{ 32 echo >&2 "Usage: $0 [-saf] [start|stop]" 33 exec intr sh 34} 35 36up() 37{ 38 # Function to dynamically start a system service 39 opt="" 40 prefix=$(expr "$1 " : '\(-\)') 41 if [ "$prefix" = "-" ]; 42 then 43 opt=$1 44 shift 45 fi 46 service=$1 47 shift 48 49 minix-service $opt up /service/$service "$@" 50} 51 52edit() 53{ 54 # Function to dynamically edit system service settings 55 opt="" 56 prefix=$(expr "$1 " : '\(-\)') 57 if [ "$prefix" = "-" ]; 58 then 59 opt=$1 60 shift 61 fi 62 service=$1 63 shift 64 65 # Assume binaries are always in /service or /usr/pkg/service 66 binlocation=/service/$service 67 if [ ! -x $binlocation ] 68 then binlocation=/usr/pkg/service/$service 69 fi 70 71 # Mostly to find init... 72 if [ ! -x $binlocation ] 73 then binlocation=/sbin/$service 74 fi 75 minix-service $opt edit $binlocation -label $service "$@" 76} 77 78set -- `sysenv bootopt` "$@" 79while getopts 'saf' opt 80do 81 case $opt in 82 s) sflag=t ;; # Single user 83 a) aflag=t ;; # Ask for /usr 84 f) fflag=-f ;; # Force a full file system check 85 *) usage 86 esac 87done 88shift `expr $OPTIND - 1` 89 90case "$#:$1" in 911:start|1:stop) 92 action=$1 93 ;; 94*) usage 95esac 96 97case $action in 98start) 99 # If booting from CD, we want some directories to be ramdisks 100 if [ ! -z "$bootcd" ] 101 then 102 . /etc/rc.cd 103 fi 104 105 # National keyboard? 106 test -f /etc/keymap && loadkeys /etc/keymap 107 108 # options for fsck. default is -r, which prompts the user for repairs. 109 optname=fsckopts 110 fsckopts=-p 111 if sysenv $optname >/dev/null 112 then fsckopts="`sysenv $optname`" 113 fi 114 115 if [ "`sysenv debug_fkeys`" != 0 ] 116 then 117 up -n is -period 5HZ 118 fi 119 120 # Set timezone. 121 export TZ=GMT0 122 if [ -f "$RC_TZ" ] 123 then 124 . "$RC_TZ" 125 fi 126 127 # Start real time clock driver & set system time, otherwise default date. 128 up readclock.drv 129 readclock -q || date 201301010000 130 131 # We are not shutting down. 132 if [ -f /etc/nologin ] 133 then 134 rm -f /etc/nologin 135 fi 136 137 # Use MFS binary only from kernel image? 138 if [ "`sysenv bin_img`" = 1 ] 139 then 140 bin_img="-i " 141 fi 142 143 # fsck + mount using /etc/fstab. 144 fsck -x / $fflag $fsckopts 145 mount -a 146 147 if [ -z "`sysenv bootramdisk`" ] 148 then 149 # Unmount and free now defunct ramdisk 150 umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk" 151 ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk" 152 fi 153 154 # Initialize files. 155 >/var/run/utmp # /etc/utmp keeps track of logins 156 >/var/run/utmpx # /etc/utmpx keeps track of logins 157 158 # Edit settings for boot system services 159 if [ "`sysenv skip_boot_config`" != 1 ] 160 then 161 edit rs 162 edit vm 163 edit pm 164 edit sched 165 edit vfs 166 edit ds 167 edit tty 168 edit memory 169 edit mib 170 edit pfs 171 edit init 172 # 173 # Keep a copy around to recover the root FS from crashes 174 # 175 rootline=`cat /etc/mtab | grep "on / "` 176 rootfs=fs_`echo "$rootline" | cut -d' ' -f1 | cut -d'/' -f3` 177 [ "$rootfs" = "fs_bootramdisk" ] && rootfs=fs_imgrd 178 roottype=`echo "$rootline" | cut -d' ' -f5` 179 minix-service -c edit /service/$roottype -label $rootfs 180 fi 181 182 if [ "$sflag" ] 183 then 184 echo "Single user. Press ^D to resume multiuser startup." 185 intr sh 186 echo 187 fi 188 189 echo "Multiuser startup in progress ..." 190 191 case "`printroot -r`":$bootcd in 192 /dev/ram:) 193 # Remove boot-only things to make space, 194 # unless booting from CD, in which case we need them. 195 rm -rf /boot 196 # put the compiler on ram 197 cp /usr/lib/em* /usr/lib/cpp* /lib 198 esac 199 200 echo -n "Starting hotplugging infrastructure... " 201 rm -f /var/run/devmand.pid 202 devmand -d /etc/devmand -d /usr/pkg/etc/devmand & 203 echo "done." 204 205 # Things should be alright now. 206 ;; 207stop) 208 sync 209 if [ -f /var/run/devmand.pid ] 210 then 211 kill -INT `cat /var/run/devmand.pid` 212 # without this delay the following will 213 # be printed in the console 214 # RS: devman not running? 215 sleep 1 216 fi 217 218 if [ -x /service/usbd ] 219 then 220 minix-service down usbd 221 fi 222 223 # Tell RS server we're going down. 224 minix-service shutdown 225 ;; 226esac 227 228# Further initialization. 229test -f /usr/etc/rc && sh /usr/etc/rc $action 230test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action 231 232# Any messages? 233if [ "$action" = start ] 234then if [ -f /etc/issue ] 235 then cat /etc/issue 236 fi 237fi 238 239exit 0 240