Magellan Linux

Contents of /trunk/mkinitrd-magellan/livecd/linuxrc.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1809 - (show annotations) (download) (as text)
Mon Apr 23 13:07:35 2012 UTC (12 years ago) by niro
File MIME type: application/x-sh
File size: 6486 byte(s)
-make SYSROOT variable and fixed variable substition while linking cloop mount dirs
1 #!/bin/sh
2 # $Id$
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=yes
59 DOFB=no
60 DOPATA=yes
61 FORCED_ROOTFS=""
62 INITEXEC="/sbin/init"
63 BREAK_ENABLED=no
64 UNIONFS=no
65 UNIONFS_FILE=""
66 SYSROOT="/sysroot"
67 CLOOPMOUNTDIR="${SYSROOT}/mnt/cloop"
68
69 ## starts here ##
70
71 # mount essential filesystems
72 mount -t proc proc /proc
73 mount -t sysfs sysfs /sys
74 if [[ -z $(grep '[[:space:]]/dev[[:space:]]' /proc/mounts | cut -d ' ' -f2) ]]
75 then
76 # many video drivers needed exec access
77 fstype=ramfs
78 # tmpfs was suggested by Greg Kroah-Hartman
79 [[ $(grep '[[:space:]]tmpfs' /proc/filesystems | cut -d $'\t' -f2) = tmpfs ]] && fstype=tmpfs
80 # mount devtmpfs if supported
81 [[ $(grep '[[:space:]]devtmpfs' /proc/filesystems | cut -d $'\t' -f2) = devtmpfs ]] && fstype=devtmpfs
82 mount -t ${fstype} dev /dev -o exec,nosuid,mode=0755,size=10M
83 fi
84
85 # install all busybox applets
86 busybox --install -s
87
88 # silencio
89 echo 0 > /proc/sys/kernel/printk
90
91 # check command line for params
92 for i in $(cat /proc/cmdline)
93 do
94 case "${i}" in
95 doscsi) DOSCSI=yes;;
96 noscsi) DOSCSI=no;;
97 dousb) DOUSB=yes;;
98 nousb) DOUSB=no;;
99 dosata) DOSATA=yes ;;
100 nosata) DOSATA=no ;;
101 dofb) DOFB=yes;;
102 nofb) DOFB=no;;
103 dopata) DOPATA=yes;;
104 nopata) DOPATA=no;;
105 rootfs=*) FORCED_ROOTFS="${i#*=}";;
106 init=*) INITEXEC="${i#*=}";;
107 break) BREAK_ENABLED=yes ;;
108 unionfs) UNIONFS=yes;;
109 unionfs_file=*) UNIONFS_FILE="${i#*=}";;
110 rootdelay=*) ROOTDELAY="${i#*=}";;
111 esac
112 done
113
114 # now load all needed modules
115 [ "${DOFB}" = "yes" ] && load_kernel_modules "framebuffer"
116 load_kernel_modules "generic"
117 [ "${DOPATA}" = "yes" ] && load_kernel_modules "pata"
118 [ "${DOSCSI}" = "yes" ] && load_kernel_modules "scsi"
119 [ "${DOUSB}" = "yes" ] && load_kernel_modules "usb"
120 [ "${DOSATA}" = "yes" ] && load_kernel_modules "sata"
121
122 # populate dev
123 mdev -s
124 # handle hotplug events properly
125 echo /sbin/mdev > /proc/sys/kernel/hotplug
126
127 # create newroot mount point
128 mkdir -p ${SYSROOT}
129 # fake a new filesystem (also needed with an initramfs!!)
130 mount -t tmpfs tmpfs ${SYSROOT}
131
132 mkdir -p ${SYSROOT}/mnt/cdrom
133 mkdir -p ${SYSROOT}/mnt/cloop
134 mkdir -p ${SYSROOT}/mnt/magellan
135
136
137 # needed for the usbstick, the timeout maybe to short
138 if [ "${DOUSB}" = "yes" ]; then
139 echo "-- Waiting 8 seconds for possible usb mount ..."
140 sleep 8
141 fi
142
143 # respect rootdelay kernel param
144 if [ ! -z "${ROOTDELAY}" ]; then
145 echo "-- Requested a rootdelay of ${ROOTDELAY} seconds ..."
146 sleep ${ROOTDELAY}
147 fi
148
149 # searching cdrom with cdid
150 BOOT_DEVICE=""
151 FSTYPE=""
152
153 echo "Searching for a boot device ..."
154
155 # searching usbstick
156 if [ "${DOUSB}" = "yes" ]; then
157 ROOTFS="vfat"
158 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
159 check_drives "/dev/sd*" "${ROOTFS}"
160 check_drives "/dev/sg*" "${ROOTFS}"
161 fi
162
163 # for cdrom_device in $CDROM_LIST (ide)
164 ROOTFS="iso9660"
165 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
166 check_drives "/dev/cdroms/*" "${ROOTFS}"
167 check_drives "/dev/hd*" "${ROOTFS}"
168
169 # scsi cdroms
170 if [ "${DOSCSI}" = "yes" ] || [ "${DOSATA}" = "yes" ]; then
171 ROOTFS="iso9660"
172 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
173 check_drives "/dev/sr*" "${ROOTFS}"
174 check_drives "/dev/sg*" "${ROOTFS}"
175 check_drives "/dev/scd*" "${ROOTFS}"
176 fi
177
178 # mount our rootfs from cdrom
179 if [ "${BOOT_DEVICE}" = "" ]
180 then
181 echo "No Magellan boot CD/USBStick found!!!"
182 ash
183 exit 1
184 else
185 echo -e "Booting from: $BOOT_DEVICE ..."
186 mount -o ro -t "${FSTYPE}" "${BOOT_DEVICE}" ${SYSROOT}/mnt/cdrom >/dev/null 2>&1
187
188 # write our boot_device to /mnt/.bootdev for later use (mtab)
189 echo "BOOTDEV=${BOOT_DEVICE}" > ${SYSROOT}/.bootdev
190 echo "FSTYPE=${FSTYPE}" >> ${SYSROOT}/.bootdev
191
192 # mount squashfs
193 echo -e "Mounting squashfs system image ..."
194 echo
195 [ ! -e /dev/loop0 ] && mknod /dev/loop0 b 7 0
196 mount -o loop,ro -t squashfs ${SYSROOT}/mnt/cdrom/livecdrootfs.sqsh "${CLOOPMOUNTDIR}"
197
198 # mount unionfs if enabled
199 if [[ ${UNIONFS} = yes ]]
200 then
201 echo -e "Mounting writeable cdbuffer (unionfs) ..."
202
203 # default setting
204 CLOOPMOUNTDIR="${SYSROOT}/mnt/unionfs"
205 [[ -z ${UNIONFS_FILE} ]] && UNIONFS_FILE="${SYSROOT}/mnt/cdrom/unionfs"
206
207 [[ ! -d ${SYSROOT}/mnt/unionfs ]] && install -d ${SYSROOT}/mnt/unionfs
208 mount -t unionfs dirs=${UNIONFS_FILE}=rw:${SYSROOT}/mnt/cloop=ro ${CLOOPMOUNTDIR}
209 fi
210
211 # symlinking cloop rootfs to /mnt as newroot
212 cd ${SYSROOT}
213
214 for x in bin sbin lib lib64 boot usr opt
215 do
216 [ -d ${CLOOPMOUNTDIR}/${x} ] && ln -s ${CLOOPMOUNTDIR#${SYSROOT}}/${x} ${x}
217 done
218 mkdir -p initrd proc tmp sys var/tmp dev media
219
220 # make ${SYSROOT}/dev/console & /mnt/dev/null
221 [ ! -e ${SYSROOT}/dev/console ] && mknod -m 600 ${SYSROOT}/dev/console c 5 1
222 [ ! -e ${SYSROOT}/dev/null ] && mknod -m 666 ${SYSROOT}/dev/null c 1 3
223 # only to be safe and to have a log channel
224 [ ! -e ${SYSROOT}/dev/tty ] && mknod ${SYSROOT}/dev/tty c 5 0
225 # busybox needs this one
226 [ ! -e ${SYSROOT}/dev/tty5 ] && mknod ${SYSROOT}/dev/tty5 c 4 5
227
228 (cd ${CLOOPMOUNTDIR}; cp -a etc root home var ${SYSROOT})
229
230 # ensure that ${SYSROOT}/linurc exists
231 [ ! -e ${SYSROOT}/linuxrc ] && ln -snf ${INITEXEC} ${SYSROOT}/linuxrc
232
233 # ensure the right permissions
234 chmod 1777 ${SYSROOT}/tmp
235 chmod 1777 ${SYSROOT}/var/tmp
236 fi
237
238 cd /
239
240 # unset hotplug event-manager
241 echo > /proc/sys/kernel/hotplug
242
243 # de-silencio
244 echo 3 > /proc/sys/kernel/printk
245
246 if [[ ${BREAK_ENABLED} = yes ]]
247 then
248 echo "-- Break requested, type 'exit' to resume operation ..."
249 ash
250 fi
251
252 echo "-- Switching to real sysroot ..."
253 mount --move /dev ${SYSROOT}/dev
254 mount --move /sys ${SYSROOT}/sys
255 mount --move /proc ${SYSROOT}/proc
256
257 exec run-init ${SYSROOT} ${INITEXEC} $@ < ${SYSROOT}/dev/console > ${SYSROOT}/dev/console