- add support for booting from USB flash device.
[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             if /bin/mount -o ro -t msdos,ext2 /dev/$partition /usr 2>&1 > /dev/null ; then
38                 # Look for the first ISO image
39                 for iso in /usr/*.iso ; do
40                     if /sbin/losetup /dev/loop0 $iso ; then
41                         echo "pl_sysinit: using $iso on $partition"
42                         device="loop0"
43                         break
44                     fi
45                 done
46                 if [ "$device" != "loop0" ] ; then
47                     /bin/umount /usr 2>&1 > /dev/null
48                 fi
49             fi
50         done
51     fi
52     
53     echo "pl_sysinit: checking $device for /usr contents"
54     /bin/mount -o ro -t iso9660 /dev/$device /usr 2>&1 > /dev/null
55     if [ $? -eq 0 ]; then
56         # it mounted, but we should probably make sure its our boot cd
57         # this can be done by making sure the /pl_version file (on initrd)
58         # matches /usr/isolinux/pl_version
59         cd_version=$(/bin/cat /usr/isolinux/pl_version)
60
61         if [ "$initrd_version" != "$cd_version" ]; then
62             # eh, wrong cd, keep trying
63             /bin/umount /usr 2>&1 /dev/null
64         else
65             echo "pl_sysinit: found cd and mounted on /usr"
66             mounted=1
67             break
68         fi
69     fi
70 done
71
72 if [ $mounted -eq 0 ]; then
73     echo "pl_sysinit: unable to find boot cdrom, cannot continue."
74     # todo: maybe we can put a staticly linked sshd here
75     /sbin/shutdown -h now
76 fi
77
78
79 # parts of this were copied from devmap_mknod.sh from the device-mapper
80 # source. Since fedora decided not to include it in the rpm, it is 
81 # being copied here
82 echo "pl_sysinit: creating device mapper control node"
83
84 DM_DIR="mapper"
85 DM_NAME="device-mapper"
86 DIR="/dev/$DM_DIR"
87 CONTROL="$DIR/control"
88
89 MAJOR=$(sed -n 's/^ *\([0-9]\+\) \+misc$/\1/p' /proc/devices)
90 MINOR=$(sed -n "s/^ *\([0-9]\+\) \+$DM_NAME\$/\1/p" /proc/misc)
91
92 if [ -n "$MAJOR" ] && [ -n "$MINOR" ]; then
93     /bin/mkdir -p --mode=755 $DIR
94     /bin/rm -f $CONTROL
95     /bin/mknod --mode=600 $CONTROL c $MAJOR $MINOR
96 else
97     echo "pl_sysinit: unable to create device mapper control node, continuing"
98 fi
99
100 echo "pl_sysinit: configuring kernel parameters"
101 /sbin/sysctl -e -p /etc/sysctl.conf
102
103 echo "pl_sysinit: bringing network online"
104 /etc/init.d/pl_netinit
105