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-blkid-temp" ]
133 rm -r "${TEMP}/initramfs-blkid-temp/"
136 mkdir -p "${TEMP}/initramfs-blkid-temp/"
138 if [[ "${DISKLABEL}" = "1" ]]; then
139 copy_binaries "${TEMP}"/initramfs-blkid-temp/ /sbin/blkid
142 cd "${TEMP}/initramfs-blkid-temp/"
143 log_future_cpio_content
144 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
145 || gen_die "compressing blkid cpio"
147 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
151 # if [ -d "${TEMP}/initramfs-fuse-temp" ]
153 # rm -r "${TEMP}/initramfs-fuse-temp"
156 # mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
157 # tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
158 # cd "${TEMP}/initramfs-fuse-temp/"
159 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
160 # || gen_die "compressing fuse cpio"
161 # rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
164 append_unionfs_fuse() {
165 if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
167 rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
170 mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
171 bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
172 gen_die 'Could not extract unionfs-fuse binary cache!'
173 chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
174 cd "${TEMP}/initramfs-unionfs-fuse-temp/"
175 log_future_cpio_content
176 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
177 || gen_die "compressing unionfs fuse cpio"
179 rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
183 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
185 # rm -r "${TEMP}/initramfs-suspend-temp/"
187 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
189 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
190 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
191 # gen_die "Could not extract suspend binary cache!"
192 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
193 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
194 # gen_die 'Could not copy /etc/suspend.conf'
195 # cd "${TEMP}/initramfs-suspend-temp/"
196 # log_future_cpio_content
197 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
198 # || gen_die "compressing suspend cpio"
199 # rm -r "${TEMP}/initramfs-suspend-temp/"
203 if [ -d "${TEMP}/initramfs-multipath-temp" ]
205 rm -r "${TEMP}/initramfs-multipath-temp"
207 print_info 1 ' Multipath support being added'
208 mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/
211 copy_binaries "${TEMP}/initramfs-multipath-temp" /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} /lib64/udev/scsi_id /bin/mountpoint
213 if [ -x /sbin/multipath ]
215 cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this'
217 # /etc/scsi_id.config does not exist in newer udevs
218 # copy it optionally.
219 if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ]
221 cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config'
223 cd "${TEMP}/initramfs-multipath-temp"
224 log_future_cpio_content
225 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
226 || gen_die "compressing multipath cpio"
228 rm -r "${TEMP}/initramfs-multipath-temp/"
232 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
234 rm -r "${TEMP}/initramfs-dmraid-temp/"
236 print_info 1 'DMRAID: Adding support (compiling binaries)...'
238 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
239 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
240 gen_die "Could not extract dmraid binary cache!";
241 cd "${TEMP}/initramfs-dmraid-temp/"
242 RAID456=`find . -type f -name raid456.ko`
243 if [ -n "${RAID456}" ]
245 cd "${RAID456/raid456.ko/}"
246 ln -sf raid456.kp raid45.ko
247 cd "${TEMP}/initramfs-dmraid-temp/"
249 log_future_cpio_content
250 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
251 || gen_die "compressing dmraid cpio"
253 rm -r "${TEMP}/initramfs-dmraid-temp/"
257 if [ -d "${TEMP}/initramfs-iscsi-temp" ]
259 rm -r "${TEMP}/initramfs-iscsi-temp/"
261 print_info 1 'iSCSI: Adding support (compiling binaries)...'
264 mkdir -p "${TEMP}/initramfs-iscsi-temp/bin/"
265 /bin/bzip2 -dc "${ISCSI_BINCACHE}" > "${TEMP}/initramfs-iscsi-temp/bin/iscsistart" ||
266 gen_die "Could not extract iscsi binary cache!"
267 chmod a+x "${TEMP}/initramfs-iscsi-temp/bin/iscsistart"
268 cd "${TEMP}/initramfs-iscsi-temp/"
269 log_future_cpio_content
270 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
271 || gen_die "compressing iscsi cpio"
273 rm -rf "${TEMP}/initramfs-iscsi-temp" > /dev/null
277 if [ -d "${TEMP}/initramfs-lvm-temp" ]
279 rm -r "${TEMP}/initramfs-lvm-temp/"
282 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
283 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
284 if false && [ -e '/sbin/lvm.static' ]
286 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm.static)...'
287 cp /sbin/lvm.static "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
288 gen_die 'Could not copy over lvm!'
290 if [ -e '/sbin/dmsetup.static' ]
292 cp /sbin/dmsetup.static "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
294 elif false && [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
296 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm)...'
297 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
298 gen_die 'Could not copy over lvm!'
300 if [ -e '/sbin/dmsetup' ] && LC_ALL="C" ldd /sbin/dmsetup | grep -q 'not a dynamic executable'
302 cp /sbin/dmsetup "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
305 print_info 1 ' LVM: Adding support (compiling binaries)...'
307 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
308 gen_die "Could not extract lvm binary cache!";
309 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
310 gen_die 'LVM error: Could not move lvm.static to lvm!'
312 mv ${TEMP}/initramfs-lvm-temp/sbin/dmsetup.static ${TEMP}/initramfs-lvm-temp/bin/dmsetup ||
313 gen_die 'LVM error: Could not move dmsetup.static to dmsetup!'
314 rm -rf ${TEMP}/initramfs-lvm-temp/{lib,share,man,include,sbin/{lvm,dmsetup}}
316 if [ -x /sbin/lvm -o -x /bin/lvm ]
318 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
322 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
323 gen_die 'Could not copy over lvm.conf!'
325 # gen_die 'Could not copy over lvm.conf!'
328 cd "${TEMP}/initramfs-lvm-temp/"
329 log_future_cpio_content
330 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
331 || gen_die "compressing lvm cpio"
333 rm -r "${TEMP}/initramfs-lvm-temp/"
337 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
339 rm -r "${TEMP}/initramfs-mdadm-temp/"
342 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
343 mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/"
344 if [ "${MDADM}" = '1' ]
346 if [ -n "${MDADM_CONFIG}" ]
348 if [ -f "${MDADM_CONFIG}" ]
350 cp -a "${MDADM_CONFIG}" "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \
351 || gen_die "Could not copy mdadm.conf!"
353 gen_die 'sl${MDADM_CONFIG} does not exist!'
356 print_info 1 ' MDADM: Skipping inclusion of mdadm.conf'
359 if [ -e '/sbin/mdadm' ] && LC_ALL="C" ldd /sbin/mdadm | grep -q 'not a dynamic executable' \
360 && [ -e '/sbin/mdmon' ] && LC_ALL="C" ldd /sbin/mdmon | grep -q 'not a dynamic executable'
362 print_info 1 ' MDADM: Adding support (using local static binaries /sbin/mdadm and /sbin/mdmon)...'
363 cp /sbin/mdadm /sbin/mdmon "${TEMP}/initramfs-mdadm-temp/sbin/" ||
364 gen_die 'Could not copy over mdadm!'
366 print_info 1 ' MDADM: Adding support (compiling binaries)...'
368 /bin/tar -jxpf "${MDADM_BINCACHE}" -C "${TEMP}/initramfs-mdadm-temp" ||
369 gen_die "Could not extract mdadm binary cache!";
372 cd "${TEMP}/initramfs-mdadm-temp/"
373 log_future_cpio_content
374 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
375 || gen_die "compressing mdadm cpio"
377 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
381 if [ -d "${TEMP}/initramfs-zfs-temp" ]
383 rm -r "${TEMP}/initramfs-zfs-temp"
386 mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs/"
388 # Copy files to /etc/zfs
389 for i in /etc/zfs/{zdev.conf,zpool.cache}
391 cp -a "${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" \
392 || gen_die "Could not copy file ${i} for ZFS"
396 copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool}
398 cd "${TEMP}/initramfs-zfs-temp/"
399 log_future_cpio_content
400 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
401 || gen_die "compressing zfs cpio"
403 rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null
407 splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
408 if [ -x "${splash_geninitramfs}" ]
410 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
411 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
412 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
413 if [ -d "${TEMP}/initramfs-splash-temp" ]
415 rm -r "${TEMP}/initramfs-splash-temp/"
417 mkdir -p "${TEMP}/initramfs-splash-temp"
420 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
421 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
422 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
423 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
424 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
426 cd "${TEMP}/initramfs-splash-temp/"
427 log_future_cpio_content
428 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
429 || gen_die "compressing splash cpio"
431 rm -r "${TEMP}/initramfs-splash-temp/"
433 print_warning 1 ' >> No splash detected; skipping!'
438 cd ${INITRAMFS_OVERLAY}
439 log_future_cpio_content
440 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
441 || gen_die "compressing overlay cpio"
445 local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]."
446 local _luks_source=/sbin/cryptsetup
447 local _luks_dest=/sbin/cryptsetup
449 if [ -d "${TEMP}/initramfs-luks-temp" ]
451 rm -r "${TEMP}/initramfs-luks-temp/"
454 mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/"
455 mkdir -p "${TEMP}/initramfs-luks-temp/sbin"
456 cd "${TEMP}/initramfs-luks-temp"
460 [ -x "${_luks_source}" ] \
461 || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")"
463 print_info 1 "Including LUKS support"
464 copy_binaries "${TEMP}/initramfs-luks-temp/" /sbin/cryptsetup
467 log_future_cpio_content
468 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
469 || gen_die "appending cryptsetup to cpio"
472 rm -r "${TEMP}/initramfs-luks-temp/"
476 if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
478 gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
480 if [ -d "${TEMP}/initramfs-firmware-temp" ]
482 rm -r "${TEMP}/initramfs-firmware-temp/"
484 mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
485 cd "${TEMP}/initramfs-firmware-temp"
486 if [ -n "${FIRMWARE_FILES}" ]
490 for i in ${FIRMWARE_FILES}
492 cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
496 cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
498 log_future_cpio_content
499 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
500 || gen_die "appending firmware to cpio"
502 rm -r "${TEMP}/initramfs-firmware-temp/"
506 if [ -d "${TEMP}/initramfs-gpg-temp" ]
508 rm -r "${TEMP}/initramfs-gpg-temp"
511 mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/"
512 if [ ! -e ${GPG_BINCACHE} ] ; then
513 print_info 1 ' GPG: Adding support (compiling binaries)...'
516 bzip2 -dc "${GPG_BINCACHE}" > "${TEMP}/initramfs-gpg-temp/sbin/gpg" ||
517 gen_die 'Could not extract gpg binary cache!'
518 chmod a+x "${TEMP}/initramfs-gpg-temp/sbin/gpg"
519 cd "${TEMP}/initramfs-gpg-temp/"
520 log_future_cpio_content
521 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
522 rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
539 print_info 2 "initramfs: >> Searching for modules..."
540 if [ "${INSTALL_MOD_PATH}" != '' ]
542 cd ${INSTALL_MOD_PATH}
547 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
549 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
551 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
552 for i in `gen_dep_list`
554 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
557 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
561 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
562 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
565 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
567 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
568 for group_modules in ${!MODULES_*}; do
569 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
570 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
572 cd "${TEMP}/initramfs-modules-${KV}-temp/"
573 log_future_cpio_content
574 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
575 || gen_die "compressing modules cpio"
577 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
581 local TDIR="${TEMP}/initramfs-modprobe.d-temp"
587 mkdir -p "${TDIR}/etc/module_options/"
589 # Load module parameters
590 for dir in $(find "${MODPROBEDIR}"/*)
596 module_name="$(echo "$x" | cut -d ' ' -f 2)"
597 [ "${module_name}" != "$(echo)" ] || continue
598 module_options="$(echo "$x" | cut -d ' ' -f 3-)"
599 [ "${module_options}" != "$(echo)" ] || continue
600 echo "${module_options}" >> "${TDIR}/etc/module_options/${module_name}.conf"
607 log_future_cpio_content
608 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
609 || gen_die "compressing modprobe.d cpio"
612 rm -rf "${TDIR}" > /dev/null
615 # check for static linked file with objdump
617 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
622 if [ -d "${TEMP}/initramfs-aux-temp" ]
624 rm -r "${TEMP}/initramfs-aux-temp/"
626 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
627 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
628 if [ -f "${CMD_LINUXRC}" ]
630 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
631 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
635 cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init"
637 if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
639 cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
641 cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
646 # Make sure it's executable
647 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
649 # Make a symlink to init .. incase we are bundled inside the kernel as one
651 cd ${TEMP}/initramfs-aux-temp
653 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
655 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
657 cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
659 cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
662 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
664 cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
666 cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
669 if [ -n "${REAL_ROOT}" ]
671 sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
674 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
675 for group_modules in ${!MODULES_*}; do
676 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
677 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
679 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
681 if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
683 cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
685 cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
687 if isTrue $CMD_DOKEYMAPAUTO
689 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
691 if isTrue $CMD_KEYMAP
693 print_info 1 " >> Copying keymaps"
694 mkdir -p "${TEMP}/initramfs-aux-temp/lib/"
695 cp -R "${GK_SHARE}/defaults/keymaps" "${TEMP}/initramfs-aux-temp/lib/" \
696 || gen_die "Error while copying keymaps"
699 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
701 chmod +x "${TEMP}/initramfs-aux-temp/init"
702 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
703 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
704 chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
708 cd "${GK_SHARE}/netboot/misc"
709 cp -pPRf * "${TEMP}/initramfs-aux-temp/"
712 cd "${TEMP}/initramfs-aux-temp/"
713 log_future_cpio_content
714 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
715 || gen_die "compressing auxilary cpio"
717 rm -r "${TEMP}/initramfs-aux-temp/"
722 local func="append_${name}"
724 [ $# -eq 0 ] && gen_die "append_data() called with zero arguments"
725 if [ $# -eq 1 ] || isTrue ${var}
727 print_info 1 " >> Appending ${name} cpio data..."
728 ${func} || gen_die "${func}() failed"
733 local compress_ext=""
734 print_info 1 "initramfs: >> Initializing..."
737 CPIO="${TMPDIR}/initramfs-${KV}"
738 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
739 || gen_die "Could not create empty cpio at ${CPIO}"
741 append_data 'base_layout'
742 append_data 'auxilary' "${BUSYBOX}"
743 append_data 'busybox' "${BUSYBOX}"
744 append_data 'lvm' "${LVM}"
745 append_data 'dmraid' "${DMRAID}"
746 append_data 'iscsi' "${ISCSI}"
747 append_data 'mdadm' "${MDADM}"
748 append_data 'luks' "${LUKS}"
749 append_data 'multipath' "${MULTIPATH}"
750 append_data 'gpg' "${GPG}"
752 if [ "${RAMDISKMODULES}" = '1' ]
754 append_data 'modules'
756 print_info 1 "initramfs: Not copying modules..."
759 append_data 'zfs' "${ZFS}"
761 append_data 'blkid' "${DISKLABEL}"
763 append_data 'unionfs_fuse' "${UNIONFS}"
765 append_data 'splash' "${SPLASH}"
767 append_data 'modprobed'
769 if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
771 append_data 'firmware'
774 # This should always be appended last
775 if [ "${INITRAMFS_OVERLAY}" != '' ]
777 append_data 'overlay'
780 if isTrue "${INTEGRATED_INITRAMFS}"
782 # Explicitly do not compress if we are integrating into the kernel.
783 # The kernel will do a better job of it than us.
784 mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio
785 sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
786 cat >>${KERNEL_DIR}/.config <<-EOF
787 CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}"
788 CONFIG_INITRAMFS_ROOT_UID=0
789 CONFIG_INITRAMFS_ROOT_GID=0
792 if isTrue "${COMPRESS_INITRD}"
794 if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then
795 # Support --kernel-config=/proc/config.gz, mainly
802 cmd_lzma=$(type -p lzma)
803 cmd_bzip2=$(type -p bzip2)
804 cmd_gzip=$(type -p gzip)
805 cmd_lzop=$(type -p lzop)
806 pkg_xz='app-arch/xz-utils'
807 pkg_lzma='app-arch/xz-utils'
808 pkg_bzip2='app-arch/bzip2'
809 pkg_gzip='app-arch/gzip'
810 pkg_lzop='app-arch/lzop'
812 case ${COMPRESS_INITRD_TYPE} in
813 xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;;
814 lzo) compression=lzop ;;
817 'CONFIG_RD_XZ cmd_xz xz' \
818 'CONFIG_RD_LZMA cmd_lzma lzma' \
819 'CONFIG_RD_BZIP2 cmd_bzip2 bzip2' \
820 'CONFIG_RD_GZIP cmd_gzip gzip' \
821 'CONFIG_RD_LZO cmd_lzop lzop'; do
825 if ${CONFGREP} -q "^${kernel_option}=y" "${KERNEL_CONFIG}" && test -n "${!cmd_variable_name}" ; then
827 [[ ${COMPRESS_INITRD_TYPE} == best ]] && break
830 [[ -z "${compression}" ]] && gen_die "None of the initramfs we tried are supported by your kernel (config file \"${KERNEL_CONFIG}\"), strange!?"
833 gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown"
837 # Check for actual availability
838 cmd_variable_name=cmd_${compression}
839 pkg_variable_name=pkg_${compression}
840 [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'."
843 xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;;
844 lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;;
845 bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;;
846 gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;;
847 lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;;
850 if [ -n "${compression}" ]; then
851 print_info 1 " >> Compressing cpio data (${compress_ext})..."
852 ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed"
853 mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed"
855 print_info 1 " >> Not compressing cpio data ..."
860 if isTrue "${CMD_INSTALL}"
862 if ! isTrue "${INTEGRATED_INITRAMFS}"
864 copy_image_with_preserve "initramfs" \
865 "${TMPDIR}/initramfs-${KV}" \
866 "initramfs-${KNAME}-${ARCH}-${KV}"