2009-10-09 03:11:09 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
umask 0022
|
|
|
|
export PATH='/usr/bin:/sbin:/bin'
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
keep="n"
|
|
|
|
CONFDIR="/etc/initramfs-tools"
|
|
|
|
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.
|
|
|
|
. /usr/share/initramfs-tools/scripts/functions
|
|
|
|
. /usr/share/initramfs-tools/hook-functions
|
|
|
|
|
|
|
|
. "${CONFDIR}/initramfs.conf"
|
|
|
|
EXTRA_CONF=''
|
|
|
|
for i in /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}
|
|
|
|
elif [ -e /usr/share/initramfs-tools/conf.d/${i} ]; then
|
|
|
|
. /usr/share/initramfs-tools/conf.d/${i}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# source package confs
|
|
|
|
for i in /usr/share/initramfs-tools/conf-hooks.d/*; do
|
|
|
|
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}
|
|
|
|
check_minkver ${version} /usr/share/initramfs-tools/hooks
|
|
|
|
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
|
2010-11-10 23:22:48 +01:00
|
|
|
COMPRESS=gzip
|
2010-05-17 17:43:30 +02:00
|
|
|
[ "${verbose}" = y ] && \
|
|
|
|
echo "No ${COMPRESS} in ${PATH}, using gzip"
|
|
|
|
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
|
|
|
|
|
2010-11-10 23:22:48 +01:00
|
|
|
[ "${compress}" = lzop ] && compress="lzop -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}"
|
|
|
|
|
|
|
|
if [ ! -e "${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
|
|
|
|
if [ ! -e "${MODULESDIR}/modules.dep" ]; then
|
|
|
|
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-02-16 08:42:10 +01:00
|
|
|
if [ -r /etc/mtab ]; then
|
|
|
|
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
|
|
|
|
|
|
|
|
for d in bin conf/conf.d etc lib/modules sbin scripts ${MODULESDIR}; do
|
|
|
|
mkdir -p "${DESTDIR}/${d}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Copy the modules.order file in
|
|
|
|
if [ -f "${MODULESDIR}/modules.order" ]; then
|
|
|
|
cp -p "${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.
|
|
|
|
for x in "${CONFDIR}/modules" /usr/share/initramfs-tools/modules.d/*; do
|
|
|
|
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
|
|
|
|
;;
|
|
|
|
netboot)
|
|
|
|
auto_add_modules base
|
|
|
|
auto_add_modules net
|
|
|
|
;;
|
|
|
|
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
|
|
|
|
2009-10-09 03:11:09 +02:00
|
|
|
cp -p /usr/share/initramfs-tools/init ${DESTDIR}/init
|
|
|
|
|
|
|
|
# add existant boot scripts
|
2011-03-05 12:20:41 +01:00
|
|
|
for b in $(cd /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}")"
|
|
|
|
cp -p "/usr/share/initramfs-tools/scripts/${b}" \
|
|
|
|
"${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
|
|
|
|
elif [ -e "/usr/share/initramfs-tools/conf.d/${i}" ]; then
|
|
|
|
copy_exec "/usr/share/initramfs-tools/conf.d/${i}" /conf/conf.d
|
|
|
|
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
|
|
|
|
|
|
|
|
# module-init-tools
|
|
|
|
copy_exec /sbin/modprobe /sbin
|
|
|
|
copy_exec /sbin/rmmod /sbin
|
|
|
|
mkdir -p "${DESTDIR}/etc/modprobe.d"
|
|
|
|
cp -a /etc/modprobe.d/* "${DESTDIR}/etc/modprobe.d/"
|
|
|
|
|
2010-11-10 23:35:41 +01:00
|
|
|
# Copy resume from klibc
|
|
|
|
copy_exec /bin/resume /bin
|
|
|
|
|
2009-10-09 03:11:09 +02:00
|
|
|
run_scripts /usr/share/initramfs-tools/hooks
|
|
|
|
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
|
|
|
|
|
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:
|
|
|
|
# cd "${DESTDIR}" && find . | cpio --quiet --dereference -o -H newc | gzip >"${outfile}" || exit 1
|
|
|
|
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
|
|
|
|
} | {
|
|
|
|
cpio --quiet --dereference -o -H newc 4>&-; echo "ec2=$?;" >&4
|
|
|
|
} | ${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
|