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