--no-kernel Do not install kernel drivers and firmware files
--strip Strip binaries in the initramfs
--nostrip Do not strip binaries in the initramfs (default)
+ --prefix Prefix initramfs files with /run/initramfs/
+ --noprefix Do not prefix initramfs files with /run/initramfs/
+ (default)
--mdadmconf Include local /etc/mdadm.conf
--nomdadmconf Do not include local /etc/mdadm.conf
--lvmconf Include local /etc/lvm/lvm.conf
--no-kernel) kernel_only="no"; no_kernel="yes";;
--strip) do_strip_l="yes";;
--nostrip) do_strip_l="no";;
+ --prefix) do_prefix_l="yes";;
+ --noprefix) do_prefix_l="no";;
--mdadmconf) mdadmconf_l="yes";;
--nomdadmconf) mdadmconf_l="no";;
--lvmconf) lvmconf_l="yes";;
[[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
[[ $do_strip_l ]] && do_strip=$do_strip_l
+[[ $do_prefix_l ]] && do_prefix=$do_prefix_l
[[ $hostonly_l ]] && hostonly=$hostonly_l
[[ $use_fstab_l ]] && use_fstab=$use_fstab_l
[[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
[[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut
[[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
[[ $do_strip ]] || do_strip=no
+[[ $do_prefix ]] || do_prefix=no
[[ $compress_l ]] && compress=$compress_l
[[ $show_modules_l ]] && show_modules=$show_modules_l
# eliminate IFS hackery when messing with fw_dir
stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
debug
+[[ $do_prefix = yes ]] && PREFIX=/run/initramfs
+
+# Create some directory structure first
+[[ $PREFIX ]] && mkdir -m 0755 -p "${initdir}${PREFIX}"
+
+mkdir -m 0755 -p "${initdir}${PREFIX}/lib"
+[[ $PREFIX ]] && ln -sfn "${PREFIX#/}/lib" "$initdir/lib"
+
if [[ $kernel_only != yes ]]; then
- # Create some directory structure first
- for d in bin sbin usr/bin usr/sbin usr/lib etc \
- proc sys sysroot tmp dev/pts var/run; do
- inst_dir "/$d";
+ for d in bin etc lib "$libdir" sbin tmp usr var; do
+ [[ -e "${initdir}${PREFIX}/$d" ]] && continue
+ mkdir -m 0755 -p "${initdir}${PREFIX}/$d"
+ [[ $PREFIX ]] && ln -sfn "${PREFIX#/}/${d#/}" "$initdir/$d"
+ done
+
+ for d in proc sys sysroot root run run/lock run/initramfs; do
+ mkdir -m 0755 -p "$initdir/$d";
done
+
+ ln -sfn /run "$initdir/var/run"
+ ln -sfn /run/lock "$initdir/var/lock"
fi
# check all our modules to see if they should be sourced.
if [[ -f $src ]]; then
inst $src $tgt
else
- ddebug "Including directory: $src"
+ ddebug "Including directory: $src"
mkdir -p "${initdir}/${tgt}"
- cp -a -t "${initdir}/${tgt}" "$src"/*
+ # check for preexisting symlinks, so we can cope with the
+ # symlinks to $PREFIX
+ for i in "$src"/*; do
+ [[ -e "$i" || -h "$i" ]] || continue
+ s=${initdir}/${tgt}/${i#$src/}
+ if [[ -d "$i" ]]; then
+ if ! [[ -e "$s" ]]; then
+ mkdir -m 0755 -p "$s"
+ chmod --reference="$i" "$s"
+ fi
+ cp -a -t "$s" "$i"/*
+ else
+ cp -a -t "$s" "$i"
+ fi
+ done
fi
fi
done
unset _tmp
fi
-if [ ! -c /dev/ptmx ]; then
+ismounted sys || \
+ mount -t sysfs -o nosuid,noexec,nodev /sys /sys >/dev/null 2>&1
+
+if ! ismounted /dev; then
# try to mount devtmpfs
- if ! mount -t devtmpfs -o mode=0755,nosuid udev /dev >/dev/null 2>&1; then
+ if ! mount -t devtmpfs -o mode=0755,nosuid,noexec,nosuid udev /dev >/dev/null 2>&1; then
# if it failed fall back to normal tmpfs
mount -t tmpfs -o mode=0755,nosuid udev /dev >/dev/null 2>&1
# Make some basic devices first, let udev handle the rest
fi
# prepare the /dev directory
-ln -s /proc/self/fd /dev/fd >/dev/null 2>&1
-ln -s /proc/self/fd/0 /dev/stdin >/dev/null 2>&1
-ln -s /proc/self/fd/1 /dev/stdout >/dev/null 2>&1
-ln -s /proc/self/fd/2 /dev/stderr >/dev/null 2>&1
-mkdir -m 0755 /dev/shm /dev/pts /run
-mount -t devpts -o gid=5,mode=620,noexec,nosuid devpts /dev/pts >/dev/null 2>&1
-mount -t tmpfs -o mode=1777,nosuid,nodev tmpfs /dev/shm >/dev/null 2>&1
-# create /run which will obsolete /var/run
-mount -t tmpfs -o mode=0755,nodev,noexec,nosuid tmpfs /run >/dev/null 2>&1
-
-mkdir -m 0755 /run/initramfs
+[ ! -h /dev/fd ] && ln -s /proc/self/fd /dev/fd >/dev/null 2>&1
+[ ! -h /dev/stdin ] && ln -s /proc/self/fd/0 /dev/stdin >/dev/null 2>&1
+[ ! -h /dev/stdout ] && ln -s /proc/self/fd/1 /dev/stdout >/dev/null 2>&1
+[ ! -h /dev/stderr ] && ln -s /proc/self/fd/2 /dev/stderr >/dev/null 2>&1
+
+if ! ismounted /dev/pts; then
+ mkdir -m 0755 /dev/pts
+ mount -t devpts -o gid=5,mode=620,noexec,nosuid devpts /dev/pts >/dev/null 2>&1
+fi
+
+if ! ismounted /dev/shm; then
+ mkdir -m 0755 /dev/shm
+ mount -t tmpfs -o mode=1777,nosuid,nodev tmpfs /dev/shm >/dev/null 2>&1
+fi
+
+if ! ismounted /run; then
+ mkdir -m 0755 /newrun
+ mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /newrun >/dev/null 2>&1
+ cp -a -t /newrun /run/*
+ mount --move /newrun /run
+ rm -fr /newrun
+fi
UDEVVERSION=$(udevadm --version)
if [ $UDEVVERSION -gt 166 ]; then
export UDEVRULESD=/dev/.udev/rules.d
fi
-[ -e /var/run ] && mv /var/run /var/run.bak
-[ -e /var/lock ] && mv /var/lock /var/lock.bak
-ln -fs /run /var/run
-mkdir -m 0755 /run/lock
-ln -fs /run/lock /var/lock
-# copy over any possible directory structure
-cp -ar /var/run.bak/* /run/ 2>/dev/null
-cp -ar /var/lock.bak/* /run/lock/ 2>/dev/null
-
if [ "$RD_DEBUG" = "yes" ]; then
mkfifo /run/initramfs/loginit.pipe
loginit $DRACUT_QUIET </run/initramfs/loginit.pipe >/dev/console 2>&1 &
esac
done
fi
+[ "$RD_DEBUG" = "yes" ] && set -x
+
+if [ -d "$NEWROOT"/run ]; then
+ NEWRUN="${NEWROOT}/run"
+ mount --bind /run "$NEWRUN"
+ NEWINITRAMFSROOT="$NEWRUN/initramfs"
-info "Switching root"
+ if [ "$NEWINITRAMFSROOT/lib" -ef "/lib" ]; then
+ for d in bin etc lib lib64 sbin tmp usr var; do
+ [ -h /$d ] && ln -fsn $NEWINITRAMFSROOT/$d /$d
+ done
+ fi
+else
+ NEWRUN=/dev/.initramfs
+ mkdir -m 0755 "$NEWRUN"
+ mount --bind /run/initramfs "$NEWRUN"
+fi
wait_for_loginit
+
+info "Switching root"
+
+umount -l /run
-if [ -d "$NEWROOT"/run ]; then
- mount --move /run "$NEWROOT"/run
-else
- if [ -e /run/initramfs ]; then
- cp -axr /run/initramfs /dev/.initramfs >/dev/null 2>&1
- if [ -e /run/initramfs/live ]; then
- mkdir -m 0755 /dev/.initramfs/live
- mount --move /run/initramfs/live /dev/.initramfs/live
- fi
- fi
- umount -l /run
-fi
+unset PS4
-export PATH="$OLD_PATH"
+CAPSH=$(command -v capsh)
+SWITCH_ROOT=$(command -v switch_root)
+PATH=$OLDPATH
+export PATH
if [ -f /etc/capsdrop ]; then
. /etc/capsdrop
info "Calling $INIT with capabilities $CAPS_INIT_DROP dropped."
unset RD_DEBUG
- exec /usr/sbin/capsh --drop="$CAPS_INIT_DROP" -- -c "exec /sbin/switch_root \"$NEWROOT\" \"$INIT\" $initargs" || {
+ exec $CAPSH --drop="$CAPS_INIT_DROP" -- \
+ -c "exec switch_root \"$NEWROOT\" \"$INIT\" $initargs" || \
+ {
warn "Command:"
warn capsh --drop=$CAPS_INIT_DROP -- -c exec switch_root "$NEWROOT" "$INIT" $initargs
warn "failed."
}
else
unset RD_DEBUG
- exec /sbin/switch_root "$NEWROOT" "$INIT" $initargs || {
+ exec $SWITCH_ROOT "$NEWROOT" "$INIT" $initargs || {
warn "Something went very badly wrong in the initramfs. Please "
warn "file a bug against dracut."
emergency_shell