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