Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1809 - (hide annotations) (download) (as text)
Mon Apr 23 13:07:35 2012 UTC (12 years, 1 month 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 niro 532 #!/bin/sh
2 niro 809 # $Id$
3 niro 532
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 niro 663 FSTYPE="${fs}"
49 niro 532 break
50     fi
51     fi
52     done
53     }
54    
55     ## some defaults ##
56     DOSCSI=no
57     DOUSB=no
58 niro 894 DOSATA=yes
59 niro 663 DOFB=no
60 niro 894 DOPATA=yes
61 niro 663 FORCED_ROOTFS=""
62 niro 1180 INITEXEC="/sbin/init"
63 niro 1188 BREAK_ENABLED=no
64 niro 1296 UNIONFS=no
65     UNIONFS_FILE=""
66 niro 1809 SYSROOT="/sysroot"
67     CLOOPMOUNTDIR="${SYSROOT}/mnt/cloop"
68 niro 532
69     ## starts here ##
70    
71     # mount essential filesystems
72     mount -t proc proc /proc
73     mount -t sysfs sysfs /sys
74 niro 1792 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 niro 532
85 niro 894 # install all busybox applets
86     busybox --install -s
87    
88 niro 532 # 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 niro 894 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 niro 1180 init=*) INITEXEC="${i#*=}";;
107 niro 1188 break) BREAK_ENABLED=yes ;;
108 niro 1296 unionfs) UNIONFS=yes;;
109     unionfs_file=*) UNIONFS_FILE="${i#*=}";;
110 niro 1513 rootdelay=*) ROOTDELAY="${i#*=}";;
111 niro 532 esac
112     done
113    
114     # now load all needed modules
115 niro 671 [ "${DOFB}" = "yes" ] && load_kernel_modules "framebuffer"
116 niro 532 load_kernel_modules "generic"
117 niro 673 [ "${DOPATA}" = "yes" ] && load_kernel_modules "pata"
118 niro 532 [ "${DOSCSI}" = "yes" ] && load_kernel_modules "scsi"
119     [ "${DOUSB}" = "yes" ] && load_kernel_modules "usb"
120     [ "${DOSATA}" = "yes" ] && load_kernel_modules "sata"
121    
122 niro 894 # populate dev
123     mdev -s
124     # handle hotplug events properly
125     echo /sbin/mdev > /proc/sys/kernel/hotplug
126    
127 niro 532 # create newroot mount point
128 niro 1809 mkdir -p ${SYSROOT}
129 niro 532 # fake a new filesystem (also needed with an initramfs!!)
130 niro 1809 mount -t tmpfs tmpfs ${SYSROOT}
131 niro 532
132 niro 1809 mkdir -p ${SYSROOT}/mnt/cdrom
133     mkdir -p ${SYSROOT}/mnt/cloop
134     mkdir -p ${SYSROOT}/mnt/magellan
135 niro 532
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 niro 1513 # respect rootdelay kernel param
144     if [ ! -z "${ROOTDELAY}" ]; then
145     echo "-- Requested a rootdelay of ${ROOTDELAY} seconds ..."
146     sleep ${ROOTDELAY}
147     fi
148    
149 niro 532 # 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 niro 663 ROOTFS="vfat"
158 niro 706 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
159 niro 663 check_drives "/dev/sd*" "${ROOTFS}"
160     check_drives "/dev/sg*" "${ROOTFS}"
161 niro 532 fi
162    
163     # for cdrom_device in $CDROM_LIST (ide)
164 niro 663 ROOTFS="iso9660"
165 niro 706 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
166 niro 663 check_drives "/dev/cdroms/*" "${ROOTFS}"
167     check_drives "/dev/hd*" "${ROOTFS}"
168 niro 532
169     # scsi cdroms
170     if [ "${DOSCSI}" = "yes" ] || [ "${DOSATA}" = "yes" ]; then
171 niro 663 ROOTFS="iso9660"
172 niro 706 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
173 niro 663 check_drives "/dev/sr*" "${ROOTFS}"
174     check_drives "/dev/sg*" "${ROOTFS}"
175     check_drives "/dev/scd*" "${ROOTFS}"
176 niro 532 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 niro 1809 mount -o ro -t "${FSTYPE}" "${BOOT_DEVICE}" ${SYSROOT}/mnt/cdrom >/dev/null 2>&1
187 niro 532
188     # write our boot_device to /mnt/.bootdev for later use (mtab)
189 niro 1809 echo "BOOTDEV=${BOOT_DEVICE}" > ${SYSROOT}/.bootdev
190     echo "FSTYPE=${FSTYPE}" >> ${SYSROOT}/.bootdev
191 niro 532
192     # mount squashfs
193     echo -e "Mounting squashfs system image ..."
194     echo
195     [ ! -e /dev/loop0 ] && mknod /dev/loop0 b 7 0
196 niro 1809 mount -o loop,ro -t squashfs ${SYSROOT}/mnt/cdrom/livecdrootfs.sqsh "${CLOOPMOUNTDIR}"
197 niro 532
198 niro 1296 # mount unionfs if enabled
199     if [[ ${UNIONFS} = yes ]]
200     then
201     echo -e "Mounting writeable cdbuffer (unionfs) ..."
202    
203     # default setting
204 niro 1809 CLOOPMOUNTDIR="${SYSROOT}/mnt/unionfs"
205     [[ -z ${UNIONFS_FILE} ]] && UNIONFS_FILE="${SYSROOT}/mnt/cdrom/unionfs"
206 niro 1296
207 niro 1809 [[ ! -d ${SYSROOT}/mnt/unionfs ]] && install -d ${SYSROOT}/mnt/unionfs
208     mount -t unionfs dirs=${UNIONFS_FILE}=rw:${SYSROOT}/mnt/cloop=ro ${CLOOPMOUNTDIR}
209 niro 1296 fi
210    
211 niro 532 # symlinking cloop rootfs to /mnt as newroot
212 niro 1809 cd ${SYSROOT}
213 niro 532
214 niro 605 for x in bin sbin lib lib64 boot usr opt
215 niro 532 do
216 niro 1809 [ -d ${CLOOPMOUNTDIR}/${x} ] && ln -s ${CLOOPMOUNTDIR#${SYSROOT}}/${x} ${x}
217 niro 532 done
218     mkdir -p initrd proc tmp sys var/tmp dev media
219    
220 niro 1809 # 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 niro 1794 # only to be safe and to have a log channel
224 niro 1809 [ ! -e ${SYSROOT}/dev/tty ] && mknod ${SYSROOT}/dev/tty c 5 0
225 niro 1794 # busybox needs this one
226 niro 1809 [ ! -e ${SYSROOT}/dev/tty5 ] && mknod ${SYSROOT}/dev/tty5 c 4 5
227 niro 532
228 niro 1809 (cd ${CLOOPMOUNTDIR}; cp -a etc root home var ${SYSROOT})
229 niro 532
230 niro 1809 # ensure that ${SYSROOT}/linurc exists
231     [ ! -e ${SYSROOT}/linuxrc ] && ln -snf ${INITEXEC} ${SYSROOT}/linuxrc
232 niro 1512
233 niro 532 # ensure the right permissions
234 niro 1809 chmod 1777 ${SYSROOT}/tmp
235     chmod 1777 ${SYSROOT}/var/tmp
236 niro 532 fi
237    
238     cd /
239    
240 niro 894 # unset hotplug event-manager
241     echo > /proc/sys/kernel/hotplug
242    
243 niro 532 # de-silencio
244     echo 3 > /proc/sys/kernel/printk
245    
246 niro 1188 if [[ ${BREAK_ENABLED} = yes ]]
247     then
248     echo "-- Break requested, type 'exit' to resume operation ..."
249     ash
250     fi
251    
252 niro 532 echo "-- Switching to real sysroot ..."
253 niro 1809 mount --move /dev ${SYSROOT}/dev
254     mount --move /sys ${SYSROOT}/sys
255     mount --move /proc ${SYSROOT}/proc
256 niro 532
257 niro 1809 exec run-init ${SYSROOT} ${INITEXEC} $@ < ${SYSROOT}/dev/console > ${SYSROOT}/dev/console