Annotation of /trunk/mkinitrd/mkinitrd-livecd.sh
Parent Directory | Revision Log
Revision 485 -
(hide annotations)
(download)
(as text)
Sun Apr 29 20:56:14 2007 UTC (17 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 8378 byte(s)
Sun Apr 29 20:56:14 2007 UTC (17 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 8378 byte(s)
- split pata modules from modules.generic to modules.pata and added nopata option
1 | niro | 333 | #!/bin/bash |
2 | niro | 485 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mkinitrd/mkinitrd-livecd.sh,v 1.6 2007-04-29 20:55:11 niro Exp $ |
3 | niro | 333 | |
4 | # mkinitrd-livecd | ||
5 | # | ||
6 | # Copyright 2005 Red Hat, Inc. | ||
7 | # | ||
8 | # Written by Erik Troan <ewt@redhat.com> | ||
9 | # | ||
10 | # Contributors: | ||
11 | # Elliot Lee <sopwith@cuc.edu> | ||
12 | # Miguel de Icaza <miguel@nuclecu.unam.mx> | ||
13 | # Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de> | ||
14 | # Michael K. Johnson <johnsonm@redhat.com> | ||
15 | # Pierre Habraken <Pierre.Habraken@ujf-grenoble.fr> | ||
16 | # Jakub Jelinek <jakub@redhat.com> | ||
17 | # Carlo Arenas Belon (carenas@chasqui.lared.net.pe> | ||
18 | # Keith Owens <kaos@ocs.com.au> | ||
19 | # Bernhard Rosenkraenzer <bero@redhat.com> | ||
20 | # Matt Wilson <msw@redhat.com> | ||
21 | # Trond Eivind Glomsrød <teg@redhat.com> | ||
22 | # Jeremy Katz <katzj@redhat.com> | ||
23 | # Preston Brown <pbrown@redhat.com> | ||
24 | # Bill Nottingham <notting@redhat.com> | ||
25 | # Guillaume Cottenceau <gc@mandrakesoft.com> | ||
26 | # Peter Jones <pjones@redhat.com> | ||
27 | |||
28 | # heavily modified for magellan-linux by Niels Rogalla <niro@magellan-linux.de> | ||
29 | |||
30 | umask 0022 | ||
31 | export MALLOC_PERTURB_=204 | ||
32 | |||
33 | PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH | ||
34 | export PATH | ||
35 | |||
36 | VERSION=5.0.8 | ||
37 | |||
38 | MODULES="" | ||
39 | NOSTRIP=false | ||
40 | |||
41 | [ -e /etc/conf.d/mkinitrd-livecd ] && . /etc/conf.d/mkinitrd-livecd | ||
42 | |||
43 | niro | 336 | LINUXRC="/usr/lib/mkinitrd/linuxrc.sh" |
44 | MODULES_GENERIC="/usr/lib/mkinitrd/modules.generic" | ||
45 | MODULES_USB="/usr/lib/mkinitrd/modules.usb" | ||
46 | MODULES_SCSI="/usr/lib/mkinitrd/modules.scsi" | ||
47 | MODULES_SATA="/usr/lib/mkinitrd/modules.sata" | ||
48 | niro | 485 | MODULES_PATA="/usr/lib/mkinitrd/modules.pata" |
49 | niro | 400 | MAKEDEV="/usr/lib/mkinitrd/MAKEDEV.sh" |
50 | niro | 333 | |
51 | compress=1 | ||
52 | allowmissing="" | ||
53 | target="" | ||
54 | kernel="" | ||
55 | force="" | ||
56 | verbose="" | ||
57 | img_vers="" | ||
58 | builtins="" | ||
59 | modulefile=/etc/modules.conf | ||
60 | rc=0 | ||
61 | |||
62 | IMAGESIZE=4000 | ||
63 | PRESCSIMODS="sd_mod" | ||
64 | fstab="/etc/fstab" | ||
65 | |||
66 | vg_list="" | ||
67 | |||
68 | die() { echo "Error: $@"; exit 1; } | ||
69 | add_initrd() { echo "$@" >> ${DEST}/init || die; } | ||
70 | |||
71 | DEST="$(mktemp -d)" | ||
72 | IMAGE="$(mktemp)" | ||
73 | |||
74 | usage() | ||
75 | { | ||
76 | echo "usage: $(basename $0) [--version] [--help] [-v] [-f]" | ||
77 | echo " [--image-version] [--no-strip] [--nocompress]" | ||
78 | echo " <initrd-image> <kernel-version>" | ||
79 | echo | ||
80 | echo " (ex: $(basename $0) /boot/initrd-2.2.5-15.img 2.2.5-15)" | ||
81 | |||
82 | exit 0 | ||
83 | } | ||
84 | |||
85 | moduledep() | ||
86 | { | ||
87 | if [ ! -f "/lib/modules/${kernel}/modules.dep" ] | ||
88 | then | ||
89 | die "No dep file found for kernel ${kernel}" | ||
90 | fi | ||
91 | |||
92 | echo "Looking for deps of module $1" | ||
93 | deps=$(awk 'BEGIN { searched=ARGV[2]; ARGV[2]=""; rc=1 } \ | ||
94 | function modname(filename) { match(filename, /\/([^\/]+)\.k?o:?$/, ret); return ret[1] } \ | ||
95 | function show() { if (orig == searched) { print dep; orig=""; rc=0; exit } } \ | ||
96 | /^\/lib/ { show(); \ | ||
97 | orig=modname($1); dep=""; \ | ||
98 | if ($2) { for (i = 2; i <= NF; i++) { dep=sprintf("%s %s", dep, modname($i)); } } } \ | ||
99 | /^ / { dep=sprintf("%s %s", dep, modname($1)); } \ | ||
100 | END { show(); exit(rc) }' /lib/modules/${kernel}/modules.dep $1) | ||
101 | [ -n "${deps}" ] && echo ":${deps}" || echo | ||
102 | } | ||
103 | |||
104 | findone() { /usr/bin/find "$@" | /bin/awk '{ print $1; exit; }'; } | ||
105 | findall() { /usr/bin/find "$@"; } | ||
106 | |||
107 | findmodule() | ||
108 | { | ||
109 | skiperrors="" | ||
110 | |||
111 | if [[ $1 = --skiperrors ]] | ||
112 | then | ||
113 | skiperrors=--skiperrors | ||
114 | shift | ||
115 | fi | ||
116 | |||
117 | local modName=$1 | ||
118 | |||
119 | if [ "${modName}" = "off" -o "${modName}" = "null" ] | ||
120 | then | ||
121 | return | ||
122 | fi | ||
123 | |||
124 | if [ $(echo ${modName} | cut -b1) = "-" ] | ||
125 | then | ||
126 | skiperrors=--skiperrors | ||
127 | modName=$(echo ${modName} | cut -b2-) | ||
128 | fi | ||
129 | |||
130 | case "${MODULES} " in | ||
131 | *"/${modName}.ko "*) return ;; | ||
132 | esac | ||
133 | |||
134 | if echo ${builtins} | egrep -q '(^| )'${modName}'( |$)' | ||
135 | then | ||
136 | echo "module ${modName} assumed to be built in" | ||
137 | return | ||
138 | fi | ||
139 | |||
140 | # special cases | ||
141 | if [[ ${modName} = i2o_block ]] | ||
142 | then | ||
143 | findmodule i2o_core | ||
144 | findmodule -i2o_pci | ||
145 | modName="i2o_block" | ||
146 | elif [[ ${modName} = ppa ]] | ||
147 | then | ||
148 | findmodule parport | ||
149 | findmodule parport_pc | ||
150 | modName="ppa" | ||
151 | elif [[ ${modName} = sbp2 ]] | ||
152 | then | ||
153 | findmodule ieee1394 | ||
154 | findmodule ohci1394 | ||
155 | modName="sbp2" | ||
156 | else | ||
157 | moduledep ${modName} | ||
158 | for i in ${deps} | ||
159 | do | ||
160 | findmodule ${i} | ||
161 | done | ||
162 | fi | ||
163 | |||
164 | for modExt in o.gz o ko | ||
165 | do | ||
166 | for modDir in /lib/modules/${kernel}/updates /lib/modules/${kernel} | ||
167 | do | ||
168 | if [ -d ${modDir} ] | ||
169 | then | ||
170 | fmPath=$(findone ${modDir} -name ${modName}.${modExt}) | ||
171 | if [ -f "${fmPath}" ] | ||
172 | then | ||
173 | break 2 | ||
174 | fi | ||
175 | fi | ||
176 | done | ||
177 | done | ||
178 | |||
179 | if [ ! -f ${fmPath} ] | ||
180 | then | ||
181 | if [ -n "${skiperrors}" ] | ||
182 | then | ||
183 | return | ||
184 | fi | ||
185 | |||
186 | # ignore the absence of the scsi modules | ||
187 | for n in ${PRESCSIMODS} | ||
188 | do | ||
189 | if [[ ${n} = ${modName} ]] | ||
190 | then | ||
191 | return | ||
192 | fi | ||
193 | done | ||
194 | |||
195 | if [ -n "${allowmissing}" ] | ||
196 | then | ||
197 | echo "WARNING: No module ${modName} found for kernel ${kernel}, continuing anyway" | ||
198 | return | ||
199 | fi | ||
200 | |||
201 | die "No module ${modName} found for kernel ${kernel}, aborting." | ||
202 | fi | ||
203 | |||
204 | # only need to add each module once | ||
205 | MODULES="${MODULES} ${fmPath}" | ||
206 | } | ||
207 | |||
208 | install_kernel_modules() | ||
209 | { | ||
210 | local list="$1" | ||
211 | local module | ||
212 | |||
213 | while read module args | ||
214 | do | ||
215 | case "${module}" in | ||
216 | \#*|"") continue ;; | ||
217 | esac | ||
218 | |||
219 | findmodule ${module} | ||
220 | done << EOF | ||
221 | $(cat ${list}; echo) | ||
222 | EOF | ||
223 | |||
224 | # create empty modules.lala file | ||
225 | :> ${DEST}/etc/$(basename ${list}) | ||
226 | |||
227 | # install detected modules | ||
228 | echo "Coping your modules to '${DEST}/lib' ..." | ||
229 | for MODULE in ${MODULES} | ||
230 | do | ||
231 | if [ -x /usr/bin/strip ] && [[ ${NOSTRIP} = false ]] | ||
232 | then | ||
233 | /usr/bin/strip -g ${verbose} ${MODULE} -o ${DEST}/lib/$(basename ${MODULE}) || die | ||
234 | else | ||
235 | cp ${verbose} -a ${MODULE} ${DEST}/lib || die | ||
236 | fi | ||
237 | |||
238 | # generate modules load file | ||
239 | echo "$(basename ${MODULE} .ko)" >> ${DEST}/etc/$(basename ${list}) || die | ||
240 | done | ||
241 | |||
242 | export ALL_MODULES="${ALL_MODULES} ${MODULES}" | ||
243 | unset MODULES | ||
244 | } | ||
245 | |||
246 | # need r00t privs | ||
247 | [[ $(id -u) != 0 ]] && die "you must be r00t." | ||
248 | |||
249 | niro | 336 | # enforce initramfs method as default |
250 | [[ -z ${IMAGE_TYPE} ]] && IMAGE_TYPE=initramfs | ||
251 | |||
252 | niro | 333 | while [ $# -gt 0 ]; do |
253 | case $1 in | ||
254 | --version) | ||
255 | echo "mkinitrd: version ${VERSION}" | ||
256 | exit 0 | ||
257 | ;; | ||
258 | |||
259 | -v) verbose=-v ;; | ||
260 | -f) force=1 ;; | ||
261 | --nocompress) compress="" ;; | ||
262 | --image-version) img_vers=yes ;; | ||
263 | --allow-missing) allowmissing=yes ;; | ||
264 | --noresume) noresume=1 ;; | ||
265 | --help) usage -n ;; | ||
266 | --initramfs) IMAGE_TYPE=initramfs ;; | ||
267 | --loopback) IMAGE_TYPE=loopback ;; | ||
268 | --no-strip) NOSTRIP=true ;; | ||
269 | *) | ||
270 | if [ -z "${target}" ] | ||
271 | then | ||
272 | target=$1 | ||
273 | elif [ -z "${kernel}" ] | ||
274 | then | ||
275 | kernel=$1 | ||
276 | else | ||
277 | usage | ||
278 | fi | ||
279 | ;; | ||
280 | esac | ||
281 | |||
282 | shift | ||
283 | done | ||
284 | |||
285 | |||
286 | # create basic filesystem layout | ||
287 | niro | 344 | install -d ${DEST}/{bin,dev,etc,lib,loopfs,proc,sbin,sys,sysroot} || die |
288 | niro | 333 | |
289 | # install busybox | ||
290 | echo "$(which busybox.mkinitrd)" | ||
291 | install -m0755 $(which busybox.mkinitrd) ${DEST}/bin/busybox || die | ||
292 | niro | 344 | for i in '[' ash basename cat cut clear cp dirname echo env false find \ |
293 | grep gunzip gzip ln ls loadkmap mkdir mknod more mount mv \ | ||
294 | ps pwd rm rmdir sh sleep test touch true umount uname \ | ||
295 | niro | 333 | xargs yes chmod chown |
296 | do | ||
297 | # static links | ||
298 | ln ${DEST}/bin/busybox ${DEST}/bin/${i} || die "${i}" | ||
299 | done | ||
300 | |||
301 | niro | 344 | # sbin related |
302 | for i in chroot init losetup modprobe pivot_root | ||
303 | do | ||
304 | # static links | ||
305 | ln ${DEST}/bin/busybox ${DEST}/sbin/${i} || die "${i}" | ||
306 | done | ||
307 | |||
308 | niro | 333 | # install run-init |
309 | echo "$(which run-init.mkinitrd)" | ||
310 | niro | 344 | install -m0755 $(which run-init.mkinitrd) ${DEST}/sbin/run-init || die |
311 | niro | 333 | |
312 | # install insmod.static | ||
313 | echo "$(which insmod.static)" | ||
314 | niro | 344 | install -m0755 $(which insmod.static) ${DEST}/sbin/insmod || die |
315 | niro | 333 | |
316 | # create some needed device nodes | ||
317 | niro | 402 | install -o root -g root -m0754 ${MAKEDEV} ${DEST}/dev/MAKEDEV || die |
318 | niro | 400 | ( cd ${DEST}/dev; ./MAKEDEV -v generic-nopty) |
319 | niro | 333 | |
320 | ## install kernel modules ## | ||
321 | # generic needed | ||
322 | install_kernel_modules "${MODULES_GENERIC}" | ||
323 | |||
324 | # usb | ||
325 | install_kernel_modules "${MODULES_USB}" | ||
326 | |||
327 | # scsi | ||
328 | install_kernel_modules "${MODULES_SCSI}" | ||
329 | |||
330 | # sata | ||
331 | install_kernel_modules "${MODULES_SATA}" | ||
332 | |||
333 | niro | 485 | # pata |
334 | install_kernel_modules "${MODULES_PATA}" | ||
335 | |||
336 | niro | 333 | # show all modules |
337 | for i in ${ALL_MODULES} | ||
338 | do | ||
339 | echo ${i} | ||
340 | done | ||
341 | |||
342 | # install linuxrc | ||
343 | install -m0755 ${LINUXRC} ${DEST}/init || die | ||
344 | |||
345 | # create the image | ||
346 | echo "Creating initrd image '${target}' ..." | ||
347 | if [[ ${IMAGE_TYPE} = initramfs ]] | ||
348 | then | ||
349 | (cd "${DEST}" ; find . | cpio --quiet -o -H newc | gzip -9 >${IMAGE}) | ||
350 | cat ${IMAGE} > ${target} || die | ||
351 | fi | ||
352 | |||
353 | if [[ ${IMAGE_TYPE} = loopback ]] | ||
354 | then | ||
355 | MOUNTTMP="$(mktemp -d)" | ||
356 | |||
357 | # create ext2 img | ||
358 | dd if=/dev/zero of=${IMAGE} bs=1024 count=${IMAGESIZE} &> /dev/null || die | ||
359 | mke2fs -m 0 -i 1024 -F ${IMAGE} &> /dev/null || die | ||
360 | mount -o loop ${IMAGE} ${MOUNTTMP} || die | ||
361 | mv ${DEST}/* ${MOUNTTMP} || die | ||
362 | umount ${MOUNTTMP} || die | ||
363 | gzip -9 ${IMAGE} || die | ||
364 | cat ${IMAGE}.gz > ${target} || die | ||
365 | [ -d ${MOUNTTMP} ] && rm -rf ${MOUNTTMP} | ||
366 | |||
367 | # create inird dir for pivot_root | ||
368 | [ ! -d /initrd ] && { install -d /initrd || die; } | ||
369 | fi | ||
370 | |||
371 | # clean up | ||
372 | [ -d ${DEST} ] && rm -rf ${DEST} | ||
373 | [ -f ${IMAGE} ] && rm -f ${IMAGE} | ||
374 | |||
375 | # all went ok at this point | ||
376 | exit 0 |