Fix hardcoded paths in multipath support
[genkernel.git] / gen_initramfs.sh
1 #!/bin/bash
2 # $Id$
3
4 CPIO_ARGS="--quiet -o -H newc"
5
6 copy_binaries() {
7
8         local destdir=$1 files=$2
9
10         # Copy files
11         lddtree $files | tr ')(' '\n' |awk  '/=>/{ if($3 ~ /^\//){print $3}}' | sort | uniq | cpio -p --make-directories --dereference --quiet $destdir
12
13 }
14
15 append_base_layout() {
16         if [ -d "${TEMP}/initramfs-base-temp" ]
17         then
18                 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
19         fi
20
21         mkdir -p ${TEMP}/initramfs-base-temp/dev
22         mkdir -p ${TEMP}/initramfs-base-temp/bin
23         mkdir -p ${TEMP}/initramfs-base-temp/etc
24         mkdir -p ${TEMP}/initramfs-base-temp/usr
25         mkdir -p ${TEMP}/initramfs-base-temp/lib
26         mkdir -p ${TEMP}/initramfs-base-temp/mnt
27         mkdir -p ${TEMP}/initramfs-base-temp/run
28         mkdir -p ${TEMP}/initramfs-base-temp/sbin
29         mkdir -p ${TEMP}/initramfs-base-temp/proc
30         mkdir -p ${TEMP}/initramfs-base-temp/temp
31         mkdir -p ${TEMP}/initramfs-base-temp/tmp
32         mkdir -p ${TEMP}/initramfs-base-temp/sys
33         mkdir -p ${TEMP}/initramfs-temp/.initrd
34         mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
35         mkdir -p ${TEMP}/initramfs-base-temp/sbin
36         mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
37         mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
38         ln -s  lib  ${TEMP}/initramfs-base-temp/lib64
39
40         echo "/dev/ram0     /           ext2    defaults        0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
41         echo "proc          /proc       proc    defaults    0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
42
43         cd ${TEMP}/initramfs-base-temp/dev
44         mknod -m 660 console c 5 1
45         mknod -m 660 null c 1 3
46         mknod -m 660 zero c 1 5
47         mknod -m 600 tty0 c 4 0
48         mknod -m 600 tty1 c 4 1
49         mknod -m 600 ttyS0 c 4 64
50
51         date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date
52
53         cd "${TEMP}/initramfs-base-temp/"
54         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
55                         || gen_die "compressing baselayout cpio"
56         cd "${TEMP}"
57         rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
58 }
59
60 append_busybox() {
61         if [ -d "${TEMP}/initramfs-busybox-temp" ]
62         then
63                 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
64         fi
65
66         mkdir -p "${TEMP}/initramfs-busybox-temp/bin/" 
67         tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
68                 gen_die 'Could not extract busybox bincache!'
69         chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
70
71         mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/"
72         cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script
73         chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script"
74
75         # Set up a few default symlinks
76         for i in ${BUSYBOX_APPLETS:-[ ash sh mount uname echo cut cat}; do
77                 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
78                 ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
79                         gen_die "Busybox error: could not link ${i}!"
80         done
81
82         cd "${TEMP}/initramfs-busybox-temp/"
83         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
84                         || gen_die "compressing busybox cpio"
85         cd "${TEMP}"
86         rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
87 }
88
89 append_blkid(){
90         if [ -d "${TEMP}/initramfs-blkid-temp" ]
91         then
92                 rm -r "${TEMP}/initramfs-blkid-temp/"
93         fi
94         cd ${TEMP}
95         mkdir -p "${TEMP}/initramfs-blkid-temp/sbin/"
96         [ "${DISKLABEL}" = '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/sbin/blkid" ||
97                 gen_die "Could not extract blkid binary cache!"; }
98         chmod a+x "${TEMP}/initramfs-blkid-temp/sbin/blkid"
99         cd "${TEMP}/initramfs-blkid-temp/"
100         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
101                         || gen_die "compressing blkid cpio"
102         cd "${TEMP}"
103         rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
104 }
105
106 #append_fuse() {
107 #       if [ -d "${TEMP}/initramfs-fuse-temp" ]
108 #       then
109 #               rm -r "${TEMP}/initramfs-fuse-temp"
110 #       fi
111 #       cd ${TEMP}
112 #       mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
113 #       tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
114 #       cd "${TEMP}/initramfs-fuse-temp/"
115 #       find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
116 #                       || gen_die "compressing fuse cpio"
117 #       rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
118 #}
119
120 append_unionfs_fuse() {
121         if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
122         then
123                 rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
124         fi
125         cd ${TEMP}
126         mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
127         bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
128                 gen_die 'Could not extract unionfs-fuse binary cache!'
129         chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
130         cd "${TEMP}/initramfs-unionfs-fuse-temp/"
131         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
132                         || gen_die "compressing unionfs fuse cpio"
133         cd "${TEMP}"
134         rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
135 }
136
137 #append_suspend(){
138 #       if [ -d "${TEMP}/initramfs-suspend-temp" ];
139 #       then
140 #               rm -r "${TEMP}/initramfs-suspend-temp/"
141 #       fi
142 #       print_info 1 'SUSPEND: Adding support (compiling binaries)...'
143 #       compile_suspend
144 #       mkdir -p "${TEMP}/initramfs-suspend-temp/"
145 #       /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
146 #               gen_die "Could not extract suspend binary cache!"
147 #       mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
148 #       cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
149 #               gen_die 'Could not copy /etc/suspend.conf'
150 #       cd "${TEMP}/initramfs-suspend-temp/"
151 #       find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
152 #                       || gen_die "compressing suspend cpio"
153 #       rm -r "${TEMP}/initramfs-suspend-temp/"
154 #}
155
156 append_multipath(){
157         if [ -d "${TEMP}/initramfs-multipath-temp" ]
158         then
159                 rm -r "${TEMP}/initramfs-multipath-temp"
160         fi
161         print_info 1 '  Multipath support being added'
162         mkdir -p "${TEMP}/initramfs-multipath-temp/bin/"
163         mkdir -p "${TEMP}/initramfs-multipath-temp/etc/" 
164         mkdir -p "${TEMP}/initramfs-multipath-temp/sbin/"
165         mkdir -p "${TEMP}/initramfs-multipath-temp/lib/"
166
167         # Copy files
168         copy_binaries "${TEMP}/initramfs-multipath-temp" "$(echo /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} /lib64/udev/scsi_id /bin/mountpoint)"
169
170         if [ -x /sbin/multipath ]
171         then
172                 cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this'
173         fi
174         # /etc/scsi_id.config does not exist in newer udevs
175         # copy it optionally.
176         if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ]
177         then
178                 cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config'
179         fi
180         cd "${TEMP}/initramfs-multipath-temp"
181         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
182                         || gen_die "compressing multipath cpio"
183         cd "${TEMP}"
184         rm -r "${TEMP}/initramfs-multipath-temp/"
185 }
186
187 append_dmraid(){
188         if [ -d "${TEMP}/initramfs-dmraid-temp" ]
189         then
190                 rm -r "${TEMP}/initramfs-dmraid-temp/"
191         fi
192         print_info 1 'DMRAID: Adding support (compiling binaries)...'
193         compile_dmraid
194         mkdir -p "${TEMP}/initramfs-dmraid-temp/"
195         /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
196                 gen_die "Could not extract dmraid binary cache!";
197         cd "${TEMP}/initramfs-dmraid-temp/"
198         RAID456=`find . -type f -name raid456.ko`
199         if [ -n "${RAID456}" ]
200         then
201                 cd "${RAID456/raid456.ko/}"
202                 ln -sf raid456.kp raid45.ko
203                 cd "${TEMP}/initramfs-dmraid-temp/"
204         fi
205         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
206                         || gen_die "compressing dmraid cpio"
207         cd "${TEMP}"
208         rm -r "${TEMP}/initramfs-dmraid-temp/"
209 }
210
211 append_iscsi(){
212         if [ -d "${TEMP}/initramfs-iscsi-temp" ]
213         then
214                 rm -r "${TEMP}/initramfs-iscsi-temp/"
215         fi
216         print_info 1 'iSCSI: Adding support (compiling binaries)...'
217         compile_iscsi
218         cd ${TEMP}
219         mkdir -p "${TEMP}/initramfs-iscsi-temp/bin/"
220         /bin/bzip2 -dc "${ISCSI_BINCACHE}" > "${TEMP}/initramfs-iscsi-temp/bin/iscsistart" ||
221                 gen_die "Could not extract iscsi binary cache!"
222         chmod a+x "${TEMP}/initramfs-iscsi-temp/bin/iscsistart"
223         cd "${TEMP}/initramfs-iscsi-temp/"
224         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
225                         || gen_die "compressing iscsi cpio"
226         cd "${TEMP}"
227         rm -rf "${TEMP}/initramfs-iscsi-temp" > /dev/null
228 }
229
230 append_lvm(){
231         if [ -d "${TEMP}/initramfs-lvm-temp" ]
232         then
233                 rm -r "${TEMP}/initramfs-lvm-temp/"
234         fi
235         cd ${TEMP}
236         mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
237         mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
238         if [ -e '/sbin/lvm.static' ]
239         then
240                 print_info 1 '          LVM: Adding support (using local static binary /sbin/lvm.static)...'
241                 cp /sbin/lvm.static "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
242                         gen_die 'Could not copy over lvm!'
243                 # See bug 382555
244                 if [ -e '/sbin/dmsetup.static' ]
245                 then
246                         cp /sbin/dmsetup.static "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
247                 fi
248         elif [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
249         then
250                 print_info 1 '          LVM: Adding support (using local static binary /sbin/lvm)...'
251                 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
252                         gen_die 'Could not copy over lvm!'
253                 # See bug 382555
254                 if [ -e '/sbin/dmsetup' ] && LC_ALL="C" ldd /sbin/dmsetup | grep -q 'not a dynamic executable'
255                 then
256                         cp /sbin/dmsetup "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
257                 fi
258         else
259                 print_info 1 '          LVM: Adding support (compiling binaries)...'
260                 compile_lvm
261                 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
262                         gen_die "Could not extract lvm binary cache!";
263                 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
264                         gen_die 'LVM error: Could not move lvm.static to lvm!'
265                 # See bug 382555
266                 mv ${TEMP}/initramfs-lvm-temp/sbin/dmsetup.static ${TEMP}/initramfs-lvm-temp/bin/dmsetup ||
267                         gen_die 'LVM error: Could not move dmsetup.static to dmsetup!'
268         fi
269         if [ -x /sbin/lvm ]
270         then
271 #               lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
272 #               ret=$?
273 #               if [ ${ret} != 0 ]
274 #               then
275                         cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
276                                 gen_die 'Could not copy over lvm.conf!'
277 #               else
278 #                       gen_die 'Could not copy over lvm.conf!'
279 #               fi
280         fi
281         cd "${TEMP}/initramfs-lvm-temp/"
282         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
283                         || gen_die "compressing lvm cpio"
284         cd "${TEMP}"
285         rm -r "${TEMP}/initramfs-lvm-temp/"
286 }
287
288 append_mdadm(){
289         if [ -d "${TEMP}/initramfs-mdadm-temp" ]
290         then
291                 rm -r "${TEMP}/initramfs-mdadm-temp/"
292         fi
293         cd ${TEMP}
294         mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
295         mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/"
296         if [ "${MDADM}" = '1' ]
297         then
298                 if [ -n "${MDADM_CONFIG}" ]
299                 then
300                         if [ -f "${MDADM_CONFIG}" ]
301                         then
302                                 cp -a "${MDADM_CONFIG}" "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \
303                                 || gen_die "Could not copy mdadm.conf!"
304                         else
305                                 gen_die 'sl${MDADM_CONFIG} does not exist!'
306                         fi
307                 else
308                         print_info 1 '          MDADM: Skipping inclusion of mdadm.conf'
309                 fi
310
311                 if [ -e '/sbin/mdadm' ] && LC_ALL="C" ldd /sbin/mdadm | grep -q 'not a dynamic executable' \
312                 && [ -e '/sbin/mdmon' ] && LC_ALL="C" ldd /sbin/mdmon | grep -q 'not a dynamic executable'
313                 then
314                         print_info 1 '          MDADM: Adding support (using local static binaries /sbin/mdadm and /sbin/mdmon)...'
315                         cp /sbin/mdadm /sbin/mdmon "${TEMP}/initramfs-mdadm-temp/sbin/" ||
316                                 gen_die 'Could not copy over mdadm!'
317                 else
318                         print_info 1 '          MDADM: Adding support (compiling binaries)...'
319                         compile_mdadm
320                         /bin/tar -jxpf "${MDADM_BINCACHE}" -C "${TEMP}/initramfs-mdadm-temp" ||
321                                 gen_die "Could not extract mdadm binary cache!";
322                 fi
323         fi
324         cd "${TEMP}/initramfs-mdadm-temp/"
325         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
326                         || gen_die "compressing mdadm cpio"
327         cd "${TEMP}"
328         rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
329 }
330
331 append_splash(){
332         splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
333         if [ -x "${splash_geninitramfs}" ]
334         then
335                 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
336                 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
337                 print_info 1 "  >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
338                 if [ -d "${TEMP}/initramfs-splash-temp" ]
339                 then
340                         rm -r "${TEMP}/initramfs-splash-temp/"
341                 fi
342                 mkdir -p "${TEMP}/initramfs-splash-temp"
343                 cd /
344                 local tmp=""
345                 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
346                 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
347                 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
348                         mkdir -p "${TEMP}/initramfs-splash-temp/etc"
349                         cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
350                 fi
351                 cd "${TEMP}/initramfs-splash-temp/"
352                 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
353                         || gen_die "compressing splash cpio"
354                 cd "${TEMP}"
355                 rm -r "${TEMP}/initramfs-splash-temp/"
356         else
357                 print_warning 1 '               >> No splash detected; skipping!'
358         fi
359 }
360
361 append_overlay(){
362         cd ${INITRAMFS_OVERLAY}
363         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
364                         || gen_die "compressing overlay cpio"
365 }
366
367 append_luks() {
368         if [ -d "${TEMP}/initramfs-luks-temp" ]
369         then
370                 rm -r "${TEMP}/initramfs-luks-temp/"
371         fi
372
373         mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/"
374         mkdir -p "${TEMP}/initramfs-luks-temp/sbin"
375         cd "${TEMP}/initramfs-luks-temp"
376
377         if isTrue ${LUKS}
378         then
379                 if is_static /bin/cryptsetup
380                 then
381                         print_info 1 "Including LUKS support"
382                         cp /bin/cryptsetup ${TEMP}/initramfs-luks-temp/sbin/cryptsetup
383                         chmod +x "${TEMP}/initramfs-luks-temp/sbin/cryptsetup"
384                 elif is_static /sbin/cryptsetup
385                 then
386                         print_info 1 "Including LUKS support"
387                         cp /sbin/cryptsetup ${TEMP}/initramfs-luks-temp/sbin/cryptsetup
388                         chmod +x "${TEMP}/initramfs-luks-temp/sbin/cryptsetup"
389                 else
390                         print_info 1 "LUKS support requires static cryptsetup at /bin/cryptsetup or /sbin/cryptsetup"
391                         print_info 1 "Not including LUKS support"
392                 fi
393         fi
394
395         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
396                 || gen_die "appending cryptsetup to cpio"
397
398         cd "${TEMP}"
399         rm -r "${TEMP}/initramfs-luks-temp/"
400 }
401
402 append_firmware() {
403         if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
404         then
405                 gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
406         fi
407         if [ -d "${TEMP}/initramfs-firmware-temp" ]
408         then
409                 rm -r "${TEMP}/initramfs-firmware-temp/"
410         fi
411         mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
412         cd "${TEMP}/initramfs-firmware-temp"
413         if [ -n "${FIRMWARE_FILES}" ]
414         then
415                 OLD_IFS=$IFS
416                 IFS=","
417                 for i in ${FIRMWARE_FILES}
418                 do
419                         cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
420                 done
421                 IFS=$OLD_IFS
422         else
423                 cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
424         fi
425         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
426                 || gen_die "appending firmware to cpio"
427         cd "${TEMP}"
428         rm -r "${TEMP}/initramfs-firmware-temp/"
429 }
430
431 append_gpg() {
432         if [ -d "${TEMP}/initramfs-gpg-temp" ]
433         then
434                 rm -r "${TEMP}/initramfs-gpg-temp"
435         fi
436         cd ${TEMP}
437         mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/"
438         if [ ! -e ${GPG_BINCACHE} ] ; then
439                 print_info 1 '          GPG: Adding support (compiling binaries)...'
440                 compile_gpg
441         fi
442         bzip2 -dc "${GPG_BINCACHE}" > "${TEMP}/initramfs-gpg-temp/sbin/gpg" ||
443                 gen_die 'Could not extract gpg binary cache!'
444         chmod a+x "${TEMP}/initramfs-gpg-temp/sbin/gpg"
445         cd "${TEMP}/initramfs-gpg-temp/"
446         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
447         rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
448 }
449
450 print_list()
451 {
452         local x
453         for x in ${*}
454         do
455                 echo ${x}
456         done
457 }
458
459 append_modules() {
460         local group
461         local group_modules
462         local MOD_EXT=".ko"
463
464         print_info 2 "initramfs: >> Searching for modules..."
465         if [ "${INSTALL_MOD_PATH}" != '' ]
466         then
467           cd ${INSTALL_MOD_PATH}
468         else
469           cd /
470         fi
471
472         if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
473         then
474                 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
475         fi
476         mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
477         for i in `gen_dep_list`
478         do
479                 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
480                 if [ -z "${mymod}" ]
481                 then
482                         print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
483                         continue;
484                 fi
485
486                 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
487                 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
488         done
489
490         cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
491
492         mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
493         for group_modules in ${!MODULES_*}; do
494                 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
495                 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
496         done
497         cd "${TEMP}/initramfs-modules-${KV}-temp/"
498         find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
499                         || gen_die "compressing modules cpio"
500         cd "${TEMP}"
501         rm -r "${TEMP}/initramfs-modules-${KV}-temp/"   
502 }
503
504 # check for static linked file with objdump
505 is_static() {
506         LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
507         return $?
508 }
509
510 append_auxilary() {
511         if [ -d "${TEMP}/initramfs-aux-temp" ]
512         then
513                 rm -r "${TEMP}/initramfs-aux-temp/"
514         fi
515         mkdir -p "${TEMP}/initramfs-aux-temp/etc"
516         mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
517         if [ -f "${CMD_LINUXRC}" ]
518         then
519                 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
520                 print_info 2 "        >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
521         else
522                 if isTrue ${NETBOOT}
523                 then
524                         cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init"
525                 else
526                         if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
527                         then
528                                 cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
529                         else
530                                 cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
531                         fi
532                 fi
533         fi
534
535         # Make sure it's executable
536         chmod 0755 "${TEMP}/initramfs-aux-temp/init"
537
538         # Make a symlink to init .. incase we are bundled inside the kernel as one
539         # big cpio.
540         cd ${TEMP}/initramfs-aux-temp
541         ln -s init linuxrc
542 #       ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
543
544         if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
545         then
546                 cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
547         else
548                 cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
549         fi
550
551         if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
552         then
553                 cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
554         else
555                 cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
556         fi
557
558         if [ -n "${REAL_ROOT}" ]
559         then
560                 sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
561         fi
562
563         echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
564         for group_modules in ${!MODULES_*}; do
565                 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
566                 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
567         done
568         echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
569
570         if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
571         then
572                 cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
573         else
574                 cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
575         fi
576         if isTrue $CMD_DOKEYMAPAUTO
577         then
578                 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
579         fi
580         if isTrue $CMD_KEYMAP
581         then
582                 mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
583                 /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/defaults/keymaps.tar.gz"
584         fi
585
586         cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
587         cd ${TEMP}
588         chmod +x "${TEMP}/initramfs-aux-temp/init"
589         chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
590         chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
591         chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
592
593         if isTrue ${NETBOOT}
594         then
595                 cd "${GK_SHARE}/netboot/misc"
596                 cp -pPRf * "${TEMP}/initramfs-aux-temp/"
597         fi
598
599         cd "${TEMP}/initramfs-aux-temp/"
600         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
601                         || gen_die "compressing auxilary cpio"
602         cd "${TEMP}"
603         rm -r "${TEMP}/initramfs-aux-temp/"
604 }
605
606 append_data() {
607         local name=$1 var=$2
608         local func="append_${name}"
609
610         [ $# -eq 0 ] && gen_die "append_data() called with zero arguments"
611         if [ $# -eq 1 ] || isTrue ${var}
612         then
613             print_info 1 "        >> Appending ${name} cpio data..."
614             ${func} || gen_die "${func}() failed"
615         fi
616 }
617
618 create_initramfs() {
619         local compress_ext=""
620         print_info 1 "initramfs: >> Initializing..."
621
622         # Create empty cpio
623         CPIO="${TMPDIR}/initramfs-${KV}"
624         echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
625                 || gen_die "Could not create empty cpio at ${CPIO}"
626
627         append_data 'base_layout'
628         append_data 'auxilary' "${BUSYBOX}"
629         append_data 'busybox' "${BUSYBOX}"
630         append_data 'lvm' "${LVM}"
631         append_data 'dmraid' "${DMRAID}"
632         append_data 'iscsi' "${ISCSI}"
633         append_data 'mdadm' "${MDADM}"
634         append_data 'luks' "${LUKS}"
635         append_data 'multipath' "${MULTIPATH}"
636         append_data 'gpg' "${GPG}"
637
638         if [ "${RAMDISKMODULES}" = '1' ]
639         then
640                 append_data 'modules'
641         else
642                 print_info 1 "initramfs: Not copying modules..."
643         fi
644
645         append_data 'blkid' "${DISKLABEL}"
646
647         append_data 'unionfs_fuse' "${UNIONFS}"
648
649         append_data 'splash' "${SPLASH}"
650
651         if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
652         then
653                 append_data 'firmware'
654         fi
655
656         # This should always be appended last
657         if [ "${INITRAMFS_OVERLAY}" != '' ]
658         then
659                 append_data 'overlay'
660         fi
661
662         # Implement support for disabling compression
663         if isTrue "${COMPRESS_INITRD}"
664         then
665                 compress_ext=".gz"
666                 print_info 1 "        >> Compressing cpio data..."
667                 gzip -9 "${CPIO}" || gen_die "Compression failed"
668                 mv -f "${CPIO}.gz" "${CPIO}" || gen_die "Rename failed"
669         fi
670
671
672         if isTrue "${INTEGRATED_INITRAMFS}"
673         then
674 #               cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/usr/initramfs_data.cpio.gz
675                 mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio${compress_ext}
676 #               sed -i "s|^.*CONFIG_INITRAMFS_SOURCE=.*$|CONFIG_INITRAMFS_SOURCE=\"${TMPDIR}/initramfs-${KV}.cpio.gz\"|" ${KERNEL_DIR}/.config
677                 sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
678                 echo -e "CONFIG_INITRAMFS_SOURCE=\"${TMPDIR}/initramfs-${KV}.cpio${compress_ext}\"\nCONFIG_INITRAMFS_ROOT_UID=0\nCONFIG_INITRAMFS_ROOT_GID=0" >> ${KERNEL_DIR}/.config
679         fi
680
681         if isTrue "${CMD_INSTALL}"
682         then
683                 if ! isTrue "${INTEGRATED_INITRAMFS}"
684                 then
685                         copy_image_with_preserve "initramfs" \
686                                 "${TMPDIR}/initramfs-${KV}" \
687                                 "initramfs-${KNAME}-${ARCH}-${KV}"
688                 fi
689         fi
690 }