#!/bin/bash
+# $Id$
+
+CPIO_ARGS="--quiet -o -H newc"
+
+# The copy_binaries function is explicitly released under the CC0 license to
+# encourage wide adoption and re-use. That means:
+# - You may use the code of copy_binaries() as CC0 outside of genkernel
+# - Contributions to this function are licensed under CC0 as well.
+# - If you change it outside of genkernel, please consider sending your
+# modifications back to genkernel@gentoo.org.
+#
+# On a side note: "Both public domain works and the simple license provided by
+# CC0 are compatible with the GNU GPL."
+# (from https://www.gnu.org/licenses/license-list.html#CC0)
+#
+# Written by:
+# - Sebastian Pipping <sebastian@pipping.org> (error checking)
+# - Robin H. Johnson <robbat2@gentoo.org> (complete rewrite)
+# - Richard Yao <ryao@cs.stonybrook.edu> (original concept)
+# Usage:
+# copy_binaries DESTDIR BINARIES...
+copy_binaries() {
+ local destdir=$1
+ shift
+
+ for binary in "$@"; do
+ [[ -e "${binary}" ]] \
+ || gen_die "Binary ${binary} could not be found"
+
+ if LC_ALL=C lddtree "${binary}" 2>&1 | fgrep -q 'not found'; then
+ gen_die "Binary ${binary} is linked to missing libraries and may need to be re-built"
+ fi
+ done
+ # This must be OUTSIDE the for loop, we only want to run lddtree etc ONCE.
+ lddtree "$@" \
+ | tr ')(' '\n' \
+ | awk '/=>/{ if($3 ~ /^\//){print $3}}' \
+ | sort \
+ | uniq \
+ | cpio -p --make-directories --dereference --quiet "${destdir}" \
+ || gen_die "Binary ${f} or some of its library dependencies could not be copied"
+}
-create_base_layout_cpio() {
+log_future_cpio_content() {
+ if [[ "${LOGLEVEL}" -gt 1 ]]; then
+ echo =================================================================
+ echo "About to add these files from '${PWD}' to cpio archive:"
+ find . | xargs ls -ald
+ echo =================================================================
+ fi
+}
+
+append_base_layout() {
if [ -d "${TEMP}/initramfs-base-temp" ]
then
rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
fi
+
mkdir -p ${TEMP}/initramfs-base-temp/dev
mkdir -p ${TEMP}/initramfs-base-temp/bin
mkdir -p ${TEMP}/initramfs-base-temp/etc
mkdir -p ${TEMP}/initramfs-base-temp/usr
+ mkdir -p ${TEMP}/initramfs-base-temp/lib
+ mkdir -p ${TEMP}/initramfs-base-temp/mnt
+ mkdir -p ${TEMP}/initramfs-base-temp/run
+ mkdir -p ${TEMP}/initramfs-base-temp/sbin
mkdir -p ${TEMP}/initramfs-base-temp/proc
mkdir -p ${TEMP}/initramfs-base-temp/temp
+ mkdir -p ${TEMP}/initramfs-base-temp/tmp
mkdir -p ${TEMP}/initramfs-base-temp/sys
mkdir -p ${TEMP}/initramfs-temp/.initrd
mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
mkdir -p ${TEMP}/initramfs-base-temp/sbin
mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
+ ln -s lib ${TEMP}/initramfs-base-temp/lib64
- echo "/dev/ram0 / ext2 defaults" > ${TEMP}/initramfs-base-temp/etc/fstab
+ echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
-
- if [ "${DEVFS}" -eq '1' ]
- then
- echo "REGISTER .* MKOLDCOMPAT" > ${TEMP}/initramfs-base-temp/etc/devfsd.conf
- echo "UNREGISTER .* RMOLDCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
- echo "REGISTER .* MKNEWCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
- echo "UNREGISTER .* RMNEWCOMPAT" >> ${TEMP}/initramfs-base-temp/etc/devfsd.conf
- fi
cd ${TEMP}/initramfs-base-temp/dev
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3
+ mknod -m 660 zero c 1 5
+ mknod -m 600 tty0 c 4 0
mknod -m 600 tty1 c 4 1
+ mknod -m 600 ttyS0 c 4 64
+
+ date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date
+
cd "${TEMP}/initramfs-base-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-base-layout.cpio.gz
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing baselayout cpio"
+ cd "${TEMP}"
rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
}
-create_busybox_cpio() {
+append_busybox() {
if [ -d "${TEMP}/initramfs-busybox-temp" ]
then
rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
fi
+
mkdir -p "${TEMP}/initramfs-busybox-temp/bin/"
- cp "${BUSYBOX_BINCACHE}" "${TEMP}/initramfs-busybox-temp/bin/busybox.bz2" ||
- gen_die 'Could not copy busybox from bincache!'
- bunzip2 "${TEMP}/initramfs-busybox-temp/bin/busybox.bz2" ||
- gen_die 'Could not uncompress busybox!'
+ tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
+ gen_die 'Could not extract busybox bincache!'
chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
- # down devfsd we use with dietlibc
-# cp "${DEVFSD_CONF_BINCACHE}" "${TEMP}/initramfs-temp/etc/devfsd.conf.bz2" ||
-# gen_die "could not copy devfsd.conf from bincache"
-# bunzip2 "${TEMP}/initramfs-temp/etc/devfsd.conf.bz2" ||
-# gen_die "could not uncompress devfsd.conf"
- for i in '[' ash sh mount uname echo cut; do
+ mkdir -p "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/"
+ cp "${GK_SHARE}/defaults/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script
+ chmod +x "${TEMP}/initramfs-busybox-temp/usr/share/udhcpc/default.script"
+
+ # Set up a few default symlinks
+ for i in ${BUSYBOX_APPLETS:-[ ash sh mount uname echo cut cat}; do
rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
- ln ${TEMP}/initramfs-busybox-temp/bin/busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
+ ln -s busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
gen_die "Busybox error: could not link ${i}!"
done
-
+
cd "${TEMP}/initramfs-busybox-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-busybox-${BUSYBOX_VER}.cpio.gz
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing busybox cpio"
+ cd "${TEMP}"
rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
}
-create_insmod_cpio() {
- if [ -d "${TEMP}/initramfs-insmod-temp" ]
+append_blkid(){
+ if [ -d "${TEMP}/initramfs-blkid-temp" ]
then
- rm -rf "${TEMP}/initramfs-insmod-temp" > /dev/null
+ rm -r "${TEMP}/initramfs-blkid-temp/"
fi
- mkdir -p "${TEMP}/initramfs-insmod-temp/bin/"
- cp "${MODULE_INIT_TOOLS_BINCACHE}" "${TEMP}/initramfs-insmod-temp/bin/insmod.static.bz2" ||
- gen_die 'Could not copy insmod.static from bincache!'
+ cd ${TEMP}
+ mkdir -p "${TEMP}/initramfs-blkid-temp/"
- bunzip2 "${TEMP}/initramfs-insmod-temp/bin/insmod.static.bz2" ||
- gen_die 'Could not uncompress insmod.static!'
- mv "${TEMP}/initramfs-insmod-temp/bin/insmod.static" "${TEMP}/initramfs-insmod-temp/bin/insmod"
- chmod +x "${TEMP}/initramfs-insmod-temp/bin/insmod"
-
- cd "${TEMP}/initramfs-insmod-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-insmod-${MODULE_INIT_TOOLS_VER}.cpio.gz
- rm -rf "${TEMP}/initramfs-insmod-temp" > /dev/null
+ if [[ "${DISKLABEL}" = "1" ]]; then
+ copy_binaries "${TEMP}"/initramfs-blkid-temp/ /sbin/blkid
+ fi
+
+ cd "${TEMP}/initramfs-blkid-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing blkid cpio"
+ cd "${TEMP}"
+ rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
}
-create_udev_cpio(){
- if [ -d "${TEMP}/initramfs-udev-temp" ]
- then
- rm -r "${TEMP}/initramfs-udev-temp/"
+#append_fuse() {
+# if [ -d "${TEMP}/initramfs-fuse-temp" ]
+# then
+# rm -r "${TEMP}/initramfs-fuse-temp"
+# fi
+# cd ${TEMP}
+# mkdir -p "${TEMP}/initramfs-fuse-temp/lib/"
+# tar -C "${TEMP}/initramfs-fuse-temp/lib/" -xjf "${FUSE_BINCACHE}"
+# cd "${TEMP}/initramfs-fuse-temp/"
+# find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+# || gen_die "compressing fuse cpio"
+# rm -rf "${TEMP}/initramfs-fuse-temp" > /dev/null
+#}
+
+append_unionfs_fuse() {
+ if [ -d "${TEMP}/initramfs-unionfs-fuse-temp" ]
+ then
+ rm -r "${TEMP}/initramfs-unionfs-fuse-temp"
fi
cd ${TEMP}
- mkdir -p "${TEMP}/initramfs-udev-temp/bin/"
- [ "${UDEV}" -eq '1' ] && { /bin/tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initramfs-udev-temp" ||
- gen_die "Could not extract udev binary cache!"; }
- cd "${TEMP}/initramfs-udev-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-udev-${UDEV_VER}.cpio.gz
- rm -rf "${TEMP}/initramfs-udev-temp" > /dev/null
+ mkdir -p "${TEMP}/initramfs-unionfs-fuse-temp/sbin/"
+ bzip2 -dc "${UNIONFS_FUSE_BINCACHE}" > "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs" ||
+ gen_die 'Could not extract unionfs-fuse binary cache!'
+ chmod a+x "${TEMP}/initramfs-unionfs-fuse-temp/sbin/unionfs"
+ cd "${TEMP}/initramfs-unionfs-fuse-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing unionfs fuse cpio"
+ cd "${TEMP}"
+ rm -rf "${TEMP}/initramfs-unionfs-fuse-temp" > /dev/null
}
-create_blkid_cpio(){
- if [ -d "${TEMP}/initramfs-blkid-temp" ]
- then
- rm -r "${TEMP}/initramfs-blkid-temp/"
- fi
- cd ${TEMP}
- mkdir -p "${TEMP}/initramfs-blkid-temp/bin/"
- [ "${DISKLABEL}" -eq '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/bin/blkid" ||
- gen_die "Could not extract blkid binary cache!"; }
- chmod a+x "${TEMP}/initramfs-blkid-temp/bin/blkid"
- cd "${TEMP}/initramfs-blkid-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-blkid-${E2FSPROGS_VER}.cpio.gz
- rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
+#append_suspend(){
+# if [ -d "${TEMP}/initramfs-suspend-temp" ];
+# then
+# rm -r "${TEMP}/initramfs-suspend-temp/"
+# fi
+# print_info 1 'SUSPEND: Adding support (compiling binaries)...'
+# compile_suspend
+# mkdir -p "${TEMP}/initramfs-suspend-temp/"
+# /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
+# gen_die "Could not extract suspend binary cache!"
+# mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
+# cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
+# gen_die 'Could not copy /etc/suspend.conf'
+# cd "${TEMP}/initramfs-suspend-temp/"
+# log_future_cpio_content
+# find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+# || gen_die "compressing suspend cpio"
+# rm -r "${TEMP}/initramfs-suspend-temp/"
+#}
+
+append_multipath(){
+ if [ -d "${TEMP}/initramfs-multipath-temp" ]
+ then
+ rm -r "${TEMP}/initramfs-multipath-temp"
+ fi
+ print_info 1 ' Multipath support being added'
+ mkdir -p "${TEMP}"/initramfs-multipath-temp/{bin,etc,sbin,lib}/
+
+ # Copy files
+ copy_binaries "${TEMP}/initramfs-multipath-temp" /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} /lib64/udev/scsi_id /bin/mountpoint
+
+ if [ -x /sbin/multipath ]
+ then
+ cp /etc/multipath.conf "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy /etc/multipath.conf please check this'
+ fi
+ # /etc/scsi_id.config does not exist in newer udevs
+ # copy it optionally.
+ if [ -x /sbin/scsi_id -a -f /etc/scsi_id.config ]
+ then
+ cp /etc/scsi_id.config "${TEMP}/initramfs-multipath-temp/etc/" || gen_die 'could not copy scsi_id.config'
+ fi
+ cd "${TEMP}/initramfs-multipath-temp"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing multipath cpio"
+ cd "${TEMP}"
+ rm -r "${TEMP}/initramfs-multipath-temp/"
}
-create_devfs_cpio(){
- if [ -d "${TEMP}/initramfs-devfs-temp" ]
+append_dmraid(){
+ if [ -d "${TEMP}/initramfs-dmraid-temp" ]
then
- rm -r "${TEMP}/initramfs-devfs-temp/"
+ rm -r "${TEMP}/initramfs-dmraid-temp/"
fi
- cd ${TEMP}
- print_info 1 'DEVFS: Adding support (compiling binaries)...'
- compile_devfsd
- mkdir -p "${TEMP}/initramfs-devfs-temp/bin/"
- cp "${DEVFSD_BINCACHE}" "${TEMP}/initramfs-devfs-temp/bin/devfsd.bz2" || gen_die "could not copy devfsd executable from bincache"
- bunzip2 "${TEMP}/initramfs-devfs-temp/bin/devfsd.bz2" || gen_die "could not uncompress devfsd"
- chmod +x "${TEMP}/initramfs-devfs-temp/bin/devfsd"
- cd "${TEMP}/initramfs-devfs-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-devfs-${DEVFSD_VER}.cpio.gz
- rm -rf "${TEMP}/initramfs-devfs-temp" > /dev/null
+ print_info 1 'DMRAID: Adding support (compiling binaries)...'
+ compile_dmraid
+ mkdir -p "${TEMP}/initramfs-dmraid-temp/"
+ /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
+ gen_die "Could not extract dmraid binary cache!";
+ cd "${TEMP}/initramfs-dmraid-temp/"
+ RAID456=`find . -type f -name raid456.ko`
+ if [ -n "${RAID456}" ]
+ then
+ cd "${RAID456/raid456.ko/}"
+ ln -sf raid456.kp raid45.ko
+ cd "${TEMP}/initramfs-dmraid-temp/"
+ fi
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing dmraid cpio"
+ cd "${TEMP}"
+ rm -r "${TEMP}/initramfs-dmraid-temp/"
}
-create_unionfs_modules_cpio(){
- #UNIONFS Modules
- if [ "${UNIONFS}" -eq '1' ]
+append_iscsi(){
+ if [ -d "${TEMP}/initramfs-iscsi-temp" ]
then
- if [ -d "${TEMP}/initramfs-unionfs-modules-temp" ]
- then
- rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
- fi
- print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
- compile_unionfs_modules
- mkdir -p "${TEMP}/initramfs-unionfs-modules-temp/"
- /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initramfs-unionfs-modules-temp" ||
- gen_die "Could not extract unionfs modules binary cache!";
- cd "${TEMP}/initramfs-unionfs-modules-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz
- rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
+ rm -r "${TEMP}/initramfs-iscsi-temp/"
fi
+ print_info 1 'iSCSI: Adding support (compiling binaries)...'
+ compile_iscsi
+ cd ${TEMP}
+ mkdir -p "${TEMP}/initramfs-iscsi-temp/bin/"
+ /bin/bzip2 -dc "${ISCSI_BINCACHE}" > "${TEMP}/initramfs-iscsi-temp/bin/iscsistart" ||
+ gen_die "Could not extract iscsi binary cache!"
+ chmod a+x "${TEMP}/initramfs-iscsi-temp/bin/iscsistart"
+ cd "${TEMP}/initramfs-iscsi-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing iscsi cpio"
+ cd "${TEMP}"
+ rm -rf "${TEMP}/initramfs-iscsi-temp" > /dev/null
}
-create_unionfs_tools_cpio(){
- #UNIONFS Tools
- if [ "${UNIONFS}" -eq '1' ]
+append_lvm(){
+ if [ -d "${TEMP}/initramfs-lvm-temp" ]
then
- if [ -d "${TEMP}/initramfs-unionfs-tools-temp" ]
+ rm -r "${TEMP}/initramfs-lvm-temp/"
+ fi
+ cd ${TEMP}
+ mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
+ mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
+ if false && [ -e '/sbin/lvm.static' ]
+ then
+ print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm.static)...'
+ cp /sbin/lvm.static "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
+ gen_die 'Could not copy over lvm!'
+ # See bug 382555
+ if [ -e '/sbin/dmsetup.static' ]
then
- rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
+ cp /sbin/dmsetup.static "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
fi
- print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
- compile_unionfs_utils
- mkdir -p "${TEMP}/initramfs-unionfs-tools-temp/bin/"
- /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initramfs-unionfs-tools-temp" ||
- gen_die "Could not extract unionfs tools binary cache!";
- cd "${TEMP}/initramfs-unionfs-tools-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz
- rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
- fi
-}
-
-create_dmraid_cpio(){
- # DMRAID
- if [ "${DMRAID}" = '1' ]
+ elif false && [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
then
- if [ -d "${TEMP}/initramfs-dmraid-temp" ]
+ print_info 1 ' LVM: Adding support (using local static binary /sbin/lvm)...'
+ cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
+ gen_die 'Could not copy over lvm!'
+ # See bug 382555
+ if [ -e '/sbin/dmsetup' ] && LC_ALL="C" ldd /sbin/dmsetup | grep -q 'not a dynamic executable'
then
- rm -r "${TEMP}/initramfs-dmraid-temp/"
+ cp /sbin/dmsetup "${TEMP}/initramfs-lvm-temp/bin/dmsetup"
fi
- print_info 1 'DMRAID: Adding support (compiling binaries)...'
- compile_dmraid
- mkdir -p "${TEMP}/initramfs-dmraid-temp/"
- /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
- gen_die "Could not extract dmraid binary cache!";
- cd "${TEMP}/initramfs-dmraid-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-dmraid-${DMRAID_VER}.cpio.gz
- rm -r "${TEMP}/initramfs-dmraid-temp/"
- fi
+ else
+ print_info 1 ' LVM: Adding support (compiling binaries)...'
+ compile_lvm
+ /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
+ gen_die "Could not extract lvm binary cache!";
+ mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
+ gen_die 'LVM error: Could not move lvm.static to lvm!'
+ # See bug 382555
+ mv ${TEMP}/initramfs-lvm-temp/sbin/dmsetup.static ${TEMP}/initramfs-lvm-temp/bin/dmsetup ||
+ gen_die 'LVM error: Could not move dmsetup.static to dmsetup!'
+ rm -rf ${TEMP}/initramfs-lvm-temp/{lib,share,man,include,sbin/{lvm,dmsetup}}
+ fi
+ if [ -x /sbin/lvm -o -x /bin/lvm ]
+ then
+# lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
+# ret=$?
+# if [ ${ret} != 0 ]
+# then
+ cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
+ gen_die 'Could not copy over lvm.conf!'
+# else
+# gen_die 'Could not copy over lvm.conf!'
+# fi
+ fi
+ cd "${TEMP}/initramfs-lvm-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing lvm cpio"
+ cd "${TEMP}"
+ rm -r "${TEMP}/initramfs-lvm-temp/"
}
-create_lvm2_cpio(){
- # LVM2
- if [ "${LVM2}" -eq '1' ]
+append_mdadm(){
+ if [ -d "${TEMP}/initramfs-mdadm-temp" ]
+ then
+ rm -r "${TEMP}/initramfs-mdadm-temp/"
+ fi
+ cd ${TEMP}
+ mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
+ mkdir -p "${TEMP}/initramfs-mdadm-temp/sbin/"
+ if [ "${MDADM}" = '1' ]
then
- if [ -d "${TEMP}/initramfs-lvm2-temp" ]
+ if [ -n "${MDADM_CONFIG}" ]
then
- rm -r "${TEMP}/initramfs-lvm2-temp/"
+ if [ -f "${MDADM_CONFIG}" ]
+ then
+ cp -a "${MDADM_CONFIG}" "${TEMP}/initramfs-mdadm-temp/etc/mdadm.conf" \
+ || gen_die "Could not copy mdadm.conf!"
+ else
+ gen_die 'sl${MDADM_CONFIG} does not exist!'
+ fi
+ else
+ print_info 1 ' MDADM: Skipping inclusion of mdadm.conf'
fi
- cd ${TEMP}
- mkdir -p "${TEMP}/initramfs-lvm2-temp/bin/"
- if [ -e '/sbin/lvm' ] && ldd /sbin/lvm|grep -q 'not a dynamic executable';
+
+ if [ -e '/sbin/mdadm' ] && LC_ALL="C" ldd /sbin/mdadm | grep -q 'not a dynamic executable' \
+ && [ -e '/sbin/mdmon' ] && LC_ALL="C" ldd /sbin/mdmon | grep -q 'not a dynamic executable'
then
- print_info 1 ' LVM2: Adding support (using local static binaries)...'
- cp /sbin/lvm "${TEMP}/initramfs-lvm2-temp/bin/lvm" ||
- gen_die 'Could not copy over lvm!'
+ print_info 1 ' MDADM: Adding support (using local static binaries /sbin/mdadm and /sbin/mdmon)...'
+ cp /sbin/mdadm /sbin/mdmon "${TEMP}/initramfs-mdadm-temp/sbin/" ||
+ gen_die 'Could not copy over mdadm!'
else
- print_info 1 ' LVM2: Adding support (compiling binaries)...'
- compile_lvm2
- /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initramfs-lvm2-temp" ||
- gen_die "Could not extract lvm2 binary cache!";
- mv ${TEMP}/initramfs-lvm2-temp/sbin/lvm.static ${TEMP}/initramfs-lvm2-temp/bin/lvm ||
- gen_die 'LVM2 error: Could not move lvm.static to lvm!'
- fi
- cd "${TEMP}/initramfs-lvm2-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-lvm2-${LVM2_VER}.cpio.gz
- rm -r "${TEMP}/initramfs-lvm2-temp/"
- else # Deprecation warning; remove in a few versions.
- if [ -e '/sbin/lvm' ]
- then
- if ldd /sbin/lvm|grep -q 'not a dynamic executable';
- then
- print_warning 1 'LVM2: For support, use --lvm2!'
- fi
+ print_info 1 ' MDADM: Adding support (compiling binaries)...'
+ compile_mdadm
+ /bin/tar -jxpf "${MDADM_BINCACHE}" -C "${TEMP}/initramfs-mdadm-temp" ||
+ gen_die "Could not extract mdadm binary cache!";
fi
fi
+ cd "${TEMP}/initramfs-mdadm-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing mdadm cpio"
+ cd "${TEMP}"
+ rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
}
-create_evms2_cpio(){
- # EVMS2
- if [ -e '/sbin/evms_activate' ]
+append_zfs(){
+ if [ -d "${TEMP}/initramfs-zfs-temp" ]
then
- if [ -d "${TEMP}/initramfs-evms2-temp" ]
- then
- rm -r "${TEMP}/initramfs-evms2-temp/"
- fi
- mkdir -p "${TEMP}/initramfs-evms2-temp/lib/evms"
- mkdir -p "${TEMP}/initramfs-evms2-temp/etc/"
- mkdir -p "${TEMP}/initramfs-evms2-temp/bin/"
- mkdir -p "${TEMP}/initramfs-evms2-temp/sbin/"
- if [ "${EVMS2}" -eq '1' ]
- then
- print_info 1 ' EVMS2: Adding support...'
- mkdir -p ${TEMP}/initramfs-evms2-temp/lib
- cp -a /lib/ld-* "${TEMP}/initramfs-evms2-temp/lib" || gen_die 'Could not copy files for EVMS2!'
- cp -a /lib/libc-* /lib/libc.* "${TEMP}/initramfs-evms2-temp/lib" || gen_die 'Could not copy files for EVMS2!'
- cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initramfs-evms2-temp/lib" || gen_die 'Could not copy files for EVMS2!'
- cp -a /lib/libpthread* "${TEMP}/initramfs-evms2-temp/lib" || gen_die 'Could not copy files for EVMS2!'
- cp -a /lib/libuuid*so* "${TEMP}/initramfs-evms2-temp/lib" || gen_die 'Could not copy files for EVMS2!'
- cp -a /lib/libevms*so* "${TEMP}/initramfs-evms2-temp/lib" || gen_die 'Could not copy files for EVMS2!'
- cp -a /lib/evms "${TEMP}/initramfs-evms2-temp/lib" || gen_die 'Could not copy files for EVMS2!'
- cp -a /lib/evms/* "${TEMP}/initramfs-evms2-temp/lib/evms" || gen_die 'Could not copy files for EVMS2!'
- cp -a /etc/evms.conf "${TEMP}/initramfs-evms2-temp/etc" || gen_die 'Could not copy files for EVMS2!'
- cp /sbin/evms_activate "${TEMP}/initramfs-evms2-temp/sbin/evms_activate" || gen_die 'Could not copy over evms_activate!'
-
- # Fix EVMS2 complaining that it can't find the swap utilities.
- # These are not required in the initramfs
- for swap_libs in "${TEMP}/initramfs-evms2-temp/lib/evms/*/swap*.so"
- do
- rm ${swap_libs}
- done
- fi
- cd "${TEMP}/initramfs-evms2-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-evms2.cpio.gz
- rm -r "${TEMP}/initramfs-evms2-temp/"
- fi
+ rm -r "${TEMP}/initramfs-zfs-temp"
+ fi
+
+ mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs/"
+
+ # Copy files to /etc/zfs
+ for i in /etc/zfs/{zdev.conf,zpool.cache}
+ do
+ cp -a "${i}" "${TEMP}/initramfs-zfs-temp/etc/zfs" \
+ || gen_die "Could not copy file ${i} for ZFS"
+ done
+
+ # Copy binaries
+ copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zfs,zpool}
+
+ cd "${TEMP}/initramfs-zfs-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing zfs cpio"
+ cd "${TEMP}"
+ rm -rf "${TEMP}/initramfs-zfs-temp" > /dev/null
}
-create_gensplash(){
- if [ "${GENSPLASH}" -eq '1' ]
+append_splash(){
+ splash_geninitramfs=`which splash_geninitramfs 2>/dev/null`
+ if [ -x "${splash_geninitramfs}" ]
then
- if [ -x /sbin/splash ]
+ [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
+ [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
+ print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
+ if [ -d "${TEMP}/initramfs-splash-temp" ]
then
- [ -z "${GENSPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
- [ -z "${GENSPLASH_THEME}" ] && GENSPLASH_THEME=default
- print_info 1 " >> Installing gensplash [ using the ${GENSPLASH_THEME} theme ]..."
- cd /
- local tmp=""
- [ -n "${GENSPLASH_RES}" ] && tmp="-r ${GENSPLASH_RES}"
- splash_geninitramfs -g ${CACHE_CPIO_DIR}/initramfs-splash-${KV}.cpio.gz ${tmp} ${GENSPLASH_THEME}
- if [ -e "/usr/share/splashutils/initrd.splash" ]; then
- if [ -d "${TEMP}/initramfs-gensplash-temp" ]
- then
- rm -r "${TEMP}/initramfs-gensplash-temp/"
- fi
- mkdir -p "${TEMP}/initramfs-gensplash-temp/etc"
- cd "${TEMP}/initramfs-gensplash-temp/"
- gunzip -c ${CACHE_CPIO_DIR}/initramfs-splash-${KV}.cpio.gz | cpio -idm --quiet -H newc
- cp "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-gensplash-temp/etc"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-splash-${KV}.cpio.gz
- rm -r "${TEMP}/initramfs-gensplash-temp/"
- fi
- else
- print_warning 1 ' >> No splash detected; skipping!'
+ rm -r "${TEMP}/initramfs-splash-temp/"
+ fi
+ mkdir -p "${TEMP}/initramfs-splash-temp"
+ cd /
+ local tmp=""
+ [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
+ splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
+ if [ -e "/usr/share/splashutils/initrd.splash" ]; then
+ mkdir -p "${TEMP}/initramfs-splash-temp/etc"
+ cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
fi
+ cd "${TEMP}/initramfs-splash-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing splash cpio"
+ cd "${TEMP}"
+ rm -r "${TEMP}/initramfs-splash-temp/"
+ else
+ print_warning 1 ' >> No splash detected; skipping!'
fi
}
-create_initramfs_overlay_cpio(){
+
+append_overlay(){
cd ${INITRAMFS_OVERLAY}
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-overlay.cpio.gz
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing overlay cpio"
+}
+
+append_luks() {
+ local _luks_error_format="LUKS support cannot be included: %s. Please emerge sys-fs/cryptsetup[static]."
+ local _luks_source=/sbin/cryptsetup
+ local _luks_dest=/sbin/cryptsetup
+
+ if [ -d "${TEMP}/initramfs-luks-temp" ]
+ then
+ rm -r "${TEMP}/initramfs-luks-temp/"
+ fi
+
+ mkdir -p "${TEMP}/initramfs-luks-temp/lib/luks/"
+ mkdir -p "${TEMP}/initramfs-luks-temp/sbin"
+ cd "${TEMP}/initramfs-luks-temp"
+
+ if isTrue ${LUKS}
+ then
+ [ -x "${_luks_source}" ] \
+ || gen_die "$(printf "${_luks_error_format}" "no file ${_luks_source}")"
+
+ print_info 1 "Including LUKS support"
+ copy_binaries "${TEMP}/initramfs-luks-temp/" /sbin/cryptsetup
+ fi
+
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "appending cryptsetup to cpio"
+
+ cd "${TEMP}"
+ rm -r "${TEMP}/initramfs-luks-temp/"
+}
+
+append_firmware() {
+ if [ -z "${FIRMWARE_FILES}" -a ! -d "${FIRMWARE_DIR}" ]
+ then
+ gen_die "specified firmware directory (${FIRMWARE_DIR}) does not exist"
+ fi
+ if [ -d "${TEMP}/initramfs-firmware-temp" ]
+ then
+ rm -r "${TEMP}/initramfs-firmware-temp/"
+ fi
+ mkdir -p "${TEMP}/initramfs-firmware-temp/lib/firmware"
+ cd "${TEMP}/initramfs-firmware-temp"
+ if [ -n "${FIRMWARE_FILES}" ]
+ then
+ OLD_IFS=$IFS
+ IFS=","
+ for i in ${FIRMWARE_FILES}
+ do
+ cp -L "${i}" ${TEMP}/initramfs-firmware-temp/lib/firmware/
+ done
+ IFS=$OLD_IFS
+ else
+ cp -a "${FIRMWARE_DIR}"/* ${TEMP}/initramfs-firmware-temp/lib/firmware/
+ fi
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "appending firmware to cpio"
+ cd "${TEMP}"
+ rm -r "${TEMP}/initramfs-firmware-temp/"
+}
+
+append_gpg() {
+ if [ -d "${TEMP}/initramfs-gpg-temp" ]
+ then
+ rm -r "${TEMP}/initramfs-gpg-temp"
+ fi
+ cd ${TEMP}
+ mkdir -p "${TEMP}/initramfs-gpg-temp/sbin/"
+ if [ ! -e ${GPG_BINCACHE} ] ; then
+ print_info 1 ' GPG: Adding support (compiling binaries)...'
+ compile_gpg
+ fi
+ bzip2 -dc "${GPG_BINCACHE}" > "${TEMP}/initramfs-gpg-temp/sbin/gpg" ||
+ gen_die 'Could not extract gpg binary cache!'
+ chmod a+x "${TEMP}/initramfs-gpg-temp/sbin/gpg"
+ cd "${TEMP}/initramfs-gpg-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
+ rm -rf "${TEMP}/initramfs-gpg-temp" > /dev/null
}
+
print_list()
{
local x
done
}
-create_initramfs_modules() {
+append_modules() {
local group
local group_modules
-
- MOD_EXT=".ko"
+ local MOD_EXT=".ko"
print_info 2 "initramfs: >> Searching for modules..."
if [ "${INSTALL_MOD_PATH}" != '' ]
else
cd /
fi
-
+
if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
then
rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
fi
- mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
+ mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
for i in `gen_dep_list`
do
mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
continue;
fi
-
+
print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
done
-
+
cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
done
cd "${TEMP}/initramfs-modules-${KV}-temp/"
- find . | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-modules-${KV}.cpio.gz
+ log_future_cpio_content
+ find . | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing modules cpio"
+ cd "${TEMP}"
rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
}
-create_initramfs_aux() {
+append_modprobed() {
+ local TDIR="${TEMP}/initramfs-modprobe.d-temp"
+ if [ -d "${TDIR}" ]
+ then
+ rm -r "${TDIR}"
+ fi
+
+ mkdir -p "${TDIR}/etc/module_options/"
+
+ # Load module parameters
+ for dir in $(find "${MODPROBEDIR}"/*)
+ do
+ while read x
+ do
+ case "${x}" in
+ options*)
+ module_name="$(echo "$x" | cut -d ' ' -f 2)"
+ [ "${module_name}" != "$(echo)" ] || continue
+ module_options="$(echo "$x" | cut -d ' ' -f 3-)"
+ [ "${module_options}" != "$(echo)" ] || continue
+ echo "${module_options}" >> "${TDIR}/etc/module_options/${module_name}.conf"
+ ;;
+ esac
+ done < "${dir}"
+ done
+
+ cd "${TDIR}"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing modprobe.d cpio"
+
+ cd "${TEMP}"
+ rm -rf "${TDIR}" > /dev/null
+}
+
+# check for static linked file with objdump
+is_static() {
+ LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
+ return $?
+}
+
+append_auxilary() {
if [ -d "${TEMP}/initramfs-aux-temp" ]
then
rm -r "${TEMP}/initramfs-aux-temp/"
fi
- mkdir -p "${TEMP}/initramfs-aux-temp/etc"
- mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
+ mkdir -p "${TEMP}/initramfs-aux-temp/etc"
+ mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
if [ -f "${CMD_LINUXRC}" ]
then
cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
- else
- if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
+ else
+ if isTrue ${NETBOOT}
then
- cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
+ cp "${GK_SHARE}/netboot/linuxrc.x" "${TEMP}/initramfs-aux-temp/init"
else
- cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initramfs-aux-temp/init"
+ if [ -f "${GK_SHARE}/arch/${ARCH}/linuxrc" ]
+ then
+ cp "${GK_SHARE}/arch/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
+ else
+ cp "${GK_SHARE}/defaults/linuxrc" "${TEMP}/initramfs-aux-temp/init"
+ fi
fi
fi
- if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
+ # Make sure it's executable
+ chmod 0755 "${TEMP}/initramfs-aux-temp/init"
+
+ # Make a symlink to init .. incase we are bundled inside the kernel as one
+ # big cpio.
+ cd ${TEMP}/initramfs-aux-temp
+ ln -s init linuxrc
+# ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
+
+ if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.scripts" ]
then
- cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
- else
- cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
+ cp "${GK_SHARE}/arch/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
+ else
+ cp "${GK_SHARE}/defaults/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
fi
- if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
+ if [ -f "${GK_SHARE}/arch/${ARCH}/initrd.defaults" ]
then
- cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
+ cp "${GK_SHARE}/arch/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
else
- cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
+ cp "${GK_SHARE}/defaults/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
fi
-
- echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
+
+ if [ -n "${REAL_ROOT}" ]
+ then
+ sed -i "s:^REAL_ROOT=.*$:REAL_ROOT='${REAL_ROOT}':" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
+ fi
+
+ echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
for group_modules in ${!MODULES_*}; do
group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
done
- echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
+ echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
- if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
+ if [ -f "${GK_SHARE}/arch/${ARCH}/modprobe" ]
then
- cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
+ cp "${GK_SHARE}/arch/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
else
- cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
+ cp "${GK_SHARE}/defaults/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
fi
if isTrue $CMD_DOKEYMAPAUTO
then
echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
fi
- mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
- /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
+ if isTrue $CMD_KEYMAP
+ then
+ print_info 1 " >> Copying keymaps"
+ mkdir -p "${TEMP}/initramfs-aux-temp/lib/"
+ cp -R "${GK_SHARE}/defaults/keymaps" "${TEMP}/initramfs-aux-temp/lib/" \
+ || gen_die "Error while copying keymaps"
+ fi
cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
cd ${TEMP}
chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
- cd "${TEMP}/initramfs-aux-temp/"
- find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-aux.cpio.gz
- rm -r "${TEMP}/initramfs-aux-temp/"
-}
-merge_initramfs_cpio_archives(){
- cd "${CACHE_CPIO_DIR}"
- MERGE_LIST="initramfs-base-layout.cpio.gz initramfs-aux.cpio.gz"
- if [ ! -e "${CACHE_CPIO_DIR}/initramfs-base-layout.cpio.gz" ]
- then
- gen_die "${CACHE_CPIO_DIR}/initramfs-base-layout.cpio.gz is missing."
- fi
- if [ ! -e "${CACHE_CPIO_DIR}/initramfs-aux.cpio.gz" ]
- then
- gen_die "${CACHE_CPIO_DIR}/initramfs-aux.cpio.gz is missing."
- fi
-
- if [ "${BUSYBOX}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-busybox-${BUSYBOX_VER}.cpio.gz ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-busybox-${BUSYBOX_VER}.cpio.gz"
- fi
-
- if [ "${NOINITRDMODULES}" = '' -a -e ${CACHE_CPIO_DIR}/initramfs-insmod-${MODULE_INIT_TOOLS_VER}.cpio.gz ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-insmod-${MODULE_INIT_TOOLS_VER}.cpio.gz"
- fi
-
- if [ "${UDEV}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-udev-${UDEV_VER}.cpio.gz ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-udev-${UDEV_VER}.cpio.gz"
- fi
- if [ "${DISKLABEL}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-blkid-${E2FSPROGS_VER}.cpio.gz ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-blkid-${E2FSPROGS_VER}.cpio.gz"
- fi
- if [ "${UNIONFS}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz"
- fi
- if [ "${UNIONFS}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz"
- fi
- if [ "${EVMS2}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-evms2.cpio.gz" ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-evms2.cpio.gz"
- fi
- if [ "${LVM2}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-lvm2-${LVM2_VER}.cpio.gz" ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-lvm2-${LVM2_VER}.cpio.gz"
- fi
- if [ "${DEVFS}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-devfs-${DEVFSD_VER}.cpio.gz" ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-devfs-${DEVFSD_VER}.cpio.gz"
- fi
- if [ "${DMRAID}" -eq '1' -a -e ${CACHE_CPIO_DIR}/initramfs-dmraid-${DMRAID_VER}.cpio.gz ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-dmraid-${DMRAID_VER}.cpio.gz"
- fi
- if [ "${NOINITRDMODULES}" = '' -a -e "${CACHE_CPIO_DIR}/initramfs-modules-${KV}.cpio.gz" ]
+ if isTrue ${NETBOOT}
then
- MERGE_LIST="${MERGE_LIST} initramfs-modules-${KV}.cpio.gz"
+ cd "${GK_SHARE}/netboot/misc"
+ cp -pPRf * "${TEMP}/initramfs-aux-temp/"
fi
- if [ "${GENSPLASH}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-splash-${KV}.cpio.gz" ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-splash-${KV}.cpio.gz"
- fi
- # This should always be appended last
- if [ "${INITRAMFS_OVERLAY}" != '' -a -e "${CACHE_CPIO_DIR}/initramfs-overlay.cpio.gz" ]
- then
- MERGE_LIST="${MERGE_LIST} initramfs-overlay.cpio.gz"
- fi
-
- echo
- print_info 1 "Merging"
- for i in ${MERGE_LIST}
- do
- echo " $i"
- done
-
- cat ${MERGE_LIST} > ${TMPDIR}/initramfs-${KV}
- [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
- [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
- cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz
+ cd "${TEMP}/initramfs-aux-temp/"
+ log_future_cpio_content
+ find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
+ || gen_die "compressing auxilary cpio"
+ cd "${TEMP}"
+ rm -r "${TEMP}/initramfs-aux-temp/"
}
-clear_cpio_dir(){
- if [ "${CLEAR_CPIO_CACHE}" == 'yes' ]
- then
+append_data() {
+ local name=$1 var=$2
+ local func="append_${name}"
- if [ -d ${CACHE_CPIO_DIR} ]
- then
- print_info 1 " >> Clearing old cpio archives..."
- rm -r ${CACHE_CPIO_DIR}
- fi
- fi
-
- if [ ! -d ${CACHE_CPIO_DIR} ]
+ [ $# -eq 0 ] && gen_die "append_data() called with zero arguments"
+ if [ $# -eq 1 ] || isTrue ${var}
then
- mkdir -p ${CACHE_CPIO_DIR}
+ print_info 1 " >> Appending ${name} cpio data..."
+ ${func} || gen_die "${func}() failed"
fi
}
create_initramfs() {
- local MOD_EXT
-
+ local compress_ext=""
print_info 1 "initramfs: >> Initializing..."
- clear_cpio_dir
- mkdir -p ${CACHE_CPIO_DIR}
- print_info 1 " >> Creating base_layout cpio archive..."
- create_base_layout_cpio
-
- print_info 1 " >> Creating auxilary cpio archive..."
- create_initramfs_aux
-
- if [ "${BUSYBOX}" -eq '1' ]
- then
- print_info 1 " >> Creating busybox cpio archive..."
- create_busybox_cpio
- fi
-
- if [ "${DEVFS}" -eq '1' ]
- then
- print_info 1 " >> Creating devfs cpio archive..."
- create_devfs_cpio
- fi
-
- if [ "${UDEV}" -eq '1' ]
- then
- print_info 1 " >> Creating udev cpio archive..."
- create_udev_cpio
- fi
-
- if [ "${UNIONFS}" -eq '1' ]
- then
- print_info 1 " >> Creating unionfs modules cpio archive..."
- create_unionfs_modules_cpio
- fi
-
- if [ "${UNIONFS}" -eq '1' ]
- then
- print_info 1 " >> Creating unionfs tools cpio archive..."
- create_unionfs_tools_cpio
- fi
- if [ "${LVM2}" -eq '1' ]
- then
-
- print_info 1 " >> Creating lvm2 cpio archive..."
- create_lvm2_cpio
- fi
-
- if [ "${DMRAID}" -eq '1' ]
- then
- print_info 1 " >> Creating dmraid cpio archive..."
- create_dmraid_cpio
- fi
-
- if [ "${EVMS2}" -eq '1' -a -e '/sbin/evms_activate' ]
- then
- print_info 1 " >> Creating evms2 cpio archive..."
- create_evms2_cpio
- fi
-
- if [ "${NOINITRDMODULES}" = '' ]
- then
- print_info 1 " >> Creating insmod cpio archive..."
- create_insmod_cpio
- print_info 1 " >> Creating modules cpio archive..."
- create_initramfs_modules
+ # Create empty cpio
+ CPIO="${TMPDIR}/initramfs-${KV}"
+ echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
+ || gen_die "Could not create empty cpio at ${CPIO}"
+
+ append_data 'base_layout'
+ append_data 'auxilary' "${BUSYBOX}"
+ append_data 'busybox' "${BUSYBOX}"
+ append_data 'lvm' "${LVM}"
+ append_data 'dmraid' "${DMRAID}"
+ append_data 'iscsi' "${ISCSI}"
+ append_data 'mdadm' "${MDADM}"
+ append_data 'luks' "${LUKS}"
+ append_data 'multipath' "${MULTIPATH}"
+ append_data 'gpg' "${GPG}"
+
+ if [ "${RAMDISKMODULES}" = '1' ]
+ then
+ append_data 'modules'
else
print_info 1 "initramfs: Not copying modules..."
fi
-
- if [ "${DISKLABEL}" -eq '1' ]
+
+ append_data 'zfs' "${ZFS}"
+
+ append_data 'blkid' "${DISKLABEL}"
+
+ append_data 'unionfs_fuse' "${UNIONFS}"
+
+ append_data 'splash' "${SPLASH}"
+
+ append_data 'modprobed'
+
+ if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
then
- print_info 1 " >> Creating blkid cpio archive..."
- create_blkid_cpio
+ append_data 'firmware'
fi
-
- create_gensplash
-
+
+ # This should always be appended last
if [ "${INITRAMFS_OVERLAY}" != '' ]
then
- print_info 1 " >> Creating initramfs_overlay cpio archive..."
- create_initramfs_overlay_cpio
+ append_data 'overlay'
fi
+
+ if isTrue "${INTEGRATED_INITRAMFS}"
+ then
+ # Explicitly do not compress if we are integrating into the kernel.
+ # The kernel will do a better job of it than us.
+ mv ${TMPDIR}/initramfs-${KV} ${TMPDIR}/initramfs-${KV}.cpio
+ sed -i '/^.*CONFIG_INITRAMFS_SOURCE=.*$/d' ${KERNEL_DIR}/.config
+ cat >>${KERNEL_DIR}/.config <<-EOF
+ CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}"
+ CONFIG_INITRAMFS_ROOT_UID=0
+ CONFIG_INITRAMFS_ROOT_GID=0
+ EOF
+ else
+ if isTrue "${COMPRESS_INITRD}"
+ then
+ if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then
+ # Support --kernel-config=/proc/config.gz, mainly
+ local CONFGREP=zgrep
+ else
+ local CONFGREP=grep
+ fi
+
+ cmd_xz=$(type -p xz)
+ cmd_lzma=$(type -p lzma)
+ cmd_bzip2=$(type -p bzip2)
+ cmd_gzip=$(type -p gzip)
+ cmd_lzop=$(type -p lzop)
+ pkg_xz='app-arch/xz-utils'
+ pkg_lzma='app-arch/xz-utils'
+ pkg_bzip2='app-arch/bzip2'
+ pkg_gzip='app-arch/gzip'
+ pkg_lzop='app-arch/lzop'
+ local compression
+ case ${COMPRESS_INITRD_TYPE} in
+ xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;;
+ lzo) compression=lzop ;;
+ best|fastest)
+ for tuple in \
+ 'CONFIG_RD_XZ cmd_xz xz' \
+ 'CONFIG_RD_LZMA cmd_lzma lzma' \
+ 'CONFIG_RD_BZIP2 cmd_bzip2 bzip2' \
+ 'CONFIG_RD_GZIP cmd_gzip gzip' \
+ 'CONFIG_RD_LZO cmd_lzop lzop'; do
+ set -- ${tuple}
+ kernel_option=$1
+ cmd_variable_name=$2
+ if ${CONFGREP} -q "^${kernel_option}=y" "${KERNEL_CONFIG}" && test -n "${!cmd_variable_name}" ; then
+ compression=$3
+ [[ ${COMPRESS_INITRD_TYPE} == best ]] && break
+ fi
+ done
+ [[ -z "${compression}" ]] && gen_die "None of the initramfs we tried are supported by your kernel (config file \"${KERNEL_CONFIG}\"), strange!?"
+ ;;
+ *)
+ gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown"
+ ;;
+ esac
+
+ # Check for actual availability
+ cmd_variable_name=cmd_${compression}
+ pkg_variable_name=pkg_${compression}
+ [[ -z "${!cmd_variable_name}" ]] && gen_die "Compression '${compression}' is not available. Please install package '${!pkg_variable_name}'."
+
+ case $compression in
+ xz) compress_ext='.xz' compress_cmd="${cmd_xz} -e --check=none -z -f -9" ;;
+ lzma) compress_ext='.lzma' compress_cmd="${cmd_lzma} -z -f -9" ;;
+ bzip2) compress_ext='.bz2' compress_cmd="${cmd_bzip2} -z -f -9" ;;
+ gzip) compress_ext='.gz' compress_cmd="${cmd_gzip} -f -9" ;;
+ lzop) compress_ext='.lzo' compress_cmd="${cmd_lzop} -f -9" ;;
+ esac
- merge_initramfs_cpio_archives
+ if [ -n "${compression}" ]; then
+ print_info 1 " >> Compressing cpio data (${compress_ext})..."
+ ${compress_cmd} "${CPIO}" || gen_die "Compression (${compress_cmd}) failed"
+ mv -f "${CPIO}${compress_ext}" "${CPIO}" || gen_die "Rename failed"
+ else
+ print_info 1 " >> Not compressing cpio data ..."
+ fi
+ fi
+ fi
- if ! isTrue "${CMD_NOINSTALL}"
+ if isTrue "${CMD_INSTALL}"
then
- cp ${TMPDIR}/initramfs-${KV} /boot/initramfs-${KNAME}-${ARCH}-${KV} ||
- gen_die 'Could not copy the initramfs to /boot!'
+ if ! isTrue "${INTEGRATED_INITRAMFS}"
+ then
+ copy_image_with_preserve "initramfs" \
+ "${TMPDIR}/initramfs-${KV}" \
+ "initramfs-${KNAME}-${ARCH}-${KV}"
+ fi
fi
}