summaryrefslogtreecommitdiff
path: root/mkinitramfs
diff options
context:
space:
mode:
Diffstat (limited to 'mkinitramfs')
-rwxr-xr-xmkinitramfs176
1 files changed, 112 insertions, 64 deletions
diff --git a/mkinitramfs b/mkinitramfs
index 3c59757..0bb7806 100755
--- a/mkinitramfs
+++ b/mkinitramfs
@@ -7,19 +7,23 @@ export PATH='/usr/bin:/sbin:/bin'
keep="n"
CONFDIR="/etc/initramfs-tools"
verbose="n"
-errors_to="2>/dev/null"
-# BUSYBOXDIR="/usr/lib/initramfs-tools/bin/"
-BUSYBOXDIR="/bin"
+test -e /bin/busybox && BUSYBOXDIR=/bin
+test -e /usr/lib/initramfs-tools/bin/busybox && BUSYBOXDIR=/usr/lib/initramfs-tools/bin
+export BUSYBOXDIR
-OPTIONS=`getopt -o d:ko:r:v --long supported-host-version:,supported-target-version: -n "$0" -- "$@"`
+OPTIONS=`getopt -o c:d:ko:r:v -n "$0" -- "$@"`
# Check for non-GNU getopt
-if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
+if [ $? != 0 ] ; then echo "W: non-GNU getopt" >&2 ; exit 1 ; fi
eval set -- "$OPTIONS"
while true; do
case "$1" in
+ -c)
+ compress="$2"
+ shift 2
+ ;;
-d)
CONFDIR="$2"
shift 2
@@ -44,14 +48,6 @@ while true; do
verbose="y"
shift
;;
- --supported-host-version)
- supported_host_version="$2"
- shift 2
- ;;
- --supported-target-version)
- supported_target_version="$2"
- shift 2
- ;;
--)
shift
break
@@ -63,21 +59,6 @@ while true; do
esac
done
-# FIXME: remove after Lenny (needed for Etch linux-images)
-if [ -n "$supported_host_version" ] || [ -n "$supported_target_version" ]; then
- if [ -n "$supported_host_version" ]; then
- host_upstream_version="${supported_host_version%%-*}"
- fi
- if [ -n "$supported_target_version" ]; then
- target_upstream_version="${supported_target_version%%-*}"
- if dpkg --compare-versions "$target_upstream_version" lt "2.6.12"; then
- exit 2
- fi
- fi
- echo "Depreciation warning: use ramdisk=mkinitramfs-kpkg."
- exit 0
-fi
-
# For dependency ordered mkinitramfs hook scripts.
. /usr/share/initramfs-tools/scripts/functions
. /usr/share/initramfs-tools/hook-functions
@@ -85,11 +66,11 @@ fi
. "${CONFDIR}/initramfs.conf"
EXTRA_CONF=''
for i in /usr/share/initramfs-tools/conf.d/* ${CONFDIR}/conf.d/*; do
- EXTRA_CONF="${EXTRA_CONF} $(basename $i \
+ [ -e $i ] && EXTRA_CONF="${EXTRA_CONF} $(basename $i \
| grep '^[[:alnum:]][[:alnum:]\._-]*$' | grep -v '\.dpkg-.*$')";
done
# FIXME: deprecated those settings on mkinitramfs run
-# these conf dirs are for boot scripts and land on initramfs
+# these conf dirs are for boot scripts and land on initramfs
for i in ${EXTRA_CONF}; do
if [ -e ${CONFDIR}/conf.d/${i} ]; then
. ${CONFDIR}/conf.d/${i}
@@ -105,7 +86,7 @@ for i in /usr/share/initramfs-tools/conf-hooks.d/*; do
fi
done
-if [ -n "${UMASK}" ]; then
+if [ -n "${UMASK:-}" ]; then
umask "${UMASK}"
fi
@@ -146,23 +127,54 @@ case "${version}" in
;;
esac
+# Check userspace and kernel support for compressed initramfs images
+if [ -z "${compress:-}" ]; then
+ compress=${COMPRESS}
+else
+ COMPRESS=${compress}
+fi
+
+if ! command -v "${compress}" >/dev/null 2>&1; then
+ compress=gzip
+ COMPRESS=gzip
+ [ "${verbose}" = y ] && \
+ echo "No ${COMPRESS} in ${PATH}, using gzip"
+fi
+
+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"
+fi
+
+[ "${compress}" = lzop ] && compress="lzop -9"
+
if [ -d "${outfile}" ]; then
- echo "${outfile} is a directory"
+ echo "${outfile} is a directory" >&2
exit 1
fi
MODULESDIR="/lib/modules/${version}"
if [ ! -e "${MODULESDIR}" ]; then
- echo "Cannot find ${MODULESDIR}"
- exit 1
+ echo "WARNING: missing ${MODULESDIR}"
+ echo "Device driver support needs thus be built-in linux image!"
fi
if [ ! -e "${MODULESDIR}/modules.dep" ]; then
depmod ${version}
fi
-DESTDIR="$(mktemp -t -d mkinitramfs_XXXXXX)" || exit 1
-__TMPCPIOGZ="$(mktemp -t mkinitramfs-OL_XXXXXX)" || exit 1
+DESTDIR="$(mktemp -d ${TMPDIR:-/tmp}/mkinitramfs_XXXXXX)" || exit 1
+chmod 755 "${DESTDIR}"
+
+# do not execute cache_run_scripts() if mounted with noexec
+NOEXEC=""
+fs=$(df $DESTDIR | tail -1 | awk '{print $6}')
+if [ -n "$fs" ] && mount | grep -q "on $fs .*noexec" ; then
+ NOEXEC=1
+fi
+
+__TMPCPIOGZ="$(mktemp ${TMPDIR:-/tmp}/mkinitramfs-OL_XXXXXX)" || exit 1
DPKG_ARCH=`dpkg --print-architecture`
@@ -176,6 +188,7 @@ export DPKG_ARCH
export verbose
export KEYMAP
export MODULES
+export BUSYBOX
# Private, used by 'catenate_cpiogz'.
export __TMPCPIOGZ
@@ -184,6 +197,12 @@ 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" \
+ "${DESTDIR}${MODULESDIR}/modules.order"
+fi
+
# MODULES=list case. Always honour.
for x in "${CONFDIR}/modules" /usr/share/initramfs-tools/modules.d/*; do
if [ -f "${x}" ]; then
@@ -207,8 +226,8 @@ list)
# nothing to add
;;
*)
- echo "mkinitramfs: Warning unsupported MODULES setting: ${MODULES}."
- echo "mkinitramfs: Falling back to MODULES=most."
+ echo "W: mkinitramfs: unsupported MODULES setting: ${MODULES}."
+ echo "W: mkinitramfs: Falling back to MODULES=most."
auto_add_modules
;;
esac
@@ -216,30 +235,25 @@ esac
# Have to do each file, because cpio --dereference doesn't recurse down
# symlinks.
-# klibc
-ln -s /usr/lib/klibc/bin/* ${DESTDIR}/bin
-ln -s /lib/klibc-*.so ${DESTDIR}/lib
-rm -f ${DESTDIR}/bin/kinit* ${DESTDIR}/bin/gzip
-
-copy_exec /usr/share/initramfs-tools/init /init
+cp -p /usr/share/initramfs-tools/init ${DESTDIR}/init
# add existant boot scripts
for b in $(cd /usr/share/initramfs-tools/scripts/ && find . \
- -regextype posix-extended -regex '.*/[[:alnum:]_]+$' -type f); do
+ -regextype posix-extended -regex '.*/[[:alnum:]\._-]+$' -type f); do
[ -d "${DESTDIR}/scripts/$(dirname "${b}")" ] \
|| mkdir -p "${DESTDIR}/scripts/$(dirname "${b}")"
cp -p "/usr/share/initramfs-tools/scripts/${b}" \
"${DESTDIR}/scripts/$(dirname "${b}")/"
done
for b in $(cd "${CONFDIR}/scripts" && find . \
- -regextype posix-extended -regex '.*/[[:alnum:]_]+$' -type f); do
+ -regextype posix-extended -regex '.*/[[:alnum:]\._-]+$' -type f); do
[ -d "${DESTDIR}/scripts/$(dirname "${b}")" ] \
|| mkdir -p "${DESTDIR}/scripts/$(dirname "${b}")"
cp -p "${CONFDIR}/scripts/${b}" "${DESTDIR}/scripts/$(dirname "${b}")/"
done
echo "DPKG_ARCH=${DPKG_ARCH}" > ${DESTDIR}/conf/arch.conf
-copy_exec "${CONFDIR}/initramfs.conf" /conf
+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
@@ -249,28 +263,17 @@ for i in ${EXTRA_CONF}; do
done
# ROOT hardcoding
-if [ -n "${ROOT}" ]; then
+if [ -n "${ROOT:-}" ]; then
echo "ROOT=${ROOT}" > ${DESTDIR}/conf/conf.d/root
fi
-# Busybox
-if [ "${BUSYBOX}" = "n" ] || [ ! -e ${BUSYBOXDIR}/busybox ]; then
- mv ${DESTDIR}/bin/sh.shared ${DESTDIR}/bin/sh
- # those root need busybox
- eval "$(mount | awk '/ \/ / {print "r_dev=" $1; exit}')"
- if [ "${r_dev#/dev/mapper/}" != "${r_dev}" ]; then
- echo "Warning: Busybox is required for successful boot!"
- fi
-else
- rm -f ${DESTDIR}/bin/sh
- rm -f ${DESTDIR}/bin/busybox
- copy_exec ${BUSYBOXDIR}/busybox /bin/busybox
- ln -s ${BUSYBOXDIR}/busybox ${DESTDIR}/bin/sh
+if ! command -v ldd >/dev/null 2>&1 ; then
+ echo "WARNING: no ldd around - install libc-bin" >&2
+ exit 1
fi
-# Modutils
+# module-init-tools
copy_exec /sbin/modprobe /sbin
-copy_exec /sbin/depmod /sbin
copy_exec /sbin/rmmod /sbin
mkdir -p "${DESTDIR}/etc/modprobe.d"
cp -a /etc/modprobe.d/* "${DESTDIR}/etc/modprobe.d/"
@@ -283,13 +286,58 @@ fi
run_scripts /usr/share/initramfs-tools/hooks
run_scripts "${CONFDIR}"/hooks
+# cache boot run order
+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
+
+# generate module deps
+depmod -a -b "${DESTDIR}" ${version}
+rm -f "${DESTDIR}/lib/modules/${version}"/modules.*map
+
# Apply DSDT to initramfs
if [ -e "${CONFDIR}/DSDT.aml" ]; then
copy_exec "${CONFDIR}/DSDT.aml" /
fi
+# Remove any looping or broken symbolic links, since they break cpio.
+[ "${verbose}" = y ] && xargs_verbose="-t"
+(cd "${DESTDIR}" && find . -type l -printf '%p %Y\n' | sed -n 's/ [LN]$//p' \
+ | xargs ${xargs_verbose:-} -rL1 rm -f)
+
[ "${verbose}" = y ] && echo "Building cpio ${outfile} initramfs"
-(cd "${DESTDIR}" && find . | cpio --quiet --dereference -o -H newc | gzip >"${outfile}") || exit 1
+(
+# 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 `
+ # 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
+`
+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
+) || exit 1
if [ -s "${__TMPCPIOGZ}" ]; then
cat "${__TMPCPIOGZ}" >>"${outfile}" || exit 1