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