4 CPIO_ARGS="--quiet -o -H newc"
6 # The copy_binaries function is explicitly released under the CC0 license to
7 # encourage wide adoption and re-use. That means:
8 # - You may use the code of copy_binaries() as CC0 outside of genkernel
9 # - Contributions to this function are licensed under CC0 as well.
10 # - If you change it outside of genkernel, please consider sending your
11 # modifications back to genkernel@gentoo.org.
13 # On a side note: "Both public domain works and the simple license provided by
14 # CC0 are compatible with the GNU GPL."
15 # (from https://www.gnu.org/licenses/license-list.html#CC0)
18 # - Sebastian Pipping <sebastian@pipping.org> (error checking)
19 # - Robin H. Johnson <robbat2@gentoo.org> (complete rewrite)
20 # - Richard Yao <ryao@cs.stonybrook.edu> (original concept)
22 # copy_binaries DESTDIR BINARIES...
27 for binary in "$@"; do
28 [[ -e "${binary}" ]] \
29 || gen_die "Binary ${binary} could not be found"
31 if LC_ALL=C lddtree "${binary}" 2>&1 | fgrep -q 'not found'; then
32 gen_die "Binary ${binary} is linked to missing libraries and may need to be re-built"
35 # This must be OUTSIDE the for loop, we only want to run lddtree etc ONCE.
38 | awk '/=>/{ if($3 ~ /^\//){print $3}}' \
41 | cpio -p --make-directories --dereference --quiet "${destdir}" \
42 || gen_die "Binary ${f} or some of its library dependencies could not be copied"
45 log_future_cpio_content() {
46 if [[ "${LOGLEVEL}" -gt 1 ]]; then
47 echo =================================================================
48 echo "About to add these files from '${PWD}' to cpio archive:"
49 find . | xargs ls -ald
50 echo =================================================================
54 append_base_layout() {
55 if [ -d "${TEMP}/initramfs-base-temp" ]
57 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
60 mkdir -p ${TEMP}/initramfs-base-temp/dev
61 mkdir -p ${TEMP}/initramfs-base-temp/bin
62 mkdir -p ${TEMP}/initramfs-base-temp/etc
63 mkdir -p ${TEMP}/initramfs-base-temp/usr
64 mkdir -p ${TEMP}/initramfs-base-temp/lib
65 mkdir -p ${TEMP}/initramfs-base-temp/mnt
66 mkdir -p ${TEMP}/initramfs-base-temp/run
67 mkdir -p ${TEMP}/initramfs-base-temp/sbin
68 mkdir -p ${TEMP}/initramfs-base-temp/proc
69 mkdir -p ${TEMP}/initramfs-base-temp/temp
70 mkdir -p ${TEMP}/initramfs-base-temp/tmp
71 mkdir -p ${TEMP}/initramfs-base-temp/sys
72 mkdir -p ${TEMP}/initramfs-temp/.initrd
73 mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
74 mkdir -p ${TEMP}/initramfs-base-temp/sbin
75 mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
76 mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
77 ln -s lib ${TEMP}/initramfs-base-temp/lib64
79 echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
80 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
82 cd ${TEMP}/initramfs-base-temp/dev
83 mknod -m 660 console c 5 1
84 mknod -m 660 null c 1 3
85 mknod -m 660 zero c 1 5
86 mknod -m 600 tty0 c 4 0
87 mknod -m 600 tty1 c 4 1
88 mknod -m 600 ttyS0 c 4 64
90 date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date
92 cd "${TEMP}/initramfs-base-temp/"
93 log_future_cpio_content
94 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
95 || gen_die "compressing baselayout cpio"
97 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
101 if [ -d "${TEMP}/initramfs-busybox-temp" ]
103 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
106 mkdir -p "${TEMP}/initramfs-busybox-temp/bin/"
107 tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
108 gen_die 'Could not extract busybox bincache!'
109 chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
111 mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/"
112 cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script
113 chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script"
115 # Set up a few default symlinks
116 for i in ${BUSYBOX_APPLETS:-[ ash sh mount uname echo cut cat}; do
117 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
118 ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
119 gen_die "Busybox error: could not link ${i}!"
122 cd "${TEMP}/initramfs-busybox-temp/"
123 log_future_cpio_content
124 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
125 || gen_die "compressing busybox cpio"
127 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
131 if [ -d "${TEMP}"/initramfs-e2fsprogs-temp ]
133 rm -r "${TEMP}"/initramfs-e2fsprogs-temp
137 || gen_die "cd '${TEMP}' failed"
138 mkdir -p initramfs-e2fsprogs-temp
139 copy_binaries "${TEMP}"/initramfs-e2fsprogs-temp/ /sbin/{e2fsck,mke2fs}
141 cd "${TEMP}"/initramfs-e2fsprogs-temp \
142 || gen_die "cd '${TEMP}/initramfs-e2fsprogs-temp' failed"
143 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
144 rm -rf "${TEMP}"/initramfs-e2fsprogs-temp > /dev/null
148 if [ -d "${TEMP}/initramfs-blkid-temp" ]
150 rm -r "${TEMP}/initramfs-blkid-temp/"
153 mkdir -p "${TEMP}/initramfs-blkid-temp/"
155 if [[ "${DISKLABEL}" = "1" ]]; then
156 copy_binaries "${TEMP}"/initramfs-blkid-temp/ /sbin/blkid
159 cd "${TEMP}/initramfs-blkid-temp/"
160 log_future_cpio_content
161 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
162 || gen_die "compressing blkid cpio"
164 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
168 # if [ -d "${TEMP}/initramfs-fuse-temp" ]
170 # rm -r "${TEMP}/initramfs-fuse-temp"
173 # mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
174 # tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
175 # cd "${TEMP}/initramfs-fuse-temp/"
176 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
177 # || gen_die "compressing fuse cpio"
178 # rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
181 append_unionfs_fuse() {
182 if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
184 rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
187 mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
188 bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
189 gen_die 'Could not extract unionfs-fuse binary cache!'
190 chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
191 cd "${TEMP}/initramfs-unionfs-fuse-temp/"
192 log_future_cpio_content
193 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
194 || gen_die "compressing unionfs fuse cpio"
196 rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
200 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
202 # rm -r "${TEMP}/initramfs-suspend-temp/"
204 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
206 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
207 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
208 # gen_die "Could not extract suspend binary cache!"
209 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
210 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
211 # gen_die 'Could not copy /etc/suspend.conf'
212 # cd "${TEMP}/initramfs-suspend-temp/"
213 # log_future_cpio_content
214 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
215 # || gen_die "compressing suspend cpio"
216 # rm -r "${TEMP}/initramfs-suspend-temp/"
220 if [ -d "${TEMP}/initramfs-multipath-temp" ]
222 rm -r "${TEMP}/initramfs-multipath-temp"
224 print_info 1 ' Multipath support being added'
225 mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/
228 copy_binaries "${TEMP}/initramfs-multipath-temp" /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} /lib64/udev/scsi_id /bin/mountpoint
230 if [ -x /sbin/multipath ]
232 cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this'
234 # /etc/scsi_id.config does not exist in newer udevs
235 # copy it optionally.
236 if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ]
238 cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config'
240 cd "${TEMP}/initramfs-multipath-temp"
241 log_future_cpio_content
242 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
243 || gen_die "compressing multipath cpio"
245 rm -r "${TEMP}/initramfs-multipath-temp/"
249 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
251 rm -r "${TEMP}/initramfs-dmraid-temp/"
253 print_info 1 'DMRAID: Adding support (compiling binaries)...'
255 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
256 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
257 gen_die "Could not extract dmraid binary cache!";
258 cd "${TEMP}/initramfs-dmraid-temp/"
259 RAID456=`find . -type f -name raid456.ko`
260 if [ -n "${RAID456}" ]
262 cd "${RAID456/raid456.ko/}"
263 ln -sf raid456.kp raid45.ko
264 cd "${TEMP}/initramfs-dmraid-temp/"
266 log_future_cpio_content
267 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
268 || gen_die "compressing dmraid cpio"
270 rm -r "${TEMP}/initramfs-dmraid-temp/"
274 if [ -d "${TEMP}/initramfs-iscsi-temp" ]
276 rm -r "${TEMP}/initramfs-iscsi-temp/"
278 print_info 1 'iSCSI: Adding support (compiling binaries)...'
281 mkdir -p "${TEMP}/initramfs-iscsi-temp/bin/"
282 /bin/bzip2 -dc "${ISCSI_BINCACHE}" > "${TEMP}/initramfs-iscsi-temp/bin/iscsistart" ||
283 gen_die "Could not extract iscsi binary cache!"
284 chmod a+x "${TEMP}/initramfs-iscsi-temp/bin/iscsistart"
285 cd "${TEMP}/initramfs-iscsi-temp/"
286 log_future_cpio_content
287 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
288 || gen_die "compressing iscsi cpio"
290 rm -rf "${TEMP}/initramfs-iscsi-temp" > /dev/null
294 if [ -d "${TEMP}/initramfs-lvm-temp" ]
296 rm -r "${TEMP}/initramfs-lvm-temp/"
299 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
300 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
301 if false && [ -e '/sbin/lvm.static' ]
303 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm.static)...'
304 cp /sbin/lvm.static "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
305 gen_die 'Could not copy over lvm!'
307 if [ -e '/sbin/dmsetup.static' ]
309 cp /sbin/dmsetup.static "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
311 elif false && [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
313 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm)...'
314 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
315 gen_die 'Could not copy over lvm!'
317 if [ -e '/sbin/dmsetup' ] && LC_ALL="C" ldd /sbin/dmsetup | grep -q 'not a dynamic executable'
319 cp /sbin/dmsetup "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
322 print_info 1 ' LVM: Adding support (compiling binaries)...'
324 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
325 gen_die "Could not extract lvm binary cache!";
326 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
327 gen_die 'LVM error: Could not move lvm.static to lvm!'
329 mv ${TEMP}/initramfs-lvm-temp/sbin/dmsetup.static ${TEMP}/initramfs-lvm-temp/bin/dmsetup ||
330 gen_die 'LVM error: Could not move dmsetup.static to dmsetup!'
331 rm -rf ${TEMP}/initramfs-lvm-temp/{lib,share,man,include,sbin/{lvm,dmsetup}}
333 if [ -x /sbin/lvm -o -x /bin/lvm ]
335 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
339 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
340 gen_die 'Could not copy over lvm.conf!'
342 # gen_die 'Could not copy over lvm.conf!'
345 cd "${TEMP}/initramfs-lvm-temp/"
346 log_future_cpio_content
347 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
348 || gen_die "compressing lvm cpio"
350 rm -r "${TEMP}/initramfs-lvm-temp/"
354 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
356 rm -r "${TEMP}/initramfs-mdadm-temp/"
359 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
360 mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/"
361 if [ "${MDADM}" = '1' ]
363 if [ -n "${MDADM_CONFIG}" ]
365 if [ -f "${MDADM_CONFIG}" ]
367 cp -a "${MDADM_CONFIG}" "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \
368 || gen_die "Could not copy mdadm.conf!"
370 gen_die 'sl${MDADM_CONFIG} does not exist!'
373 print_info 1 ' MDADM: Skipping inclusion of mdadm.conf'
376 if [ -e '/sbin/mdadm' ] && LC_ALL="C" ldd /sbin/mdadm | grep -q 'not a dynamic executable' \
377 && [ -e '/sbin/mdmon' ] && LC_ALL="C" ldd /sbin/mdmon | grep -q 'not a dynamic executable'
379 print_info 1 ' MDADM: Adding support (using local static binaries /sbin/mdadm and /sbin/mdmon)...'
380 cp /sbin/mdadm /sbin/mdmon "${TEMP}/initramfs-mdadm-temp/sbin/" ||
381 gen_die 'Could not copy over mdadm!'
383 print_info 1 ' MDADM: Adding support (compiling binaries)...'
385 /bin/tar -jxpf "${MDADM_BINCACHE}" -C "${TEMP}/initramfs-mdadm-temp" ||
386 gen_die "Could not extract mdadm binary cache!";
389 cd "${TEMP}/initramfs-mdadm-temp/"
390 log_future_cpio_content
391 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
392 || gen_die "compressing mdadm cpio"
394 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
398 if [ -d "${TEMP}/initramfs-zfs-temp" ]
400 rm -r "${TEMP}/initramfs-zfs-temp"
403 mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs/"
405 # Copy files to /etc/zfs
406 for i in /etc/zfs/{zdev.conf,zpool.cache}
408 cp -a "${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" \
409 || gen_die "Could not copy file ${i} for ZFS"
413 copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool}
415 cd "${TEMP}/initramfs-zfs-temp/"
416 log_future_cpio_content
417 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
418 || gen_die "compressing zfs cpio"
420 rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null
424 splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
425 if [ -x "${splash_geninitramfs}" ]
427 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
428 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
429 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
430 if [ -d "${TEMP}/initramfs-splash-temp" ]
432 rm -r "${TEMP}/initramfs-splash-temp/"
434 mkdir -p "${TEMP}/initramfs-splash-temp"
437 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
438 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
439 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
440 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
441 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
443 cd "${TEMP}/initramfs-splash-temp/"
444 log_future_cpio_content
445 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
446 || gen_die "compressing splash cpio"
448 rm -r "${TEMP}/initramfs-splash-temp/"
450 print_warning 1 ' >> No splash detected; skipping!'
455 cd ${INITRAMFS_OVERLAY}
456 log_future_cpio_content
457 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
458 || gen_die "compressing overlay cpio"
462 local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]."
463 local _luks_source=/sbin/cryptsetup
464 local _luks_dest=/sbin/cryptsetup
466 if [ -d "${TEMP}/initramfs-luks-temp" ]
468 rm -r "${TEMP}/initramfs-luks-temp/"
471 mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/"
472 mkdir -p "${TEMP}/initramfs-luks-temp/sbin"
473 cd "${TEMP}/initramfs-luks-temp"
477 [ -x "${_luks_source}" ] \
478 || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")"
480 print_info 1 "Including LUKS support"
481 copy_binaries "${TEMP}/initramfs-luks-temp/" /sbin/cryptsetup
484 log_future_cpio_content
485 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
486 || gen_die "appending cryptsetup to cpio"
489 rm -r "${TEMP}/initramfs-luks-temp/"
493 if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
495 gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
497 if [ -d "${TEMP}/initramfs-firmware-temp" ]
499 rm -r "${TEMP}/initramfs-firmware-temp/"
501 mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
502 cd "${TEMP}/initramfs-firmware-temp"
503 if [ -n "${FIRMWARE_FILES}" ]
507 for i in ${FIRMWARE_FILES}
509 cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
513 cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
515 log_future_cpio_content
516 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
517 || gen_die "appending firmware to cpio"
519 rm -r "${TEMP}/initramfs-firmware-temp/"
523 if [ -d "${TEMP}/initramfs-gpg-temp" ]
525 rm -r "${TEMP}/initramfs-gpg-temp"
528 mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/"
529 if [ ! -e ${GPG_BINCACHE} ] ; then
530 print_info 1 ' GPG: Adding support (compiling binaries)...'
533 bzip2 -dc "${GPG_BINCACHE}" > "${TEMP}/initramfs-gpg-temp/sbin/gpg" ||
534 gen_die 'Could not extract gpg binary cache!'
535 chmod a+x "${TEMP}/initramfs-gpg-temp/sbin/gpg"
536 cd "${TEMP}/initramfs-gpg-temp/"
537 log_future_cpio_content
538 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
539 rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
556 print_info 2 "initramfs: >> Searching for modules..."
557 if [ "${INSTALL_MOD_PATH}" != '' ]
559 cd ${INSTALL_MOD_PATH}
564 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
566 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
568 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
569 for i in `gen_dep_list`
571 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
574 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
578 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
579 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
582 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
584 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
585 for group_modules in ${!MODULES_*}; do
586 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
587 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
589 cd "${TEMP}/initramfs-modules-${KV}-temp/"
590 log_future_cpio_content
591 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
592 || gen_die "compressing modules cpio"
594 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
598 local TDIR="${TEMP}/initramfs-modprobe.d-temp"
604 mkdir -p "${TDIR}/etc/module_options/"
606 # Load module parameters
607 for dir in $(find "${MODPROBEDIR}"/*)
613 module_name="$(echo "$x" | cut -d ' ' -f 2)"
614 [ "${module_name}" != "$(echo)" ] || continue
615 module_options="$(echo "$x" | cut -d ' ' -f 3-)"
616 [ "${module_options}" != "$(echo)" ] || continue
617 echo "${module_options}" >> "${TDIR}/etc/module_options/${module_name}.conf"
624 log_future_cpio_content
625 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
626 || gen_die "compressing modprobe.d cpio"
629 rm -rf "${TDIR}" > /dev/null
632 # check for static linked file with objdump
634 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
639 if [ -d "${TEMP}/initramfs-aux-temp" ]
641 rm -r "${TEMP}/initramfs-aux-temp/"
643 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
644 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
645 if [ -f "${CMD_LINUXRC}" ]
647 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
648 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
652 cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init"
654 if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
656 cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
658 cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
663 # Make sure it's executable
664 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
666 # Make a symlink to init .. incase we are bundled inside the kernel as one
668 cd ${TEMP}/initramfs-aux-temp
670 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
672 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
674 cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
676 cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
679 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
681 cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
683 cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
686 if [ -n "${REAL_ROOT}" ]
688 sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
691 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
692 for group_modules in ${!MODULES_*}; do
693 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
694 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
696 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
698 if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
700 cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
702 cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
704 if isTrue $CMD_DOKEYMAPAUTO
706 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
708 if isTrue $CMD_KEYMAP
710 print_info 1 " >> Copying keymaps"
711 mkdir -p "${TEMP}/initramfs-aux-temp/lib/"
712 cp -R "${GK_SHARE}/defaults/keymaps" "${TEMP}/initramfs-aux-temp/lib/" \
713 || gen_die "Error while copying keymaps"
716 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
718 chmod +x "${TEMP}/initramfs-aux-temp/init"
719 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
720 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
721 chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
725 cd "${GK_SHARE}/netboot/misc"
726 cp -pPRf * "${TEMP}/initramfs-aux-temp/"
729 cd "${TEMP}/initramfs-aux-temp/"
730 log_future_cpio_content
731 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
732 || gen_die "compressing auxilary cpio"
734 rm -r "${TEMP}/initramfs-aux-temp/"
739 local func="append_${name}"
741 [ $# -eq 0 ] && gen_die "append_data() called with zero arguments"
742 if [ $# -eq 1 ] || isTrue ${var}
744 print_info 1 " >> Appending ${name} cpio data..."
745 ${func} || gen_die "${func}() failed"
750 local compress_ext=""
751 print_info 1 "initramfs: >> Initializing..."
754 CPIO="${TMPDIR}/initramfs-${KV}"
755 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
756 || gen_die "Could not create empty cpio at ${CPIO}"
758 append_data 'base_layout'
759 append_data 'auxilary' "${BUSYBOX}"
760 append_data 'busybox' "${BUSYBOX}"
761 append_data 'e2fstools'
762 append_data 'lvm' "${LVM}"
763 append_data 'dmraid' "${DMRAID}"
764 append_data 'iscsi' "${ISCSI}"
765 append_data 'mdadm' "${MDADM}"
766 append_data 'luks' "${LUKS}"
767 append_data 'multipath' "${MULTIPATH}"
768 append_data 'gpg' "${GPG}"
770 if [ "${RAMDISKMODULES}" = '1' ]
772 append_data 'modules'
774 print_info 1 "initramfs: Not copying modules..."
777 append_data 'zfs' "${ZFS}"
779 append_data 'blkid' "${DISKLABEL}"
781 append_data 'unionfs_fuse' "${UNIONFS}"
783 append_data 'splash' "${SPLASH}"
785 append_data 'modprobed'
787 if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
789 append_data 'firmware'
792 # This should always be appended last
793 if [ "${INITRAMFS_OVERLAY}" != '' ]
795 append_data 'overlay'
798 if isTrue "${INTEGRATED_INITRAMFS}"
800 # Explicitly do not compress if we are integrating into the kernel.
801 # The kernel will do a better job of it than us.
802 mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio
803 sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
804 cat >>${KERNEL_DIR}/.config <<-EOF
805 CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}"
806 CONFIG_INITRAMFS_ROOT_UID=0
807 CONFIG_INITRAMFS_ROOT_GID=0
810 if isTrue "${COMPRESS_INITRD}"
812 if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then
813 # Support --kernel-config=/proc/config.gz, mainly
820 cmd_lzma=$(type -p lzma)
821 cmd_bzip2=$(type -p bzip2)
822 cmd_gzip=$(type -p gzip)
823 cmd_lzop=$(type -p lzop)
824 pkg_xz='app-arch/xz-utils'
825 pkg_lzma='app-arch/xz-utils'
826 pkg_bzip2='app-arch/bzip2'
827 pkg_gzip='app-arch/gzip'
828 pkg_lzop='app-arch/lzop'
830 case ${COMPRESS_INITRD_TYPE} in
831 xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;;
832 lzo) compression=lzop ;;
835 'CONFIG_RD_XZ cmd_xz xz' \
836 'CONFIG_RD_LZMA cmd_lzma lzma' \
837 'CONFIG_RD_BZIP2 cmd_bzip2 bzip2' \
838 'CONFIG_RD_GZIP cmd_gzip gzip' \
839 'CONFIG_RD_LZO cmd_lzop lzop'; do
843 if ${CONFGREP} -q "^${kernel_option}=y" "${KERNEL_CONFIG}" && test -n "${!cmd_variable_name}" ; then
845 [[ ${COMPRESS_INITRD_TYPE} == best ]] && break
848 [[ -z "${compression}" ]] && gen_die "None of the initramfs we tried are supported by your kernel (config file \"${KERNEL_CONFIG}\"), strange!?"
851 gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown"
855 # Check for actual availability
856 cmd_variable_name=cmd_${compression}
857 pkg_variable_name=pkg_${compression}
858 [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'."
861 xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;;
862 lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;;
863 bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;;
864 gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;;
865 lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;;
868 if [ -n "${compression}" ]; then
869 print_info 1 " >> Compressing cpio data (${compress_ext})..."
870 ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed"
871 mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed"
873 print_info 1 " >> Not compressing cpio data ..."
878 if isTrue "${CMD_INSTALL}"
880 if ! isTrue "${INTEGRATED_INITRAMFS}"
882 copy_image_with_preserve "initramfs" \
883 "${TMPDIR}/initramfs-${KV}" \
884 "initramfs-${KNAME}-${ARCH}-${KV}"