4 CPIO_ARGS="--quiet -o -H newc"
11 | awk '/=>/{ if($3 ~ /^\//){print $3}}' \
14 | cpio -p --make-directories --dereference --quiet $destdir
18 append_base_layout() {
19 if [ -d "${TEMP}/initramfs-base-temp" ]
21 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
24 mkdir -p ${TEMP}/initramfs-base-temp/dev
25 mkdir -p ${TEMP}/initramfs-base-temp/bin
26 mkdir -p ${TEMP}/initramfs-base-temp/etc
27 mkdir -p ${TEMP}/initramfs-base-temp/usr
28 mkdir -p ${TEMP}/initramfs-base-temp/lib
29 mkdir -p ${TEMP}/initramfs-base-temp/mnt
30 mkdir -p ${TEMP}/initramfs-base-temp/run
31 mkdir -p ${TEMP}/initramfs-base-temp/sbin
32 mkdir -p ${TEMP}/initramfs-base-temp/proc
33 mkdir -p ${TEMP}/initramfs-base-temp/temp
34 mkdir -p ${TEMP}/initramfs-base-temp/tmp
35 mkdir -p ${TEMP}/initramfs-base-temp/sys
36 mkdir -p ${TEMP}/initramfs-temp/.initrd
37 mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
38 mkdir -p ${TEMP}/initramfs-base-temp/sbin
39 mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
40 mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
41 ln -s lib ${TEMP}/initramfs-base-temp/lib64
43 echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
44 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
46 cd ${TEMP}/initramfs-base-temp/dev
47 mknod -m 660 console c 5 1
48 mknod -m 660 null c 1 3
49 mknod -m 660 zero c 1 5
50 mknod -m 600 tty0 c 4 0
51 mknod -m 600 tty1 c 4 1
52 mknod -m 600 ttyS0 c 4 64
54 date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date
56 cd "${TEMP}/initramfs-base-temp/"
57 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
58 || gen_die "compressing baselayout cpio"
60 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
64 if [ -d "${TEMP}/initramfs-busybox-temp" ]
66 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
69 mkdir -p "${TEMP}/initramfs-busybox-temp/bin/"
70 tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
71 gen_die 'Could not extract busybox bincache!'
72 chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
74 mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/"
75 cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script
76 chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script"
78 # Set up a few default symlinks
79 for i in ${BUSYBOX_APPLETS:-[ ash sh mount uname echo cut cat}; do
80 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
81 ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
82 gen_die "Busybox error: could not link ${i}!"
85 cd "${TEMP}/initramfs-busybox-temp/"
86 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
87 || gen_die "compressing busybox cpio"
89 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
93 if [ -d "${TEMP}/initramfs-blkid-temp" ]
95 rm -r "${TEMP}/initramfs-blkid-temp/"
98 mkdir -p "${TEMP}/initramfs-blkid-temp/sbin/"
99 [ "${DISKLABEL}" = '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/sbin/blkid" ||
100 gen_die "Could not extract blkid binary cache!"; }
101 chmod a+x "${TEMP}/initramfs-blkid-temp/sbin/blkid"
102 cd "${TEMP}/initramfs-blkid-temp/"
103 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
104 || gen_die "compressing blkid cpio"
106 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
110 # if [ -d "${TEMP}/initramfs-fuse-temp" ]
112 # rm -r "${TEMP}/initramfs-fuse-temp"
115 # mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
116 # tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
117 # cd "${TEMP}/initramfs-fuse-temp/"
118 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
119 # || gen_die "compressing fuse cpio"
120 # rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
123 append_unionfs_fuse() {
124 if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
126 rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
129 mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
130 bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
131 gen_die 'Could not extract unionfs-fuse binary cache!'
132 chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
133 cd "${TEMP}/initramfs-unionfs-fuse-temp/"
134 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
135 || gen_die "compressing unionfs fuse cpio"
137 rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
141 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
143 # rm -r "${TEMP}/initramfs-suspend-temp/"
145 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
147 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
148 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
149 # gen_die "Could not extract suspend binary cache!"
150 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
151 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
152 # gen_die 'Could not copy /etc/suspend.conf'
153 # cd "${TEMP}/initramfs-suspend-temp/"
154 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
155 # || gen_die "compressing suspend cpio"
156 # rm -r "${TEMP}/initramfs-suspend-temp/"
160 if [ -d "${TEMP}/initramfs-multipath-temp" ]
162 rm -r "${TEMP}/initramfs-multipath-temp"
164 print_info 1 ' Multipath support being added'
165 mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/
168 copy_binaries "${TEMP}/initramfs-multipath-temp" /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} /lib64/udev/scsi_id /bin/mountpoint
170 if [ -x /sbin/multipath ]
172 cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this'
174 # /etc/scsi_id.config does not exist in newer udevs
175 # copy it optionally.
176 if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ]
178 cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config'
180 cd "${TEMP}/initramfs-multipath-temp"
181 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
182 || gen_die "compressing multipath cpio"
184 rm -r "${TEMP}/initramfs-multipath-temp/"
188 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
190 rm -r "${TEMP}/initramfs-dmraid-temp/"
192 print_info 1 'DMRAID: Adding support (compiling binaries)...'
194 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
195 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
196 gen_die "Could not extract dmraid binary cache!";
197 cd "${TEMP}/initramfs-dmraid-temp/"
198 RAID456=`find . -type f -name raid456.ko`
199 if [ -n "${RAID456}" ]
201 cd "${RAID456/raid456.ko/}"
202 ln -sf raid456.kp raid45.ko
203 cd "${TEMP}/initramfs-dmraid-temp/"
205 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
206 || gen_die "compressing dmraid cpio"
208 rm -r "${TEMP}/initramfs-dmraid-temp/"
212 if [ -d "${TEMP}/initramfs-iscsi-temp" ]
214 rm -r "${TEMP}/initramfs-iscsi-temp/"
216 print_info 1 'iSCSI: Adding support (compiling binaries)...'
219 mkdir -p "${TEMP}/initramfs-iscsi-temp/bin/"
220 /bin/bzip2 -dc "${ISCSI_BINCACHE}" > "${TEMP}/initramfs-iscsi-temp/bin/iscsistart" ||
221 gen_die "Could not extract iscsi binary cache!"
222 chmod a+x "${TEMP}/initramfs-iscsi-temp/bin/iscsistart"
223 cd "${TEMP}/initramfs-iscsi-temp/"
224 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
225 || gen_die "compressing iscsi cpio"
227 rm -rf "${TEMP}/initramfs-iscsi-temp" > /dev/null
231 if [ -d "${TEMP}/initramfs-lvm-temp" ]
233 rm -r "${TEMP}/initramfs-lvm-temp/"
236 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
237 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
238 if false && [ -e '/sbin/lvm.static' ]
240 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm.static)...'
241 cp /sbin/lvm.static "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
242 gen_die 'Could not copy over lvm!'
244 if [ -e '/sbin/dmsetup.static' ]
246 cp /sbin/dmsetup.static "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
248 elif false && [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
250 print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm)...'
251 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
252 gen_die 'Could not copy over lvm!'
254 if [ -e '/sbin/dmsetup' ] && LC_ALL="C" ldd /sbin/dmsetup | grep -q 'not a dynamic executable'
256 cp /sbin/dmsetup "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
259 print_info 1 ' LVM: Adding support (compiling binaries)...'
261 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
262 gen_die "Could not extract lvm binary cache!";
263 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
264 gen_die 'LVM error: Could not move lvm.static to lvm!'
266 mv ${TEMP}/initramfs-lvm-temp/sbin/dmsetup.static ${TEMP}/initramfs-lvm-temp/bin/dmsetup ||
267 gen_die 'LVM error: Could not move dmsetup.static to dmsetup!'
268 rm -rf ${TEMP}/initramfs-lvm-temp/{lib,share,man,include,sbin/{lvm,dmsetup}}
272 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
276 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
277 gen_die 'Could not copy over lvm.conf!'
279 # gen_die 'Could not copy over lvm.conf!'
282 cd "${TEMP}/initramfs-lvm-temp/"
283 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
284 || gen_die "compressing lvm cpio"
286 rm -r "${TEMP}/initramfs-lvm-temp/"
290 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
292 rm -r "${TEMP}/initramfs-mdadm-temp/"
295 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
296 mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/"
297 if [ "${MDADM}" = '1' ]
299 if [ -n "${MDADM_CONFIG}" ]
301 if [ -f "${MDADM_CONFIG}" ]
303 cp -a "${MDADM_CONFIG}" "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \
304 || gen_die "Could not copy mdadm.conf!"
306 gen_die 'sl${MDADM_CONFIG} does not exist!'
309 print_info 1 ' MDADM: Skipping inclusion of mdadm.conf'
312 if [ -e '/sbin/mdadm' ] && LC_ALL="C" ldd /sbin/mdadm | grep -q 'not a dynamic executable' \
313 && [ -e '/sbin/mdmon' ] && LC_ALL="C" ldd /sbin/mdmon | grep -q 'not a dynamic executable'
315 print_info 1 ' MDADM: Adding support (using local static binaries /sbin/mdadm and /sbin/mdmon)...'
316 cp /sbin/mdadm /sbin/mdmon "${TEMP}/initramfs-mdadm-temp/sbin/" ||
317 gen_die 'Could not copy over mdadm!'
319 print_info 1 ' MDADM: Adding support (compiling binaries)...'
321 /bin/tar -jxpf "${MDADM_BINCACHE}" -C "${TEMP}/initramfs-mdadm-temp" ||
322 gen_die "Could not extract mdadm binary cache!";
325 cd "${TEMP}/initramfs-mdadm-temp/"
326 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
327 || gen_die "compressing mdadm cpio"
329 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
333 if [ -d "${TEMP}/initramfs-zfs-temp" ]
335 rm -r "${TEMP}/initramfs-zfs-temp"
338 mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs/"
340 # Copy files to /etc/zfs
341 for i in /etc/zfs/{zdev.conf,zpool.cache}
343 cp -a "${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" \
344 || gen_die "Could not copy file ${i} for ZFS"
348 copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool}
350 cd "${TEMP}/initramfs-zfs-temp/"
351 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
352 || gen_die "compressing zfs cpio"
354 rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null
358 splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
359 if [ -x "${splash_geninitramfs}" ]
361 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
362 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
363 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
364 if [ -d "${TEMP}/initramfs-splash-temp" ]
366 rm -r "${TEMP}/initramfs-splash-temp/"
368 mkdir -p "${TEMP}/initramfs-splash-temp"
371 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
372 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
373 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
374 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
375 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
377 cd "${TEMP}/initramfs-splash-temp/"
378 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
379 || gen_die "compressing splash cpio"
381 rm -r "${TEMP}/initramfs-splash-temp/"
383 print_warning 1 ' >> No splash detected; skipping!'
388 cd ${INITRAMFS_OVERLAY}
389 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
390 || gen_die "compressing overlay cpio"
394 local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]."
395 local _luks_source=/sbin/cryptsetup
396 local _luks_dest=/sbin/cryptsetup
398 if [ -d "${TEMP}/initramfs-luks-temp" ]
400 rm -r "${TEMP}/initramfs-luks-temp/"
403 mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/"
404 mkdir -p "${TEMP}/initramfs-luks-temp/sbin"
405 cd "${TEMP}/initramfs-luks-temp"
409 [ -x "${_luks_source}" ] \
410 || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")"
412 is_static "${_luks_source}" \
413 || gen_die "$(printf "${_luks_error_format}" "${_luks_source} not a static binary")"
415 print_info 1 "Including LUKS support"
416 cp "${_luks_source}" ${TEMP}/initramfs-luks-temp${_luks_dest}
417 chmod +x "${TEMP}/initramfs-luks-temp${_luks_dest}"
420 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
421 || gen_die "appending cryptsetup to cpio"
424 rm -r "${TEMP}/initramfs-luks-temp/"
428 if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
430 gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
432 if [ -d "${TEMP}/initramfs-firmware-temp" ]
434 rm -r "${TEMP}/initramfs-firmware-temp/"
436 mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
437 cd "${TEMP}/initramfs-firmware-temp"
438 if [ -n "${FIRMWARE_FILES}" ]
442 for i in ${FIRMWARE_FILES}
444 cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
448 cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
450 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
451 || gen_die "appending firmware to cpio"
453 rm -r "${TEMP}/initramfs-firmware-temp/"
457 if [ -d "${TEMP}/initramfs-gpg-temp" ]
459 rm -r "${TEMP}/initramfs-gpg-temp"
462 mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/"
463 if [ ! -e ${GPG_BINCACHE} ] ; then
464 print_info 1 ' GPG: Adding support (compiling binaries)...'
467 bzip2 -dc "${GPG_BINCACHE}" > "${TEMP}/initramfs-gpg-temp/sbin/gpg" ||
468 gen_die 'Could not extract gpg binary cache!'
469 chmod a+x "${TEMP}/initramfs-gpg-temp/sbin/gpg"
470 cd "${TEMP}/initramfs-gpg-temp/"
471 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
472 rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
489 print_info 2 "initramfs: >> Searching for modules..."
490 if [ "${INSTALL_MOD_PATH}" != '' ]
492 cd ${INSTALL_MOD_PATH}
497 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
499 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
501 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
502 for i in `gen_dep_list`
504 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
507 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
511 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
512 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
515 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
517 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
518 for group_modules in ${!MODULES_*}; do
519 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
520 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
522 cd "${TEMP}/initramfs-modules-${KV}-temp/"
523 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
524 || gen_die "compressing modules cpio"
526 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
529 # check for static linked file with objdump
531 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
536 if [ -d "${TEMP}/initramfs-aux-temp" ]
538 rm -r "${TEMP}/initramfs-aux-temp/"
540 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
541 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
542 if [ -f "${CMD_LINUXRC}" ]
544 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
545 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
549 cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init"
551 if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
553 cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
555 cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
560 # Make sure it's executable
561 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
563 # Make a symlink to init .. incase we are bundled inside the kernel as one
565 cd ${TEMP}/initramfs-aux-temp
567 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
569 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
571 cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
573 cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
576 if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
578 cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
580 cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
583 if [ -n "${REAL_ROOT}" ]
585 sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
588 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
589 for group_modules in ${!MODULES_*}; do
590 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
591 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
593 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
595 if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
597 cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
599 cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
601 if isTrue $CMD_DOKEYMAPAUTO
603 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
605 if isTrue $CMD_KEYMAP
607 mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
608 /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/defaults/keymaps.tar.gz"
611 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
613 chmod +x "${TEMP}/initramfs-aux-temp/init"
614 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
615 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
616 chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
620 cd "${GK_SHARE}/netboot/misc"
621 cp -pPRf * "${TEMP}/initramfs-aux-temp/"
624 cd "${TEMP}/initramfs-aux-temp/"
625 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
626 || gen_die "compressing auxilary cpio"
628 rm -r "${TEMP}/initramfs-aux-temp/"
633 local func="append_${name}"
635 [ $# -eq 0 ] && gen_die "append_data() called with zero arguments"
636 if [ $# -eq 1 ] || isTrue ${var}
638 print_info 1 " >> Appending ${name} cpio data..."
639 ${func} || gen_die "${func}() failed"
644 local compress_ext=""
645 print_info 1 "initramfs: >> Initializing..."
648 CPIO="${TMPDIR}/initramfs-${KV}"
649 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
650 || gen_die "Could not create empty cpio at ${CPIO}"
652 append_data 'base_layout'
653 append_data 'auxilary' "${BUSYBOX}"
654 append_data 'busybox' "${BUSYBOX}"
655 append_data 'lvm' "${LVM}"
656 append_data 'dmraid' "${DMRAID}"
657 append_data 'iscsi' "${ISCSI}"
658 append_data 'mdadm' "${MDADM}"
659 append_data 'luks' "${LUKS}"
660 append_data 'multipath' "${MULTIPATH}"
661 append_data 'gpg' "${GPG}"
663 if [ "${RAMDISKMODULES}" = '1' ]
665 append_data 'modules'
667 print_info 1 "initramfs: Not copying modules..."
670 append_data 'zfs' "${ZFS}"
672 append_data 'blkid' "${DISKLABEL}"
674 append_data 'unionfs_fuse' "${UNIONFS}"
676 append_data 'splash' "${SPLASH}"
678 if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
680 append_data 'firmware'
683 # This should always be appended last
684 if [ "${INITRAMFS_OVERLAY}" != '' ]
686 append_data 'overlay'
689 if isTrue "${INTEGRATED_INITRAMFS}"
691 # Explicitly do not compress if we are integrating into the kernel.
692 # The kernel will do a better job of it than us.
693 mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio
694 sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
695 cat >>${KERNEL_DIR}/.config <<-EOF
696 CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}"
697 CONFIG_INITRAMFS_ROOT_UID=0
698 CONFIG_INITRAMFS_ROOT_GID=0
701 if isTrue "${COMPRESS_INITRD}"
704 cmd_lzma=$(type -p lzma)
705 cmd_bzip2=$(type -p bzip2)
706 cmd_gzip=$(type -p gzip)
707 cmd_lzop=$(type -p lzop)
708 pkg_xz='app-arch/xz-utils'
709 pkg_lzma='app-arch/xz-utils'
710 pkg_bzip2='app-arch/bzip2'
711 pkg_gzip='app-arch/gzip'
712 pkg_lzop='app-arch/lzop'
714 case ${COMPRESS_INITRD_TYPE} in
715 xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;;
716 lzo) compression=lzop ;;
719 'CONFIG_RD_XZ cmd_xz xz' \
720 'CONFIG_RD_LZMA cmd_lzma lzma' \
721 'CONFIG_RD_BZIP2 cmd_bzip2 bzip' \
722 'CONFIG_RD_GZIP cmd_gzip gzip' \
723 'CONFIG_RD_LZO cmd_lzop lzop'; do
727 if grep -sq "^${kernel_option}=y" ${KERNEL_DIR}/.config && test -n "${!cmd_variable_name}" ; then
729 [[ ${COMPRESS_INITRD_TYPE} == best ]] && break
734 gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown"
738 # Check for actual availability
739 cmd_variable_name=cmd_${compression}
740 pkg_variable_name=pkg_${compression}
741 [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'."
744 xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;;
745 lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;;
746 bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;;
747 gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;;
748 lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;;
751 if [ -n "${compression}" ]; then
752 print_info 1 " >> Compressing cpio data (${compress_ext})..."
753 ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed"
754 mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed"
756 print_info 1 " >> Not compressing cpio data ..."
761 if isTrue "${CMD_INSTALL}"
763 if ! isTrue "${INTEGRATED_INITRAMFS}"
765 copy_image_with_preserve "initramfs" \
766 "${TMPDIR}/initramfs-${KV}" \
767 "initramfs-${KNAME}-${ARCH}-${KV}"