4 CPIO_ARGS="--quiet -o -H newc"
10 for binary in "$@"; do
11 [[ -e "${binary}" ]] \
12 || gen_die "Binary ${binary} could not be found"
14 if LC_ALL=C lddtree "${binary}" 2>&1 | fgrep -q 'not found'; then
15 gen_die "Binary ${binary} is linked to missing libraries and may need to be re-built"
20 | awk '/=>/{ if($3 ~ /^\//){print $3}}' \
23 | cpio -p --make-directories --dereference --quiet "${destdir}" \
24 || gen_die "Binary ${f} or some of its library dependencies could not be copied"
28 append_base_layout() {
29 if [ -d "${TEMP}/initramfs-base-temp" ]
31 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
34 mkdir -p ${TEMP}/initramfs-base-temp/dev
35 mkdir -p ${TEMP}/initramfs-base-temp/bin
36 mkdir -p ${TEMP}/initramfs-base-temp/etc
37 mkdir -p ${TEMP}/initramfs-base-temp/usr
38 mkdir -p ${TEMP}/initramfs-base-temp/lib
39 mkdir -p ${TEMP}/initramfs-base-temp/mnt
40 mkdir -p ${TEMP}/initramfs-base-temp/run
41 mkdir -p ${TEMP}/initramfs-base-temp/sbin
42 mkdir -p ${TEMP}/initramfs-base-temp/proc
43 mkdir -p ${TEMP}/initramfs-base-temp/temp
44 mkdir -p ${TEMP}/initramfs-base-temp/tmp
45 mkdir -p ${TEMP}/initramfs-base-temp/sys
46 mkdir -p ${TEMP}/initramfs-temp/.initrd
47 mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
48 mkdir -p ${TEMP}/initramfs-base-temp/sbin
49 mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
50 mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
51 ln -s lib ${TEMP}/initramfs-base-temp/lib64
53 echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
54 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
56 cd ${TEMP}/initramfs-base-temp/dev
57 mknod -m 660 console c 5 1
58 mknod -m 660 null c 1 3
59 mknod -m 660 zero c 1 5
60 mknod -m 600 tty0 c 4 0
61 mknod -m 600 tty1 c 4 1
62 mknod -m 600 ttyS0 c 4 64
64 date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date
66 cd "${TEMP}/initramfs-base-temp/"
67 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
68 || gen_die "compressing baselayout cpio"
70 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
74 if [ -d "${TEMP}/initramfs-busybox-temp" ]
76 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
79 mkdir -p "${TEMP}/initramfs-busybox-temp/bin/"
80 tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
81 gen_die 'Could not extract busybox bincache!'
82 chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
84 mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/"
85 cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script
86 chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script"
88 # Set up a few default symlinks
89 for i in ${BUSYBOX_APPLETS:-[ ash sh mount uname echo cut cat}; do
90 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
91 ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
92 gen_die "Busybox error: could not link ${i}!"
95 cd "${TEMP}/initramfs-busybox-temp/"
96 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
97 || gen_die "compressing busybox cpio"
99 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
103 if [ -d "${TEMP}/initramfs-blkid-temp" ]
105 rm -r "${TEMP}/initramfs-blkid-temp/"
108 mkdir -p "${TEMP}/initramfs-blkid-temp/sbin/"
109 [ "${DISKLABEL}" = '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/sbin/blkid" ||
110 gen_die "Could not extract blkid binary cache!"; }
111 chmod a+x "${TEMP}/initramfs-blkid-temp/sbin/blkid"
112 cd "${TEMP}/initramfs-blkid-temp/"
113 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
114 || gen_die "compressing blkid cpio"
116 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
120 # if [ -d "${TEMP}/initramfs-fuse-temp" ]
122 # rm -r "${TEMP}/initramfs-fuse-temp"
125 # mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
126 # tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
127 # cd "${TEMP}/initramfs-fuse-temp/"
128 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
129 # || gen_die "compressing fuse cpio"
130 # rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
133 append_unionfs_fuse() {
134 if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
136 rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
139 mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
140 bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
141 gen_die 'Could not extract unionfs-fuse binary cache!'
142 chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
143 cd "${TEMP}/initramfs-unionfs-fuse-temp/"
144 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
145 || gen_die "compressing unionfs fuse cpio"
147 rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
151 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
153 # rm -r "${TEMP}/initramfs-suspend-temp/"
155 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
157 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
158 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
159 # gen_die "Could not extract suspend binary cache!"
160 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
161 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
162 # gen_die 'Could not copy /etc/suspend.conf'
163 # cd "${TEMP}/initramfs-suspend-temp/"
164 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
165 # || gen_die "compressing suspend cpio"
166 # rm -r "${TEMP}/initramfs-suspend-temp/"
170 if [ -d "${TEMP}/initramfs-multipath-temp" ]
172 rm -r "${TEMP}/initramfs-multipath-temp"
174 print_info 1 ' Multipath support being added'
175 mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/
178 copy_binaries "${TEMP}/initramfs-multipath-temp" /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} /lib64/udev/scsi_id /bin/mountpoint
180 if [ -x /sbin/multipath ]
182 cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this'
184 # /etc/scsi_id.config does not exist in newer udevs
185 # copy it optionally.
186 if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ]
188 cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config'
190 cd "${TEMP}/initramfs-multipath-temp"
191 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
192 || gen_die "compressing multipath cpio"
194 rm -r "${TEMP}/initramfs-multipath-temp/"
198 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
200 rm -r "${TEMP}/initramfs-dmraid-temp/"
202 print_info 1 'DMRAID: Adding support (compiling binaries)...'
204 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
205 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
206 gen_die "Could not extract dmraid binary cache!";
207 cd "${TEMP}/initramfs-dmraid-temp/"
208 RAID456=`find . -type f -name raid456.ko`
209 if [ -n "${RAID456}" ]
211 cd "${RAID456/raid456.ko/}"
212 ln -sf raid456.kp raid45.ko
213 cd "${TEMP}/initramfs-dmraid-temp/"
215 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
216 || gen_die "compressing dmraid cpio"
218 rm -r "${TEMP}/initramfs-dmraid-temp/"
222 if [ -d "${TEMP}/initramfs-iscsi-temp" ]
224 rm -r "${TEMP}/initramfs-iscsi-temp/"
226 print_info 1 'iSCSI: Adding support (compiling binaries)...'
229 mkdir -p "${TEMP}/initramfs-iscsi-temp/bin/"
230 /bin/bzip2 -dc "${ISCSI_BINCACHE}" > "${TEMP}/initramfs-iscsi-temp/bin/iscsistart" ||
231 gen_die "Could not extract iscsi binary cache!"
232 chmod a+x "${TEMP}/initramfs-iscsi-temp/bin/iscsistart"
233 cd "${TEMP}/initramfs-iscsi-temp/"
234 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
235 || gen_die "compressing iscsi cpio"
237 rm -rf "${TEMP}/initramfs-iscsi-temp" > /dev/null
241 if [ -d "${TEMP}/initramfs-lvm-temp" ]
243 rm -r "${TEMP}/initramfs-lvm-temp/"
246 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
247 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
248 if false && [ -e '/sbin/lvm.static' ]
250 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm.static)...'
251 cp /sbin/lvm.static "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
252 gen_die 'Could not copy over lvm!'
254 if [ -e '/sbin/dmsetup.static' ]
256 cp /sbin/dmsetup.static "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
258 elif false && [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
260 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm)...'
261 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
262 gen_die 'Could not copy over lvm!'
264 if [ -e '/sbin/dmsetup' ] && LC_ALL="C" ldd /sbin/dmsetup | grep -q 'not a dynamic executable'
266 cp /sbin/dmsetup "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
269 print_info 1 ' LVM: Adding support (compiling binaries)...'
271 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
272 gen_die "Could not extract lvm binary cache!";
273 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
274 gen_die 'LVM error: Could not move lvm.static to lvm!'
276 mv ${TEMP}/initramfs-lvm-temp/sbin/dmsetup.static ${TEMP}/initramfs-lvm-temp/bin/dmsetup ||
277 gen_die 'LVM error: Could not move dmsetup.static to dmsetup!'
278 rm -rf ${TEMP}/initramfs-lvm-temp/{lib,share,man,include,sbin/{lvm,dmsetup}}
282 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
286 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
287 gen_die 'Could not copy over lvm.conf!'
289 # gen_die 'Could not copy over lvm.conf!'
292 cd "${TEMP}/initramfs-lvm-temp/"
293 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
294 || gen_die "compressing lvm cpio"
296 rm -r "${TEMP}/initramfs-lvm-temp/"
300 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
302 rm -r "${TEMP}/initramfs-mdadm-temp/"
305 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
306 mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/"
307 if [ "${MDADM}" = '1' ]
309 if [ -n "${MDADM_CONFIG}" ]
311 if [ -f "${MDADM_CONFIG}" ]
313 cp -a "${MDADM_CONFIG}" "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \
314 || gen_die "Could not copy mdadm.conf!"
316 gen_die 'sl${MDADM_CONFIG} does not exist!'
319 print_info 1 ' MDADM: Skipping inclusion of mdadm.conf'
322 if [ -e '/sbin/mdadm' ] && LC_ALL="C" ldd /sbin/mdadm | grep -q 'not a dynamic executable' \
323 && [ -e '/sbin/mdmon' ] && LC_ALL="C" ldd /sbin/mdmon | grep -q 'not a dynamic executable'
325 print_info 1 ' MDADM: Adding support (using local static binaries /sbin/mdadm and /sbin/mdmon)...'
326 cp /sbin/mdadm /sbin/mdmon "${TEMP}/initramfs-mdadm-temp/sbin/" ||
327 gen_die 'Could not copy over mdadm!'
329 print_info 1 ' MDADM: Adding support (compiling binaries)...'
331 /bin/tar -jxpf "${MDADM_BINCACHE}" -C "${TEMP}/initramfs-mdadm-temp" ||
332 gen_die "Could not extract mdadm binary cache!";
335 cd "${TEMP}/initramfs-mdadm-temp/"
336 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
337 || gen_die "compressing mdadm cpio"
339 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
343 if [ -d "${TEMP}/initramfs-zfs-temp" ]
345 rm -r "${TEMP}/initramfs-zfs-temp"
348 mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs/"
350 # Copy files to /etc/zfs
351 for i in /etc/zfs/{zdev.conf,zpool.cache}
353 cp -a "${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" \
354 || gen_die "Could not copy file ${i} for ZFS"
358 copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool}
360 cd "${TEMP}/initramfs-zfs-temp/"
361 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
362 || gen_die "compressing zfs cpio"
364 rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null
368 splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
369 if [ -x "${splash_geninitramfs}" ]
371 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
372 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
373 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
374 if [ -d "${TEMP}/initramfs-splash-temp" ]
376 rm -r "${TEMP}/initramfs-splash-temp/"
378 mkdir -p "${TEMP}/initramfs-splash-temp"
381 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
382 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
383 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
384 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
385 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
387 cd "${TEMP}/initramfs-splash-temp/"
388 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
389 || gen_die "compressing splash cpio"
391 rm -r "${TEMP}/initramfs-splash-temp/"
393 print_warning 1 ' >> No splash detected; skipping!'
398 cd ${INITRAMFS_OVERLAY}
399 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
400 || gen_die "compressing overlay cpio"
404 local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]."
405 local _luks_source=/sbin/cryptsetup
406 local _luks_dest=/sbin/cryptsetup
408 if [ -d "${TEMP}/initramfs-luks-temp" ]
410 rm -r "${TEMP}/initramfs-luks-temp/"
413 mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/"
414 mkdir -p "${TEMP}/initramfs-luks-temp/sbin"
415 cd "${TEMP}/initramfs-luks-temp"
419 [ -x "${_luks_source}" ] \
420 || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")"
422 print_info 1 "Including LUKS support"
423 copy_binaries "${TEMP}/initramfs-luks-temp/" /sbin/cryptsetup
426 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
427 || gen_die "appending cryptsetup to cpio"
430 rm -r "${TEMP}/initramfs-luks-temp/"
434 if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
436 gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
438 if [ -d "${TEMP}/initramfs-firmware-temp" ]
440 rm -r "${TEMP}/initramfs-firmware-temp/"
442 mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
443 cd "${TEMP}/initramfs-firmware-temp"
444 if [ -n "${FIRMWARE_FILES}" ]
448 for i in ${FIRMWARE_FILES}
450 cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
454 cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
456 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
457 || gen_die "appending firmware to cpio"
459 rm -r "${TEMP}/initramfs-firmware-temp/"
463 if [ -d "${TEMP}/initramfs-gpg-temp" ]
465 rm -r "${TEMP}/initramfs-gpg-temp"
468 mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/"
469 if [ ! -e ${GPG_BINCACHE} ] ; then
470 print_info 1 ' GPG: Adding support (compiling binaries)...'
473 bzip2 -dc "${GPG_BINCACHE}" > "${TEMP}/initramfs-gpg-temp/sbin/gpg" ||
474 gen_die 'Could not extract gpg binary cache!'
475 chmod a+x "${TEMP}/initramfs-gpg-temp/sbin/gpg"
476 cd "${TEMP}/initramfs-gpg-temp/"
477 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
478 rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
495 print_info 2 "initramfs: >> Searching for modules..."
496 if [ "${INSTALL_MOD_PATH}" != '' ]
498 cd ${INSTALL_MOD_PATH}
503 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
505 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
507 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
508 for i in `gen_dep_list`
510 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
513 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
517 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
518 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
521 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
523 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
524 for group_modules in ${!MODULES_*}; do
525 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
526 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
528 cd "${TEMP}/initramfs-modules-${KV}-temp/"
529 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
530 || gen_die "compressing modules cpio"
532 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
535 # check for static linked file with objdump
537 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
542 if [ -d "${TEMP}/initramfs-aux-temp" ]
544 rm -r "${TEMP}/initramfs-aux-temp/"
546 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
547 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
548 if [ -f "${CMD_LINUXRC}" ]
550 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
551 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
555 cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init"
557 if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
559 cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
561 cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
566 # Make sure it's executable
567 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
569 # Make a symlink to init .. incase we are bundled inside the kernel as one
571 cd ${TEMP}/initramfs-aux-temp
573 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
575 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
577 cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
579 cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
582 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
584 cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
586 cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
589 if [ -n "${REAL_ROOT}" ]
591 sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
594 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
595 for group_modules in ${!MODULES_*}; do
596 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
597 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
599 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
601 if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
603 cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
605 cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
607 if isTrue $CMD_DOKEYMAPAUTO
609 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
611 if isTrue $CMD_KEYMAP
613 print_info 1 " >> Copying keymaps"
614 mkdir -p "${TEMP}/initramfs-aux-temp/lib/"
615 cp -R "${GK_SHARE}/defaults/keymaps" "${TEMP}/initramfs-aux-temp/lib/" \
616 || gen_die "Error while copying keymaps"
619 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
621 chmod +x "${TEMP}/initramfs-aux-temp/init"
622 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
623 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
624 chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
628 cd "${GK_SHARE}/netboot/misc"
629 cp -pPRf * "${TEMP}/initramfs-aux-temp/"
632 cd "${TEMP}/initramfs-aux-temp/"
633 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
634 || gen_die "compressing auxilary cpio"
636 rm -r "${TEMP}/initramfs-aux-temp/"
641 local func="append_${name}"
643 [ $# -eq 0 ] && gen_die "append_data() called with zero arguments"
644 if [ $# -eq 1 ] || isTrue ${var}
646 print_info 1 " >> Appending ${name} cpio data..."
647 ${func} || gen_die "${func}() failed"
652 local compress_ext=""
653 print_info 1 "initramfs: >> Initializing..."
656 CPIO="${TMPDIR}/initramfs-${KV}"
657 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
658 || gen_die "Could not create empty cpio at ${CPIO}"
660 append_data 'base_layout'
661 append_data 'auxilary' "${BUSYBOX}"
662 append_data 'busybox' "${BUSYBOX}"
663 append_data 'lvm' "${LVM}"
664 append_data 'dmraid' "${DMRAID}"
665 append_data 'iscsi' "${ISCSI}"
666 append_data 'mdadm' "${MDADM}"
667 append_data 'luks' "${LUKS}"
668 append_data 'multipath' "${MULTIPATH}"
669 append_data 'gpg' "${GPG}"
671 if [ "${RAMDISKMODULES}" = '1' ]
673 append_data 'modules'
675 print_info 1 "initramfs: Not copying modules..."
678 append_data 'zfs' "${ZFS}"
680 append_data 'blkid' "${DISKLABEL}"
682 append_data 'unionfs_fuse' "${UNIONFS}"
684 append_data 'splash' "${SPLASH}"
686 if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
688 append_data 'firmware'
691 # This should always be appended last
692 if [ "${INITRAMFS_OVERLAY}" != '' ]
694 append_data 'overlay'
697 if isTrue "${INTEGRATED_INITRAMFS}"
699 # Explicitly do not compress if we are integrating into the kernel.
700 # The kernel will do a better job of it than us.
701 mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio
702 sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
703 cat >>${KERNEL_DIR}/.config <<-EOF
704 CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}"
705 CONFIG_INITRAMFS_ROOT_UID=0
706 CONFIG_INITRAMFS_ROOT_GID=0
709 if isTrue "${COMPRESS_INITRD}"
712 cmd_lzma=$(type -p lzma)
713 cmd_bzip2=$(type -p bzip2)
714 cmd_gzip=$(type -p gzip)
715 cmd_lzop=$(type -p lzop)
716 pkg_xz='app-arch/xz-utils'
717 pkg_lzma='app-arch/xz-utils'
718 pkg_bzip2='app-arch/bzip2'
719 pkg_gzip='app-arch/gzip'
720 pkg_lzop='app-arch/lzop'
722 case ${COMPRESS_INITRD_TYPE} in
723 xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;;
724 lzo) compression=lzop ;;
727 'CONFIG_RD_XZ cmd_xz xz' \
728 'CONFIG_RD_LZMA cmd_lzma lzma' \
729 'CONFIG_RD_BZIP2 cmd_bzip2 bzip' \
730 'CONFIG_RD_GZIP cmd_gzip gzip' \
731 'CONFIG_RD_LZO cmd_lzop lzop'; do
735 if grep -sq "^${kernel_option}=y" ${KERNEL_DIR}/.config && test -n "${!cmd_variable_name}" ; then
737 [[ ${COMPRESS_INITRD_TYPE} == best ]] && break
742 gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown"
746 # Check for actual availability
747 cmd_variable_name=cmd_${compression}
748 pkg_variable_name=pkg_${compression}
749 [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'."
752 xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;;
753 lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;;
754 bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;;
755 gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;;
756 lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;;
759 if [ -n "${compression}" ]; then
760 print_info 1 " >> Compressing cpio data (${compress_ext})..."
761 ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed"
762 mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed"
764 print_info 1 " >> Not compressing cpio data ..."
769 if isTrue "${CMD_INSTALL}"
771 if ! isTrue "${INTEGRATED_INITRAMFS}"
773 copy_image_with_preserve "initramfs" \
774 "${TMPDIR}/initramfs-${KV}" \
775 "initramfs-${KNAME}-${ARCH}-${KV}"