Patch to actually use busybox bincache. Thanks to Pat Double
[genkernel.git] / gen_initramfs.sh
1 #!/bin/bash
2
3 CPIO_ARGS="--quiet -o -H newc"
4
5 append_base_layout() {
6         if [ -d "${TEMP}/initramfs-base-temp" ]
7         then
8                 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
9         fi
10         mkdir -p ${TEMP}/initramfs-base-temp/dev
11         mkdir -p ${TEMP}/initramfs-base-temp/bin
12         mkdir -p ${TEMP}/initramfs-base-temp/etc
13         mkdir -p ${TEMP}/initramfs-base-temp/usr
14         mkdir -p ${TEMP}/initramfs-base-temp/proc
15         mkdir -p ${TEMP}/initramfs-base-temp/temp
16         mkdir -p ${TEMP}/initramfs-base-temp/sys
17         mkdir -p ${TEMP}/initramfs-temp/.initrd
18         mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
19         mkdir -p ${TEMP}/initramfs-base-temp/sbin
20         mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
21         mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
22         ln -s  lib  ${TEMP}/initramfs-base-temp/lib64
23
24         echo "/dev/ram0     /           ext2    defaults        0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
25         echo "proc          /proc       proc    defaults    0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
26         
27         if [ "${DEVFS}" -eq '1' ]
28         then
29             echo "REGISTER        .*           MKOLDCOMPAT" > ${TEMP}/initramfs-base-temp/etc/devfsd.conf
30             echo "UNREGISTER      .*           RMOLDCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
31             echo "REGISTER        .*           MKNEWCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
32             echo "UNREGISTER      .*           RMNEWCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
33         fi
34
35         cd ${TEMP}/initramfs-base-temp/dev
36         mknod -m 660 console c 5 1
37         mknod -m 660 null c 1 3
38         mknod -m 600 tty1 c 4 1
39         cd "${TEMP}/initramfs-base-temp/"
40         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
41         rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
42 }
43
44 append_busybox() {
45         if [ -d "${TEMP}/initramfs-busybox-temp" ]
46         then
47                 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
48         fi
49         mkdir -p "${TEMP}/initramfs-busybox-temp/bin/" 
50
51         cp "${GK_SHARE}/generic/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/bin/
52         chmod +x "${TEMP}/initramfs-busybox-temp/bin/udhcpc.scripts"
53         cp "${BUSYBOX_BINCACHE}" "${TEMP}/initramfs-busybox-temp/bin/busybox.tar.bz2" ||
54                 gen_die 'Could not copy busybox from bincache!'
55         tar -xjf "${TEMP}/initramfs-busybox-temp/bin/busybox.tar.bz2" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
56                 gen_die 'Could not extract busybox bincache!'
57         chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
58
59         # down devfsd we use with dietlibc
60 #       cp "${DEVFSD_CONF_BINCACHE}" "${TEMP}/initramfs-temp/etc/devfsd.conf.bz2" ||
61 #               gen_die "could not copy devfsd.conf from bincache"
62 #       bunzip2 "${TEMP}/initramfs-temp/etc/devfsd.conf.bz2" ||
63 #               gen_die "could not uncompress devfsd.conf"
64         for i in '[' ash sh mount uname echo cut; do
65                 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
66                 ln ${TEMP}/initramfs-busybox-temp/bin/busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
67                         gen_die "Busybox error: could not link ${i}!"
68         done
69         
70         cd "${TEMP}/initramfs-busybox-temp/"
71         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
72         rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
73 }
74
75 append_insmod() {
76         if [ -d "${TEMP}/initramfs-insmod-temp" ]
77         then
78                 rm -rf "${TEMP}/initramfs-insmod-temp" > /dev/null
79         fi
80         mkdir -p "${TEMP}/initramfs-insmod-temp/bin/" 
81         cp "${MODULE_INIT_TOOLS_BINCACHE}" "${TEMP}/initramfs-insmod-temp/bin/insmod.static.bz2" ||
82                 gen_die 'Could not copy insmod.static from bincache!'
83
84         bunzip2 "${TEMP}/initramfs-insmod-temp/bin/insmod.static.bz2" ||
85                 gen_die 'Could not uncompress insmod.static!'
86         mv "${TEMP}/initramfs-insmod-temp/bin/insmod.static" "${TEMP}/initramfs-insmod-temp/bin/insmod"
87         chmod +x "${TEMP}/initramfs-insmod-temp/bin/insmod"
88         
89         cd "${TEMP}/initramfs-insmod-temp/"
90         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
91         rm -rf "${TEMP}/initramfs-insmod-temp" > /dev/null
92 }
93
94 append_udev(){
95         if [ -d "${TEMP}/initramfs-udev-temp" ]
96         then
97                 rm -r "${TEMP}/initramfs-udev-temp/"
98         fi
99         cd ${TEMP}
100         mkdir -p "${TEMP}/initramfs-udev-temp/bin/"
101         [ "${UDEV}" -eq '1' ] && { /bin/tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initramfs-udev-temp" ||
102                 gen_die "Could not extract udev binary cache!"; }
103         cd "${TEMP}/initramfs-udev-temp/"
104         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
105         rm -rf "${TEMP}/initramfs-udev-temp" > /dev/null
106 }
107
108 append_blkid(){
109         if [ -d "${TEMP}/initramfs-blkid-temp" ]
110         then
111                 rm -r "${TEMP}/initramfs-blkid-temp/"
112         fi
113         cd ${TEMP}
114         mkdir -p "${TEMP}/initramfs-blkid-temp/bin/"
115         [ "${DISKLABEL}" -eq '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/bin/blkid" ||
116                 gen_die "Could not extract blkid binary cache!"; }
117         chmod a+x "${TEMP}/initramfs-blkid-temp/bin/blkid"
118         cd "${TEMP}/initramfs-blkid-temp/"
119         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
120         rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
121 }
122
123 append_devfs(){
124         if [ -d "${TEMP}/initramfs-devfs-temp" ]
125         then
126                 rm -r "${TEMP}/initramfs-devfs-temp/"
127         fi
128         cd ${TEMP}
129         print_info 1 'DEVFS: Adding support (compiling binaries)...'
130         compile_devfsd
131         mkdir -p "${TEMP}/initramfs-devfs-temp/bin/"
132         cp "${DEVFSD_BINCACHE}" "${TEMP}/initramfs-devfs-temp/bin/devfsd.bz2" || gen_die "could not copy devfsd executable from bincache"
133         bunzip2 "${TEMP}/initramfs-devfs-temp/bin/devfsd.bz2" || gen_die "could not uncompress devfsd"
134         chmod +x "${TEMP}/initramfs-devfs-temp/bin/devfsd"
135         cd "${TEMP}/initramfs-devfs-temp/"
136         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
137         rm -rf "${TEMP}/initramfs-devfs-temp" > /dev/null
138 }
139
140 append_unionfs_modules(){
141         if [ -d "${TEMP}/initramfs-unionfs-modules-temp" ]
142         then
143                 rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
144         fi
145         print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
146         compile_unionfs_modules
147         mkdir -p "${TEMP}/initramfs-unionfs-modules-temp/"
148         /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initramfs-unionfs-modules-temp" ||
149                 gen_die "Could not extract unionfs modules binary cache!";
150         cd "${TEMP}/initramfs-unionfs-modules-temp/"
151         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
152         rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
153 }
154
155 append_unionfs_tools(){
156         if [ -d "${TEMP}/initramfs-unionfs-tools-temp" ]
157         then
158                 rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
159         fi
160         print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
161         compile_unionfs_utils
162         mkdir -p "${TEMP}/initramfs-unionfs-tools-temp/bin/"
163         /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initramfs-unionfs-tools-temp" ||
164                 gen_die "Could not extract unionfs tools binary cache!";
165         cd "${TEMP}/initramfs-unionfs-tools-temp/"
166         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
167         rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
168 }
169
170 append_suspend(){
171         if [ -d "${TEMP}/initramfs-suspend-temp" ];
172         then
173                 rm -r "${TEMP}/initramfs-suspend-temp/"
174         fi
175         print_info 1 'SUSPEND: Adding support (compiling binaries)...'
176         compile_suspend
177         mkdir -p "${TEMP}/initramfs-suspend-temp/"
178         /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
179                 gen_die "Could not extract suspend binary cache!"
180         mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
181         cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
182                 gen_die 'Could not copy /etc/suspend.conf'
183         cd "${TEMP}/initramfs-suspend-temp/"
184         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
185         rm -r "${TEMP}/initramfs-suspend-temp/"
186 }
187
188 append_dmraid(){
189         if [ -d "${TEMP}/initramfs-dmraid-temp" ]
190         then
191                 rm -r "${TEMP}/initramfs-dmraid-temp/"
192         fi
193         print_info 1 'DMRAID: Adding support (compiling binaries)...'
194         compile_dmraid
195         mkdir -p "${TEMP}/initramfs-dmraid-temp/"
196         /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
197                 gen_die "Could not extract dmraid binary cache!";
198         cd "${TEMP}/initramfs-dmraid-temp/"
199         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
200         rm -r "${TEMP}/initramfs-dmraid-temp/"
201 }
202
203 append_lvm2(){
204         if [ -d "${TEMP}/initramfs-lvm2-temp" ]
205         then
206                 rm -r "${TEMP}/initramfs-lvm2-temp/"
207         fi
208         cd ${TEMP}
209         mkdir -p "${TEMP}/initramfs-lvm2-temp/bin/"
210         mkdir -p "${TEMP}/initramfs-lvm2-temp/etc/lvm/"
211         if [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
212         then
213                 print_info 1 '          LVM2: Adding support (using local static binaries)...'
214                 cp /sbin/lvm "${TEMP}/initramfs-lvm2-temp/bin/lvm" ||
215                         gen_die 'Could not copy over lvm!'
216         else
217                 print_info 1 '          LVM2: Adding support (compiling binaries)...'
218                 compile_lvm2
219                 /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initramfs-lvm2-temp" ||
220                         gen_die "Could not extract lvm2 binary cache!";
221                 mv ${TEMP}/initramfs-lvm2-temp/sbin/lvm.static ${TEMP}/initramfs-lvm2-temp/bin/lvm ||
222                         gen_die 'LVM2 error: Could not move lvm.static to lvm!'
223         fi
224         if [ -x /sbin/lvm ]
225         then
226 #               lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
227 #               ret=$?
228 #               if [ ${ret} != 0 ]
229 #               then
230                         cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm2-temp/etc/lvm/" ||
231                                 gen_die 'Could not copy over lvm.conf!'
232 #               else
233 #                       gen_die 'Could not copy over lvm.conf!'
234 #               fi
235         fi
236         cd "${TEMP}/initramfs-lvm2-temp/"
237         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
238         rm -r "${TEMP}/initramfs-lvm2-temp/"
239 }
240
241 append_evms2(){
242         if [ -d "${TEMP}/initramfs-evms2-temp" ]
243         then
244                 rm -r "${TEMP}/initramfs-evms2-temp/"
245         fi
246         mkdir -p "${TEMP}/initramfs-evms2-temp/lib/evms"
247         mkdir -p "${TEMP}/initramfs-evms2-temp/etc/"
248         mkdir -p "${TEMP}/initramfs-evms2-temp/bin/"
249         mkdir -p "${TEMP}/initramfs-evms2-temp/sbin/"
250         if [ "${EVMS2}" -eq '1' ]
251         then
252                 print_info 1 '          EVMS2: Adding support...'
253                 mkdir -p ${TEMP}/initramfs-evms2-temp/lib
254                 cp -a /lib/ld-* "${TEMP}/initramfs-evms2-temp/lib" \
255                         || gen_die 'Could not copy files for EVMS2!'
256                 if [ -n "`ls /lib/libgcc_s*`" ]
257                 then
258                         cp -a /lib/libgcc_s* "${TEMP}/initramfs-evms2-temp/lib" \
259                                 || gen_die 'Could not copy files for EVMS2!'
260                 fi
261                 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initramfs-evms2-temp/lib" \
262                         || gen_die 'Could not copy files for EVMS2!'
263                 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initramfs-evms2-temp/lib" \
264                         || gen_die 'Could not copy files for EVMS2!'
265                 cp -a /lib/libpthread* "${TEMP}/initramfs-evms2-temp/lib" \
266                         || gen_die 'Could not copy files for EVMS2!'
267                 cp -a /lib/libuuid*so* "${TEMP}/initramfs-evms2-temp/lib" \
268                         || gen_die 'Could not copy files for EVMS2!'
269                 cp -a /lib/libevms*so* "${TEMP}/initramfs-evms2-temp/lib" \
270                         || gen_die 'Could not copy files for EVMS2!'
271                 cp -a /lib/evms "${TEMP}/initramfs-evms2-temp/lib" \
272                         || gen_die 'Could not copy files for EVMS2!'
273                 cp -a /lib/evms/* "${TEMP}/initramfs-evms2-temp/lib/evms" \
274                         || gen_die 'Could not copy files for EVMS2!'
275                 cp -a /etc/evms.conf "${TEMP}/initramfs-evms2-temp/etc" \
276                         || gen_die 'Could not copy files for EVMS2!'
277                 cp /sbin/evms_activate "${TEMP}/initramfs-evms2-temp/sbin" \
278                         || gen_die 'Could not copy over evms_activate!'
279
280                 # Fix EVMS2 complaining that it can't find the swap utilities.
281                 # These are not required in the initramfs
282                 for swap_libs in "${TEMP}/initramfs-evms2-temp/lib/evms/*/swap*.so"
283                 do
284                         rm ${swap_libs}
285                 done
286         fi
287         cd "${TEMP}/initramfs-evms2-temp/"
288         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
289         rm -r "${TEMP}/initramfs-evms2-temp/"
290 }
291
292 append_gensplash(){
293         if [ -x /usr/bin/splash_geninitramfs ] || [ -x /sbin/splash_geninitramfs ]
294         then
295                 [ -z "${GENSPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
296                 [ -z "${GENSPLASH_THEME}" ] && GENSPLASH_THEME=default
297                 print_info 1 "  >> Installing gensplash [ using the ${GENSPLASH_THEME} theme ]..."
298                 if [ -d "${TEMP}/initramfs-gensplash-temp" ]
299                 then
300                         rm -r "${TEMP}/initramfs-gensplash-temp/"
301                 fi
302                 mkdir -p "${TEMP}/initramfs-gensplash-temp"
303                 cd /
304                 local tmp=""
305                 [ -n "${GENSPLASH_RES}" ] && tmp="-r ${GENSPLASH_RES}"
306                 splash_geninitramfs -c "${TEMP}/initramfs-gensplash-temp" ${tmp} ${GENSPLASH_THEME} || gen_die "Could not build splash cpio archive"
307                 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
308                         mkdir -p "${TEMP}/initramfs-gensplash-temp/etc"
309                         cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-gensplash-temp/etc"
310                 fi
311                 cd "${TEMP}/initramfs-gensplash-temp/"
312                 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
313                         || gen_die "compressing splash cpio"
314                 rm -r "${TEMP}/initramfs-gensplash-temp/"
315         else
316                 print_warning 1 '               >> No splash detected; skipping!'
317         fi
318 }
319
320 append_overlay(){
321         cd ${INITRAMFS_OVERLAY}
322         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
323 }
324 print_list()
325 {
326         local x
327         for x in ${*}
328         do
329                 echo ${x}
330         done
331 }
332
333 append_modules() {
334         local group
335         local group_modules
336         local MOD_EXT=".ko"
337
338         print_info 2 "initramfs: >> Searching for modules..."
339         if [ "${INSTALL_MOD_PATH}" != '' ]
340         then
341           cd ${INSTALL_MOD_PATH}
342         else
343           cd /
344         fi
345         
346         if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
347         then
348                 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
349         fi
350         mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"       
351         for i in `gen_dep_list`
352         do
353                 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
354                 if [ -z "${mymod}" ]
355                 then
356                         print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
357                         continue;
358                 fi
359                 
360                 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
361                 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
362         done
363         
364         cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
365
366         mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
367         for group_modules in ${!MODULES_*}; do
368                 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
369                 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
370         done
371         cd "${TEMP}/initramfs-modules-${KV}-temp/"
372         find . | cpio ${CPIO_ARGS} --append -F "${CPIO}"
373         rm -r "${TEMP}/initramfs-modules-${KV}-temp/"   
374 }
375
376 # check for static linked file with objdump
377 is_static() {
378         LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
379         return $?
380 }
381
382 append_auxilary() {
383         if [ -d "${TEMP}/initramfs-aux-temp" ]
384         then
385                 rm -r "${TEMP}/initramfs-aux-temp/"
386         fi
387         mkdir -p "${TEMP}/initramfs-aux-temp/etc"       
388         mkdir -p "${TEMP}/initramfs-aux-temp/sbin"      
389         if [ -f "${CMD_LINUXRC}" ]
390         then
391                 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
392                 print_info 2 "        >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
393         else    
394                 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
395                 then
396                         cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
397                 else
398                         cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initramfs-aux-temp/init"
399                 fi
400         fi
401
402         # Make sure it's executable
403         chmod 0755 "${TEMP}/initramfs-aux-temp/init"
404
405         # Make a symlink to init .. incase we are bundled inside the kernel as one
406         # big cpio.
407         cd ${TEMP}/initramfs-aux-temp
408         ln -s init linuxrc
409 #       ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc 
410
411         if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
412         then
413                 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
414         else    
415                 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
416         fi
417
418         if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
419         then
420                 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
421         else
422                 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
423         fi
424         
425         echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"  
426         for group_modules in ${!MODULES_*}; do
427                 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
428                 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
429         done
430         echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"    
431
432         if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
433         then
434                 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
435         else
436                 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
437         fi
438         if isTrue $CMD_DOKEYMAPAUTO
439         then
440                 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
441         fi
442         mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
443         /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
444         if isTrue $CMD_SLOWUSB
445         then
446                 echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
447         fi
448         if isTrue ${LUKS}
449         then
450                 if is_static /bin/cryptsetup
451                 then
452                         print_info 1 "Including LUKS support"
453                         rm -f ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
454                         cp /bin/cryptsetup ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
455                         chmod +x "${TEMP}/initramfs-aux-temp/sbin/cryptsetup"
456                 else
457                         print_info 1 "LUKS support requires static cryptsetup at /bin/cryptsetup"
458                         print_info 1 "Not including LUKS support"
459                 fi
460         fi
461
462         cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
463         cd ${TEMP}
464         chmod +x "${TEMP}/initramfs-aux-temp/init"
465         chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
466         chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
467         chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
468         cd "${TEMP}/initramfs-aux-temp/"
469         find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
470         rm -r "${TEMP}/initramfs-aux-temp/"     
471 }
472
473 append_data() {
474         local name=$1 var=$2
475         local func="append_${name}"
476
477         if [ $# -eq '1' ] || [ "${var}" -eq '1' ]
478         then
479             print_info 1 "        >> Appending ${name} cpio data..."
480             ${func}
481         fi
482 }
483
484 create_initramfs() {
485         print_info 1 "initramfs: >> Initializing..."
486
487         # Create empty cpio
488         CPIO="${TMPDIR}/initramfs-${KV}"
489         echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
490                 || gen_die "Could not create empty cpio at ${CPIO}"
491
492         append_data 'base_layout'
493         append_data 'auxilary'
494         append_data 'busybox' "${BUSYBOX}"
495         append_data 'devfs' "${DEVFS}"
496 #       append_data 'udev' "${UDEV}"
497         append_data 'unionfs_modules' "${UNIONFS}"
498         append_data 'unionfs_tools' "${UNIONFS}"
499         append_data 'suspend' "${SUSPEND}"
500         append_data 'lvm2' "${LVM2}"
501         append_data 'dmraid' "${DMRAID}"
502         append_data 'evms2' "${EVMS2}"
503         
504         if [ "${NOINITRDMODULES}" = '' ]
505         then
506                 append_data 'insmod'
507                 append_data 'modules'
508         else
509                 print_info 1 "initramfs: Not copying modules..."
510         fi
511
512         append_data 'blkid' "${DISKLABEL}"
513         append_data 'gensplash' "${GENSPLASH}"
514
515         # This should always be appended last
516         if [ "${INITRAMFS_OVERLAY}" != '' ]
517         then
518                 append_data 'overlay'
519         fi
520
521         gzip -9 "${CPIO}"
522         mv -f "${CPIO}.gz" "${CPIO}"
523
524         # Pegasos hack for merging the initramfs into the kernel at compile time
525         [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
526                 [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
527                         cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/arch/powerpc/boot/ramdisk.image.gz &&
528                         rm ${TMPDIR}/initramfs-${KV}
529
530         # Mips also mimics Pegasos to merge the initramfs into the kernel
531         if [ ${BUILD_INITRAMFS} -eq 1 ]; then
532                 cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/initramfs.cpio.gz
533                 gunzip -f ${KERNEL_DIR}/initramfs.cpio.gz
534         fi
535
536         if ! isTrue "${CMD_NOINSTALL}"
537         then
538                 if [ "${GENERATE_Z_IMAGE}" != '1' ]
539                 then
540                         copy_image_with_preserve "initramfs" \
541                                 "${TMPDIR}/initramfs-${KV}" \
542                                 "initramfs-${KNAME}-${ARCH}-${KV}"
543                 fi
544         fi
545 }