minix/etc/rc
Jean-Baptiste Boric 2b03b192f0 x86 iso: overhaul creation of installation CD
The CD now boots directly from the ISO 9660 filesystem instead of using
MBR partitioning with Minix file systems. This saves some space on the
CD and reduces memory requirements by some unknown amount as the root
ramdisk is completely eliminated.

The setup is also modified to be more NetBSD-like (unpacking sets
tarballs instead of blindly copying the CD contents). This allows
massive space savings because only the base system used for installation
is stored uncompressed and more modularity (to be exploited at a later
time). The sets themselves are to be refined, but are enough for now.

Those two steps are melded together because copying the CD contents with
isofs as the root filesystem results in some failed tests in
minix-posix, probably due to some obscure corner-case bugs in isofs.

Having a read-only root filesystem outputs some error messages because
it isn't properly supported. Ramdisks on /var and /tmp are used to
mitigate this, but the clean solution would involve union mounts,
something Minix 3 doesn't support for the time being.

Change-Id: Ib4700d9f10c5b4b297e0994b5338847951fc79b4
2015-05-16 13:21:25 +02:00

251 lines
5.2 KiB
Plaintext
Executable File

# /etc/rc - System startup script run by init before going multiuser.
# Are we booting from CD?
bootcd="`/bin/sysenv bootcd`"
exec >/dev/log
exec 2>/dev/log
exec </dev/null
umask 022
# Same settings as in the default /etc/profile. We do not source this file
# as the system administrator may decide to change those values for his users.
RC_TZ=/etc/rc.timezone
PATH=/usr/local/sbin:/usr/pkg/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/pkg/bin:/usr/bin:/bin
# Set TERM to minix if not present.
TERM="${TERM-minix}"
export TERM PATH
# Local variables
ARCH="`sysenv arch`"
usage()
{
echo >&2 "Usage: $0 [-saf] autoboot|start|stop|down"
exec intr sh
}
up()
{
# Function to dynamically start a system service
opt=""
prefix=$(expr "$1 " : '\(-\)')
if [ "$prefix" = "-" ];
then
opt=$1
shift
fi
service=$1
shift
service $opt up /service/$service "$@"
}
edit()
{
# Function to dynamically edit system service settings
opt=""
prefix=$(expr "$1 " : '\(-\)')
if [ "$prefix" = "-" ];
then
opt=$1
shift
fi
service=$1
shift
# Assume binaries are always in /service or /usr/pkg/service
binlocation=/service/$service
if [ ! -x $binlocation ]
then binlocation=/usr/pkg/service/$service
fi
# Mostly to find init...
if [ ! -x $binlocation ]
then binlocation=/sbin/$service
fi
service $opt edit $binlocation -label $service "$@"
}
while getopts 'saf' opt
do
case $opt in
s) sflag=t ;; # Single user
a) aflag=t ;; # Ask for /usr
f) fflag=-f ;; # Force a full file system check
*) usage
esac
done
shift `expr $OPTIND - 1`
case "$#:$1" in
1:start|1:stop|1:down|1:autoboot)
action=$1
;;
*) usage
esac
case $action in
autoboot|start)
# National keyboard?
test -f /etc/keymap && loadkeys /etc/keymap
# options for fsck. default is -r, which prompts the user for repairs.
optname=fsckopts
fsckopts=-p
if sysenv $optname >/dev/null
then fsckopts="`sysenv $optname`"
fi
if [ "`sysenv debug_fkeys`" != 0 ]
then
up -n is -period 5HZ
fi
# Set timezone.
export TZ=GMT0
if [ -f "$RC_TZ" ]
then . "$RC_TZ"
fi
# Start real time clock driver & set system time, otherwise default date.
up readclock.drv
readclock -q || date 201301010000
# We are not shutting down.
rm -f /etc/nologin
# Are we booting from CD?
bootcd="`/bin/sysenv cdproberoot`"
# Use MFS binary only from kernel image?
if [ "`sysenv bin_img`" = 1 ]
then
bin_img="-i "
fi
if [ -z "$bootcd" ]
then
# If we're not booting from CD, fsck + mount using /etc/fstab.
fsck -x / $fflag $fsckopts
mount -a
# Initialize files.
>/var/run/utmp # /etc/utmp keeps track of logins
fi
# Unmount and free now defunct ramdisk
umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk"
ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk"
# If booting from CD, we want some directories to be ramdisks
if [ ! -z "$bootcd" ]
then
echo "Creating ramdisks..."
RAMDISK_VAR_SIZE=512
RAMDISK_TMP_SIZE=512
# Create /var ramdisk
dirs_var=$(find /var -type d | sed '1d')
ramdisk $RAMDISK_VAR_SIZE /dev/ram0
mkfs.mfs /dev/ram0
mount /dev/ram0 /var
for i in $dirs_var; do mkdir $i; done
# Create /tmp ramdisk
ramdisk $RAMDISK_VAR_SIZE /dev/ram1
mkfs.mfs /dev/ram1
mount /dev/ram1 /tmp
fi
# Initialize files.
>/var/run/utmp # /etc/utmp keeps track of logins
>/var/run/utmpx # /etc/utmpx keeps track of logins
# Edit settings for boot system services
if [ "`sysenv skip_boot_config`" != 1 ]
then
edit rs
edit vm
edit pm
edit sched
edit vfs
edit ds
edit tty
edit memory
edit pfs
edit init
fi
if [ "$sflag" ]
then
echo "Single user. Press ^D to resume multiuser startup."
intr sh
echo
fi
echo "Multiuser startup in progress ..."
case "`printroot -r`":$bootcd in
/dev/ram:)
# Remove boot-only things to make space,
# unless booting from CD, in which case we need them.
rm -rf /boot
# put the compiler on ram
cp /usr/lib/em* /usr/lib/cpp* /lib
esac
echo -n "Starting hotplugging infrastructure... "
rm -f /var/run/devmand.pid
devmand -d /etc/devmand -d /usr/pkg/etc/devmand &
echo "done."
# Things should be alright now.
;;
down|stop)
sync
if [ -f /var/run/devmand.pid ]
then
kill -INT `cat /var/run/devmand.pid`
# without this delay the following will
# be printed in the console
# RS: devman not running?
sleep 1
fi
#
# usbd needs to be stopped exactly
# at this stage(before stopping devman
# and after stopping the services
# stated by devmand)
if [ -x /usr/pkg/etc/rc.d/usbd ]
then
/usr/pkg/etc/rc.d/usbd stop
fi
if [ -x /service/usbd ]
then
service down usbd
fi
# Tell RS server we're going down.
service shutdown
;;
esac
# Further initialization.
test -f /usr/etc/rc && sh /usr/etc/rc $action
test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action
# Any messages?
if [ "$action" = start -o "$action" = autoboot ]
then if [ -f /etc/issue ]
then cat /etc/issue
fi
fi
exit 0