source: npl/kernel/initrd_scripts/root/etc/initrd.scripts

Last change on this file 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 100644
File size: 7.7 KB
Line 
1#!/bin/sh
2
3source /etc/initrd.defaults
4backup() {
5        echo -ne "\033[0G\033[0K"
6}
7
8parse_opt() {
9        case "$1" in
10                *\=*)
11                        echo "$1" | cut -f2 -d=
12                ;;
13        esac
14}
15
16
17error_shell()
18{
19
20        echo
21        MSG="$*"
22        if [ "$MSG" == "" ]; then
23                MSG="Fatal error!"
24        fi
25        /bin/splasherror "$MSG"
26        if [ "$DEBUG" == "" ] && cat /proc/cmdline|grep test >/dev/null; then
27                echo "You are testing a kernel-upgrade, but something went wrong!"
28                echo "The normal (working) kernel should be started again."
29                echo "Press enter for a shell, or wait 60 seconds before normal reboot..."
30                if ! read -t 60 BLA; then
31                        reboot
32                fi
33        fi
34        echo "Starting shell: "
35        setsid cttyhack sh
36}
37
38debug_shell()
39{
40        echo
41        echo "[ Debug mode, next step: $* ]"
42        setsid cttyhack sh
43}
44
45
46modules_scan() {
47        local MODS
48        [ -d /etc/modules/${1} ] || touch /etc/modules/${1}
49
50        MODS=`cat /etc/modules/${1}`
51        for x in ${MODS}
52        do
53                echo -ne "Scanning for ${x}... \c"
54                if ! modprobe ${x} 2>/dev/null 1>/dev/null; then
55                    echo -e "${BAD} FAILED!${NORMAL}"
56                fi
57                backup
58        done
59}
60
61#use hwsetup to detect the other modules
62hwinstall()
63{
64        echo -ne "${BOLD}   ::${NORMAL} "
65        hwsetup -p -n -a -v|while read bla; do
66                read bla class
67                read bla bus
68                read bla device
69                read bla driver
70                read bla desc
71                if test "$driver" != "ignore"; then
72                        if test "$driver" != "unknown"; then
73                                if ! echo "$driver"|grep ' '>/dev/null; then
74                                        echo -ne "${BOLD}   ::${NORMAL} $desc: $BOLD$driver...";
75                                        if OUTPUT=`modprobe $driver 2>&1`; then
76                                                echo -e "$GOOD OK $NORMAL"
77                                        else
78                                                echo -e "$WARN skipped $NORMAL"
79                                        fi
80                                fi
81                        fi
82                fi
83        done
84}
85
86
87check_xfs()
88{
89        echo -ne "${BOLD}   ::${NORMAL} Mounting $@..."
90
91        #first replay the log by mounting it
92        mkdir /.mnt 2>/dev/null
93        mount -o inode32 $1 /.mnt 2>/dev/null
94
95        if [ -e /.mnt/.cleanshutdown ]; then
96                umount /.mnt 2>/dev/null
97                echo -n "(last shutdown was clean) "
98        else
99                umount /.mnt 2>/dev/null
100                echo -n "Last shutdown was not clean, checking..."
101                #Check for xfs error's
102                #Dont use xfs_check, since it requires too much memory for big filesystems (>2TB)
103                if ! xfs_repair -n $1 >/dev/null 2>/dev/null; then
104                        echo -en "${WARN}Reparing..."
105
106                        #try a 'normal' repair
107                        if ! /sbin/xfs_repair $1 >/dev/null 2>/dev/null; then
108                                echo -n "flushing journal..."
109                                #try a repair by flushing the log
110                                if ! /sbin/xfs_repair -L $1 >/dev/null 2> /dev/null; then
111                                        #its broken!
112                                        echo -e "${BAD} FAILED!${NORMAL}"
113                                        error_shell "Filesystem error, please fix manually!"
114                                fi
115                        fi
116                fi
117        fi
118        echo -e " ${GOOD}OK${NORMAL}"
119}
120
121
122random()
123{
124        echo -n $RANDOM
125}
126
127
128#cleanup the initrd environment, before exiting
129cleanupinitrd()
130{
131        #if support environment is active, leave the initrd alone
132        if [ "$SUP" == "" ]; then
133                #unmount and kill everything, so the initrd is unused from now on.
134                killall -9 udevd v86d udhcpc 2>/dev/null #we keep our IP!
135                #umount /proc/bus/usb 2>/dev/null
136                #umount /sys 2>/dev/null
137                #umount /proc 2>/dev/null
138                #umount /dev/pts 2>/dev/null
139                #umount /dev 2>/dev/null
140        fi
141}
142
143boot_image()
144{
145        ###################################### find MEDIA and mount it under /newroot/mnt/cdrom
146        splashstep "Searching boot image"
147
148        #prepare /newroot
149        #NOTE: the live image will be mounted under /newroot/mnt/live, and then there will be symlinks to it.
150        mkdir /newroot
151        mount -t tmpfs tmpfs /newroot
152
153        mkdir -p /newroot/dev /newroot/mnt /newroot/tmp /newroot/initrd
154
155        #the installer-cdrom or usbstick is mounted here. If NET_SERVER is specified, it mounts the server here.
156        mkdir /newroot/mnt/cdrom
157
158        #the live-environment image that needs to be started is mounted here:
159        mkdir /newroot/mnt/live
160
161
162        #network mode
163        if [ "$NET_SERVER" ]; then
164                #network  mode
165                splashinfo "Preparing to boot from network image"
166                if [ "$NET_PASS_ASK" ]; then
167                        while true; do
168                                splashmode verbose
169                                splashinfo "Please enter password for user $NET_USER at share $NET_SERVER ..."
170                                echo -n "Password: "
171                                read NET_PASS
172                                mount.cifs "$NET_SERVER" /newroot/mnt/cdrom -o user=$NET_USER,pass=$NET_PASS,noserverino && break
173                                echo "Error while connecting, please try again."
174                        done
175                else
176                        echo " Mounting samba share $NET_SERVER with user $NET_USER..."
177                        mount.cifs "$NET_SERVER" /newroot/mnt/cdrom -o user=$NET_USER,pass=$NET_PASS,noserverino || error_shell "Error while connecting to server"
178                fi
179
180        #cdrom/usb install mode
181        else
182
183                #loadusb-storage and wait for usbstick detection
184                modprobe usb-storage
185                modprobe vfat
186                udevadm settle
187
188                #scan all removable devices, also USB sticks
189                FOUND=0
190                SLEPT=0
191                while [ "$FOUND" == "0" ]; do
192                        for x in `ls -d /sys/block/*/device | sed 's#/device$##' | sed 's#/sys/block#/dev#' | grep -v fd0`
193                        do
194                                echo -en " Identifying $x: "
195                                VOLNAME=`volname $x` 2>/dev/null
196                                echo -n "[ $VOLNAME ] "
197                                if echo $VOLNAME | grep "^Syn-3 installer" >/dev/null; then
198                                        echo -n "mounting..."
199                                        mount -r ${x} /newroot/mnt/cdrom > /dev/null 2>&1
200                                        mount -r ${x}1 /newroot/mnt/cdrom > /dev/null 2>&1
201                                        if [ -e /newroot/mnt/cdrom/$BOOTIMAGE ];
202                                        then
203                                                FOUND=1
204                                                echo -e " ${GOOD}OK${NORMAL}"
205                                                break
206                                        else
207                                                echo -e " ${WARN}NOT FOUND${NORMAL}"
208                                        fi
209                                        umount /newroot/mnt/cdrom >/dev/null 2>&1
210                                else
211                                        echo "skipped"
212                                fi
213                        done
214                        if [ "$FOUND" == "0" ] && [ "$SLEPT" == "0" ]; then
215                                echo "Waiting for usb storage devices to settle and trying again..."
216                                sleep 15
217                                SLEPT=1
218                        else
219                                break;
220                        fi
221                done
222
223                #something bad happend while searching installer media
224                if [ "$FOUND" = "0" ]
225                then
226                        error_shell "Can't find boot media! ( Please mount it under /newroot/mnt/cdrom )"
227                fi
228        fi
229
230
231        # from this point on, the media is mounted under /newroot/mnt/cdrom
232
233        ################################################# mount bootimage or copy bootimage to a block device?
234        if [ "$INSTALL_DEVICE" != "" ]; then
235                splashstep "Copying install image $BOOTIMAGE to $INSTALL_DEVICE ..."
236                gunzip -c /newroot/mnt/cdrom/$BOOTIMAGE > $INSTALL_DEVICE || error_shell "Error while copying install image"
237                sync
238                reboot -f
239        else
240                splashstep "Opening $BOOTIMAGE ..."
241                mount -o loop,ro /newroot/mnt/cdrom/$BOOTIMAGE /newroot/mnt/live || error_shell "Error while opening boot image"
242        fi
243
244
245
246        ################################################## prepare live environment
247        #NOTE: We dont mount the live environment over /newroot, but use symlinks and copying instead.
248        #      This way its writable AND we can access all the stuff thats already mounted. (cdrom, network mounts)
249        splashstep
250        #link to all readonly stuff:
251        for x in bin sbin lib boot usr opt
252        do
253               ln -s "/mnt/live/${x}" "/newroot/${x}"
254        done
255        #copy stuff that needs to be modified
256        (cd /newroot/mnt/live; cp -a etc root home var /newroot)
257        #copy over the dev tree
258        #NO: we use a bindmount
259        #cp -a /dev /newroot
260
261
262        ################################################ start live image
263        splashstep "Starting boot image"
264
265
266
267        #pivot to the bootimage, never to return from it:
268        if [ "$PIVOTIMAGE" ]; then
269                cleanupinitrd
270
271                #swap system root to newroot
272                cd /newroot
273                pivot_root . initrd
274
275                #everything prepared, it's time to handover control to the 'real' system
276                export CONSOLE=/dev/tty1
277                exec /sbin/init
278
279                error_shell "Can't start the init system!"
280                echo "Can't start the init system!"
281        #chroot to the bootimage and continue booting when it returns
282        else
283                #we can only run one udevd:
284                mkdir /newroot/dev 2>/dev/null
285                mount -o bind /dev /newroot/dev
286
287                #start it
288                if ! chroot /newroot "/sbin/init" ; then
289                        error_shell "Error while running live image! Please reboot."
290                fi
291                umount /newroot/dev
292        fi
293
294
295        if [ ! -e /newroot/INSTALLOK ]; then
296                error_shell "Installation failed!"
297        fi
298
299        ################################################ cleanup
300        #restore splash
301        splashmode silent
302        splashstep "Closing boot image"
303
304        cd /
305        umount -d /newroot/mnt/live
306        umount /newroot/mnt/cdrom
307        umount /newroot
308        sync
309
310
311
312}
Note: See TracBrowser for help on using the repository browser.