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