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.
36 # lddtree does not have the -V (version) nor the -l (list) options prior to version 1.18
38 if lddtree -V > /dev/null 2>&1 ; then
43 | awk '/=>/{ if($3 ~ /^\//){print $3}}'
47 | cpio -p --make-directories --dereference --quiet "${destdir}" \
48 || gen_die "Binary ${f} or some of its library dependencies could not be copied"
51 log_future_cpio_content() {
52 if [[ "${LOGLEVEL}" -gt 1 ]]; then
53 echo =================================================================
54 echo "About to add these files from '${PWD}' to cpio archive:"
55 find . | xargs ls -ald
56 echo =================================================================
60 append_base_layout() {
61 if [ -d "${TEMP}/initramfs-base-temp" ]
63 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
66 mkdir -p ${TEMP}/initramfs-base-temp/dev
67 mkdir -p ${TEMP}/initramfs-base-temp/bin
68 mkdir -p ${TEMP}/initramfs-base-temp/etc
69 mkdir -p ${TEMP}/initramfs-base-temp/usr
70 mkdir -p ${TEMP}/initramfs-base-temp/lib
71 mkdir -p ${TEMP}/initramfs-base-temp/mnt
72 mkdir -p ${TEMP}/initramfs-base-temp/run
73 mkdir -p ${TEMP}/initramfs-base-temp/sbin
74 mkdir -p ${TEMP}/initramfs-base-temp/proc
75 mkdir -p ${TEMP}/initramfs-base-temp/temp
76 mkdir -p ${TEMP}/initramfs-base-temp/tmp
77 mkdir -p ${TEMP}/initramfs-base-temp/sys
78 mkdir -p ${TEMP}/initramfs-temp/.initrd
79 mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
80 mkdir -p ${TEMP}/initramfs-base-temp/sbin
81 mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
82 mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
83 ln -s lib ${TEMP}/initramfs-base-temp/lib64
85 echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
86 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
88 cd ${TEMP}/initramfs-base-temp/dev
89 mknod -m 660 console c 5 1
90 mknod -m 660 null c 1 3
91 mknod -m 660 zero c 1 5
92 mknod -m 600 tty0 c 4 0
93 mknod -m 600 tty1 c 4 1
94 mknod -m 600 ttyS0 c 4 64
96 date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date
97 echo "Genkernel $GK_V" > ${TEMP}/initramfs-base-temp/etc/build_id
99 cd "${TEMP}/initramfs-base-temp/"
100 log_future_cpio_content
101 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
102 || gen_die "compressing baselayout cpio"
104 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
108 if [ -d "${TEMP}/initramfs-busybox-temp" ]
110 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
113 mkdir -p "${TEMP}/initramfs-busybox-temp/bin/"
114 tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
115 gen_die 'Could not extract busybox bincache!'
116 chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
118 mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/"
119 cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script
120 chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script"
122 # Set up a few default symlinks
123 for i in ${BUSYBOX_APPLETS:-[ ash sh mount uname echo cut cat}; do
124 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
125 ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
126 gen_die "Busybox error: could not link ${i}!"
129 cd "${TEMP}/initramfs-busybox-temp/"
130 log_future_cpio_content
131 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
132 || gen_die "compressing busybox cpio"
134 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
138 if [ -d "${TEMP}"/initramfs-e2fsprogs-temp ]
140 rm -r "${TEMP}"/initramfs-e2fsprogs-temp
144 || gen_die "cd '${TEMP}' failed"
145 mkdir -p initramfs-e2fsprogs-temp
146 copy_binaries "${TEMP}"/initramfs-e2fsprogs-temp/ /sbin/{e2fsck,mke2fs}
148 cd "${TEMP}"/initramfs-e2fsprogs-temp \
149 || gen_die "cd '${TEMP}/initramfs-e2fsprogs-temp' failed"
150 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
151 rm -rf "${TEMP}"/initramfs-e2fsprogs-temp > /dev/null
155 if [ -d "${TEMP}/initramfs-blkid-temp" ]
157 rm -r "${TEMP}/initramfs-blkid-temp/"
160 mkdir -p "${TEMP}/initramfs-blkid-temp/"
162 if [[ "${DISKLABEL}" = "1" ]]; then
163 copy_binaries "${TEMP}"/initramfs-blkid-temp/ /sbin/blkid
166 cd "${TEMP}/initramfs-blkid-temp/"
167 log_future_cpio_content
168 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
169 || gen_die "compressing blkid cpio"
171 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
175 # if [ -d "${TEMP}/initramfs-fuse-temp" ]
177 # rm -r "${TEMP}/initramfs-fuse-temp"
180 # mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
181 # tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
182 # cd "${TEMP}/initramfs-fuse-temp/"
183 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
184 # || gen_die "compressing fuse cpio"
185 # rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
188 append_unionfs_fuse() {
189 if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
191 rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
194 mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
195 bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
196 gen_die 'Could not extract unionfs-fuse binary cache!'
197 chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
198 cd "${TEMP}/initramfs-unionfs-fuse-temp/"
199 log_future_cpio_content
200 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
201 || gen_die "compressing unionfs fuse cpio"
203 rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
207 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
209 # rm -r "${TEMP}/initramfs-suspend-temp/"
211 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
213 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
214 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
215 # gen_die "Could not extract suspend binary cache!"
216 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
217 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
218 # gen_die 'Could not copy /etc/suspend.conf'
219 # cd "${TEMP}/initramfs-suspend-temp/"
220 # log_future_cpio_content
221 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
222 # || gen_die "compressing suspend cpio"
223 # rm -r "${TEMP}/initramfs-suspend-temp/"
227 if [ -d "${TEMP}/initramfs-multipath-temp" ]
229 rm -r "${TEMP}/initramfs-multipath-temp"
231 print_info 1 ' Multipath support being added'
232 mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/
235 copy_binaries "${TEMP}/initramfs-multipath-temp" \
237 /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} \
238 /{lib,lib64}/{udev/scsi_id,multipath/*so}
240 if [ -x /sbin/multipath ]
242 cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this'
244 # /etc/scsi_id.config does not exist in newer udevs
245 # copy it optionally.
246 if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ]
248 cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config'
250 cd "${TEMP}/initramfs-multipath-temp"
251 log_future_cpio_content
252 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
253 || gen_die "compressing multipath cpio"
255 rm -r "${TEMP}/initramfs-multipath-temp/"
259 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
261 rm -r "${TEMP}/initramfs-dmraid-temp/"
263 print_info 1 'DMRAID: Adding support (compiling binaries)...'
265 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
266 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
267 gen_die "Could not extract dmraid binary cache!";
268 cd "${TEMP}/initramfs-dmraid-temp/"
269 RAID456=`find . -type f -name raid456.ko`
270 if [ -n "${RAID456}" ]
272 cd "${RAID456/raid456.ko/}"
273 ln -sf raid456.kp raid45.ko
274 cd "${TEMP}/initramfs-dmraid-temp/"
276 log_future_cpio_content
277 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
278 || gen_die "compressing dmraid cpio"
280 rm -r "${TEMP}/initramfs-dmraid-temp/"
284 if [ -d "${TEMP}/initramfs-iscsi-temp" ]
286 rm -r "${TEMP}/initramfs-iscsi-temp/"
288 print_info 1 'iSCSI: Adding support (compiling binaries)...'
291 mkdir -p "${TEMP}/initramfs-iscsi-temp/bin/"
292 /bin/bzip2 -dc "${ISCSI_BINCACHE}" > "${TEMP}/initramfs-iscsi-temp/bin/iscsistart" ||
293 gen_die "Could not extract iscsi binary cache!"
294 chmod a+x "${TEMP}/initramfs-iscsi-temp/bin/iscsistart"
295 cd "${TEMP}/initramfs-iscsi-temp/"
296 log_future_cpio_content
297 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
298 || gen_die "compressing iscsi cpio"
300 rm -rf "${TEMP}/initramfs-iscsi-temp" > /dev/null
304 if [ -d "${TEMP}/initramfs-lvm-temp" ]
306 rm -r "${TEMP}/initramfs-lvm-temp/"
309 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
310 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
311 if false && [ -e '/sbin/lvm.static' ]
313 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm.static)...'
314 cp /sbin/lvm.static "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
315 gen_die 'Could not copy over lvm!'
317 if [ -e '/sbin/dmsetup.static' ]
319 cp /sbin/dmsetup.static "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
321 elif false && [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
323 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm)...'
324 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
325 gen_die 'Could not copy over lvm!'
327 if [ -e '/sbin/dmsetup' ] && LC_ALL="C" ldd /sbin/dmsetup | grep -q 'not a dynamic executable'
329 cp /sbin/dmsetup "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
332 print_info 1 ' LVM: Adding support (compiling binaries)...'
334 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
335 gen_die "Could not extract lvm binary cache!";
336 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
337 gen_die 'LVM error: Could not move lvm.static to lvm!'
339 mv ${TEMP}/initramfs-lvm-temp/sbin/dmsetup.static ${TEMP}/initramfs-lvm-temp/bin/dmsetup ||
340 gen_die 'LVM error: Could not move dmsetup.static to dmsetup!'
341 rm -rf ${TEMP}/initramfs-lvm-temp/{lib,share,man,include,sbin/{lvm,dmsetup}}
343 if [ -x /sbin/lvm -o -x /bin/lvm ]
345 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
349 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
350 gen_die 'Could not copy over lvm.conf!'
352 # gen_die 'Could not copy over lvm.conf!'
355 cd "${TEMP}/initramfs-lvm-temp/"
356 log_future_cpio_content
357 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
358 || gen_die "compressing lvm cpio"
360 rm -r "${TEMP}/initramfs-lvm-temp/"
364 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
366 rm -r "${TEMP}/initramfs-mdadm-temp/"
369 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
370 mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/"
371 if [ "${MDADM}" = '1' ]
373 if [ -n "${MDADM_CONFIG}" ]
375 if [ -f "${MDADM_CONFIG}" ]
377 cp -a "${MDADM_CONFIG}" "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \
378 || gen_die "Could not copy mdadm.conf!"
380 gen_die 'sl${MDADM_CONFIG} does not exist!'
383 print_info 1 ' MDADM: Skipping inclusion of mdadm.conf'
386 if [ -e '/sbin/mdadm' ] && LC_ALL="C" ldd /sbin/mdadm | grep -q 'not a dynamic executable' \
387 && [ -e '/sbin/mdmon' ] && LC_ALL="C" ldd /sbin/mdmon | grep -q 'not a dynamic executable'
389 print_info 1 ' MDADM: Adding support (using local static binaries /sbin/mdadm and /sbin/mdmon)...'
390 cp /sbin/mdadm /sbin/mdmon "${TEMP}/initramfs-mdadm-temp/sbin/" ||
391 gen_die 'Could not copy over mdadm!'
393 print_info 1 ' MDADM: Adding support (compiling binaries)...'
395 /bin/tar -jxpf "${MDADM_BINCACHE}" -C "${TEMP}/initramfs-mdadm-temp" ||
396 gen_die "Could not extract mdadm binary cache!";
399 cd "${TEMP}/initramfs-mdadm-temp/"
400 log_future_cpio_content
401 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
402 || gen_die "compressing mdadm cpio"
404 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
408 if [ -d "${TEMP}/initramfs-zfs-temp" ]
410 rm -r "${TEMP}/initramfs-zfs-temp"
413 mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs/"
415 # Copy files to /etc/zfs
416 for i in /etc/zfs/{zdev.conf,zpool.cache}
418 cp -a "${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" \
419 || print_warning 1 "Could not copy file ${i} for ZFS"
423 copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool}
425 cd "${TEMP}/initramfs-zfs-temp/"
426 log_future_cpio_content
427 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
428 || gen_die "compressing zfs cpio"
430 rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null
434 splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
435 if [ -x "${splash_geninitramfs}" ]
437 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
438 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
439 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
440 if [ -d "${TEMP}/initramfs-splash-temp" ]
442 rm -r "${TEMP}/initramfs-splash-temp/"
444 mkdir -p "${TEMP}/initramfs-splash-temp"
447 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
448 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
449 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
450 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
451 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
453 cd "${TEMP}/initramfs-splash-temp/"
454 log_future_cpio_content
455 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
456 || gen_die "compressing splash cpio"
458 rm -r "${TEMP}/initramfs-splash-temp/"
460 print_warning 1 ' >> No splash detected; skipping!'
465 cd ${INITRAMFS_OVERLAY}
466 log_future_cpio_content
467 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
468 || gen_die "compressing overlay cpio"
472 local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]."
473 local _luks_source=/sbin/cryptsetup
474 local _luks_dest=/sbin/cryptsetup
476 if [ -d "${TEMP}/initramfs-luks-temp" ]
478 rm -r "${TEMP}/initramfs-luks-temp/"
481 mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/"
482 mkdir -p "${TEMP}/initramfs-luks-temp/sbin"
483 cd "${TEMP}/initramfs-luks-temp"
487 [ -x "${_luks_source}" ] \
488 || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")"
490 print_info 1 "Including LUKS support"
491 copy_binaries "${TEMP}/initramfs-luks-temp/" /sbin/cryptsetup
494 log_future_cpio_content
495 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
496 || gen_die "appending cryptsetup to cpio"
499 rm -r "${TEMP}/initramfs-luks-temp/"
503 if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
505 gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
507 if [ -d "${TEMP}/initramfs-firmware-temp" ]
509 rm -r "${TEMP}/initramfs-firmware-temp/"
511 mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
512 cd "${TEMP}/initramfs-firmware-temp"
513 if [ -n "${FIRMWARE_FILES}" ]
517 for i in ${FIRMWARE_FILES}
519 cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
523 cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
525 log_future_cpio_content
526 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
527 || gen_die "appending firmware to cpio"
529 rm -r "${TEMP}/initramfs-firmware-temp/"
533 if [ -d "${TEMP}/initramfs-gpg-temp" ]
535 rm -r "${TEMP}/initramfs-gpg-temp"
538 mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/"
539 if [ ! -e ${GPG_BINCACHE} ] ; then
540 print_info 1 ' GPG: Adding support (compiling binaries)...'
543 bzip2 -dc "${GPG_BINCACHE}" > "${TEMP}/initramfs-gpg-temp/sbin/gpg" ||
544 gen_die 'Could not extract gpg binary cache!'
545 chmod a+x "${TEMP}/initramfs-gpg-temp/sbin/gpg"
546 cd "${TEMP}/initramfs-gpg-temp/"
547 log_future_cpio_content
548 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
549 rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
566 print_info 2 "initramfs: >> Searching for modules..."
567 if [ "${INSTALL_MOD_PATH}" != '' ]
569 cd ${INSTALL_MOD_PATH}
574 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
576 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
578 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
579 for i in `gen_dep_list`
581 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
584 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
588 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
589 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
592 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
594 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
595 for group_modules in ${!MODULES_*}; do
596 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
597 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
599 cd "${TEMP}/initramfs-modules-${KV}-temp/"
600 log_future_cpio_content
601 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
602 || gen_die "compressing modules cpio"
604 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
608 local TDIR="${TEMP}/initramfs-modprobe.d-temp"
614 mkdir -p "${TDIR}/etc/module_options/"
616 # Load module parameters
617 for dir in $(find "${MODPROBEDIR}"/*)
623 module_name="$(echo "$x" | cut -d ' ' -f 2)"
624 [ "${module_name}" != "$(echo)" ] || continue
625 module_options="$(echo "$x" | cut -d ' ' -f 3-)"
626 [ "${module_options}" != "$(echo)" ] || continue
627 echo "${module_options}" >> "${TDIR}/etc/module_options/${module_name}.conf"
634 log_future_cpio_content
635 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
636 || gen_die "compressing modprobe.d cpio"
639 rm -rf "${TDIR}" > /dev/null
642 # check for static linked file with objdump
644 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
649 if [ -d "${TEMP}/initramfs-aux-temp" ]
651 rm -r "${TEMP}/initramfs-aux-temp/"
653 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
654 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
655 if [ -f "${CMD_LINUXRC}" ]
657 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
658 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
662 cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init"
664 if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
666 cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
668 cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
673 # Make sure it's executable
674 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
676 # Make a symlink to init .. incase we are bundled inside the kernel as one
678 cd ${TEMP}/initramfs-aux-temp
680 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
682 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
684 cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
686 cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
689 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
691 cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
693 cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
696 if [ -n "${REAL_ROOT}" ]
698 sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
701 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
702 for group_modules in ${!MODULES_*}; do
703 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
704 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
706 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
708 if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
710 cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
712 cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
714 if isTrue $CMD_DOKEYMAPAUTO
716 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
718 if isTrue $CMD_KEYMAP
720 print_info 1 " >> Copying keymaps"
721 mkdir -p "${TEMP}/initramfs-aux-temp/lib/"
722 cp -R "${GK_SHARE}/defaults/keymaps" "${TEMP}/initramfs-aux-temp/lib/" \
723 || gen_die "Error while copying keymaps"
726 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
728 chmod +x "${TEMP}/initramfs-aux-temp/init"
729 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
730 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
731 chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
735 cd "${GK_SHARE}/netboot/misc"
736 cp -pPRf * "${TEMP}/initramfs-aux-temp/"
739 cd "${TEMP}/initramfs-aux-temp/"
740 log_future_cpio_content
741 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
742 || gen_die "compressing auxilary cpio"
744 rm -r "${TEMP}/initramfs-aux-temp/"
749 local func="append_${name}"
751 [ $# -eq 0 ] && gen_die "append_data() called with zero arguments"
752 if [ $# -eq 1 ] || isTrue ${var}
754 print_info 1 " >> Appending ${name} cpio data..."
755 ${func} || gen_die "${func}() failed"
760 local compress_ext=""
761 print_info 1 "initramfs: >> Initializing..."
764 CPIO="${TMPDIR}/initramfs-${KV}"
765 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
766 || gen_die "Could not create empty cpio at ${CPIO}"
768 append_data 'base_layout'
769 append_data 'auxilary' "${BUSYBOX}"
770 append_data 'busybox' "${BUSYBOX}"
771 isTrue "${CMD_E2FSPROGS}" && append_data 'e2fsprogs'
772 append_data 'lvm' "${LVM}"
773 append_data 'dmraid' "${DMRAID}"
774 append_data 'iscsi' "${ISCSI}"
775 append_data 'mdadm' "${MDADM}"
776 append_data 'luks' "${LUKS}"
777 append_data 'multipath' "${MULTIPATH}"
778 append_data 'gpg' "${GPG}"
780 if [ "${RAMDISKMODULES}" = '1' ]
782 append_data 'modules'
784 print_info 1 "initramfs: Not copying modules..."
787 append_data 'zfs' "${ZFS}"
789 append_data 'blkid' "${DISKLABEL}"
791 append_data 'unionfs_fuse' "${UNIONFS}"
793 append_data 'splash' "${SPLASH}"
795 append_data 'modprobed'
797 if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
799 append_data 'firmware'
802 # This should always be appended last
803 if [ "${INITRAMFS_OVERLAY}" != '' ]
805 append_data 'overlay'
808 if isTrue "${INTEGRATED_INITRAMFS}"
810 # Explicitly do not compress if we are integrating into the kernel.
811 # The kernel will do a better job of it than us.
812 mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio
813 sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
814 compress_config='INITRAMFS_COMPRESSION_NONE'
815 case ${compress_ext} in
816 gz) compress_config='INITRAMFS_COMPRESSION_GZIP' ;;
817 bz2) compress_config='INITRAMFS_COMPRESSION_BZIP2' ;;
818 lzma) compress_config='INITRAMFS_COMPRESSION_LZMA' ;;
819 xz) compress_config='INITRAMFS_COMPRESSION_XZ' ;;
820 lzo) compress_config='INITRAMFS_COMPRESSION_LZO' ;;
821 *) compress_config='INITRAMFS_COMPRESSION_NONE' ;;
823 # All N default except XZ, so there it gets used if the kernel does
824 # compression on it's own.
825 cat >>${KERNEL_DIR}/.config <<-EOF
826 CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}"
827 CONFIG_INITRAMFS_ROOT_UID=0
828 CONFIG_INITRAMFS_ROOT_GID=0
829 CONFIG_INITRAMFS_COMPRESSION_NONE=n
830 CONFIG_INITRAMFS_COMPRESSION_GZIP=n
831 CONFIG_INITRAMFS_COMPRESSION_BZIP2=n
832 CONFIG_INITRAMFS_COMPRESSION_LZMA=n
833 CONFIG_INITRAMFS_COMPRESSION_XZ=y
834 CONFIG_INITRAMFS_COMPRESSION_LZO=n
835 CONFIG_${compress_config}=y
838 if isTrue "${COMPRESS_INITRD}"
840 # NOTE: We do not work with ${KERNEL_CONFIG} here, since things like
841 # "make oldconfig" or --noclean could be in effect.
842 if [ -f "${KERNEL_DIR}"/.config ]; then
843 local ACTUAL_KERNEL_CONFIG="${KERNEL_DIR}"/.config
845 local ACTUAL_KERNEL_CONFIG="${KERNEL_CONFIG}"
848 if [[ "$(file --brief --mime-type "${ACTUAL_KERNEL_CONFIG}")" == application/x-gzip ]]; then
849 # Support --kernel-config=/proc/config.gz, mainly
856 cmd_lzma=$(type -p lzma)
857 cmd_bzip2=$(type -p bzip2)
858 cmd_gzip=$(type -p gzip)
859 cmd_lzop=$(type -p lzop)
860 pkg_xz='app-arch/xz-utils'
861 pkg_lzma='app-arch/xz-utils'
862 pkg_bzip2='app-arch/bzip2'
863 pkg_gzip='app-arch/gzip'
864 pkg_lzop='app-arch/lzop'
866 case ${COMPRESS_INITRD_TYPE} in
867 xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;;
868 lzo) compression=lzop ;;
871 'CONFIG_RD_XZ cmd_xz xz' \
872 'CONFIG_RD_LZMA cmd_lzma lzma' \
873 'CONFIG_RD_BZIP2 cmd_bzip2 bzip2' \
874 'CONFIG_RD_GZIP cmd_gzip gzip' \
875 'CONFIG_RD_LZO cmd_lzop lzop'; do
879 if ${CONFGREP} -q "^${kernel_option}=y" "${ACTUAL_KERNEL_CONFIG}" && test -n "${!cmd_variable_name}" ; then
881 [[ ${COMPRESS_INITRD_TYPE} == best ]] && break
884 [[ -z "${compression}" ]] && gen_die "None of the initramfs compression methods we tried are supported by your kernel (config file \"${ACTUAL_KERNEL_CONFIG}\"), strange!?"
887 gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown"
891 # Check for actual availability
892 cmd_variable_name=cmd_${compression}
893 pkg_variable_name=pkg_${compression}
894 [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'."
897 xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;;
898 lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;;
899 bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;;
900 gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;;
901 lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;;
904 if [ -n "${compression}" ]; then
905 print_info 1 " >> Compressing cpio data (${compress_ext})..."
906 ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed"
907 mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed"
909 print_info 1 " >> Not compressing cpio data ..."
914 if isTrue "${CMD_INSTALL}"
916 if ! isTrue "${INTEGRATED_INITRAMFS}"
918 copy_image_with_preserve "initramfs" \
919 "${TMPDIR}/initramfs-${KV}" \
920 "initramfs-${KNAME}-${ARCH}-${KV}"