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