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
91 echo "Genkernel $GK_V" > ${TEMP}/initramfs-base-temp/etc/build_id
93 cd "${TEMP}/initramfs-base-temp/"
94 log_future_cpio_content
95 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
96 || gen_die "compressing baselayout cpio"
98 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
102 if [ -d "${TEMP}/initramfs-busybox-temp" ]
104 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
107 mkdir -p "${TEMP}/initramfs-busybox-temp/bin/"
108 tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
109 gen_die 'Could not extract busybox bincache!'
110 chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
112 mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/"
113 cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script
114 chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script"
116 # Set up a few default symlinks
117 for i in ${BUSYBOX_APPLETS:-[ ash sh mount uname echo cut cat}; do
118 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
119 ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
120 gen_die "Busybox error: could not link ${i}!"
123 cd "${TEMP}/initramfs-busybox-temp/"
124 log_future_cpio_content
125 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
126 || gen_die "compressing busybox cpio"
128 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
132 if [ -d "${TEMP}"/initramfs-e2fsprogs-temp ]
134 rm -r "${TEMP}"/initramfs-e2fsprogs-temp
138 || gen_die "cd '${TEMP}' failed"
139 mkdir -p initramfs-e2fsprogs-temp
140 copy_binaries "${TEMP}"/initramfs-e2fsprogs-temp/ /sbin/{e2fsck,mke2fs}
142 cd "${TEMP}"/initramfs-e2fsprogs-temp \
143 || gen_die "cd '${TEMP}/initramfs-e2fsprogs-temp' failed"
144 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
145 rm -rf "${TEMP}"/initramfs-e2fsprogs-temp > /dev/null
149 if [ -d "${TEMP}/initramfs-blkid-temp" ]
151 rm -r "${TEMP}/initramfs-blkid-temp/"
154 mkdir -p "${TEMP}/initramfs-blkid-temp/"
156 if [[ "${DISKLABEL}" = "1" ]]; then
157 copy_binaries "${TEMP}"/initramfs-blkid-temp/ /sbin/blkid
160 cd "${TEMP}/initramfs-blkid-temp/"
161 log_future_cpio_content
162 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
163 || gen_die "compressing blkid cpio"
165 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
169 # if [ -d "${TEMP}/initramfs-fuse-temp" ]
171 # rm -r "${TEMP}/initramfs-fuse-temp"
174 # mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
175 # tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
176 # cd "${TEMP}/initramfs-fuse-temp/"
177 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
178 # || gen_die "compressing fuse cpio"
179 # rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
182 append_unionfs_fuse() {
183 if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
185 rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
188 mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
189 bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
190 gen_die 'Could not extract unionfs-fuse binary cache!'
191 chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
192 cd "${TEMP}/initramfs-unionfs-fuse-temp/"
193 log_future_cpio_content
194 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
195 || gen_die "compressing unionfs fuse cpio"
197 rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
201 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
203 # rm -r "${TEMP}/initramfs-suspend-temp/"
205 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
207 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
208 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
209 # gen_die "Could not extract suspend binary cache!"
210 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
211 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
212 # gen_die 'Could not copy /etc/suspend.conf'
213 # cd "${TEMP}/initramfs-suspend-temp/"
214 # log_future_cpio_content
215 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
216 # || gen_die "compressing suspend cpio"
217 # rm -r "${TEMP}/initramfs-suspend-temp/"
221 if [ -d "${TEMP}/initramfs-multipath-temp" ]
223 rm -r "${TEMP}/initramfs-multipath-temp"
225 print_info 1 ' Multipath support being added'
226 mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/
229 copy_binaries "${TEMP}/initramfs-multipath-temp" \
231 /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} \
232 /{lib,lib64}/{udev/scsi_id,multipath/*so}
234 if [ -x /sbin/multipath ]
236 cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this'
238 # /etc/scsi_id.config does not exist in newer udevs
239 # copy it optionally.
240 if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ]
242 cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config'
244 cd "${TEMP}/initramfs-multipath-temp"
245 log_future_cpio_content
246 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
247 || gen_die "compressing multipath cpio"
249 rm -r "${TEMP}/initramfs-multipath-temp/"
253 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
255 rm -r "${TEMP}/initramfs-dmraid-temp/"
257 print_info 1 'DMRAID: Adding support (compiling binaries)...'
259 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
260 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
261 gen_die "Could not extract dmraid binary cache!";
262 cd "${TEMP}/initramfs-dmraid-temp/"
263 RAID456=`find . -type f -name raid456.ko`
264 if [ -n "${RAID456}" ]
266 cd "${RAID456/raid456.ko/}"
267 ln -sf raid456.kp raid45.ko
268 cd "${TEMP}/initramfs-dmraid-temp/"
270 log_future_cpio_content
271 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
272 || gen_die "compressing dmraid cpio"
274 rm -r "${TEMP}/initramfs-dmraid-temp/"
278 if [ -d "${TEMP}/initramfs-iscsi-temp" ]
280 rm -r "${TEMP}/initramfs-iscsi-temp/"
282 print_info 1 'iSCSI: Adding support (compiling binaries)...'
285 mkdir -p "${TEMP}/initramfs-iscsi-temp/bin/"
286 /bin/bzip2 -dc "${ISCSI_BINCACHE}" > "${TEMP}/initramfs-iscsi-temp/bin/iscsistart" ||
287 gen_die "Could not extract iscsi binary cache!"
288 chmod a+x "${TEMP}/initramfs-iscsi-temp/bin/iscsistart"
289 cd "${TEMP}/initramfs-iscsi-temp/"
290 log_future_cpio_content
291 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
292 || gen_die "compressing iscsi cpio"
294 rm -rf "${TEMP}/initramfs-iscsi-temp" > /dev/null
298 if [ -d "${TEMP}/initramfs-lvm-temp" ]
300 rm -r "${TEMP}/initramfs-lvm-temp/"
303 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
304 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
305 if false && [ -e '/sbin/lvm.static' ]
307 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm.static)...'
308 cp /sbin/lvm.static "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
309 gen_die 'Could not copy over lvm!'
311 if [ -e '/sbin/dmsetup.static' ]
313 cp /sbin/dmsetup.static "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
315 elif false && [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
317 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm)...'
318 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
319 gen_die 'Could not copy over lvm!'
321 if [ -e '/sbin/dmsetup' ] && LC_ALL="C" ldd /sbin/dmsetup | grep -q 'not a dynamic executable'
323 cp /sbin/dmsetup "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
326 print_info 1 ' LVM: Adding support (compiling binaries)...'
328 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
329 gen_die "Could not extract lvm binary cache!";
330 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
331 gen_die 'LVM error: Could not move lvm.static to lvm!'
333 mv ${TEMP}/initramfs-lvm-temp/sbin/dmsetup.static ${TEMP}/initramfs-lvm-temp/bin/dmsetup ||
334 gen_die 'LVM error: Could not move dmsetup.static to dmsetup!'
335 rm -rf ${TEMP}/initramfs-lvm-temp/{lib,share,man,include,sbin/{lvm,dmsetup}}
337 if [ -x /sbin/lvm -o -x /bin/lvm ]
339 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
343 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
344 gen_die 'Could not copy over lvm.conf!'
346 # gen_die 'Could not copy over lvm.conf!'
349 cd "${TEMP}/initramfs-lvm-temp/"
350 log_future_cpio_content
351 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
352 || gen_die "compressing lvm cpio"
354 rm -r "${TEMP}/initramfs-lvm-temp/"
358 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
360 rm -r "${TEMP}/initramfs-mdadm-temp/"
363 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
364 mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/"
365 if [ "${MDADM}" = '1' ]
367 if [ -n "${MDADM_CONFIG}" ]
369 if [ -f "${MDADM_CONFIG}" ]
371 cp -a "${MDADM_CONFIG}" "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \
372 || gen_die "Could not copy mdadm.conf!"
374 gen_die 'sl${MDADM_CONFIG} does not exist!'
377 print_info 1 ' MDADM: Skipping inclusion of mdadm.conf'
380 if [ -e '/sbin/mdadm' ] && LC_ALL="C" ldd /sbin/mdadm | grep -q 'not a dynamic executable' \
381 && [ -e '/sbin/mdmon' ] && LC_ALL="C" ldd /sbin/mdmon | grep -q 'not a dynamic executable'
383 print_info 1 ' MDADM: Adding support (using local static binaries /sbin/mdadm and /sbin/mdmon)...'
384 cp /sbin/mdadm /sbin/mdmon "${TEMP}/initramfs-mdadm-temp/sbin/" ||
385 gen_die 'Could not copy over mdadm!'
387 print_info 1 ' MDADM: Adding support (compiling binaries)...'
389 /bin/tar -jxpf "${MDADM_BINCACHE}" -C "${TEMP}/initramfs-mdadm-temp" ||
390 gen_die "Could not extract mdadm binary cache!";
393 cd "${TEMP}/initramfs-mdadm-temp/"
394 log_future_cpio_content
395 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
396 || gen_die "compressing mdadm cpio"
398 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
402 if [ -d "${TEMP}/initramfs-zfs-temp" ]
404 rm -r "${TEMP}/initramfs-zfs-temp"
407 mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs/"
409 # Copy files to /etc/zfs
410 for i in /etc/zfs/{zdev.conf,zpool.cache}
412 cp -a "${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" \
413 || gen_die "Could not copy file ${i} for ZFS"
417 copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool}
419 cd "${TEMP}/initramfs-zfs-temp/"
420 log_future_cpio_content
421 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
422 || gen_die "compressing zfs cpio"
424 rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null
428 splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
429 if [ -x "${splash_geninitramfs}" ]
431 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
432 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
433 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
434 if [ -d "${TEMP}/initramfs-splash-temp" ]
436 rm -r "${TEMP}/initramfs-splash-temp/"
438 mkdir -p "${TEMP}/initramfs-splash-temp"
441 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
442 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
443 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
444 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
445 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
447 cd "${TEMP}/initramfs-splash-temp/"
448 log_future_cpio_content
449 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
450 || gen_die "compressing splash cpio"
452 rm -r "${TEMP}/initramfs-splash-temp/"
454 print_warning 1 ' >> No splash detected; skipping!'
459 cd ${INITRAMFS_OVERLAY}
460 log_future_cpio_content
461 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
462 || gen_die "compressing overlay cpio"
466 local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]."
467 local _luks_source=/sbin/cryptsetup
468 local _luks_dest=/sbin/cryptsetup
470 if [ -d "${TEMP}/initramfs-luks-temp" ]
472 rm -r "${TEMP}/initramfs-luks-temp/"
475 mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/"
476 mkdir -p "${TEMP}/initramfs-luks-temp/sbin"
477 cd "${TEMP}/initramfs-luks-temp"
481 [ -x "${_luks_source}" ] \
482 || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")"
484 print_info 1 "Including LUKS support"
485 copy_binaries "${TEMP}/initramfs-luks-temp/" /sbin/cryptsetup
488 log_future_cpio_content
489 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
490 || gen_die "appending cryptsetup to cpio"
493 rm -r "${TEMP}/initramfs-luks-temp/"
497 if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
499 gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
501 if [ -d "${TEMP}/initramfs-firmware-temp" ]
503 rm -r "${TEMP}/initramfs-firmware-temp/"
505 mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
506 cd "${TEMP}/initramfs-firmware-temp"
507 if [ -n "${FIRMWARE_FILES}" ]
511 for i in ${FIRMWARE_FILES}
513 cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
517 cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
519 log_future_cpio_content
520 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
521 || gen_die "appending firmware to cpio"
523 rm -r "${TEMP}/initramfs-firmware-temp/"
527 if [ -d "${TEMP}/initramfs-gpg-temp" ]
529 rm -r "${TEMP}/initramfs-gpg-temp"
532 mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/"
533 if [ ! -e ${GPG_BINCACHE} ] ; then
534 print_info 1 ' GPG: Adding support (compiling binaries)...'
537 bzip2 -dc "${GPG_BINCACHE}" > "${TEMP}/initramfs-gpg-temp/sbin/gpg" ||
538 gen_die 'Could not extract gpg binary cache!'
539 chmod a+x "${TEMP}/initramfs-gpg-temp/sbin/gpg"
540 cd "${TEMP}/initramfs-gpg-temp/"
541 log_future_cpio_content
542 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
543 rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
560 print_info 2 "initramfs: >> Searching for modules..."
561 if [ "${INSTALL_MOD_PATH}" != '' ]
563 cd ${INSTALL_MOD_PATH}
568 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
570 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
572 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
573 for i in `gen_dep_list`
575 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
578 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
582 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
583 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
586 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
588 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
589 for group_modules in ${!MODULES_*}; do
590 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
591 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
593 cd "${TEMP}/initramfs-modules-${KV}-temp/"
594 log_future_cpio_content
595 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
596 || gen_die "compressing modules cpio"
598 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
602 local TDIR="${TEMP}/initramfs-modprobe.d-temp"
608 mkdir -p "${TDIR}/etc/module_options/"
610 # Load module parameters
611 for dir in $(find "${MODPROBEDIR}"/*)
617 module_name="$(echo "$x" | cut -d ' ' -f 2)"
618 [ "${module_name}" != "$(echo)" ] || continue
619 module_options="$(echo "$x" | cut -d ' ' -f 3-)"
620 [ "${module_options}" != "$(echo)" ] || continue
621 echo "${module_options}" >> "${TDIR}/etc/module_options/${module_name}.conf"
628 log_future_cpio_content
629 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
630 || gen_die "compressing modprobe.d cpio"
633 rm -rf "${TDIR}" > /dev/null
636 # check for static linked file with objdump
638 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
643 if [ -d "${TEMP}/initramfs-aux-temp" ]
645 rm -r "${TEMP}/initramfs-aux-temp/"
647 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
648 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
649 if [ -f "${CMD_LINUXRC}" ]
651 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
652 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
656 cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init"
658 if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
660 cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
662 cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
667 # Make sure it's executable
668 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
670 # Make a symlink to init .. incase we are bundled inside the kernel as one
672 cd ${TEMP}/initramfs-aux-temp
674 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
676 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
678 cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
680 cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
683 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
685 cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
687 cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
690 if [ -n "${REAL_ROOT}" ]
692 sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
695 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
696 for group_modules in ${!MODULES_*}; do
697 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
698 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
700 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
702 if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
704 cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
706 cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
708 if isTrue $CMD_DOKEYMAPAUTO
710 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
712 if isTrue $CMD_KEYMAP
714 print_info 1 " >> Copying keymaps"
715 mkdir -p "${TEMP}/initramfs-aux-temp/lib/"
716 cp -R "${GK_SHARE}/defaults/keymaps" "${TEMP}/initramfs-aux-temp/lib/" \
717 || gen_die "Error while copying keymaps"
720 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
722 chmod +x "${TEMP}/initramfs-aux-temp/init"
723 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
724 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
725 chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
729 cd "${GK_SHARE}/netboot/misc"
730 cp -pPRf * "${TEMP}/initramfs-aux-temp/"
733 cd "${TEMP}/initramfs-aux-temp/"
734 log_future_cpio_content
735 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
736 || gen_die "compressing auxilary cpio"
738 rm -r "${TEMP}/initramfs-aux-temp/"
743 local func="append_${name}"
745 [ $# -eq 0 ] && gen_die "append_data() called with zero arguments"
746 if [ $# -eq 1 ] || isTrue ${var}
748 print_info 1 " >> Appending ${name} cpio data..."
749 ${func} || gen_die "${func}() failed"
754 local compress_ext=""
755 print_info 1 "initramfs: >> Initializing..."
758 CPIO="${TMPDIR}/initramfs-${KV}"
759 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
760 || gen_die "Could not create empty cpio at ${CPIO}"
762 append_data 'base_layout'
763 append_data 'auxilary' "${BUSYBOX}"
764 append_data 'busybox' "${BUSYBOX}"
765 isTrue "${CMD_E2FSPROGS}" && append_data 'e2fsprogs'
766 append_data 'lvm' "${LVM}"
767 append_data 'dmraid' "${DMRAID}"
768 append_data 'iscsi' "${ISCSI}"
769 append_data 'mdadm' "${MDADM}"
770 append_data 'luks' "${LUKS}"
771 append_data 'multipath' "${MULTIPATH}"
772 append_data 'gpg' "${GPG}"
774 if [ "${RAMDISKMODULES}" = '1' ]
776 append_data 'modules'
778 print_info 1 "initramfs: Not copying modules..."
781 append_data 'zfs' "${ZFS}"
783 append_data 'blkid' "${DISKLABEL}"
785 append_data 'unionfs_fuse' "${UNIONFS}"
787 append_data 'splash' "${SPLASH}"
789 append_data 'modprobed'
791 if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
793 append_data 'firmware'
796 # This should always be appended last
797 if [ "${INITRAMFS_OVERLAY}" != '' ]
799 append_data 'overlay'
802 if isTrue "${INTEGRATED_INITRAMFS}"
804 # Explicitly do not compress if we are integrating into the kernel.
805 # The kernel will do a better job of it than us.
806 mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio
807 sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
808 compress_config='INITRAMFS_COMPRESSION_NONE'
809 case ${compress_ext} in
810 gz) compress_config='INITRAMFS_COMPRESSION_GZIP' ;;
811 bz2) compress_config='INITRAMFS_COMPRESSION_BZIP2' ;;
812 lzma) compress_config='INITRAMFS_COMPRESSION_LZMA' ;;
813 xz) compress_config='INITRAMFS_COMPRESSION_XZ' ;;
814 lzo) compress_config='INITRAMFS_COMPRESSION_LZO' ;;
815 *) compress_config='INITRAMFS_COMPRESSION_NONE' ;;
817 # All N default except XZ, so there it gets used if the kernel does
818 # compression on it's own.
819 cat >>${KERNEL_DIR}/.config <<-EOF
820 CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}"
821 CONFIG_INITRAMFS_ROOT_UID=0
822 CONFIG_INITRAMFS_ROOT_GID=0
823 CONFIG_INITRAMFS_COMPRESSION_NONE=n
824 CONFIG_INITRAMFS_COMPRESSION_GZIP=n
825 CONFIG_INITRAMFS_COMPRESSION_BZIP2=n
826 CONFIG_INITRAMFS_COMPRESSION_LZMA=n
827 CONFIG_INITRAMFS_COMPRESSION_XZ=y
828 CONFIG_INITRAMFS_COMPRESSION_LZO=n
829 CONFIG_${compress_config}=y
832 if isTrue "${COMPRESS_INITRD}"
834 # NOTE: We do not work with ${KERNEL_CONFIG} here, since things like
835 # "make oldconfig" or --noclean could be in effect.
836 if [ -f "${KERNEL_DIR}"/.config ]; then
837 local ACTUAL_KERNEL_CONFIG="${KERNEL_DIR}"/.config
839 local ACTUAL_KERNEL_CONFIG="${KERNEL_CONFIG}"
842 if [[ "$(file --brief --mime-type "${ACTUAL_KERNEL_CONFIG}")" == application/x-gzip ]]; then
843 # Support --kernel-config=/proc/config.gz, mainly
850 cmd_lzma=$(type -p lzma)
851 cmd_bzip2=$(type -p bzip2)
852 cmd_gzip=$(type -p gzip)
853 cmd_lzop=$(type -p lzop)
854 pkg_xz='app-arch/xz-utils'
855 pkg_lzma='app-arch/xz-utils'
856 pkg_bzip2='app-arch/bzip2'
857 pkg_gzip='app-arch/gzip'
858 pkg_lzop='app-arch/lzop'
860 case ${COMPRESS_INITRD_TYPE} in
861 xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;;
862 lzo) compression=lzop ;;
865 'CONFIG_RD_XZ cmd_xz xz' \
866 'CONFIG_RD_LZMA cmd_lzma lzma' \
867 'CONFIG_RD_BZIP2 cmd_bzip2 bzip2' \
868 'CONFIG_RD_GZIP cmd_gzip gzip' \
869 'CONFIG_RD_LZO cmd_lzop lzop'; do
873 if ${CONFGREP} -q "^${kernel_option}=y" "${ACTUAL_KERNEL_CONFIG}" && test -n "${!cmd_variable_name}" ; then
875 [[ ${COMPRESS_INITRD_TYPE} == best ]] && break
878 [[ -z "${compression}" ]] && gen_die "None of the initramfs compression methods we tried are supported by your kernel (config file \"${ACTUAL_KERNEL_CONFIG}\"), strange!?"
881 gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown"
885 # Check for actual availability
886 cmd_variable_name=cmd_${compression}
887 pkg_variable_name=pkg_${compression}
888 [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'."
891 xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;;
892 lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;;
893 bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;;
894 gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;;
895 lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;;
898 if [ -n "${compression}" ]; then
899 print_info 1 " >> Compressing cpio data (${compress_ext})..."
900 ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed"
901 mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed"
903 print_info 1 " >> Not compressing cpio data ..."
908 if isTrue "${CMD_INSTALL}"
910 if ! isTrue "${INTEGRATED_INITRAMFS}"
912 copy_image_with_preserve "initramfs" \
913 "${TMPDIR}/initramfs-${KV}" \
914 "initramfs-${KNAME}-${ARCH}-${KV}"