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