2009-10-09 03:11:09 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
umask 0022
|
|
|
|
export PATH='/usr/bin:/sbin:/bin'
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
keep="n"
|
2011-10-17 18:09:15 +02:00
|
|
|
CONFDIR="${ROOTDIR}/etc/initramfs-tools"
|
2009-10-09 03:11:09 +02:00
|
|
|
verbose="n"
|
|
|
|
|
2010-05-17 17:43:30 +02:00
|
|
|
OPTIONS=`getopt -o c:d:ko:r:v -n "$0" -- "$@"`
|
2009-10-09 03:11:09 +02:00
|
|
|
|
|
|
|
# Check for non-GNU getopt
|
2010-11-10 23:22:48 +01:00
|
|
|
if [ $? != 0 ] ; then echo "W: non-GNU getopt" >&2 ; exit 1 ; fi
|
2009-10-09 03:11:09 +02:00
|
|
|
|
|
|
|
eval set -- "$OPTIONS"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2010-05-17 17:43:30 +02:00
|
|
|
-c)
|
|
|
|
compress="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2009-10-09 03:11:09 +02:00
|
|
|
-d)
|
|
|
|
CONFDIR="$2"
|
|
|
|
shift 2
|
|
|
|
if [ ! -d "${CONFDIR}" ]; then
|
|
|
|
echo "${0}: ${CONFDIR}: Not a directory" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
-o)
|
|
|
|
outfile="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-k)
|
|
|
|
keep="y"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-r)
|
|
|
|
ROOT="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-v)
|
|
|
|
verbose="y"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Internal error!" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# For dependency ordered mkinitramfs hook scripts.
|
2011-10-17 18:09:15 +02:00
|
|
|
. ${ROOTDIR}/usr/share/initramfs-tools/scripts/functions
|
|
|
|
. ${ROOTDIR}/usr/share/initramfs-tools/hook-functions
|
2009-10-09 03:11:09 +02:00
|
|
|
|
|
|
|
. "${CONFDIR}/initramfs.conf"
|
|
|
|
EXTRA_CONF=''
|
2011-10-17 18:09:15 +02:00
|
|
|
for i in ${ROOTDIR}/usr/share/initramfs-tools/conf.d/* ${CONFDIR}/conf.d/*; do
|
2010-06-03 01:35:01 +02:00
|
|
|
[ -e $i ] && EXTRA_CONF="${EXTRA_CONF} $(basename $i \
|
2009-10-09 03:11:09 +02:00
|
|
|
| grep '^[[:alnum:]][[:alnum:]\._-]*$' | grep -v '\.dpkg-.*$')";
|
|
|
|
done
|
|
|
|
# FIXME: deprecated those settings on mkinitramfs run
|
2010-11-10 23:22:48 +01:00
|
|
|
# these conf dirs are for boot scripts and land on initramfs
|
2009-10-09 03:11:09 +02:00
|
|
|
for i in ${EXTRA_CONF}; do
|
|
|
|
if [ -e ${CONFDIR}/conf.d/${i} ]; then
|
|
|
|
. ${CONFDIR}/conf.d/${i}
|
2011-10-17 18:09:15 +02:00
|
|
|
elif [ -e ${ROOTDIR}/usr/share/initramfs-tools/conf.d/${i} ]; then
|
|
|
|
. ${ROOTDIR}/usr/share/initramfs-tools/conf.d/${i}
|
2009-10-09 03:11:09 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# source package confs
|
2011-10-17 18:09:15 +02:00
|
|
|
for i in ${ROOTDIR}/usr/share/initramfs-tools/conf-hooks.d/*; do
|
2009-10-09 03:11:09 +02:00
|
|
|
if [ -e "${i}" ]; then
|
|
|
|
. "${i}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2010-06-03 01:35:01 +02:00
|
|
|
if [ -n "${UMASK:-}" ]; then
|
2009-10-09 03:11:09 +02:00
|
|
|
umask "${UMASK}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${outfile}" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
touch "$outfile"
|
|
|
|
outfile="$(readlink -f "$outfile")"
|
|
|
|
|
|
|
|
# And by "version" we really mean path to kernel modules
|
|
|
|
# This is braindead, and exists to preserve the interface with mkinitrd
|
|
|
|
if [ ${#} -ne 1 ]; then
|
|
|
|
version="$(uname -r)"
|
|
|
|
else
|
|
|
|
version="${1}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that we're using a new enough kernel version, first for ourselves,
|
|
|
|
# then for each of the hooks, which can have a MINKVER variable defined
|
|
|
|
check_minkver ${version}
|
2011-10-17 18:09:15 +02:00
|
|
|
check_minkver ${version} ${ROOTDIR}/usr/share/initramfs-tools/hooks
|
2009-10-09 03:11:09 +02:00
|
|
|
check_minkver ${version} ${CONFDIR}/hooks
|
|
|
|
|
|
|
|
case "${version}" in
|
|
|
|
/lib/modules/*/[!/]*)
|
|
|
|
;;
|
|
|
|
/lib/modules/[!/]*)
|
|
|
|
version="${version#/lib/modules/}"
|
|
|
|
version="${version%%/*}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "${version}" in
|
|
|
|
*/*)
|
|
|
|
echo "$PROG: ${version} is not a valid kernel version" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-05-17 17:43:30 +02:00
|
|
|
# Check userspace and kernel support for compressed initramfs images
|
2010-06-03 01:35:01 +02:00
|
|
|
if [ -z "${compress:-}" ]; then
|
2010-05-17 17:43:30 +02:00
|
|
|
compress=${COMPRESS}
|
|
|
|
else
|
|
|
|
COMPRESS=${compress}
|
|
|
|
fi
|
|
|
|
|
2010-11-10 23:22:48 +01:00
|
|
|
if ! command -v "${compress}" >/dev/null 2>&1; then
|
2010-05-17 17:43:30 +02:00
|
|
|
compress=gzip
|
|
|
|
[ "${verbose}" = y ] && \
|
|
|
|
echo "No ${COMPRESS} in ${PATH}, using gzip"
|
2011-07-22 09:14:02 +02:00
|
|
|
COMPRESS=gzip
|
2010-05-17 17:43:30 +02:00
|
|
|
fi
|
|
|
|
|
2010-11-10 23:22:48 +01:00
|
|
|
if ! `grep -q -i ^config_rd_${COMPRESS%p} /boot/config-${version}` ; then
|
|
|
|
compress=gzip
|
|
|
|
[ "${verbose}" = y ] && \
|
|
|
|
echo "linux-2.6 misses ${COMPRESS} support, using gzip"
|
2010-05-17 17:43:30 +02:00
|
|
|
fi
|
|
|
|
|
2011-05-25 12:07:18 +02:00
|
|
|
# Always compress with best compression mode to save space.
|
2011-05-25 13:29:55 +02:00
|
|
|
[ "$compress" = xz ] && compress="xz --check=crc32"
|
2011-05-25 12:07:18 +02:00
|
|
|
compress="$compress -9"
|
2010-06-03 01:35:01 +02:00
|
|
|
|
2009-10-09 03:11:09 +02:00
|
|
|
if [ -d "${outfile}" ]; then
|
2010-11-10 23:22:48 +01:00
|
|
|
echo "${outfile} is a directory" >&2
|
2009-10-09 03:11:09 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
MODULESDIR="/lib/modules/${version}"
|
|
|
|
|
2011-10-17 18:09:15 +02:00
|
|
|
if [ ! -e "${ROOTDIR}${MODULESDIR}" ]; then
|
2010-05-17 17:43:30 +02:00
|
|
|
echo "WARNING: missing ${MODULESDIR}"
|
|
|
|
echo "Device driver support needs thus be built-in linux image!"
|
2009-10-09 03:11:09 +02:00
|
|
|
fi
|
2011-10-17 18:09:15 +02:00
|
|
|
if [ ! -e "${ROOTDIR}${MODULESDIR}/modules.dep" ]; then
|
2009-10-09 03:11:09 +02:00
|
|
|
depmod ${version}
|
|
|
|
fi
|
|
|
|
|
2010-06-03 01:35:01 +02:00
|
|
|
DESTDIR="$(mktemp -d ${TMPDIR:-/tmp}/mkinitramfs_XXXXXX)" || exit 1
|
2010-05-17 17:43:30 +02:00
|
|
|
chmod 755 "${DESTDIR}"
|
2010-11-10 23:22:48 +01:00
|
|
|
|
|
|
|
# do not execute cache_run_scripts() if mounted with noexec
|
|
|
|
NOEXEC=""
|
2011-10-17 18:09:15 +02:00
|
|
|
if [ -r ${ROOTDIR}/etc/mtab ]; then
|
2011-02-16 08:42:10 +01:00
|
|
|
fs=$(df -P $DESTDIR | tail -1 | awk '{print $6}')
|
|
|
|
if [ -n "$fs" ] && mount | grep -q "on $fs .*noexec" ; then
|
|
|
|
NOEXEC=1
|
|
|
|
fi
|
2010-11-10 23:22:48 +01:00
|
|
|
fi
|
|
|
|
|
2010-06-03 01:35:01 +02:00
|
|
|
__TMPCPIOGZ="$(mktemp ${TMPDIR:-/tmp}/mkinitramfs-OL_XXXXXX)" || exit 1
|
2009-10-09 03:11:09 +02:00
|
|
|
|
|
|
|
DPKG_ARCH=`uname -m`
|
|
|
|
|
|
|
|
# Export environment for hook scripts.
|
|
|
|
#
|
|
|
|
export MODULESDIR
|
|
|
|
export version
|
|
|
|
export CONFDIR
|
|
|
|
export DESTDIR
|
|
|
|
export DPKG_ARCH
|
|
|
|
export verbose
|
|
|
|
export KEYMAP
|
|
|
|
export MODULES
|
|
|
|
|
|
|
|
# Private, used by 'catenate_cpiogz'.
|
|
|
|
export __TMPCPIOGZ
|
|
|
|
|
2011-07-22 09:14:02 +02:00
|
|
|
for d in bin conf/conf.d etc lib/modules run sbin scripts ${MODULESDIR}; do
|
2009-10-09 03:11:09 +02:00
|
|
|
mkdir -p "${DESTDIR}/${d}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Copy the modules.order file in
|
2011-10-17 18:09:15 +02:00
|
|
|
if [ -f "${ROOTDIR}${MODULESDIR}/modules.order" ]; then
|
|
|
|
cp -p "${ROOTDIR}${MODULESDIR}/modules.order" \
|
2010-11-10 23:22:48 +01:00
|
|
|
"${DESTDIR}${MODULESDIR}/modules.order"
|
2009-10-09 03:11:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# MODULES=list case. Always honour.
|
2011-10-17 18:09:15 +02:00
|
|
|
for x in "${CONFDIR}/modules" ${ROOTDIR}/usr/share/initramfs-tools/modules.d/*; do
|
2009-10-09 03:11:09 +02:00
|
|
|
if [ -f "${x}" ]; then
|
|
|
|
add_modules_from_file "${x}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# MODULES=most is default
|
|
|
|
case "${MODULES}" in
|
|
|
|
dep)
|
|
|
|
dep_add_modules
|
|
|
|
;;
|
|
|
|
most)
|
|
|
|
auto_add_modules
|
|
|
|
;;
|
|
|
|
list)
|
|
|
|
# nothing to add
|
|
|
|
;;
|
|
|
|
*)
|
2010-11-10 23:22:48 +01:00
|
|
|
echo "W: mkinitramfs: unsupported MODULES setting: ${MODULES}."
|
|
|
|
echo "W: mkinitramfs: Falling back to MODULES=most."
|
2009-10-09 03:11:09 +02:00
|
|
|
auto_add_modules
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2011-02-13 17:43:18 +01:00
|
|
|
# Resolve hidden dependencies
|
|
|
|
hidden_dep_add_modules
|
|
|
|
|
2009-10-09 03:11:09 +02:00
|
|
|
# Have to do each file, because cpio --dereference doesn't recurse down
|
|
|
|
# symlinks.
|
2010-11-10 23:22:48 +01:00
|
|
|
|
2011-10-17 18:09:15 +02:00
|
|
|
cp -p ${ROOTDIR}/usr/share/initramfs-tools/init ${DESTDIR}/init
|
2009-10-09 03:11:09 +02:00
|
|
|
|
|
|
|
# add existant boot scripts
|
2011-10-17 18:09:15 +02:00
|
|
|
for b in $(cd ${ROOTDIR}/usr/share/initramfs-tools/scripts/ && find -L . \
|
2010-11-10 23:22:48 +01:00
|
|
|
-regextype posix-extended -regex '.*/[[:alnum:]\._-]+$' -type f); do
|
2009-10-09 03:11:09 +02:00
|
|
|
[ -d "${DESTDIR}/scripts/$(dirname "${b}")" ] \
|
|
|
|
|| mkdir -p "${DESTDIR}/scripts/$(dirname "${b}")"
|
2011-10-17 18:09:15 +02:00
|
|
|
cp -p "${ROOTDIR}/usr/share/initramfs-tools/scripts/${b}" \
|
2009-10-09 03:11:09 +02:00
|
|
|
"${DESTDIR}/scripts/$(dirname "${b}")/"
|
|
|
|
done
|
2011-03-05 12:20:41 +01:00
|
|
|
for b in $(cd "${CONFDIR}/scripts" && find -L . \
|
2010-11-10 23:22:48 +01:00
|
|
|
-regextype posix-extended -regex '.*/[[:alnum:]\._-]+$' -type f); do
|
2009-10-09 03:11:09 +02:00
|
|
|
[ -d "${DESTDIR}/scripts/$(dirname "${b}")" ] \
|
|
|
|
|| mkdir -p "${DESTDIR}/scripts/$(dirname "${b}")"
|
|
|
|
cp -p "${CONFDIR}/scripts/${b}" "${DESTDIR}/scripts/$(dirname "${b}")/"
|
|
|
|
done
|
|
|
|
|
|
|
|
cp -p "${CONFDIR}/initramfs.conf" ${DESTDIR}/conf
|
|
|
|
for i in ${EXTRA_CONF}; do
|
|
|
|
if [ -e "${CONFDIR}/conf.d/${i}" ]; then
|
|
|
|
copy_exec "${CONFDIR}/conf.d/${i}" /conf/conf.d
|
2011-10-17 18:09:15 +02:00
|
|
|
elif [ -e "${ROOTDIR}/usr/share/initramfs-tools/conf.d/${i}" ]; then
|
|
|
|
copy_exec "${ROOTDIR}/usr/share/initramfs-tools/conf.d/${i}" /conf/conf.d
|
2009-10-09 03:11:09 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# ROOT hardcoding
|
2010-06-03 01:35:01 +02:00
|
|
|
if [ -n "${ROOT:-}" ]; then
|
2009-10-09 03:11:09 +02:00
|
|
|
echo "ROOT=${ROOT}" > ${DESTDIR}/conf/conf.d/root
|
|
|
|
fi
|
|
|
|
|
2010-11-10 23:22:48 +01:00
|
|
|
if ! command -v ldd >/dev/null 2>&1 ; then
|
|
|
|
echo "WARNING: no ldd around - install libc-bin" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-10-17 18:09:15 +02:00
|
|
|
run_scripts ${ROOTDIR}/usr/share/initramfs-tools/hooks
|
2009-10-09 03:11:09 +02:00
|
|
|
run_scripts "${CONFDIR}"/hooks
|
|
|
|
|
2010-05-17 17:43:30 +02:00
|
|
|
# cache boot run order
|
2010-11-10 23:22:48 +01:00
|
|
|
if [ -n "$NOEXEC" ]; then
|
|
|
|
echo "W: TMPDIR is mounted noexec, will not cache run scripts."
|
|
|
|
else
|
|
|
|
for b in $(cd "${DESTDIR}/scripts" && find . -mindepth 1 -type d); do
|
|
|
|
cache_run_scripts "${DESTDIR}" "/scripts/${b#./}"
|
|
|
|
done
|
|
|
|
fi
|
2010-05-17 18:39:55 +02:00
|
|
|
|
2010-05-17 17:43:30 +02:00
|
|
|
# generate module deps
|
|
|
|
depmod -a -b "${DESTDIR}" ${version}
|
|
|
|
rm -f "${DESTDIR}/lib/modules/${version}"/modules.*map
|
|
|
|
|
2011-07-22 09:14:02 +02:00
|
|
|
# make sure that library search path is up to date
|
2011-10-17 18:09:15 +02:00
|
|
|
cp -ar ${ROOTDIR}/etc/ld.so.conf* "$DESTDIR"/etc/
|
2011-07-22 09:14:02 +02:00
|
|
|
if ! ldconfig -r "$DESTDIR" ; then
|
|
|
|
[ $(id -u) != "0" ] \
|
|
|
|
&& echo "ldconfig might need uid=0 (root) for chroot()" >&2
|
|
|
|
fi
|
|
|
|
|
2009-10-09 03:11:09 +02:00
|
|
|
# Apply DSDT to initramfs
|
|
|
|
if [ -e "${CONFDIR}/DSDT.aml" ]; then
|
|
|
|
copy_exec "${CONFDIR}/DSDT.aml" /
|
|
|
|
fi
|
|
|
|
|
2010-05-17 17:43:30 +02:00
|
|
|
# Remove any looping or broken symbolic links, since they break cpio.
|
2010-06-03 01:35:01 +02:00
|
|
|
[ "${verbose}" = y ] && xargs_verbose="-t"
|
2010-11-10 23:22:48 +01:00
|
|
|
(cd "${DESTDIR}" && find . -type l -printf '%p %Y\n' | sed -n 's/ [LN]$//p' \
|
|
|
|
| xargs ${xargs_verbose:-} -rL1 rm -f)
|
2010-02-19 06:44:50 +01:00
|
|
|
|
2010-05-17 17:43:30 +02:00
|
|
|
[ "${verbose}" = y ] && echo "Building cpio ${outfile} initramfs"
|
2009-10-09 03:11:09 +02:00
|
|
|
(
|
|
|
|
# work around lack of "set -o pipefail" for the following pipe:
|
2011-07-22 09:14:02 +02:00
|
|
|
# cd "${DESTDIR}" && find . | cpio --quiet -R 0:0 -o -H newc | gzip >"${outfile}" || exit 1
|
2009-10-09 03:11:09 +02:00
|
|
|
exec 3>&1
|
|
|
|
eval `
|
2010-11-10 23:22:48 +01:00
|
|
|
# http://cfaj.freeshell.org/shell/cus-faq-2.html
|
|
|
|
exec 4>&1 >&3 3>&-
|
|
|
|
cd "${DESTDIR}"
|
|
|
|
{
|
|
|
|
find . 4>&-; echo "ec1=$?;" >&4
|
|
|
|
} | {
|
2011-07-22 09:14:02 +02:00
|
|
|
cpio --quiet -R 0:0 -o -H newc 4>&-; echo "ec2=$?;" >&4
|
2010-11-10 23:22:48 +01:00
|
|
|
} | ${compress} >"${outfile}"
|
|
|
|
echo "ec3=$?;" >&4
|
2009-10-09 03:11:09 +02:00
|
|
|
`
|
2010-11-10 23:22:48 +01:00
|
|
|
if [ "$ec1" -ne 0 ]; then
|
|
|
|
echo "E: mkinitramfs failure find $ec1 cpio $ec2 $compress $ec3"
|
|
|
|
exit "$ec1"
|
|
|
|
fi
|
|
|
|
if [ "$ec2" -ne 0 ]; then
|
|
|
|
echo "E: mkinitramfs failure cpio $ec2 $compress $ec3"
|
|
|
|
exit "$ec2"
|
|
|
|
fi
|
|
|
|
if [ "$ec3" -ne 0 ]; then
|
|
|
|
echo "E: mkinitramfs failure $compress $ec3"
|
|
|
|
exit "$ec3"
|
|
|
|
fi
|
2009-10-09 03:11:09 +02:00
|
|
|
) || exit 1
|
|
|
|
|
|
|
|
if [ -s "${__TMPCPIOGZ}" ]; then
|
|
|
|
cat "${__TMPCPIOGZ}" >>"${outfile}" || exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${keep}" = "y" ]; then
|
|
|
|
echo "Working files in ${DESTDIR} and overlay in ${__TMPCPIOGZ}"
|
|
|
|
else
|
|
|
|
rm -rf "${DESTDIR}"
|
|
|
|
rm -rf "${__TMPCPIOGZ}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|