Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2154 - (hide annotations) (download) (as text)
Wed Aug 7 10:17:30 2013 UTC (10 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 7003 byte(s)
-respect cpufreq.governor kernel param
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 2154 cpufreq.governor=*) CPUFREQ_GOVERNOR="${i#*=}";;
112 niro 532 esac
113     done
114    
115     # now load all needed modules
116 niro 671 [ "${DOFB}" = "yes" ] && load_kernel_modules "framebuffer"
117 niro 532 load_kernel_modules "generic"
118 niro 673 [ "${DOPATA}" = "yes" ] && load_kernel_modules "pata"
119 niro 532 [ "${DOSCSI}" = "yes" ] && load_kernel_modules "scsi"
120     [ "${DOUSB}" = "yes" ] && load_kernel_modules "usb"
121     [ "${DOSATA}" = "yes" ] && load_kernel_modules "sata"
122    
123 niro 894 # populate dev
124     mdev -s
125     # handle hotplug events properly
126     echo /sbin/mdev > /proc/sys/kernel/hotplug
127    
128 niro 532 # create newroot mount point
129 niro 1809 mkdir -p ${SYSROOT}
130 niro 532 # fake a new filesystem (also needed with an initramfs!!)
131 niro 1809 mount -t tmpfs tmpfs ${SYSROOT}
132 niro 532
133 niro 1809 mkdir -p ${SYSROOT}/mnt/cdrom
134     mkdir -p ${SYSROOT}/mnt/cloop
135     mkdir -p ${SYSROOT}/mnt/magellan
136 niro 532
137    
138     # needed for the usbstick, the timeout maybe to short
139     if [ "${DOUSB}" = "yes" ]; then
140     echo "-- Waiting 8 seconds for possible usb mount ..."
141     sleep 8
142     fi
143    
144 niro 1513 # respect rootdelay kernel param
145     if [ ! -z "${ROOTDELAY}" ]; then
146     echo "-- Requested a rootdelay of ${ROOTDELAY} seconds ..."
147     sleep ${ROOTDELAY}
148     fi
149    
150 niro 2154 # respect cpufreq.governor kernel param
151     if [ ! -z "${CPUFREQ_GOVERNOR}" ];
152     then
153     case "${CPUFREQ_GOVERNOR}" in
154     performance|conservative|powersave|ondemand|userspace)
155     echo "-- Set ${CPUFREQ_GOVERNOR} as default cpufreq.governor"
156     for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
157     do
158     echo "${CPUFREQ_GOVERNOR}" > "${cpu}"
159     done
160     ;;
161     *)
162     echo "-- Unknown cpufreq.governor ${CPUFREQ_GOVERNOR} selected, doing nothing"
163     ;;
164     esac
165     fi
166    
167 niro 532 # searching cdrom with cdid
168     BOOT_DEVICE=""
169     FSTYPE=""
170    
171     echo "Searching for a boot device ..."
172    
173     # searching usbstick
174     if [ "${DOUSB}" = "yes" ]; then
175 niro 663 ROOTFS="vfat"
176 niro 706 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
177 niro 663 check_drives "/dev/sd*" "${ROOTFS}"
178     check_drives "/dev/sg*" "${ROOTFS}"
179 niro 532 fi
180    
181     # for cdrom_device in $CDROM_LIST (ide)
182 niro 663 ROOTFS="iso9660"
183 niro 706 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
184 niro 663 check_drives "/dev/cdroms/*" "${ROOTFS}"
185     check_drives "/dev/hd*" "${ROOTFS}"
186 niro 532
187     # scsi cdroms
188     if [ "${DOSCSI}" = "yes" ] || [ "${DOSATA}" = "yes" ]; then
189 niro 663 ROOTFS="iso9660"
190 niro 706 [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}"
191 niro 663 check_drives "/dev/sr*" "${ROOTFS}"
192     check_drives "/dev/sg*" "${ROOTFS}"
193     check_drives "/dev/scd*" "${ROOTFS}"
194 niro 532 fi
195    
196     # mount our rootfs from cdrom
197     if [ "${BOOT_DEVICE}" = "" ]
198     then
199     echo "No Magellan boot CD/USBStick found!!!"
200     ash
201     exit 1
202     else
203     echo -e "Booting from: $BOOT_DEVICE ..."
204 niro 1809 mount -o ro -t "${FSTYPE}" "${BOOT_DEVICE}" ${SYSROOT}/mnt/cdrom >/dev/null 2>&1
205 niro 532
206     # write our boot_device to /mnt/.bootdev for later use (mtab)
207 niro 1809 echo "BOOTDEV=${BOOT_DEVICE}" > ${SYSROOT}/.bootdev
208     echo "FSTYPE=${FSTYPE}" >> ${SYSROOT}/.bootdev
209 niro 532
210     # mount squashfs
211     echo -e "Mounting squashfs system image ..."
212     echo
213     [ ! -e /dev/loop0 ] && mknod /dev/loop0 b 7 0
214 niro 1809 mount -o loop,ro -t squashfs ${SYSROOT}/mnt/cdrom/livecdrootfs.sqsh "${CLOOPMOUNTDIR}"
215 niro 532
216 niro 1296 # mount unionfs if enabled
217     if [[ ${UNIONFS} = yes ]]
218     then
219     echo -e "Mounting writeable cdbuffer (unionfs) ..."
220    
221     # default setting
222 niro 1809 CLOOPMOUNTDIR="${SYSROOT}/mnt/unionfs"
223     [[ -z ${UNIONFS_FILE} ]] && UNIONFS_FILE="${SYSROOT}/mnt/cdrom/unionfs"
224 niro 1296
225 niro 1809 [[ ! -d ${SYSROOT}/mnt/unionfs ]] && install -d ${SYSROOT}/mnt/unionfs
226     mount -t unionfs dirs=${UNIONFS_FILE}=rw:${SYSROOT}/mnt/cloop=ro ${CLOOPMOUNTDIR}
227 niro 1296 fi
228    
229 niro 532 # symlinking cloop rootfs to /mnt as newroot
230 niro 1809 cd ${SYSROOT}
231 niro 532
232 niro 605 for x in bin sbin lib lib64 boot usr opt
233 niro 532 do
234 niro 1809 [ -d ${CLOOPMOUNTDIR}/${x} ] && ln -s ${CLOOPMOUNTDIR#${SYSROOT}}/${x} ${x}
235 niro 532 done
236     mkdir -p initrd proc tmp sys var/tmp dev media
237    
238 niro 1809 # make ${SYSROOT}/dev/console & /mnt/dev/null
239     [ ! -e ${SYSROOT}/dev/console ] && mknod -m 600 ${SYSROOT}/dev/console c 5 1
240     [ ! -e ${SYSROOT}/dev/null ] && mknod -m 666 ${SYSROOT}/dev/null c 1 3
241 niro 1794 # only to be safe and to have a log channel
242 niro 1809 [ ! -e ${SYSROOT}/dev/tty ] && mknod ${SYSROOT}/dev/tty c 5 0
243 niro 1794 # busybox needs this one
244 niro 1809 [ ! -e ${SYSROOT}/dev/tty5 ] && mknod ${SYSROOT}/dev/tty5 c 4 5
245 niro 532
246 niro 1809 (cd ${CLOOPMOUNTDIR}; cp -a etc root home var ${SYSROOT})
247 niro 532
248 niro 1809 # ensure that ${SYSROOT}/linurc exists
249     [ ! -e ${SYSROOT}/linuxrc ] && ln -snf ${INITEXEC} ${SYSROOT}/linuxrc
250 niro 1512
251 niro 532 # ensure the right permissions
252 niro 1809 chmod 1777 ${SYSROOT}/tmp
253     chmod 1777 ${SYSROOT}/var/tmp
254 niro 532 fi
255    
256     cd /
257    
258 niro 894 # unset hotplug event-manager
259     echo > /proc/sys/kernel/hotplug
260    
261 niro 532 # de-silencio
262     echo 3 > /proc/sys/kernel/printk
263    
264 niro 1188 if [[ ${BREAK_ENABLED} = yes ]]
265     then
266     echo "-- Break requested, type 'exit' to resume operation ..."
267     ash
268     fi
269    
270 niro 532 echo "-- Switching to real sysroot ..."
271 niro 1809 mount --move /dev ${SYSROOT}/dev
272     mount --move /sys ${SYSROOT}/sys
273     mount --move /proc ${SYSROOT}/proc
274 niro 532
275 niro 1809 exec run-init ${SYSROOT} ${INITEXEC} $@ < ${SYSROOT}/dev/console > ${SYSROOT}/dev/console