#!/bin/sh usage() { cat >&2 << EOF Usage: ${0} [OPTION]... <-o outfile> [version] Options: -d confdir Specify an alternative configuration directory. -k Keep temporary directory used to make the image. -o outfile Write to outfile. -r root Override ROOT setting in mkinitrd.conf. See ${0}(8) for further details. EOF exit 1 } # Defaults keep="n" CONFDIR="/etc/mkinitramfs" while getopts "d:ko:r:" flag; do case $flag in d) CONFDIR="${OPTAGS}" if [ ! d "${CONFDIR}" ]; then echo "${0}: ${CONFDIR}: Not a directory" >&2 exit 1 fi ;; o) outfile="${OPTARG}" ;; v) version="${OPTARG}" ;; k) keep="y" ;; esac done shift $((${OPTIND} - 1)) . ${CONFDIR}/initramfs.conf if [ x${outfile} = x ] || [ ${#} -ne 1 ]; then usage fi if [ -d ${outfile} ]; then echo "${outfile} is a directory" exit 1 fi if [ ! -e /lib/modules/${version} ]; then echo "Cannot find /lib/modules/${version}" exit 1 fi TMPDIR=$(mktemp -d) || exit 1 mkdir -p ${TMPDIR}/modules ${TMPDIR}/conf ${TMPDIR}/etc mkdir -p ${TMPDIR}/bin ${TMPDIR}/lib ${TMPDIR}/scripts for x in $(sed -e '/^#/d' ${CONFDIR}/modules); do for y in $(modprobe --set-version=${version} --show-depends ${x} | awk '{ print $2 }'); do # Prune duplicates if [ -e ${TMPDIR}/modules/$(basename ${y}) ]; then continue fi ln -s ${y} ${TMPDIR}/modules echo $(basename ${y}) >>${TMPDIR}/conf/modules done done # Have to do each file, because cpio --dereference doesn't recurse down # symlinks. ln -s /usr/lib/klibc/bin/* ${TMPDIR}/bin ln -s /usr/lib/klibc/lib/* ${TMPDIR}/lib ln -s /usr/share/initramfs-tools/init ${TMPDIR}/init ln -s /usr/share/initramfs-tools/scripts/* ${TMPDIR}/scripts ln -s ${CONFDIR}/initramfs.conf ${TMPDIR}/conf ln -s /etc/udev ${TMPDIR}/etc # Hack until udev is built with klibc ln -s /sbin/udev ${TMPDIR}/bin ln -s /sbin/udevstart ${TMPDIR}/bin ln -s /lib/libc.so.* ${TMPDIR}/lib ln -s /lib/ld*.so.* ${TMPDIR}/lib rm ${TMPDIR}/lib/*lsb* # Busybox if [ "x${BUSYBOX}" = "xy" ]; then rm ${TMPDIR}/bin/sh ln -s /bin/busybox ${TMPDIR}/bin/sh fi # Raid ln -s /sbin/mdadm ${TMPDIR}/bin ln -s /sbin/mdrun ${TMPDIR}/bin ln -s /bin/grep ${TMPDIR}/bin ln -s /bin/sed ${TMPDIR}/bin (cd ${TMPDIR} && find . | cpio --quiet --dereference -o -H newc | gzip -9 >${outfile}) if [ "${keep}" = "y" ]; then echo "Working files in ${TMPDIR}" else rm -rf "${TMPDIR}" fi