Should check for /sbin/splash_geninitramfs instead of /usr/sbin/...
[genkernel.git] / gen_initramfs.sh
1 #!/bin/bash
2
3 create_base_layout_cpio() {
4         if [ -d "${TEMP}/initramfs-base-temp" ]
5         then
6                 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
7         fi
8         mkdir -p ${TEMP}/initramfs-base-temp/dev
9         mkdir -p ${TEMP}/initramfs-base-temp/bin
10         mkdir -p ${TEMP}/initramfs-base-temp/etc
11         mkdir -p ${TEMP}/initramfs-base-temp/usr
12         mkdir -p ${TEMP}/initramfs-base-temp/proc
13         mkdir -p ${TEMP}/initramfs-base-temp/temp
14         mkdir -p ${TEMP}/initramfs-base-temp/sys
15         mkdir -p ${TEMP}/initramfs-temp/.initrd
16         mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
17         mkdir -p ${TEMP}/initramfs-base-temp/sbin
18         mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
19         mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
20         ln -s  ../lib  ${TEMP}/initramfs-base-temp/lib64
21
22         echo "/dev/ram0     /           ext2    defaults        0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
23         echo "proc          /proc       proc    defaults    0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
24         
25         if [ "${DEVFS}" -eq '1' ]
26         then
27             echo "REGISTER        .*           MKOLDCOMPAT" > ${TEMP}/initramfs-base-temp/etc/devfsd.conf
28             echo "UNREGISTER      .*           RMOLDCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
29             echo "REGISTER        .*           MKNEWCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
30             echo "UNREGISTER      .*           RMNEWCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
31         fi
32
33         cd ${TEMP}/initramfs-base-temp/dev
34         mknod -m 660 console c 5 1
35         mknod -m 660 null c 1 3
36         mknod -m 600 tty1 c 4 1
37         cd "${TEMP}/initramfs-base-temp/"
38         find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-base-layout.cpio.gz
39         rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
40 }
41
42 create_busybox_cpio() {
43         if [ -d "${TEMP}/initramfs-busybox-temp" ]
44         then
45                 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
46         fi
47         mkdir -p "${TEMP}/initramfs-busybox-temp/bin/" 
48         cp "${BUSYBOX_BINCACHE}" "${TEMP}/initramfs-busybox-temp/bin/busybox.bz2" ||
49                 gen_die 'Could not copy busybox from bincache!'
50         bunzip2 "${TEMP}/initramfs-busybox-temp/bin/busybox.bz2" ||
51                 gen_die 'Could not uncompress busybox!'
52         chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
53
54         # down devfsd we use with dietlibc
55 #       cp "${DEVFSD_CONF_BINCACHE}" "${TEMP}/initramfs-temp/etc/devfsd.conf.bz2" ||
56 #               gen_die "could not copy devfsd.conf from bincache"
57 #       bunzip2 "${TEMP}/initramfs-temp/etc/devfsd.conf.bz2" ||
58 #               gen_die "could not uncompress devfsd.conf"
59         for i in '[' ash sh mount uname echo cut; do
60                 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
61                 ln ${TEMP}/initramfs-busybox-temp/bin/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 --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-busybox-${BUSYBOX_VER}.cpio.gz
67         rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
68 }
69
70 create_insmod_cpio() {
71         if [ -d "${TEMP}/initramfs-insmod-temp" ]
72         then
73                 rm -rf "${TEMP}/initramfs-insmod-temp" > /dev/null
74         fi
75         mkdir -p "${TEMP}/initramfs-insmod-temp/bin/" 
76         cp "${MODULE_INIT_TOOLS_BINCACHE}" "${TEMP}/initramfs-insmod-temp/bin/insmod.static.bz2" ||
77                 gen_die 'Could not copy insmod.static from bincache!'
78
79         bunzip2 "${TEMP}/initramfs-insmod-temp/bin/insmod.static.bz2" ||
80                 gen_die 'Could not uncompress insmod.static!'
81         mv "${TEMP}/initramfs-insmod-temp/bin/insmod.static" "${TEMP}/initramfs-insmod-temp/bin/insmod"
82         chmod +x "${TEMP}/initramfs-insmod-temp/bin/insmod"
83         
84         cd "${TEMP}/initramfs-insmod-temp/"
85         find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-insmod-${MODULE_INIT_TOOLS_VER}.cpio.gz
86         rm -rf "${TEMP}/initramfs-insmod-temp" > /dev/null
87 }
88
89 create_udev_cpio(){
90         if [ -d "${TEMP}/initramfs-udev-temp" ]
91         then
92                 rm -r "${TEMP}/initramfs-udev-temp/"
93         fi
94         cd ${TEMP}
95         mkdir -p "${TEMP}/initramfs-udev-temp/bin/"
96         [ "${UDEV}" -eq '1' ] && { /bin/tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initramfs-udev-temp" ||
97                 gen_die "Could not extract udev binary cache!"; }
98         cd "${TEMP}/initramfs-udev-temp/"
99         find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-udev-${UDEV_VER}.cpio.gz
100         rm -rf "${TEMP}/initramfs-udev-temp" > /dev/null
101 }
102
103 create_blkid_cpio(){
104         if [ -d "${TEMP}/initramfs-blkid-temp" ]
105         then
106                 rm -r "${TEMP}/initramfs-blkid-temp/"
107         fi
108         cd ${TEMP}
109         mkdir -p "${TEMP}/initramfs-blkid-temp/bin/"
110         [ "${DISKLABEL}" -eq '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/bin/blkid" ||
111                 gen_die "Could not extract blkid binary cache!"; }
112         chmod a+x "${TEMP}/initramfs-blkid-temp/bin/blkid"
113         cd "${TEMP}/initramfs-blkid-temp/"
114         find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-blkid-${E2FSPROGS_VER}.cpio.gz
115         rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
116 }
117
118 create_devfs_cpio(){
119         if [ -d "${TEMP}/initramfs-devfs-temp" ]
120         then
121                 rm -r "${TEMP}/initramfs-devfs-temp/"
122         fi
123         cd ${TEMP}
124         print_info 1 'DEVFS: Adding support (compiling binaries)...'
125         compile_devfsd
126         mkdir -p "${TEMP}/initramfs-devfs-temp/bin/"
127         cp "${DEVFSD_BINCACHE}" "${TEMP}/initramfs-devfs-temp/bin/devfsd.bz2" || gen_die "could not copy devfsd executable from bincache"
128         bunzip2 "${TEMP}/initramfs-devfs-temp/bin/devfsd.bz2" || gen_die "could not uncompress devfsd"
129         chmod +x "${TEMP}/initramfs-devfs-temp/bin/devfsd"
130         cd "${TEMP}/initramfs-devfs-temp/"
131         find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-devfs-${DEVFSD_VER}.cpio.gz
132         rm -rf "${TEMP}/initramfs-devfs-temp" > /dev/null
133 }
134
135 create_unionfs_modules_cpio(){
136         #UNIONFS Modules
137         if [ "${UNIONFS}" -eq '1' ]
138         then
139                 if [ -d "${TEMP}/initramfs-unionfs-modules-temp" ]
140                 then
141                         rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
142                 fi
143                 print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
144                 compile_unionfs_modules
145                 mkdir -p "${TEMP}/initramfs-unionfs-modules-temp/"
146                 /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initramfs-unionfs-modules-temp" ||
147                         gen_die "Could not extract unionfs modules binary cache!";
148         cd "${TEMP}/initramfs-unionfs-modules-temp/"
149         find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz
150         rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
151         fi
152 }
153
154 create_unionfs_tools_cpio(){
155         #UNIONFS Tools
156         if [ "${UNIONFS}" -eq '1' ]
157         then
158                 if [ -d "${TEMP}/initramfs-unionfs-tools-temp" ]
159                 then
160                         rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
161                 fi
162                 print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
163                 compile_unionfs_utils
164                 mkdir -p "${TEMP}/initramfs-unionfs-tools-temp/bin/"
165                 /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initramfs-unionfs-tools-temp" ||
166                         gen_die "Could not extract unionfs tools binary cache!";
167                 cd "${TEMP}/initramfs-unionfs-tools-temp/"
168                 find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz
169                 rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
170         fi                                                                                      
171 }
172
173 create_dmraid_cpio(){
174         # DMRAID
175         if [ "${DMRAID}" = '1' ]
176         then
177                 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
178                 then
179                         rm -r "${TEMP}/initramfs-dmraid-temp/"
180                 fi
181                 print_info 1 'DMRAID: Adding support (compiling binaries)...'
182                 compile_dmraid
183                 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
184                 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
185                         gen_die "Could not extract dmraid binary cache!";
186                 cd "${TEMP}/initramfs-dmraid-temp/"
187                 find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-dmraid-${DMRAID_VER}.cpio.gz
188                 rm -r "${TEMP}/initramfs-dmraid-temp/"
189         fi                                                                                      
190 }
191
192 create_lvm2_cpio(){
193         # LVM2
194         if [ "${LVM2}" -eq '1' ]
195         then
196                 if [ -d "${TEMP}/initramfs-lvm2-temp" ]
197                 then
198                         rm -r "${TEMP}/initramfs-lvm2-temp/"
199                 fi
200                 cd ${TEMP}
201                 mkdir -p "${TEMP}/initramfs-lvm2-temp/bin/"
202                 mkdir -p "${TEMP}/initramfs-lvm2-temp/etc/lvm/"
203                 if [ -e '/sbin/lvm' ] && ldd /sbin/lvm|grep -q 'not a dynamic executable';
204                 then
205                         print_info 1 '          LVM2: Adding support (using local static binaries)...'
206                         cp /sbin/lvm "${TEMP}/initramfs-lvm2-temp/bin/lvm" ||
207                                 gen_die 'Could not copy over lvm!'
208                 else
209                         print_info 1 '          LVM2: Adding support (compiling binaries)...'
210                         compile_lvm2
211                         /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initramfs-lvm2-temp" ||
212                                 gen_die "Could not extract lvm2 binary cache!";
213                         mv ${TEMP}/initramfs-lvm2-temp/sbin/lvm.static ${TEMP}/initramfs-lvm2-temp/bin/lvm ||
214                                 gen_die 'LVM2 error: Could not move lvm.static to lvm!'
215                 fi
216                 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm2-temp/etc/lvm/lvm.conf" ||
217                         gen_die 'Could not copy over lvm.conf!'
218                 cd "${TEMP}/initramfs-lvm2-temp/"
219                 find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-lvm2-${LVM2_VER}.cpio.gz
220                 rm -r "${TEMP}/initramfs-lvm2-temp/"
221         else # Deprecation warning; remove in a few versions.
222                 if [ -e '/sbin/lvm' ]
223                 then
224                         if ldd /sbin/lvm|grep -q 'not a dynamic executable';
225                         then
226                                 print_warning 1 'LVM2: For support, use --lvm2!'
227                         fi
228                 fi
229         fi
230 }
231
232 create_evms2_cpio(){    
233         # EVMS2
234         if [ -e '/sbin/evms_activate' ]
235         then
236                 if [ -d "${TEMP}/initramfs-evms2-temp" ]
237                 then
238                         rm -r "${TEMP}/initramfs-evms2-temp/"
239                 fi
240                 mkdir -p "${TEMP}/initramfs-evms2-temp/lib/evms"
241                 mkdir -p "${TEMP}/initramfs-evms2-temp/etc/"
242                 mkdir -p "${TEMP}/initramfs-evms2-temp/bin/"
243                 mkdir -p "${TEMP}/initramfs-evms2-temp/sbin/"
244                 if [ "${EVMS2}" -eq '1' ]
245                 then
246                         print_info 1 '          EVMS2: Adding support...'       
247                         mkdir -p ${TEMP}/initramfs-evms2-temp/lib
248                         cp -a /lib/ld-* "${TEMP}/initramfs-evms2-temp/lib" \
249                                 || gen_die 'Could not copy files for EVMS2!'
250                         if [ -n "`ls /lib/libgcc_s*`" ]
251                         then
252                                 cp -a /lib/libgcc_s* "${TEMP}/initramfs-evms2-temp/lib" \
253                                         || gen_die 'Could not copy files for EVMS2!'
254                         fi
255                         cp -a /lib/libc-* /lib/libc.* "${TEMP}/initramfs-evms2-temp/lib" \
256                                 || gen_die 'Could not copy files for EVMS2!'
257                         cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initramfs-evms2-temp/lib" \
258                                 || gen_die 'Could not copy files for EVMS2!'
259                         cp -a /lib/libpthread* "${TEMP}/initramfs-evms2-temp/lib" \
260                                 || gen_die 'Could not copy files for EVMS2!'
261                         cp -a /lib/libuuid*so* "${TEMP}/initramfs-evms2-temp/lib" \
262                                 || gen_die 'Could not copy files for EVMS2!'
263                         cp -a /lib/libevms*so* "${TEMP}/initramfs-evms2-temp/lib" \
264                                 || gen_die 'Could not copy files for EVMS2!'
265                         cp -a /lib/evms "${TEMP}/initramfs-evms2-temp/lib" \
266                                 || gen_die 'Could not copy files for EVMS2!'
267                         cp -a /lib/evms/* "${TEMP}/initramfs-evms2-temp/lib/evms" \
268                                 || gen_die 'Could not copy files for EVMS2!'
269                         cp -a /etc/evms.conf "${TEMP}/initramfs-evms2-temp/etc" \
270                                 || gen_die 'Could not copy files for EVMS2!'
271                         cp /sbin/evms_activate "${TEMP}/initramfs-evms2-temp/sbin" \
272                                 || gen_die 'Could not copy over evms_activate!'
273
274                         # Fix EVMS2 complaining that it can't find the swap utilities.
275                         # These are not required in the initramfs
276                         for swap_libs in "${TEMP}/initramfs-evms2-temp/lib/evms/*/swap*.so"
277                         do
278                                 rm ${swap_libs}
279                         done
280                 fi
281                 cd "${TEMP}/initramfs-evms2-temp/"
282                 find . -print | cpio --quiet -o -H newc \
283                         | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-evms2.cpio.gz
284                 rm -r "${TEMP}/initramfs-evms2-temp/"
285         fi      
286 }
287
288 create_gensplash(){     
289         if [ "${GENSPLASH}" -eq '1' ]
290         then
291                 if [ -x /usr/bin/splash_geninitramfs ] || [ -x /sbin/splash_geninitramfs ]
292                 then
293                         [ -z "${GENSPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
294                         [ -z "${GENSPLASH_THEME}" ] && GENSPLASH_THEME=default
295                         print_info 1 "  >> Installing gensplash [ using the ${GENSPLASH_THEME} theme ]..."
296                         cd /
297                         local tmp=""
298                         [ -n "${GENSPLASH_RES}" ] && tmp="-r ${GENSPLASH_RES}"
299                         splash_geninitramfs -g ${CACHE_CPIO_DIR}/initramfs-splash-${KV}.cpio.gz ${tmp} ${GENSPLASH_THEME} || gen_die "Could not build splash cpio archive"
300                         if [ -e "/usr/share/splashutils/initrd.splash" ]; then
301                                 if [ -d "${TEMP}/initramfs-gensplash-temp" ]
302                                 then
303                                         rm -r "${TEMP}/initramfs-gensplash-temp/"
304                                 fi
305                                 mkdir -p "${TEMP}/initramfs-gensplash-temp/etc"
306                                 cd "${TEMP}/initramfs-gensplash-temp/"
307                                 gunzip -c ${CACHE_CPIO_DIR}/initramfs-splash-${KV}.cpio.gz | cpio -idm --quiet -H newc || gen_die "unpacking splash cpio"
308                                 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-gensplash-temp/etc"
309                                 find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-splash-${KV}.cpio.gz || gen_die "compressing splash cpio"
310                                 rm -r "${TEMP}/initramfs-gensplash-temp/"
311                         fi
312                 else
313                         print_warning 1 '               >> No splash detected; skipping!'
314                 fi
315         fi
316 }
317
318 create_initramfs_overlay_cpio(){
319         cd ${INITRAMFS_OVERLAY}
320         find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-overlay.cpio.gz
321 }
322 print_list()
323 {
324         local x
325         for x in ${*}
326         do
327                 echo ${x}
328         done
329 }
330
331 create_initramfs_modules() {
332         local group
333         local group_modules
334         
335         MOD_EXT=".ko"
336
337         print_info 2 "initramfs: >> Searching for modules..."
338         if [ "${INSTALL_MOD_PATH}" != '' ]
339         then
340           cd ${INSTALL_MOD_PATH}
341         else
342           cd /
343         fi
344         
345         if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
346         then
347                 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
348         fi
349         mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"       
350         for i in `gen_dep_list`
351         do
352                 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
353                 if [ -z "${mymod}" ]
354                 then
355                         print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
356                         continue;
357                 fi
358                 
359                 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
360                 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
361         done
362         
363         cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
364
365         mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
366         for group_modules in ${!MODULES_*}; do
367                 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
368                 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
369         done
370         cd "${TEMP}/initramfs-modules-${KV}-temp/"
371         find . | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-modules-${KV}.cpio.gz
372         rm -r "${TEMP}/initramfs-modules-${KV}-temp/"   
373 }
374
375 # check for static linked file with objdump
376 is_static() {
377         objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
378         return $?
379 }
380
381 create_initramfs_aux() {
382         if [ -d "${TEMP}/initramfs-aux-temp" ]
383         then
384                 rm -r "${TEMP}/initramfs-aux-temp/"
385         fi
386         mkdir -p "${TEMP}/initramfs-aux-temp/etc"       
387         mkdir -p "${TEMP}/initramfs-aux-temp/sbin"      
388         if [ -f "${CMD_LINUXRC}" ]
389         then
390                 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
391                 print_info 2 "        >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
392         else    
393                 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
394                 then
395                         cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
396                 else
397                         cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initramfs-aux-temp/init"
398                 fi
399         fi
400
401         # Make sure it's executable
402         chmod 0755 "${TEMP}/initramfs-aux-temp/init"
403
404         # Make a symlink to init .. incase we are bundled inside the kernel as one
405         # big cpio.
406         cd ${TEMP}/initramfs-aux-temp
407         ln -s init linuxrc
408 #       ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc 
409
410         if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
411         then
412                 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
413         else    
414                 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
415         fi
416
417         if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
418         then
419                 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
420         else
421                 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
422         fi
423         
424         echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"  
425         for group_modules in ${!MODULES_*}; do
426                 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
427                 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
428         done
429         echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"    
430
431         if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
432         then
433                 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
434         else
435                 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
436         fi
437         if isTrue $CMD_DOKEYMAPAUTO
438         then
439                 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
440         fi
441         mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
442         /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
443         if isTrue $CMD_SLOWUSB
444         then
445                 echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
446         fi
447         if isTrue ${LUKS}
448         then
449                 if is_static /bin/cryptsetup
450                 then
451                         print_info "Including LUKS support"
452                         rm -f ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
453                         cp /bin/cryptsetup ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
454                         chmod +x "${TEMP}/initramfs-aux-temp/sbin/cryptsetup"
455                 else
456                         print_info "LUKS support requires static cryptsetup at /bin/cryptsetup"
457                         print_info "Not including LUKS support"
458                 fi
459         fi
460
461         cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
462         cd ${TEMP}
463         chmod +x "${TEMP}/initramfs-aux-temp/init"
464         chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
465         chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
466         chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
467         cd "${TEMP}/initramfs-aux-temp/"
468         find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-aux.cpio.gz
469         rm -r "${TEMP}/initramfs-aux-temp/"     
470 }
471
472 merge_initramfs_cpio_archives(){
473         cd "${CACHE_CPIO_DIR}"
474         MERGE_LIST="initramfs-base-layout.cpio.gz initramfs-aux.cpio.gz"        
475         if [ ! -e "${CACHE_CPIO_DIR}/initramfs-base-layout.cpio.gz" ]
476         then
477                 gen_die "${CACHE_CPIO_DIR}/initramfs-base-layout.cpio.gz is missing."
478         fi
479         if [ ! -e "${CACHE_CPIO_DIR}/initramfs-aux.cpio.gz" ]
480         then
481                 gen_die "${CACHE_CPIO_DIR}/initramfs-aux.cpio.gz is missing."
482         fi
483         
484         if [ "${BUSYBOX}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-busybox-${BUSYBOX_VER}.cpio.gz ]
485         then
486                 MERGE_LIST="${MERGE_LIST} initramfs-busybox-${BUSYBOX_VER}.cpio.gz"
487         fi
488         
489         if [ "${NOINITRDMODULES}" = '' -a -e ${CACHE_CPIO_DIR}/initramfs-insmod-${MODULE_INIT_TOOLS_VER}.cpio.gz ]
490         then
491                 MERGE_LIST="${MERGE_LIST} initramfs-insmod-${MODULE_INIT_TOOLS_VER}.cpio.gz"
492         fi
493         
494 #       if [ "${UDEV}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-udev-${UDEV_VER}.cpio.gz ]
495 #       then
496 #               MERGE_LIST="${MERGE_LIST} initramfs-udev-${UDEV_VER}.cpio.gz"
497 #       fi
498         if [ "${DISKLABEL}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-blkid-${E2FSPROGS_VER}.cpio.gz ]
499         then
500                 MERGE_LIST="${MERGE_LIST} initramfs-blkid-${E2FSPROGS_VER}.cpio.gz"
501         fi
502         if [ "${UNIONFS}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz ]
503         then
504                 MERGE_LIST="${MERGE_LIST} initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz"
505         fi
506         if [ "${UNIONFS}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz ]
507         then
508                 MERGE_LIST="${MERGE_LIST} initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz"
509         fi
510         if [ "${EVMS2}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-evms2.cpio.gz" ]
511         then
512                 MERGE_LIST="${MERGE_LIST} initramfs-evms2.cpio.gz"
513         fi
514         if [ "${LVM2}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-lvm2-${LVM2_VER}.cpio.gz" ]
515         then
516                 MERGE_LIST="${MERGE_LIST} initramfs-lvm2-${LVM2_VER}.cpio.gz"
517         fi
518         if [ "${DEVFS}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-devfs-${DEVFSD_VER}.cpio.gz" ]
519         then
520                 MERGE_LIST="${MERGE_LIST} initramfs-devfs-${DEVFSD_VER}.cpio.gz"
521         fi
522         if [ "${DMRAID}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-dmraid-${DMRAID_VER}.cpio.gz ]
523         then
524                 MERGE_LIST="${MERGE_LIST} initramfs-dmraid-${DMRAID_VER}.cpio.gz"
525         fi
526         if [ "${NOINITRDMODULES}" = '' -a -e "${CACHE_CPIO_DIR}/initramfs-modules-${KV}.cpio.gz" ]
527         then
528                 MERGE_LIST="${MERGE_LIST} initramfs-modules-${KV}.cpio.gz"
529         fi
530         if [ "${GENSPLASH}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-splash-${KV}.cpio.gz" ]
531         then
532                 MERGE_LIST="${MERGE_LIST} initramfs-splash-${KV}.cpio.gz"
533         fi
534         # This should always be appended last
535         if [ "${INITRAMFS_OVERLAY}" != '' -a -e "${CACHE_CPIO_DIR}/initramfs-overlay.cpio.gz" ]
536         then
537                 MERGE_LIST="${MERGE_LIST} initramfs-overlay.cpio.gz"
538         fi
539         
540         echo
541         print_info 1 "Merging"
542         for i in ${MERGE_LIST}
543         do
544                 print_info 1 "    $i"
545         done
546
547         cat ${MERGE_LIST} > ${TMPDIR}/initramfs-${KV}
548
549         # Pegasos hack for merging the initramfs into the kernel at compile time
550         [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
551                 [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
552                         cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/arch/powerpc/boot/ramdisk.image.gz &&
553                         rm ${TMPDIR}/initramfs-${KV}
554
555         # Mips also mimics Pegasos to merge the initramfs into the kernel
556         if [ ${BUILD_INITRAMFS} -eq 1 ]; then
557                 cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/initramfs.cpio.gz
558                 gunzip -f ${KERNEL_DIR}/initramfs.cpio.gz
559         fi
560 }
561
562 clear_cpio_dir(){
563         if [ "${CLEAR_CPIO_CACHE}" == 'yes' ]
564         then
565
566                 if [ -d ${CACHE_CPIO_DIR} ]
567                 then
568                         print_info 1 "        >> Clearing old cpio archives..."
569                         rm -r ${CACHE_CPIO_DIR}
570                 fi
571         fi
572         
573         if [ ! -d ${CACHE_CPIO_DIR} ]
574         then
575                 mkdir -p ${CACHE_CPIO_DIR}
576         fi
577 }
578
579 create_initramfs() {
580         local MOD_EXT
581
582         print_info 1 "initramfs: >> Initializing..."
583         clear_cpio_dir
584         mkdir -p ${CACHE_CPIO_DIR}
585         print_info 1 "        >> Creating base_layout cpio archive..."
586         create_base_layout_cpio
587         
588         print_info 1 "        >> Creating auxilary cpio archive..."
589         create_initramfs_aux
590         
591         if [ "${BUSYBOX}" -eq '1' ]
592         then
593             print_info 1 "        >> Creating busybox cpio archive..."
594             create_busybox_cpio
595         fi
596         
597         if [ "${DEVFS}" -eq '1' ]
598         then
599             print_info 1 "        >> Creating devfs cpio archive..."
600             create_devfs_cpio
601         fi
602         
603 #       if [ "${UDEV}" -eq '1' ]
604 #       then
605 #           print_info 1 "        >> Creating udev cpio archive..."
606 #           create_udev_cpio
607 #       fi
608         
609         if [ "${UNIONFS}" -eq '1' ]
610         then
611             print_info 1 "        >> Creating unionfs modules cpio archive..."
612             create_unionfs_modules_cpio
613             print_info 1 "        >> Creating unionfs tools cpio archive..."
614             create_unionfs_tools_cpio
615         fi
616         
617         if [ "${LVM2}" -eq '1' ]
618         then
619             
620             print_info 1 "        >> Creating lvm2 cpio archive..."
621             create_lvm2_cpio
622         fi
623         
624         if [ "${DMRAID}" -eq '1' ]
625         then
626             print_info 1 "        >> Creating dmraid cpio archive..."
627             create_dmraid_cpio
628         fi
629         
630         if [ "${EVMS2}" -eq '1' -a -e '/sbin/evms_activate' ]
631         then
632                 print_info 1 "        >> Creating evms2 cpio archive..."
633                 create_evms2_cpio
634         fi
635         
636         if [ "${NOINITRDMODULES}" = '' ]
637         then
638                 print_info 1 "        >> Creating insmod cpio archive..."
639                 create_insmod_cpio
640                 print_info 1 "        >> Creating modules cpio archive..."
641                 create_initramfs_modules
642         else
643                 print_info 1 "initramfs: Not copying modules..."
644         fi
645         
646         if [ "${DISKLABEL}" -eq '1' ]
647         then
648                 print_info 1 "        >> Creating blkid cpio archive..."
649                 create_blkid_cpio
650         fi
651                 
652         create_gensplash
653         
654         if [ "${INITRAMFS_OVERLAY}" != '' ]
655         then
656                 print_info 1 "        >> Creating initramfs_overlay cpio archive..."
657                 create_initramfs_overlay_cpio
658         fi
659         
660         merge_initramfs_cpio_archives
661
662         if ! isTrue "${CMD_NOINSTALL}"
663         then
664                 if [ "${GENERATE_Z_IMAGE}" != '1' ]
665                 then
666                         cp ${TMPDIR}/initramfs-${KV} ${BOOTDIR}/initramfs-${KNAME}-${ARCH}-${KV} ||
667                                 gen_die 'Could not copy the initramfs to ${BOOTDIR}!'
668                 fi
669         fi
670 }