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