#!/bin/sh #(C)2005 DatuX, used examples/concepts of knoppix and gentoo live cd's. cat /etc/syn3.txt ################################################## script initiation source /etc/initrd.defaults source /etc/initrd.scripts echo -e "\n${NORMAL}${BOLD} [ Welcome to the Syn-3 boot ramdisk ] ${NORMAL}\n" #bare system basics SHELL=0 export PATH=/sbin:/bin:/usr/sbin:/usr/bin mount -n -t devtmpfs devtmpfs /dev mkdir /dev/pts mount -n -t devpts devpts /dev/pts mount -n -t proc proc /proc mount -n -t sysfs sysfs /sys echo '4' > /proc/sys/kernel/printk #WORKAROUND: for issue http://fhackts.wordpress.com/2014/03/10/very-slow-disk-write-performance-linux/ #(needed on 32bits systems with 3.4+ kernel and >8G mem.) echo 1 > /proc/sys/vm/highmem_is_dirtyable #start device management udevd --daemon --resolve-names=late 2>/dev/null >/dev/null udevadm trigger # udevadm settle #slow and not neccesary ln -s /proc/self/fd /dev/fd echo -en "$NOBLANK" #usb keyboard/mouse support while inside initrd modprobe usbhid #determine kernel parameters that are interesting for us CMDLINE=`cat /proc/cmdline` SPLASH=1 FSCHECK=1 NET_USER=guest NET_PASS=guest for x in ${CMDLINE} do case "${x}" in # real_root\=*) # REAL_ROOT=`parse_opt "${x}"` # ;; #primary node ip local_ip\=*) LOCAL_IP=`parse_opt "${x}"` DRBD=1 ;; #secondary node ip remote_ip\=*) REMOTE_IP=`parse_opt "${x}"` ;; #ethernet device eth\=*) ETH=`parse_opt "${x}"` ;; #sync rate rate\=*) RATE=`parse_opt "${x}"` ;; #rebuild local side and discard metadata rebuild) REBUILD=1 ;; #force local side to be primary and discard metadata forceprimary) FORCEPRIMARY=1 ;; #step by step debugging mode, enter shell after every step debug) DEBUG=1 ;; #very verbose output (show all shell commands) verbose) set -x ;; #enters a shell two times: before doing all the initrd stuff, and after it. shell) SHELL=1 ;; #disables splashscreen text) SPLASH= ;; #disables filesystem checks nofscheck) FSCHECK= ;; #start network + telnet deamon for support shell sup) SUP=1 ;; #network device to configure net_dev\=*) NET_DEV=`parse_opt "${x}"` ;; #network IP to apply (omit for dhcp) net_ip\=*) NET_IP=`parse_opt "${x}"` ;; #network install server. Should be a CIFS share with guest/guest access. #For example: //192.168.13.2/tftp/normal net_server\=*) NET_SERVER=`parse_opt "${x}"` ;; #user and password for this share, default is guest/guest. net_user\=*) NET_USER=`parse_opt "${x}"` ;; net_pass\=*) NET_PASS=`parse_opt "${x}"` ;; #ask for password (usefull for admins to configure permanent stuff) net_pass_ask) NET_PASS_ASK=1 ;; #boots this live image #Autodetects installer CDrom or USB stick. #If NET_SERVER is specified, it assumes that has the cdrom-contents bootimage\=*) BOOTIMAGE=`parse_opt "${x}"` ;; #pivot to the image instead of chrooting to it. #this lets you unmount the initrd and regain memory, but you cant turn back to the initrd. pivotimage) PIVOTIMAGE=1 ;; #DANGEROUS: does not boot the image, but instead gunzips BOOTIMAGE and writes it to block-device INSTALL_DEVICE #This is used to "flash" embedded systems like Alix boards. install_device\=*) INSTALL_DEVICE=`parse_opt "${x}"` ;; driver\=*) D=`parse_opt "${x}"` EXTRA_MODS="${EXTRA_MODS} ${D}" ;; *) ;; esac done ############################################# do we want a splashscreen? if [ "$SPLASH" ]; then modprobe uvesafb mode_option=800x600-16 splashreset boot & sleep 1 fi ############################################## init initrd filesystem #debuggin hack :) if [ "${DEBUG}" == "1" ]; then splashmode verbose 2>/dev/null splashstep () { debug_shell "$*" /bin/splashstep "$*" } splashinfo () { debug_shell "$*" /bin/splashinfo "$*" } splasherror () { debug_shell "$*" /bin/splasherror "$*" } splashwarn () { debug_shell "$*" /bin/splashwarn "$*" } fi if [ "${SHELL}" -eq '1' ]; then splashmode verbose 2>/dev/null error_shell "Entered pre-boot shell" fi ############################################## LOAD MODULES echo '4' > /proc/sys/kernel/printk #When we're in a virtual machine, autoload open_vm_modules: echo -en "Checking if we're a vmware guest..." if vmware-checkvm 2>/dev/null ; then echo "YES" splashinfo "Loading vmware guest modules" modprobe vmhgfs modprobe vmblock #unresovled symbols: modprobe vsock modprobe pvscsi modprobe vmxnet modprobe vmci modprobe vmsync modprobe vmmemctl else echo "NO" fi splashstep "Detecting hardware" #make absolutely sure that we cant load any framebuffer drivers in the hardware detection routines: rm -r /lib/modules/*/kernel/drivers/video/ 2>/dev/null #WORKAROUND: voor cqparray, deze MOET eerst geladen worden, indien #er bepaalde andere scsi controllers zijn. (sym5xxx) #OBSOLETE in 2.6.27?: modprobe cpqarray #Autoload all modules for the detected modaliases in /sys: echo -en "${GOOD}* ${NORMAL}${BOLD} Detecting devices: ${NORMAL}" for D in `find /sys -name modalias`; do echo -en "." modprobe `cat $D` 2>/dev/null; done echo #load extra modules for D in ${EXTRA_MODS}; do echo -en "${GOOD}* ${NORMAL}${BOLD} Loading extra driver ${D}:${NORMAL}" modprobe ${D} backup done #echo -e "${GOOD} DONE ${NORMAL}" #echo '0' > /proc/sys/kernel/printk cd / splashstep "Loading modules" # Load appropriate kernel modules for modules in $MY_HWOPTS do modules_scan $modules eval DO_`echo $modules | sed 's/-//'`=1 splashstep done ########################################## START SUPPORT SHELL? if [ "$SUP" ]; then sup fi ########################################## CONFIGURE NETWORK? # Used for network installs and images if [ "$NET_DEV" ]; then splashstep "Getting network address" ifconfig $NET_DEV up if [ "$NET_IP" ]; then ifconfig $NET_DEV $NET_IP else udhcpc -i $NET_DEV fi fi ########################################## BOOT an image instead of the harddisks? if [ "$BOOTIMAGE" ]; then #Because we have no config yet, this will assign network cards in order of mac-adress. #This is to give the user a nice consistent order in case of redundancy installation. source /etc/if-assign.boot boot_image #after the image we will just continue the normal boot procedure fi ############################################## RAID DETECTION #Activate software raid splashstep "Activating raid" #mknod /dev/md0 b 9 0 2>/dev/null #mknod /dev/md1 b 9 1 2>/dev/null #mdadm -Ac partitions -m dev /dev/md0 2>/dev/null #mdadm -Ac partitions -m dev /dev/md1 2>/dev/null echo "Assembling md0 (legacy 0.9 mode only)..." mdadm --assemble --scan --super-minor=0 --run echo "Assembling md1 (legacy 0.9 mode only)..." mdadm --assemble --scan --super-minor=1 --run echo "Assembling md0 and md1 (1.0+ mode only)..." #speed up creation, because we have no udev rules for this: mkdir /dev/md mknod /dev/md/0 b 9 0 mknod /dev/md/1 b 9 1 mdadm --assemble --scan #wait for device nodes to be created. udevadm settle echo -ne "${BOLD} ::${NORMAL} Checking boot RAID status (/dev/md0)..." mdadm --detail --test /dev/md0 >/dev/null 2>&1 STATUS=$? if [ "$STATUS" = "0" ] || [ "$STATUS" = "1" ]; then echo -e "${GOOD} OK ${NORMAL}" else echo -e "${BAD} FAILED! ${NORMAL}" error_shell "Problem with boot RAID partition!" fi echo -ne "${BOLD} ::${NORMAL} Checking system RAID status (/dev/md1)..." mdadm --detail --test /dev/md1 >/dev/null 2>&1 STATUS=$? if [ "$STATUS" = "0" ]; then echo -e "${GOOD} RAID OK ${NORMAL}" elif [ "$STATUS" = "1" ]; then echo -e "${WARN} RAID DEGRADED, PLEASE CHECK STATUS AFTER BOOTING. ${NORMAL}" elif [ "$STATUS" = "2" ]; then echo -e "${BAD} RAID FAILED! ${NORMAL}" error_shell "Problem with RAID system!" elif [ "$STATUS" = "4" ]; then echo -e "not used" fi ############################################## LVM DETECTION splashstep "Activating volume groups" if vgscan ; then echo -e "${GOOD} Scan OK ${NORMAL}" else echo -e "${BAD} Scan FAILED! ${NORMAL}" error_shell "Can't find volume groups!" fi splashstep if vgchange --sysinit -ay syn3; then echo -e "${GOOD} Activation OK ${NORMAL}" else echo -e "${BAD} Activation FAILED! ${NORMAL}" error_shell "Can't activate volume groups!" fi if [ `vgs --noheadings | grep ' syn3 '| wc -l` != "1" ]; then error_shell "Multiple SYN-3 installations found. Please remove or clean old SYN-3 installations from other discs and reboot." fi ############################################ Mount /boot (/dev/md0) under /mnt # This is neccesary for BOOTCONFIG stuff below. splashinfo "Loading boottime configuration" mkdir /mnt 2>/dev/null if ! mount -o ro,norecovery /dev/md0 /mnt ; then error_shell "Error: Reading of boottime configuration failed. Only continue booting if you dont have redundancy. If you DO have redundancy and the other node still works, then reinitalize this node." fi ############################################ BOOTCONFIG: Restore a backup? source /etc/restore.boot ############################################ BOOTCONFIG: Network interface assigning section splashinfo "Assigning network interfaces" #if-assign reads config from /mnt: source /etc/if-assign.boot ############################################# BOOTCONFIG: Linux HA and blockdevice symlinks #try to load the drbd configuration #(this file will overwrite the bootparameters) splashinfo "Loading redundancy configuration" if [ -r "/mnt/drbd.conf" ]; then source /mnt/drbd.conf fi #force our node to be primary? (used for first time initialisation) if [ -r "/mnt/drbd.primary" ]; then FORCEPRIMARY=1 fi #last BOOTCONFIG step, now unmount mnt so that we can do drbd syncing stuff: umount /mnt if [ "$DRBD" == "1" ]; then #use drbd echo "Using drbd" ln -s drbd0 /dev/boot ln -s drbd1 /dev/home ln -s drbd2 /dev/root ln -s syn3/swap /dev/swap source /etc/drbd.boot || error_shell else #dont use drbd echo "Not using drbd" ln -s md0 /dev/boot ln -s syn3/home /dev/home ln -s syn3/root /dev/root ln -s syn3/swap /dev/swap fi #make rebuild slow, to speedup boot and diskchecks echo 1000 > /proc/sys/dev/raid/speed_limit_max #(return to normal after boot at end of rc.M) #wait for device nodes to be created. udevadm settle ############################################## FS CHECK & REPAIR if [ "$FSCHECK" ]; then splashstep "Checking filesystems..." #big discs use a lot of memory (150mb was not enough for my 250gig disc!), try to use swap #try to use swap during disccheck swapon /dev/swap 2>/dev/null #Check the home and the root partition check_xfs "/dev/home" splashstep check_xfs "/dev/root" splashstep if blkid /dev/boot | grep xfs >/dev/null; then #we changed to ext4 because thats better supported in syslinux check_xfs "/dev/boot" fi splashstep swapoff /dev/swap 2>/dev/null else splashstep splashstep splashstep splashstep fi ############################################## Try to mount root splashstep "Mounting root filesystem" mkdir /newroot >/dev/null 2>&1 if ! mount -o inode32,rw "/dev/root" /newroot; then error_shell "Can't mount root filesystem!" fi if [ "${SHELL}" -eq '1' ]; then error_shell "Entering post-boot shell" fi ##################################################### BOOT our mounted /newroot #re-activate kernel messages on console echo '4' > /proc/sys/kernel/printk #update mtab in /newroot cat /proc/mounts > /newroot/etc/mtab splashstep "Starting Syn-3" #populate the dev directory of the new system #(it should be on a tmpfs to allow lvm snapshots) #echo "Copying dev directory..." #mkdir /newroot/dev 2>/dev/null #mount -t tmpfs -o size=2M udev /newroot/dev #cp -a /dev /newroot #cleanup some initrd stuff, like udevd cleanupinitrd #move over the splash stuff cp /var/lib/splash/* /newroot/var/lib/splash 2>/dev/null #finally do the big /-swap :) #cd /newroot #mkdir -p /newroot/initrd >/dev/null 2>&1 #swap system root to newroot #pivot_root . initrd #everything prepared, it's time to handover control to the 'real' system export CONSOLE=/dev/tty1 exec switch_root /newroot /sbin/init #exec switch_root /newroot /bin/bash #fallback error_shell "Can't start the init system!" echo "Can't start the init system!" /bin/bash /bin/sh /bin/ash