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}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/bin/
44 chmod +x "${TEMP}/initramfs-busybox-temp/bin/udhcpc.scripts"
45 tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
46 gen_die 'Could not extract busybox bincache!'
47 chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
49 for i in '[' ash sh mount uname echo cut; do
50 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
51 ln ${TEMP}/initramfs-busybox-temp/bin/busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
52 gen_die "Busybox error: could not link ${i}!"
55 cd "${TEMP}/initramfs-busybox-temp/"
56 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
57 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
61 if [ -d "${TEMP}/initramfs-blkid-temp" ]
63 rm -r "${TEMP}/initramfs-blkid-temp/"
66 mkdir -p "${TEMP}/initramfs-blkid-temp/bin/"
67 [ "${DISKLABEL}" -eq '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/bin/blkid" ||
68 gen_die "Could not extract blkid binary cache!"; }
69 chmod a+x "${TEMP}/initramfs-blkid-temp/bin/blkid"
70 cd "${TEMP}/initramfs-blkid-temp/"
71 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
72 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
76 if [ -d "${TEMP}/initramfs-fuse-temp" ]
78 rm -r "${TEMP}/initramfs-fuse-temp"
81 mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
82 tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
83 cd "${TEMP}/initramfs-fuse-temp/"
84 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
85 rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
88 append_unionfs_fuse() {
89 if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
91 rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
94 mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
95 bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
96 gen_die 'Could not extract unionfs-fuse binary cache!'
97 cd "${TEMP}/initramfs-unionfs-fuse-temp/"
98 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
99 rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
103 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
105 # rm -r "${TEMP}/initramfs-suspend-temp/"
107 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
109 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
110 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
111 # gen_die "Could not extract suspend binary cache!"
112 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
113 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
114 # gen_die 'Could not copy /etc/suspend.conf'
115 # cd "${TEMP}/initramfs-suspend-temp/"
116 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
117 # rm -r "${TEMP}/initramfs-suspend-temp/"
121 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
123 rm -r "${TEMP}/initramfs-dmraid-temp/"
125 print_info 1 'DMRAID: Adding support (compiling binaries)...'
127 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
128 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
129 gen_die "Could not extract dmraid binary cache!";
130 cd "${TEMP}/initramfs-dmraid-temp/"
131 RAID456=`find . -type f -name raid456.ko`
132 if [ -n "${RAID456}" ]
134 cd "${RAID456/raid456.ko/}"
135 ln -sf raid456.kp raid45.ko
136 cd "${TEMP}/initramfs-dmraid-temp/"
138 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
139 rm -r "${TEMP}/initramfs-dmraid-temp/"
143 if [ -d "${TEMP}/initramfs-lvm-temp" ]
145 rm -r "${TEMP}/initramfs-lvm-temp/"
148 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
149 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
150 if [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
152 print_info 1 ' LVM: Adding support (using local static binaries)...'
153 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
154 gen_die 'Could not copy over lvm!'
156 print_info 1 ' LVM: Adding support (compiling binaries)...'
158 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
159 gen_die "Could not extract lvm binary cache!";
160 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
161 gen_die 'LVM error: Could not move lvm.static to lvm!'
165 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
169 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
170 gen_die 'Could not copy over lvm.conf!'
172 # gen_die 'Could not copy over lvm.conf!'
175 cd "${TEMP}/initramfs-lvm-temp/"
176 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
177 rm -r "${TEMP}/initramfs-lvm-temp/"
181 if [ -d "${TEMP}/initramfs-evms-temp" ]
183 rm -r "${TEMP}/initramfs-evms-temp/"
185 mkdir -p "${TEMP}/initramfs-evms-temp/lib/evms"
186 mkdir -p "${TEMP}/initramfs-evms-temp/etc/"
187 mkdir -p "${TEMP}/initramfs-evms-temp/bin/"
188 mkdir -p "${TEMP}/initramfs-evms-temp/sbin/"
189 if [ "${EVMS}" -eq '1' ]
191 print_info 1 ' EVMS: Adding support...'
192 mkdir -p ${TEMP}/initramfs-evms-temp/lib
193 cp -a /lib/ld-* "${TEMP}/initramfs-evms-temp/lib" \
194 || gen_die 'Could not copy files for EVMS!'
195 if [ -n "`ls /lib/libgcc_s*`" ]
197 cp -a /lib/libgcc_s* "${TEMP}/initramfs-evms-temp/lib" \
198 || gen_die 'Could not copy files for EVMS!'
200 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initramfs-evms-temp/lib" \
201 || gen_die 'Could not copy files for EVMS!'
202 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initramfs-evms-temp/lib" \
203 || gen_die 'Could not copy files for EVMS!'
204 cp -a /lib/libpthread* "${TEMP}/initramfs-evms-temp/lib" \
205 || gen_die 'Could not copy files for EVMS!'
206 cp -a /lib/libuuid*so* "${TEMP}/initramfs-evms-temp/lib" \
207 || gen_die 'Could not copy files for EVMS!'
208 cp -a /lib/libevms*so* "${TEMP}/initramfs-evms-temp/lib" \
209 || gen_die 'Could not copy files for EVMS!'
210 cp -a /lib/evms "${TEMP}/initramfs-evms-temp/lib" \
211 || gen_die 'Could not copy files for EVMS!'
212 cp -a /lib/evms/* "${TEMP}/initramfs-evms-temp/lib/evms" \
213 || gen_die 'Could not copy files for EVMS!'
214 cp -a /etc/evms.conf "${TEMP}/initramfs-evms-temp/etc" \
215 || gen_die 'Could not copy files for EVMS!'
216 cp /sbin/evms_activate "${TEMP}/initramfs-evms-temp/sbin" \
217 || gen_die 'Could not copy over evms_activate!'
219 # Fix EVMS complaining that it can't find the swap utilities.
220 # These are not required in the initramfs
221 for swap_libs in "${TEMP}/initramfs-evms-temp/lib/evms/*/swap*.so"
226 cd "${TEMP}/initramfs-evms-temp/"
227 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
228 rm -r "${TEMP}/initramfs-evms-temp/"
232 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
234 rm -r "${TEMP}/initramfs-mdadm-temp/"
237 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
238 if [ "${MDADM}" -eq '1' ]
240 cp -a /etc/mdadm.conf "${TEMP}/initramfs-mdadm-temp/etc" \
241 || gen_die "Could not copy mdadm.conf!"
243 cd "${TEMP}/initramfs-mdadm-temp/"
244 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
245 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
249 splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
250 if [ -x "${splash_geninitramfs}" ]
252 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
253 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
254 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
255 if [ -d "${TEMP}/initramfs-splash-temp" ]
257 rm -r "${TEMP}/initramfs-splash-temp/"
259 mkdir -p "${TEMP}/initramfs-splash-temp"
262 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
263 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
264 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
265 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
266 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
268 cd "${TEMP}/initramfs-splash-temp/"
269 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
270 || gen_die "compressing splash cpio"
271 rm -r "${TEMP}/initramfs-splash-temp/"
273 print_warning 1 ' >> No splash detected; skipping!'
278 cd ${INITRAMFS_OVERLAY}
279 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
283 if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
285 gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
287 if [ -d "${TEMP}/initramfs-firmware-temp" ]
289 rm -r "${TEMP}/initramfs-firmware-temp/"
291 mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
292 cd "${TEMP}/initramfs-firmware-temp"
293 if [ -n "${FIRMWARE_FILES}" ]
297 for i in ${FIRMWARE_FILES}
299 cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
303 cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
305 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
306 || gen_die "appending firmware to cpio"
307 rm -r "${TEMP}/initramfs-firmware-temp/"
324 print_info 2 "initramfs: >> Searching for modules..."
325 if [ "${INSTALL_MOD_PATH}" != '' ]
327 cd ${INSTALL_MOD_PATH}
332 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
334 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
336 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
337 for i in `gen_dep_list`
339 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
342 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
346 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
347 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
350 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
352 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
353 for group_modules in ${!MODULES_*}; do
354 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
355 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
357 cd "${TEMP}/initramfs-modules-${KV}-temp/"
358 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}"
360 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
363 # check for static linked file with objdump
365 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
370 if [ -d "${TEMP}/initramfs-aux-temp" ]
372 rm -r "${TEMP}/initramfs-aux-temp/"
374 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
375 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
376 if [ -f "${CMD_LINUXRC}" ]
378 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
379 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
381 if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
383 cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
385 cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
389 # Make sure it's executable
390 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
392 # Make a symlink to init .. incase we are bundled inside the kernel as one
394 cd ${TEMP}/initramfs-aux-temp
396 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
398 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
400 cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
402 cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
405 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
407 cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
409 cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
412 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
413 for group_modules in ${!MODULES_*}; do
414 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
415 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
417 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
419 if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
421 cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
423 cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
425 if isTrue $CMD_DOKEYMAPAUTO
427 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
429 if isTrue $CMD_KEYMAP
431 mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
432 /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/defaults/keymaps.tar.gz"
434 if isTrue $CMD_SLOWUSB
436 echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
440 if is_static /bin/cryptsetup
442 print_info 1 "Including LUKS support"
443 rm -f ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
444 cp /bin/cryptsetup ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
445 chmod +x "${TEMP}/initramfs-aux-temp/sbin/cryptsetup"
446 elif is_static /sbin/cryptsetup
448 print_info 1 "Including LUKS support"
449 rm -f ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
450 cp /sbin/cryptsetup ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
451 chmod +x "${TEMP}/initramfs-aux-temp/sbin/cryptsetup"
454 print_info 1 "LUKS support requires static cryptsetup at /bin/cryptsetup or /sbin/cryptsetup"
455 print_info 1 "Not including LUKS support"
459 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
461 chmod +x "${TEMP}/initramfs-aux-temp/init"
462 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
463 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
464 chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
465 cd "${TEMP}/initramfs-aux-temp/"
466 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
468 rm -r "${TEMP}/initramfs-aux-temp/"
473 local func="append_${name}"
475 if [ $# -eq 1 ] || [ ${var} -eq 1 ]
477 print_info 1 " >> Appending ${name} cpio data..."
483 print_info 1 "initramfs: >> Initializing..."
486 CPIO="${TMPDIR}/initramfs-${KV}"
487 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
488 || gen_die "Could not create empty cpio at ${CPIO}"
490 append_data 'base_layout'
491 append_data 'auxilary'
492 append_data 'busybox' "${BUSYBOX}"
493 append_data 'lvm' "${LVM}"
494 append_data 'dmraid' "${DMRAID}"
495 append_data 'evms' "${EVMS}"
496 append_data 'mdadm' "${MDADM}"
498 if [ "${NORAMDISKMODULES}" -eq '0' ]
500 append_data 'modules'
502 print_info 1 "initramfs: Not copying modules..."
505 append_data 'blkid' "${DISKLABEL}"
508 append_data 'unionfs_fuse'
510 if isTrue "${SPLASH}"
512 append_data 'splash' "${SPLASH}"
515 if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
517 append_data 'firmware'
520 # This should always be appended last
521 if [ "${INITRAMFS_OVERLAY}" != '' ]
523 append_data 'overlay'
527 mv -f "${CPIO}.gz" "${CPIO}"
529 if isTrue "${INTEGRATED_INITRAMFS}"
531 # cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/usr/initramfs_data.cpio.gz
532 mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio.gz
533 # sed -i "s|^.*CONFIG_INITRAMFS_SOURCE=.*$|CONFIG_INITRAMFS_SOURCE=\"${TMPDIR}/initramfs-${KV}.cpio.gz\"|" ${KERNEL_DIR}/.config
534 sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
535 echo -e "CONFIG_INITRAMFS_SOURCE=\"${TMPDIR}/initramfs-${KV}.cpio.gz\"\nCONFIG_INITRAMFS_ROOT_UID=0\nCONFIG_INITRAMFS_ROOT_GID=0" >> ${KERNEL_DIR}/.config
538 if ! isTrue "${CMD_NOINSTALL}"
540 if ! isTrue "${INTEGRATED_INITRAMFS}"
542 copy_image_with_preserve "initramfs" \
543 "${TMPDIR}/initramfs-${KV}" \
544 "initramfs-${KNAME}-${ARCH}-${KV}"