b5295b497bf11c685714d8507424fd3f4c5371bc
[bootcd.git] / conf_files / pl_sysinit
1 #!/bin/sh
2
3 echo "pl_sysinit: bringing system online"
4
5 echo "pl_sysinit: mounting file systems"
6 /bin/mount -v -a
7
8 echo "pl_sysinit: invoking hardware initialization script"
9 /etc/init.d/pl_hwinit
10
11 check_initrd()
12 {
13     _mounted=0
14     if [ -f /usr/isolinux/pl_version ] ; then
15         # it mounted, but we should probably make sure its our boot cd
16         # this can be done by making sure the /pl_version file (on initrd)
17         # matches /usr/isolinux/pl_version
18         initrd_version=$(/bin/cat /pl_version)
19         cd_version=$(/bin/cat /usr/isolinux/pl_version)
20         if [ "$initrd_version" == "$cd_version" ]; then
21             _mounted=1 
22         fi
23     fi
24     return $_mounted
25 }
26
27 check_block_devices()
28 {
29     _mounted=0
30
31     # so that * expands to empty string if there are no block devices
32     shopt -s nullglob
33
34     for device in /sys/block/*; do
35         device=$(/bin/basename $device)
36
37         # skipping any devices that start with md or ra (ram) or lo
38         # (loop) or fd (floppy)
39
40         start_device=${device:0:2}
41         if [ "$start_device" == "ra" ] || [ "$start_device" == "md" ] ||
42             [ "$start_device" == "lo" ] || [ "$start_device" == "fd" ]; then
43             continue
44         fi
45
46         # If this is a removable (e.g., USB flash) device, then try to
47         # look for an ISO image on each of its partitions.
48         if [ "$(cat /sys/block/$device/removable)" = "1" ] ; then
49             partitions=$(/bin/awk "\$4 ~ /${device}[0-9]*/ { print \$4 }" /proc/partitions)
50             for partition in $partitions ; do
51                 echo "pl_sysinit: checking $partition for iso image"
52                 mkdir -p /tmp/$partition
53                 if /bin/mount -o ro -t msdos,ext2 /dev/$partition /tmp/$partition 2>&1 > /dev/null ; then
54                 # Look for the first ISO image
55                     for iso in /tmp/$partition/*.iso ; do
56                         if /sbin/losetup /dev/loop0 $iso ; then
57                             echo "pl_sysinit: using $(basename $iso) on $partition"
58                             device="loop0"
59                             break
60                         fi
61                     done
62                     if [ "$device" != "loop0" ] ; then
63                         /bin/umount /tmp/$partition 2>&1 > /dev/null
64                     fi
65                 fi
66             done
67         fi
68         
69         echo "pl_sysinit: checking $device for /usr contents"
70         /bin/mount -o ro -t iso9660 /dev/$device /usr 2>&1 > /dev/null
71         if [ $? -eq 0 ]; then
72         # it mounted, but we should probably make sure its our boot cd
73         # this can be done by making sure the /pl_version file (on initrd)
74         # matches /usr/isolinux/pl_version
75             initrd_version=$(/bin/cat /pl_version)
76             cd_version=$(/bin/cat /usr/isolinux/pl_version)
77
78             if [ "$initrd_version" != "$cd_version" ]; then
79             # eh, wrong cd, keep trying
80                 /bin/umount /usr 2>&1 /dev/null
81             else
82                 echo "pl_sysinit: found cd and mounted on /usr"
83                 _mounted=1
84                 break
85             fi
86         fi
87     done
88     return $_mounted
89 }
90
91 echo "pl_sysinit: finding cd to mount on /usr"
92 mounted=0
93 check_initrd
94 if [ $? -eq 1 ]; then
95     mounted=1
96 else
97     [ ! -d /usr ] && mkdir /usr
98     check_block_devices
99     [ $? -eq 1 ] && mounted=1
100 fi
101
102 if [ $mounted -eq 0 ]; then
103     echo "pl_sysinit: unable to find boot cdrom, cannot continue."
104     # todo: maybe we can put a staticly linked sshd here
105     /sbin/shutdown -h now
106 fi
107
108
109 # parts of this were copied from devmap_mknod.sh from the device-mapper
110 # source. Since fedora decided not to include it in the rpm, it is 
111 # being copied here
112 echo "pl_sysinit: creating device mapper control node"
113
114 DM_DIR="mapper"
115 DM_NAME="device-mapper"
116 DIR="/dev/$DM_DIR"
117 CONTROL="$DIR/control"
118
119 MAJOR=$(sed -n 's/^ *\([0-9]\+\) \+misc$/\1/p' /proc/devices)
120 MINOR=$(sed -n "s/^ *\([0-9]\+\) \+$DM_NAME\$/\1/p" /proc/misc)
121
122 if [ -n "$MAJOR" ] && [ -n "$MINOR" ]; then
123     /bin/mkdir -p --mode=755 $DIR
124     /bin/rm -f $CONTROL
125     /bin/mknod --mode=600 $CONTROL c $MAJOR $MINOR
126 else
127     echo "pl_sysinit: unable to create device mapper control node, continuing"
128 fi
129
130 echo "pl_sysinit: configuring kernel parameters"
131 /sbin/sysctl -e -p /etc/sysctl.conf
132
133 echo "pl_sysinit: bringing network online"
134 /etc/init.d/pl_netinit
135