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