Make missing ZFS config file failures into warnings, bug #438200
[genkernel.git] / gen_initramfs.sh
index 9ccd5f3092b4f1f1de26d2792a6b31d760b5e8e7..99bd3f37523a2cfd7f35392f6a2c103255ac37eb 100755 (executable)
@@ -88,6 +88,7 @@ append_base_layout() {
        mknod -m 600 ttyS0 c 4 64
 
        date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date
+       echo "Genkernel $GK_V" > ${TEMP}/initramfs-base-temp/etc/build_id
 
        cd "${TEMP}/initramfs-base-temp/"
        log_future_cpio_content
@@ -127,6 +128,23 @@ append_busybox() {
        rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
 }
 
+append_e2fsprogs(){
+       if [ -d "${TEMP}"/initramfs-e2fsprogs-temp ]
+       then
+               rm -r "${TEMP}"/initramfs-e2fsprogs-temp
+       fi
+
+       cd "${TEMP}" \
+                       || gen_die "cd '${TEMP}' failed"
+       mkdir -p initramfs-e2fsprogs-temp
+       copy_binaries "${TEMP}"/initramfs-e2fsprogs-temp/ /sbin/{e2fsck,mke2fs}
+
+       cd "${TEMP}"/initramfs-e2fsprogs-temp \
+                       || gen_die "cd '${TEMP}/initramfs-e2fsprogs-temp' failed"
+       find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
+       rm -rf "${TEMP}"/initramfs-e2fsprogs-temp > /dev/null
+}
+
 append_blkid(){
        if [ -d "${TEMP}/initramfs-blkid-temp" ]
        then
@@ -208,7 +226,10 @@ append_multipath(){
        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
+       copy_binaries "${TEMP}/initramfs-multipath-temp" \
+               /bin/mountpoint \
+               /sbin/{multipath,kpartx,mpath_prio_*,devmap_name,dmsetup} \
+               /{lib,lib64}/{udev/scsi_id,multipath/*so} 
 
        if [ -x /sbin/multipath ]
        then
@@ -389,7 +410,7 @@ append_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"
+                       || print_warning 1 "Could not copy file ${i} for ZFS"
        done
 
        # Copy binaries
@@ -577,6 +598,41 @@ append_modules() {
        rm -r "${TEMP}/initramfs-modules-${KV}-temp/"   
 }
 
+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
@@ -706,6 +762,7 @@ create_initramfs() {
        append_data 'base_layout'
        append_data 'auxilary' "${BUSYBOX}"
        append_data 'busybox' "${BUSYBOX}"
+       isTrue "${CMD_E2FSPROGS}" && append_data 'e2fsprogs'
        append_data 'lvm' "${LVM}"
        append_data 'dmraid' "${DMRAID}"
        append_data 'iscsi' "${ISCSI}"
@@ -729,6 +786,8 @@ create_initramfs() {
 
        append_data 'splash' "${SPLASH}"
 
+       append_data 'modprobed'
+
        if isTrue "${FIRMWARE}" && [ -n "${FIRMWARE_DIR}" ]
        then
                append_data 'firmware'
@@ -746,15 +805,41 @@ create_initramfs() {
                # 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
+               compress_config='INITRAMFS_COMPRESSION_NONE'
+               case ${compress_ext} in
+                       gz)  compress_config='INITRAMFS_COMPRESSION_GZIP' ;;
+                       bz2) compress_config='INITRAMFS_COMPRESSION_BZIP2' ;;
+                       lzma) compress_config='INITRAMFS_COMPRESSION_LZMA' ;;
+                       xz) compress_config='INITRAMFS_COMPRESSION_XZ' ;;
+                       lzo) compress_config='INITRAMFS_COMPRESSION_LZO' ;;
+                       *) compress_config='INITRAMFS_COMPRESSION_NONE' ;;
+               esac
+               # All N default except XZ, so there it gets used if the kernel does
+               # compression on it's own.
                cat >>${KERNEL_DIR}/.config     <<-EOF
                CONFIG_INITRAMFS_SOURCE="${TMPDIR}/initramfs-${KV}.cpio${compress_ext}"
                CONFIG_INITRAMFS_ROOT_UID=0
                CONFIG_INITRAMFS_ROOT_GID=0
+               CONFIG_INITRAMFS_COMPRESSION_NONE=n
+               CONFIG_INITRAMFS_COMPRESSION_GZIP=n
+               CONFIG_INITRAMFS_COMPRESSION_BZIP2=n
+               CONFIG_INITRAMFS_COMPRESSION_LZMA=n
+               CONFIG_INITRAMFS_COMPRESSION_XZ=y
+               CONFIG_INITRAMFS_COMPRESSION_LZO=n
+               CONFIG_${compress_config}=y
                EOF
        else
                if isTrue "${COMPRESS_INITRD}"
                then
-                       if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then
+                       # NOTE:  We do not work with ${KERNEL_CONFIG} here, since things like
+                       #        "make oldconfig" or --noclean could be in effect.
+                       if [ -f "${KERNEL_DIR}"/.config ]; then
+                               local ACTUAL_KERNEL_CONFIG="${KERNEL_DIR}"/.config
+                       else
+                               local ACTUAL_KERNEL_CONFIG="${KERNEL_CONFIG}"
+                       fi
+
+                       if [[ "$(file --brief --mime-type "${ACTUAL_KERNEL_CONFIG}")" == application/x-gzip ]]; then
                                # Support --kernel-config=/proc/config.gz, mainly
                                local CONFGREP=zgrep
                        else
@@ -779,17 +864,18 @@ create_initramfs() {
                                        for tuple in \
                                                        'CONFIG_RD_XZ    cmd_xz    xz' \
                                                        'CONFIG_RD_LZMA  cmd_lzma  lzma' \
-                                                       'CONFIG_RD_BZIP2 cmd_bzip2 bzip' \
+                                                       '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
+                                               if ${CONFGREP} -q "^${kernel_option}=y" "${ACTUAL_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 compression methods we tried are supported by your kernel (config file \"${ACTUAL_KERNEL_CONFIG}\"), strange!?"
                                        ;;
                                *)
                                        gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown"