Magellan Linux

Contents of /trunk/mkinitrd/lib/linuxrc.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 400 - (show annotations) (download) (as text)
Fri Nov 24 17:27:28 2006 UTC (17 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 3830 byte(s)
removed udev, using a static /dev for initial boots. udev gets started later

1 #!/bin/sh
2 # $Header: /home/cvsd/magellan-cvs/magellan-src/mkinitrd/lib/linuxrc.sh,v 1.6 2006-11-24 17:27:28 niro Exp $
3
4 # loads given kernel modules
5 load_kernel_modules()
6 {
7 local type="$1"
8 local module
9 local args
10
11 echo -e "-- Loading ${type} modules:"
12 ( cat /etc/modules.${type}; echo) | while read module args
13 do
14 case "${module}" in
15 \#*|"") continue ;;
16 esac
17
18 if [ -e /lib/${module}.ko ]
19 then
20 insmod -f /lib/${module}.ko ${args} > /dev/null 2>&1
21 [ $? -eq 0 ] && echo -e "-- ${module}"
22 fi
23 done
24 echo
25 }
26
27 # check_drives $devices $fstype
28 check_drives()
29 {
30 local devices="$1"
31 local fs="$2"
32
33 for dev in ${devices}
34 do
35 mount -t ${fs} ${dev} /sysroot/mnt/cdrom >/dev/null 2>&1
36 media_found=$?
37
38 # if mount was ok check if cdid exists
39 if [ "${media_found}" -eq 0 ]
40 then
41 [ -e /sysroot/mnt/cdrom/livecdrootfs.sqsh ] && media_id_ok=$?
42 umount /sysroot/mnt/cdrom
43
44 if [ "${media_id_ok}" -eq 0 ]
45 then
46 echo -e "Magellan boot device found."
47 BOOT_DEVICE="${dev}"
48 FSTYPE=${fs}
49 break
50 fi
51 fi
52 done
53 }
54
55 ## some defaults ##
56 DOSCSI=no
57 DOUSB=no
58 DOSATA=no
59
60 ## starts here ##
61
62 # mount essential filesystems
63 mount -t proc proc /proc
64 mount -t sysfs sysfs /sys
65
66 # silencio
67 echo 0 > /proc/sys/kernel/printk
68
69 # check command line for params
70 for i in $(cat /proc/cmdline)
71 do
72 case "${i}" in
73 doscsi)
74 DOSCSI=yes
75 ;;
76 dousb)
77 DOUSB=yes
78 ;;
79 dosata)
80 DOSATA=yes
81 ;;
82 esac
83 done
84
85 # now load all needed modules
86 load_kernel_modules "generic"
87 [ "${DOSCSI}" = "yes" ] && load_kernel_modules "scsi"
88 [ "${DOUSB}" = "yes" ] && load_kernel_modules "usb"
89 [ "${DOSATA}" = "yes" ] && load_kernel_modules "sata"
90
91 # create newroot mount point
92 mkdir -p /sysroot
93 # fake a new filesystem (also needed with an initramfs!!)
94 mount -t tmpfs tmpfs /sysroot
95
96 mkdir -p /sysroot/mnt/cdrom
97 mkdir -p /sysroot/mnt/cloop
98 mkdir -p /sysroot/mnt/magellan
99
100
101 # needed for the usbstick, the timeout maybe to short
102 if [ "${DOUSB}" = "yes" ]; then
103 echo "-- Waiting 8 seconds for possible usb mount ..."
104 sleep 8
105 fi
106
107 # searching cdrom with cdid
108 BOOT_DEVICE=""
109 FSTYPE=""
110
111 echo "Searching for a boot device ..."
112
113 # searching usbstick
114 if [ "${DOUSB}" = "yes" ]; then
115 check_drives "/dev/scsi/host[0-99]/bus[0-99]/target[0-99]/lun[0-99]/part[0-99]" "vfat"
116 fi
117
118 # for cdrom_device in $CDROM_LIST (ide)
119 check_drives "/dev/cdroms/*" iso9660
120 check_drives "/dev/hd*" iso9660
121
122 # scsi cdroms
123 if [ "${DOSCSI}" = "yes" ] || [ "${DOSATA}" = "yes" ]; then
124 check_drives "/dev/sr*" iso9660
125 fi
126
127 # mount our rootfs from cdrom
128 if [ "${BOOT_DEVICE}" = "" ]
129 then
130 echo "No Magellan boot CD/USBStick found!!!"
131 ash
132 exit 1
133 else
134 echo -e "Booting from: $BOOT_DEVICE ..."
135 mount -o ro -t "${FSTYPE}" "${BOOT_DEVICE}" /sysroot/mnt/cdrom >/dev/null 2>&1
136
137 # write our boot_device to /mnt/.bootdev for later use (mtab)
138 echo "BOOTDEV=${BOOT_DEVICE}" > /sysroot/.bootdev
139 echo "FSTYPE=${FSTYPE}" >> /sysroot/.bootdev
140
141 # mount squashfs
142 echo -e "Mounting squashfs system image ..."
143 echo
144 [ ! -e /dev/loop0 ] && mknod /dev/loop0 b 7 0
145 mount -o loop,ro -t squashfs /sysroot/mnt/cdrom/livecdrootfs.sqsh /sysroot/mnt/cloop
146
147 # symlinking cloop rootfs to /mnt as newroot
148 cd /sysroot
149
150 for x in bin sbin lib boot usr opt
151 do
152 ln -s mnt/cloop/${x} ${x}
153 done
154 mkdir -p initrd proc tmp sys var/tmp dev media
155
156 # make /sysroot/dev/console & /mnt/dev/null
157 [ ! -e /sysroot/dev/console ] && mknod -m 600 /sysroot/dev/console c 5 1
158 [ ! -e /sysroot/dev/null ] && mknod -m 666 /sysroot/dev/null c 1 3
159
160 (cd /sysroot/mnt/cloop; cp -a etc root home var /sysroot)
161
162 # ensure the right permissions
163 chmod 1777 /sysroot/tmp
164 chmod 1777 /sysroot/var/tmp
165 fi
166
167 cd /
168
169 # de-silencio
170 echo 3 > /proc/sys/kernel/printk
171
172 echo "-- Switching to real sysroot ..."
173 umount /sys
174 umount /proc
175
176 exec run-init /sysroot /sbin/init $@ </sysroot/dev/console >/sysroot/dev/console