3 CPIO_ARGS="--quiet -o -H newc"
6 if [ -d "${TEMP}/initramfs-base-temp" ]
8 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
10 mkdir -p ${TEMP}/initramfs-base-temp/dev
11 mkdir -p ${TEMP}/initramfs-base-temp/bin
12 mkdir -p ${TEMP}/initramfs-base-temp/etc
13 mkdir -p ${TEMP}/initramfs-base-temp/usr
14 mkdir -p ${TEMP}/initramfs-base-temp/proc
15 mkdir -p ${TEMP}/initramfs-base-temp/temp
16 mkdir -p ${TEMP}/initramfs-base-temp/sys
17 mkdir -p ${TEMP}/initramfs-temp/.initrd
18 mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
19 mkdir -p ${TEMP}/initramfs-base-temp/sbin
20 mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
21 mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
22 ln -s lib ${TEMP}/initramfs-base-temp/lib64
24 echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
25 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
27 cd ${TEMP}/initramfs-base-temp/dev
28 mknod -m 660 console c 5 1
29 mknod -m 660 null c 1 3
30 mknod -m 600 tty1 c 4 1
31 cd "${TEMP}/initramfs-base-temp/"
32 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
33 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
37 if [ -d "${TEMP}/initramfs-busybox-temp" ]
39 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
41 mkdir -p "${TEMP}/initramfs-busybox-temp/bin/"
43 cp "${GK_SHARE}/generic/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/bin/
44 chmod +x "${TEMP}/initramfs-busybox-temp/bin/udhcpc.scripts"
45 cp "${BUSYBOX_BINCACHE}" "${TEMP}/initramfs-busybox-temp/bin/busybox.tar.bz2" ||
46 gen_die 'Could not copy busybox from bincache!'
47 tar -xjf "${TEMP}/initramfs-busybox-temp/bin/busybox.tar.bz2" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
48 gen_die 'Could not extract busybox bincache!'
49 chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
51 for i in '[' ash sh mount uname echo cut; do
52 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
53 ln ${TEMP}/initramfs-busybox-temp/bin/busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
54 gen_die "Busybox error: could not link ${i}!"
57 cd "${TEMP}/initramfs-busybox-temp/"
58 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
59 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
63 if [ -d "${TEMP}/initramfs-blkid-temp" ]
65 rm -r "${TEMP}/initramfs-blkid-temp/"
68 mkdir -p "${TEMP}/initramfs-blkid-temp/bin/"
69 [ "${DISKLABEL}" -eq '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/bin/blkid" ||
70 gen_die "Could not extract blkid binary cache!"; }
71 chmod a+x "${TEMP}/initramfs-blkid-temp/bin/blkid"
72 cd "${TEMP}/initramfs-blkid-temp/"
73 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
74 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
77 append_unionfs_modules(){
78 if [ -d "${TEMP}/initramfs-unionfs-modules-temp" ]
80 rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
82 print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
83 compile_unionfs_modules
84 mkdir -p "${TEMP}/initramfs-unionfs-modules-temp/"
85 /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initramfs-unionfs-modules-temp" ||
86 gen_die "Could not extract unionfs modules binary cache!";
87 cd "${TEMP}/initramfs-unionfs-modules-temp/"
88 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
89 rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
92 append_unionfs_tools(){
93 if [ -d "${TEMP}/initramfs-unionfs-tools-temp" ]
95 rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
97 print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
99 mkdir -p "${TEMP}/initramfs-unionfs-tools-temp/bin/"
100 /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initramfs-unionfs-tools-temp" ||
101 gen_die "Could not extract unionfs tools binary cache!";
102 cd "${TEMP}/initramfs-unionfs-tools-temp/"
103 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
104 rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
108 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
110 # rm -r "${TEMP}/initramfs-suspend-temp/"
112 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
114 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
115 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
116 # gen_die "Could not extract suspend binary cache!"
117 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
118 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
119 # gen_die 'Could not copy /etc/suspend.conf'
120 # cd "${TEMP}/initramfs-suspend-temp/"
121 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
122 # rm -r "${TEMP}/initramfs-suspend-temp/"
126 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
128 rm -r "${TEMP}/initramfs-dmraid-temp/"
130 print_info 1 'DMRAID: Adding support (compiling binaries)...'
132 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
133 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
134 gen_die "Could not extract dmraid binary cache!";
135 cd "${TEMP}/initramfs-dmraid-temp/"
136 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
137 rm -r "${TEMP}/initramfs-dmraid-temp/"
141 if [ -d "${TEMP}/initramfs-lvm-temp" ]
143 rm -r "${TEMP}/initramfs-lvm-temp/"
146 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
147 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
148 if [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
150 print_info 1 ' LVM: Adding support (using local static binaries)...'
151 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
152 gen_die 'Could not copy over lvm!'
154 print_info 1 ' LVM: Adding support (compiling binaries)...'
156 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
157 gen_die "Could not extract lvm binary cache!";
158 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
159 gen_die 'LVM error: Could not move lvm.static to lvm!'
163 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
167 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
168 gen_die 'Could not copy over lvm.conf!'
170 # gen_die 'Could not copy over lvm.conf!'
173 cd "${TEMP}/initramfs-lvm-temp/"
174 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
175 rm -r "${TEMP}/initramfs-lvm-temp/"
179 if [ -d "${TEMP}/initramfs-evms-temp" ]
181 rm -r "${TEMP}/initramfs-evms-temp/"
183 mkdir -p "${TEMP}/initramfs-evms-temp/lib/evms"
184 mkdir -p "${TEMP}/initramfs-evms-temp/etc/"
185 mkdir -p "${TEMP}/initramfs-evms-temp/bin/"
186 mkdir -p "${TEMP}/initramfs-evms-temp/sbin/"
187 if [ "${EVMS}" -eq '1' ]
189 print_info 1 ' EVMS: Adding support...'
190 mkdir -p ${TEMP}/initramfs-evms-temp/lib
191 cp -a /lib/ld-* "${TEMP}/initramfs-evms-temp/lib" \
192 || gen_die 'Could not copy files for EVMS!'
193 if [ -n "`ls /lib/libgcc_s*`" ]
195 cp -a /lib/libgcc_s* "${TEMP}/initramfs-evms-temp/lib" \
196 || gen_die 'Could not copy files for EVMS!'
198 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initramfs-evms-temp/lib" \
199 || gen_die 'Could not copy files for EVMS!'
200 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initramfs-evms-temp/lib" \
201 || gen_die 'Could not copy files for EVMS!'
202 cp -a /lib/libpthread* "${TEMP}/initramfs-evms-temp/lib" \
203 || gen_die 'Could not copy files for EVMS!'
204 cp -a /lib/libuuid*so* "${TEMP}/initramfs-evms-temp/lib" \
205 || gen_die 'Could not copy files for EVMS!'
206 cp -a /lib/libevms*so* "${TEMP}/initramfs-evms-temp/lib" \
207 || gen_die 'Could not copy files for EVMS!'
208 cp -a /lib/evms "${TEMP}/initramfs-evms-temp/lib" \
209 || gen_die 'Could not copy files for EVMS!'
210 cp -a /lib/evms/* "${TEMP}/initramfs-evms-temp/lib/evms" \
211 || gen_die 'Could not copy files for EVMS!'
212 cp -a /etc/evms.conf "${TEMP}/initramfs-evms-temp/etc" \
213 || gen_die 'Could not copy files for EVMS!'
214 cp /sbin/evms_activate "${TEMP}/initramfs-evms-temp/sbin" \
215 || gen_die 'Could not copy over evms_activate!'
217 # Fix EVMS complaining that it can't find the swap utilities.
218 # These are not required in the initramfs
219 for swap_libs in "${TEMP}/initramfs-evms-temp/lib/evms/*/swap*.so"
224 cd "${TEMP}/initramfs-evms-temp/"
225 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
226 rm -r "${TEMP}/initramfs-evms-temp/"
230 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
232 rm -r "${TEMP}/initramfs-mdadm-temp/"
235 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
236 if [ "${MDADM}" -eq '1' ]
238 cp -a /etc/mdadm.conf "${TEMP}/initramfs-mdadm-temp/etc" \
239 || gen_die "Could not copy mdadm.conf!"
241 cd "${TEMP}/initramfs-mdadm-temp/"
242 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
243 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
247 if [ -x /usr/bin/splash_geninitramfs ] || [ -x /sbin/splash_geninitramfs ]
249 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
250 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
251 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
252 if [ -d "${TEMP}/initramfs-splash-temp" ]
254 rm -r "${TEMP}/initramfs-splash-temp/"
256 mkdir -p "${TEMP}/initramfs-splash-temp"
259 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
260 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
261 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
262 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
263 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
265 cd "${TEMP}/initramfs-splash-temp/"
266 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
267 || gen_die "compressing splash cpio"
268 rm -r "${TEMP}/initramfs-splash-temp/"
270 print_warning 1 ' >> No splash detected; skipping!'
275 cd ${INITRAMFS_OVERLAY}
276 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
292 print_info 2 "initramfs: >> Searching for modules..."
293 if [ "${INSTALL_MOD_PATH}" != '' ]
295 cd ${INSTALL_MOD_PATH}
300 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
302 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
304 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
305 for i in `gen_dep_list`
307 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
310 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
314 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
315 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
318 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
320 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
321 for group_modules in ${!MODULES_*}; do
322 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
323 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
325 cd "${TEMP}/initramfs-modules-${KV}-temp/"
326 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}"
328 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
331 # check for static linked file with objdump
333 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
338 if [ -d "${TEMP}/initramfs-aux-temp" ]
340 rm -r "${TEMP}/initramfs-aux-temp/"
342 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
343 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
344 if [ -f "${CMD_LINUXRC}" ]
346 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
347 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
349 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
351 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
353 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initramfs-aux-temp/init"
357 # Make sure it's executable
358 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
360 # Make a symlink to init .. incase we are bundled inside the kernel as one
362 cd ${TEMP}/initramfs-aux-temp
364 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
366 if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
368 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
370 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
373 if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
375 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
377 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
380 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
381 for group_modules in ${!MODULES_*}; do
382 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
383 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
385 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
387 if isTrue $CMD_DOKEYMAPAUTO
389 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
391 mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
392 /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
393 if isTrue $CMD_SLOWUSB
395 echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
399 if is_static /bin/cryptsetup
401 print_info 1 "Including LUKS support"
402 rm -f ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
403 cp /bin/cryptsetup ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
404 chmod +x "${TEMP}/initramfs-aux-temp/sbin/cryptsetup"
406 print_info 1 "LUKS support requires static cryptsetup at /bin/cryptsetup"
407 print_info 1 "Not including LUKS support"
411 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
413 chmod +x "${TEMP}/initramfs-aux-temp/init"
414 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
415 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
416 cd "${TEMP}/initramfs-aux-temp/"
417 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
419 rm -r "${TEMP}/initramfs-aux-temp/"
424 local func="append_${name}"
426 if [ $# -eq 1 ] || [ ${var} -eq 1 ]
428 print_info 1 " >> Appending ${name} cpio data..."
434 print_info 1 "initramfs: >> Initializing..."
437 CPIO="${TMPDIR}/initramfs-${KV}"
438 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
439 || gen_die "Could not create empty cpio at ${CPIO}"
441 append_data 'base_layout'
442 append_data 'auxilary'
443 append_data 'busybox' "${BUSYBOX}"
444 # append_data 'devfs' "${DEVFS}"
445 append_data 'unionfs_modules' "${UNIONFS}"
446 append_data 'unionfs_tools' "${UNIONFS}"
447 append_data 'lvm' "${LVM}"
448 append_data 'dmraid' "${DMRAID}"
449 append_data 'evms' "${EVMS}"
450 append_data 'mdadm' "${MDADM}"
452 if [ "${NOINITRDMODULES}" = '' ]
454 append_data 'modules'
456 print_info 1 "initramfs: Not copying modules..."
459 append_data 'blkid' "${DISKLABEL}"
460 append_data 'splash' "${SPLASH}"
462 # This should always be appended last
463 if [ "${INITRAMFS_OVERLAY}" != '' ]
465 append_data 'overlay'
469 mv -f "${CPIO}.gz" "${CPIO}"
471 # Pegasos hack for merging the initramfs into the kernel at compile time
472 [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
473 [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
474 cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/arch/powerpc/boot/ramdisk.image.gz &&
475 rm ${TMPDIR}/initramfs-${KV}
477 # Mips also mimics Pegasos to merge the initramfs into the kernel
478 if [ ${BUILD_INITRAMFS} -eq 1 ]; then
479 cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/initramfs.cpio.gz
480 gunzip -f ${KERNEL_DIR}/initramfs.cpio.gz
483 if ! isTrue "${CMD_NOINSTALL}"
485 if [ "${GENERATE_Z_IMAGE}" != '1' ]
487 copy_image_with_preserve "initramfs" \
488 "${TMPDIR}/initramfs-${KV}" \
489 "initramfs-${KNAME}-${ARCH}-${KV}"