Contents of /trunk/mkinitrd-magellan/livecd/linuxrc.sh
Parent Directory | Revision Log
Revision 2154 -
(show annotations)
(download)
(as text)
Wed Aug 7 10:17:30 2013 UTC (11 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 7003 byte(s)
Wed Aug 7 10:17:30 2013 UTC (11 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 7003 byte(s)
-respect cpufreq.governor kernel param
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 | cpufreq.governor=*) CPUFREQ_GOVERNOR="${i#*=}";; |
112 | esac |
113 | done |
114 | |
115 | # now load all needed modules |
116 | [ "${DOFB}" = "yes" ] && load_kernel_modules "framebuffer" |
117 | load_kernel_modules "generic" |
118 | [ "${DOPATA}" = "yes" ] && load_kernel_modules "pata" |
119 | [ "${DOSCSI}" = "yes" ] && load_kernel_modules "scsi" |
120 | [ "${DOUSB}" = "yes" ] && load_kernel_modules "usb" |
121 | [ "${DOSATA}" = "yes" ] && load_kernel_modules "sata" |
122 | |
123 | # populate dev |
124 | mdev -s |
125 | # handle hotplug events properly |
126 | echo /sbin/mdev > /proc/sys/kernel/hotplug |
127 | |
128 | # create newroot mount point |
129 | mkdir -p ${SYSROOT} |
130 | # fake a new filesystem (also needed with an initramfs!!) |
131 | mount -t tmpfs tmpfs ${SYSROOT} |
132 | |
133 | mkdir -p ${SYSROOT}/mnt/cdrom |
134 | mkdir -p ${SYSROOT}/mnt/cloop |
135 | mkdir -p ${SYSROOT}/mnt/magellan |
136 | |
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 | # respect rootdelay kernel param |
145 | if [ ! -z "${ROOTDELAY}" ]; then |
146 | echo "-- Requested a rootdelay of ${ROOTDELAY} seconds ..." |
147 | sleep ${ROOTDELAY} |
148 | fi |
149 | |
150 | # 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 | # 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 | ROOTFS="vfat" |
176 | [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}" |
177 | check_drives "/dev/sd*" "${ROOTFS}" |
178 | check_drives "/dev/sg*" "${ROOTFS}" |
179 | fi |
180 | |
181 | # for cdrom_device in $CDROM_LIST (ide) |
182 | ROOTFS="iso9660" |
183 | [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}" |
184 | check_drives "/dev/cdroms/*" "${ROOTFS}" |
185 | check_drives "/dev/hd*" "${ROOTFS}" |
186 | |
187 | # scsi cdroms |
188 | if [ "${DOSCSI}" = "yes" ] || [ "${DOSATA}" = "yes" ]; then |
189 | ROOTFS="iso9660" |
190 | [[ ! -z ${FORCED_ROOTFS} ]] && ROOTFS="${FORCED_ROOTFS}" |
191 | check_drives "/dev/sr*" "${ROOTFS}" |
192 | check_drives "/dev/sg*" "${ROOTFS}" |
193 | check_drives "/dev/scd*" "${ROOTFS}" |
194 | 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 | mount -o ro -t "${FSTYPE}" "${BOOT_DEVICE}" ${SYSROOT}/mnt/cdrom >/dev/null 2>&1 |
205 | |
206 | # write our boot_device to /mnt/.bootdev for later use (mtab) |
207 | echo "BOOTDEV=${BOOT_DEVICE}" > ${SYSROOT}/.bootdev |
208 | echo "FSTYPE=${FSTYPE}" >> ${SYSROOT}/.bootdev |
209 | |
210 | # mount squashfs |
211 | echo -e "Mounting squashfs system image ..." |
212 | echo |
213 | [ ! -e /dev/loop0 ] && mknod /dev/loop0 b 7 0 |
214 | mount -o loop,ro -t squashfs ${SYSROOT}/mnt/cdrom/livecdrootfs.sqsh "${CLOOPMOUNTDIR}" |
215 | |
216 | # mount unionfs if enabled |
217 | if [[ ${UNIONFS} = yes ]] |
218 | then |
219 | echo -e "Mounting writeable cdbuffer (unionfs) ..." |
220 | |
221 | # default setting |
222 | CLOOPMOUNTDIR="${SYSROOT}/mnt/unionfs" |
223 | [[ -z ${UNIONFS_FILE} ]] && UNIONFS_FILE="${SYSROOT}/mnt/cdrom/unionfs" |
224 | |
225 | [[ ! -d ${SYSROOT}/mnt/unionfs ]] && install -d ${SYSROOT}/mnt/unionfs |
226 | mount -t unionfs dirs=${UNIONFS_FILE}=rw:${SYSROOT}/mnt/cloop=ro ${CLOOPMOUNTDIR} |
227 | fi |
228 | |
229 | # symlinking cloop rootfs to /mnt as newroot |
230 | cd ${SYSROOT} |
231 | |
232 | for x in bin sbin lib lib64 boot usr opt |
233 | do |
234 | [ -d ${CLOOPMOUNTDIR}/${x} ] && ln -s ${CLOOPMOUNTDIR#${SYSROOT}}/${x} ${x} |
235 | done |
236 | mkdir -p initrd proc tmp sys var/tmp dev media |
237 | |
238 | # 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 | # only to be safe and to have a log channel |
242 | [ ! -e ${SYSROOT}/dev/tty ] && mknod ${SYSROOT}/dev/tty c 5 0 |
243 | # busybox needs this one |
244 | [ ! -e ${SYSROOT}/dev/tty5 ] && mknod ${SYSROOT}/dev/tty5 c 4 5 |
245 | |
246 | (cd ${CLOOPMOUNTDIR}; cp -a etc root home var ${SYSROOT}) |
247 | |
248 | # ensure that ${SYSROOT}/linurc exists |
249 | [ ! -e ${SYSROOT}/linuxrc ] && ln -snf ${INITEXEC} ${SYSROOT}/linuxrc |
250 | |
251 | # ensure the right permissions |
252 | chmod 1777 ${SYSROOT}/tmp |
253 | chmod 1777 ${SYSROOT}/var/tmp |
254 | fi |
255 | |
256 | cd / |
257 | |
258 | # unset hotplug event-manager |
259 | echo > /proc/sys/kernel/hotplug |
260 | |
261 | # de-silencio |
262 | echo 3 > /proc/sys/kernel/printk |
263 | |
264 | if [[ ${BREAK_ENABLED} = yes ]] |
265 | then |
266 | echo "-- Break requested, type 'exit' to resume operation ..." |
267 | ash |
268 | fi |
269 | |
270 | echo "-- Switching to real sysroot ..." |
271 | mount --move /dev ${SYSROOT}/dev |
272 | mount --move /sys ${SYSROOT}/sys |
273 | mount --move /proc ${SYSROOT}/proc |
274 | |
275 | exec run-init ${SYSROOT} ${INITEXEC} $@ < ${SYSROOT}/dev/console > ${SYSROOT}/dev/console |