source: npl/kernel/initrd_scripts/root/init @ 26ffad7

Last change on this file since 26ffad7 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 12.1 KB
RevLine 
[c5c522c]1#!/bin/sh
2#(C)2005 DatuX, used examples/concepts of knoppix and gentoo live cd's.
3
4cat /etc/syn3.txt
5
6################################################## script initiation
7
8source /etc/initrd.defaults
9source /etc/initrd.scripts
10
11
12echo -e "\n${NORMAL}${BOLD} [ Welcome to the Syn-3 boot ramdisk ] ${NORMAL}\n"
13
14
15
16#bare system basics
17SHELL=0
18export PATH=/sbin:/bin:/usr/sbin:/usr/bin
19
20mount -n -t devtmpfs devtmpfs /dev
21mkdir /dev/pts
22mount -n -t devpts devpts /dev/pts
23mount -n -t proc proc /proc
24mount -n -t sysfs sysfs /sys
25
26echo '4' > /proc/sys/kernel/printk
27
28
29#WORKAROUND: for issue http://fhackts.wordpress.com/2014/03/10/very-slow-disk-write-performance-linux/
30#(needed on 32bits systems with 3.4+ kernel and >8G mem.)
31echo 1 > /proc/sys/vm/highmem_is_dirtyable
32
33
34#start device management
35udevd --daemon --resolve-names=late 2>/dev/null >/dev/null
36udevadm trigger
37# udevadm settle #slow and not neccesary
38ln -s /proc/self/fd /dev/fd
39
40echo -en "$NOBLANK"
41
42#usb keyboard/mouse support while inside initrd
43modprobe usbhid
44
45
46
47#determine kernel parameters that are interesting for us
48CMDLINE=`cat /proc/cmdline`
49SPLASH=1
50FSCHECK=1
51NET_USER=guest
52NET_PASS=guest
53for x in ${CMDLINE}
54do
55        case "${x}" in
56#               real_root\=*)
57#                       REAL_ROOT=`parse_opt "${x}"`
58#               ;;
59                #primary node ip
60                local_ip\=*)
61                        LOCAL_IP=`parse_opt "${x}"`
62                        DRBD=1
63                ;;
64                #secondary node ip
65                remote_ip\=*)
66                        REMOTE_IP=`parse_opt "${x}"`
67                ;;
68                #ethernet device
69                eth\=*)
70                        ETH=`parse_opt "${x}"`
71                ;;
72                #sync rate
73                rate\=*)
74                        RATE=`parse_opt "${x}"`
75                ;;
76                #rebuild local side and discard metadata
77                rebuild)
78                        REBUILD=1
79                ;;
80                #force local side to be primary and discard metadata
81                forceprimary)
82                        FORCEPRIMARY=1
83                ;;
84                #step by step debugging mode, enter shell after every step
85                debug)
86                        DEBUG=1
87                ;;
88                #very verbose output (show all shell commands)
89                verbose)
90                        set -x
91                ;;
92                #enters a shell two times: before doing all the initrd stuff, and after it.
93                shell)
94                        SHELL=1
95                ;;
96                #disables splashscreen
97                text)
98                        SPLASH=
99                ;;
100                #disables filesystem checks
101                nofscheck)
102                        FSCHECK=
103                ;;
104
105                #start network + telnet deamon for support shell
106                sup)
107                        SUP=1
108                ;;
109
110                #network device to configure
111                net_dev\=*)
112                        NET_DEV=`parse_opt "${x}"`
113                ;;
114
115                #network IP to apply (omit for dhcp)
116                net_ip\=*)
117                        NET_IP=`parse_opt "${x}"`
118                ;;
119
120                #network install server. Should be a CIFS share with guest/guest access.
121                #For example: //192.168.13.2/tftp/normal
122                net_server\=*)
123                        NET_SERVER=`parse_opt "${x}"`
124                ;;
125
126                #user and password for this share, default is guest/guest.
127                net_user\=*)
128                        NET_USER=`parse_opt "${x}"`
129                ;;
130
131                net_pass\=*)
132                        NET_PASS=`parse_opt "${x}"`
133                ;;
134
135                #ask for password (usefull for admins to configure permanent stuff)
136                net_pass_ask)
137                        NET_PASS_ASK=1
138                ;;
139
140                #boots this live image
141                #Autodetects installer CDrom or USB stick.
142                #If NET_SERVER is specified, it assumes that has the cdrom-contents
143                bootimage\=*)
144                        BOOTIMAGE=`parse_opt "${x}"`
145                ;;
146
147                #pivot to the image instead of chrooting to it.
148                #this lets you unmount the initrd and regain memory, but you cant turn back to the initrd.
149                pivotimage)
150                        PIVOTIMAGE=1
151                ;;
152
153                #DANGEROUS: does not boot the image, but instead gunzips BOOTIMAGE and writes it to block-device INSTALL_DEVICE
154                #This is used to "flash" embedded systems like Alix boards.
155                install_device\=*)
156                        INSTALL_DEVICE=`parse_opt "${x}"`
157                ;;
158
159                driver\=*)
160                        D=`parse_opt "${x}"`
161                        EXTRA_MODS="${EXTRA_MODS} ${D}"
162                ;;
163                *)
164                ;;
165        esac
166done
167
168
169############################################# do we want a splashscreen?
170
171if [ "$SPLASH" ]; then
172        modprobe uvesafb mode_option=800x600-16
173        splashreset boot &
174        sleep 1
175fi
176
177############################################## init initrd filesystem
178
179
180#debuggin hack :)
181if [ "${DEBUG}" == "1" ]; then
182        splashmode verbose 2>/dev/null
183        splashstep ()
184        {
185                debug_shell "$*"
186                /bin/splashstep "$*"
187        }
188        splashinfo ()
189        {
190                debug_shell "$*"
191                /bin/splashinfo "$*"
192        }
193        splasherror ()
194        {
195                debug_shell "$*"
196                /bin/splasherror "$*"
197        }
198        splashwarn ()
199        {
200                debug_shell "$*"
201                /bin/splashwarn "$*"
202        }
203fi
204
205if [ "${SHELL}" -eq '1' ]; then
206        splashmode verbose 2>/dev/null
207        error_shell "Entered pre-boot shell"
208fi
209
210
211############################################## LOAD MODULES
212
213echo '4' > /proc/sys/kernel/printk
214
215#When we're in a virtual machine, autoload open_vm_modules:
216echo -en "Checking if we're a vmware guest..."
217if vmware-checkvm 2>/dev/null ; then
218        echo "YES"
219        splashinfo "Loading vmware guest modules"
220        modprobe vmhgfs
221        modprobe vmblock
222        #unresovled symbols: modprobe vsock
223        modprobe pvscsi
224        modprobe vmxnet
225        modprobe vmci
226        modprobe vmsync
227        modprobe vmmemctl
228else
229        echo "NO"
230fi
231
232
233splashstep "Detecting hardware"
234
235#make absolutely sure that we cant load any framebuffer drivers in the hardware detection routines:
236rm -r /lib/modules/*/kernel/drivers/video/ 2>/dev/null
237
238#WORKAROUND: voor cqparray, deze MOET eerst geladen worden, indien
239#er bepaalde andere scsi controllers zijn. (sym5xxx)
240#OBSOLETE in 2.6.27?: modprobe cpqarray
241
242
243#Autoload all modules for the detected modaliases in /sys:
244echo -en "${GOOD}* ${NORMAL}${BOLD} Detecting devices: ${NORMAL}"
245for D in `find /sys -name modalias`; do
246    echo -en "."
247    modprobe `cat $D` 2>/dev/null;
248done
249echo
250
251#load extra modules
252for D in ${EXTRA_MODS}; do
253    echo -en "${GOOD}* ${NORMAL}${BOLD} Loading extra driver ${D}:${NORMAL}"
254    modprobe ${D}
255    backup
256done
257
258
259#echo -e "${GOOD} DONE ${NORMAL}"
260#echo '0' > /proc/sys/kernel/printk
261cd /
262
263splashstep "Loading modules"
264# Load appropriate kernel modules
265for modules in $MY_HWOPTS
266do
267        modules_scan $modules
268        eval DO_`echo $modules | sed 's/-//'`=1
269        splashstep
270done
271
272
273########################################## START SUPPORT SHELL?
274if [ "$SUP" ]; then
275        sup
276fi
277
278########################################## CONFIGURE NETWORK?
279# Used for network installs and images
280if [ "$NET_DEV" ]; then
281        splashstep "Getting network address"
282        ifconfig $NET_DEV up
283        if [ "$NET_IP" ]; then
284                ifconfig $NET_DEV $NET_IP
285        else
286                udhcpc -i $NET_DEV
287        fi
288fi
289
290
291########################################## BOOT an image instead of the harddisks?
292if [ "$BOOTIMAGE" ]; then
293        #Because we have no config yet, this will assign network cards in order of mac-adress.
294        #This is to give the user a nice consistent order in case of redundancy installation.
295        source /etc/if-assign.boot
296
297        boot_image
298        #after the image we will just continue the normal boot procedure
299fi
300
301############################################## RAID DETECTION
302
303#Activate software raid
304splashstep "Activating raid"
305
306#mknod /dev/md0 b 9 0 2>/dev/null
307#mknod /dev/md1 b 9 1 2>/dev/null
308
309#mdadm -Ac partitions -m dev /dev/md0 2>/dev/null
310#mdadm -Ac partitions -m dev /dev/md1 2>/dev/null
311echo "Assembling md0 (legacy 0.9 mode only)..."
312mdadm --assemble --scan --super-minor=0 --run
313
314echo "Assembling md1 (legacy 0.9 mode only)..."
315mdadm --assemble --scan --super-minor=1 --run
316
317echo "Assembling md0 and md1 (1.0+ mode only)..."
318#speed up creation, because we have no udev rules for this:
319mkdir /dev/md
320mknod /dev/md/0 b 9 0
321mknod /dev/md/1 b 9 1
322mdadm --assemble --scan
323
324#wait for device nodes to be created.
325udevadm settle
326
327echo -ne "${BOLD}   ::${NORMAL} Checking boot RAID status (/dev/md0)..."
328mdadm --detail --test /dev/md0 >/dev/null 2>&1
329STATUS=$?
330if [ "$STATUS" = "0" ] || [ "$STATUS" = "1" ]; then
331        echo -e "${GOOD} OK ${NORMAL}"
332else
333        echo -e "${BAD} FAILED! ${NORMAL}"
334        error_shell "Problem with boot RAID partition!"
335fi
336
337echo -ne "${BOLD}   ::${NORMAL} Checking system RAID status (/dev/md1)..."
338mdadm --detail --test /dev/md1 >/dev/null 2>&1
339STATUS=$?
340if [ "$STATUS" = "0" ]; then
341        echo -e "${GOOD} RAID OK ${NORMAL}"
342elif [ "$STATUS" = "1" ]; then
343        echo -e "${WARN} RAID DEGRADED, PLEASE CHECK STATUS AFTER BOOTING. ${NORMAL}"
344elif [ "$STATUS" = "2" ]; then
345        echo -e "${BAD} RAID FAILED! ${NORMAL}"
346        error_shell "Problem with RAID system!"
347elif [ "$STATUS" = "4" ]; then
348        echo -e "not used"
349fi
350
351
352
353############################################## LVM DETECTION
354splashstep "Activating volume groups"
355if vgscan ; then
356        echo -e "${GOOD} Scan OK ${NORMAL}"
357else
358        echo -e "${BAD} Scan FAILED! ${NORMAL}"
359        error_shell "Can't find volume groups!"
360fi
361
362splashstep
363if vgchange --sysinit -ay syn3; then
364        echo -e "${GOOD} Activation OK ${NORMAL}"
365else
366        echo -e "${BAD} Activation FAILED! ${NORMAL}"
367        error_shell "Can't activate volume groups!"
368fi
369
370if [ `vgs --noheadings | grep ' syn3 '| wc -l` != "1" ]; then
371        error_shell "Multiple SYN-3 installations found. Please remove or clean old SYN-3 installations from other discs and reboot."
372fi
373
374############################################ Mount /boot (/dev/md0) under /mnt
375# This is neccesary for BOOTCONFIG stuff below.
376splashinfo "Loading boottime configuration"
377mkdir /mnt 2>/dev/null
378if ! mount -o ro,norecovery /dev/md0 /mnt ; then
379        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."
380fi
381
382############################################ BOOTCONFIG: Restore a backup?
383source /etc/restore.boot
384
385############################################ BOOTCONFIG: Network interface assigning section
386splashinfo "Assigning network interfaces"
387#if-assign reads config from /mnt:
388source /etc/if-assign.boot
389
390
391############################################# BOOTCONFIG: Linux HA and blockdevice symlinks
392
393#try to load the drbd configuration
394#(this file will overwrite the bootparameters)
395splashinfo "Loading redundancy configuration"
396if [ -r "/mnt/drbd.conf" ]; then
397        source /mnt/drbd.conf
398fi
399#force our node to be primary? (used for first time initialisation)
400if [ -r "/mnt/drbd.primary" ]; then
401        FORCEPRIMARY=1
402fi
403
404#last BOOTCONFIG step, now unmount mnt so that we can do drbd syncing stuff:
405umount /mnt
406
407if [ "$DRBD" == "1" ]; then
408        #use drbd
409        echo "Using drbd"
410        ln -s drbd0 /dev/boot
411        ln -s drbd1 /dev/home
412        ln -s drbd2 /dev/root
413        ln -s syn3/swap /dev/swap
414        source /etc/drbd.boot || error_shell
415else
416        #dont use drbd
417        echo "Not using drbd"
418        ln -s md0 /dev/boot
419        ln -s syn3/home /dev/home
420        ln -s syn3/root /dev/root
421        ln -s syn3/swap /dev/swap
422fi
423
424#make rebuild slow, to speedup boot and diskchecks
425echo 1000 > /proc/sys/dev/raid/speed_limit_max
426#(return to normal after boot at end of rc.M)
427
428#wait for device nodes to be created.
429udevadm settle
430
431############################################## FS CHECK & REPAIR
432if [ "$FSCHECK" ]; then
433        splashstep "Checking filesystems..."
434
435        #big discs use a lot of memory (150mb was not enough for my 250gig disc!), try to use swap
436        #try to use swap during disccheck
437        swapon /dev/swap 2>/dev/null
438
439        #Check the home and the root partition
440        check_xfs "/dev/home"
441        splashstep
442
443        check_xfs "/dev/root"
444        splashstep
445
446        if blkid /dev/boot | grep xfs >/dev/null; then
447                #we changed to ext4 because thats better supported in syslinux
448                check_xfs "/dev/boot"
449        fi
450        splashstep
451
452        swapoff /dev/swap 2>/dev/null
453else
454        splashstep
455        splashstep
456        splashstep
457        splashstep
458fi
459
460############################################## Try to mount root
461splashstep "Mounting root filesystem"
462
463mkdir /newroot >/dev/null 2>&1
464if ! mount -o inode32,rw "/dev/root" /newroot; then
465        error_shell "Can't mount root filesystem!"
466fi
467
468if [ "${SHELL}" -eq '1' ]; then
469        error_shell "Entering post-boot shell"
470fi
471
472##################################################### BOOT our mounted /newroot
473
474
475#re-activate kernel messages on console
476echo '4' > /proc/sys/kernel/printk
477
478#update mtab in /newroot
479cat /proc/mounts > /newroot/etc/mtab
480
481splashstep "Starting Syn-3"
482
483
484#populate the dev directory of the new system
485#(it should be on a tmpfs to allow lvm snapshots)
486#echo "Copying dev directory..."
487#mkdir /newroot/dev 2>/dev/null
488#mount -t tmpfs -o size=2M udev /newroot/dev
489#cp -a /dev /newroot
490
491#cleanup some initrd stuff, like udevd
492cleanupinitrd
493
494#move over the splash stuff
495cp /var/lib/splash/* /newroot/var/lib/splash 2>/dev/null
496
497#finally do the big /-swap :)
498#cd /newroot
499#mkdir -p /newroot/initrd >/dev/null 2>&1
500#swap system root to newroot
501#pivot_root . initrd
502
503#everything prepared, it's time to handover control to the 'real' system
504export CONSOLE=/dev/tty1
505exec switch_root /newroot /sbin/init
506#exec switch_root /newroot /bin/bash
507
508#fallback
509error_shell "Can't start the init system!"
510echo "Can't start the init system!"
511/bin/bash
512/bin/sh
513/bin/ash
Note: See TracBrowser for help on using the repository browser.