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