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