* [PATCH 00/10] All recent patches linearly
@ 2011-10-18 18:33 Michal Soltys
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
0 siblings, 1 reply; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
As they kind of slowly started piling up and messing with each other.
Only new things are (last two patches):
- thorough checks for chosen/fallback terminal before calling shell
- emergency_shell moved into single place in dracut-lib, with two simple knobs
- added documentation for --ctty
Additionally,
The following changes since commit d239b550ce9e6a80342965974c4503cfde736fbe:
explicitly verify bash version (2011-10-11 09:37:02 +0200)
are available in the git repository at:
git://git.hasevolq.net/dracut.git fixup
Michal Soltys (10):
features: RUNDIR, imgdir, prefix, prefix_mnt and related changes
features: RUNDIR, imgdir, ... [update 1]
minor changes
dracut: remove duplicate options
dracut: detect lib paths more carefully
check root candidates more carefully
introduce optional job control
job control fixup
prepare common emergency_shell function (1), shell job control fixups (2)
optional shell job control - add documentation
dracut | 130 ++++++++++++++----------
dracut-functions | 71 +++++++++-----
dracut.8.xml | 9 ++
dracut.kernel.7.xml | 15 +++
modules.d/10i18n/console_init | 1 +
modules.d/99base/dracut-lib.sh | 109 ++++++++++++++++++++
modules.d/99base/init | 205 ++++++++++++++++++--------------------
modules.d/99base/module-setup.sh | 14 ++-
modules.d/99shutdown/shutdown | 29 +-----
9 files changed, 363 insertions(+), 220 deletions(-)
--
1.7.5.3
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 01/10] features: RUNDIR, imgdir, prefix, prefix_mnt and related changes
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 02/10] features: RUNDIR, imgdir, ... [update 1] Michal Soltys
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
1) $prefix, $prefix_mnt
The prefix itself (and new prefix_mnt option) is used only during /run --move
(pre-pivot, preiously --bind), while internally - dracut files and /run are
kept _separately_ in $imgdir and $rundir.
$prefix is sanitized before use, and its final (adjusted) value is always
relative to /run (not being under /run has little point). If user provided
$prefix doesn't start with /run, or consists only of /run - it's assumed to be
/run relative. Otherwise (2 or more components and beginning with /run) it's
assumed to be absolute.
$prefix_mnt allows us to request tmpfs mount at $newrun/$prefix, before copying
dracut tree.
2) $RUNDIR (inside init only), $imgdir
The crux of changes are these two. Internal split, which previously was based
on $prefix is now based on $imgdir. All /run references from $imgdir point to
/run, which inside init is adjusted to /run -> $RUNDIR. All tmp references
point to just initramfs root's /tmp (as we don't care about the junk after
pivot).
This gives us decoupled runtime tree and dracut image tree. The latter can be
installed if $prefix is set or completely ignored. runtime is always --moved.
Furthermore, $RUNDIR is symlinked from run, so it can be easily kept fully
functional, with trivial symlink adjustment.
Everything in imgdir is symlinked from initramfs's root (similary as it's been
done until now).
All inst*() functions are aware of $imgdir; imgdir, prefix, prefix_mnt and
newroot are exported, and also available in init (after uppercasing, sourced
from simple config file).
Of course, /tmp and /run stuff has to be set differently during installation
phase (e.g. ..../var/run -> ${initdir}/run, etc.) and differenty during
initramfs execution (e.g. ..../var/run -> /run). In dracut script, it's
respectively "initial sewing pass" and "final sewing pass". The latter one also
verifies if all symlinks are valid.
This way of handling $prefix opens path to making it runtime argument (e.g.
rd.prefix).
3) /run ($RUNDIR) move
/run is moved to either $NEWROOT/run or if not possible - to /dev/.run (with
/dev/.initramfs -> .run/initramfs symlink). If $prefix is specified, contents
of $imgdir are copied to the $NEWRUN/$prefix or alternatively (if $prefix_mnt
is set), tmpfs is mounted at $NEWRUN/$prefix and then the $imgdir is copied;
init will refuse overmount, if the directory is already present.
4) udev and /dev/.udev vs /run/udev
There's possibility, that sufficiently new udev will prefer /run during
initramfs stage, while host may still be not run ready. This might lead to
losing certain db entries (e.g. lvm's). If we detect such situation, contents
of /run/udev are moved to /dev/.udev before pivoting.
5) enforcing options of premounted directories
For special directories - /proc, /sys, etc. - as we should assure that the
actual mount options are sane. Though the only realistically pre-mountable
thing is /dev (for now at least).
6) other smaller changes:
- copying cp -a -t <dst> . after cd <src>, instead of <dst> <src>/* - as this
also handles .* files (otherwise we would have to tinker with some crude
globbing and/or dotglob)
- We don't try to mimic host's directory layout anymore (if some directories
are symlinked, which is rarely the case either way and serves little
purpose)
- removed certain mkdirs, that are guaranteed to be handled by dracut
---
dracut | 115 +++++++++++++++++++------------
dracut-functions | 50 +++++++-------
modules.d/99base/init | 137 ++++++++++++++++++++++++--------------
modules.d/99base/module-setup.sh | 13 ++--
4 files changed, 189 insertions(+), 126 deletions(-)
diff --git a/dracut b/dracut
index 205f5d1..1d5f2f4 100755
--- a/dracut
+++ b/dracut
@@ -53,7 +53,11 @@ Creates initial ramdisk images for preloading modules
--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 [DIR] Prefix initramfs files with [DIR]
+ --prefix [DIR] Prefix initramfs files with [DIR]. If DIR doesn't
+ start with /run (or if it's the only component), it's
+ assumed to be relative to /run.
+ --prefix_mnt Copy initramfs into additional tmpfs mount, instead of
+ directly into prefix subdirectory.
--noprefix Do not prefix initramfs files (default)
--mdadmconf Include local /etc/mdadm.conf
--nomdadmconf Do not include local /etc/mdadm.conf
@@ -222,6 +226,7 @@ while (($# > 0)); do
--strip) do_strip_l="yes";;
--nostrip) do_strip_l="no";;
--noprefix) prefix_l="/";;
+ --prefix_mnt) prefix_mnt_l="yes";;
--mdadmconf) mdadmconf_l="yes";;
--nomdadmconf) mdadmconf_l="no";;
--lvmconf) lvmconf_l="yes";;
@@ -378,8 +383,6 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
[[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
[[ $do_strip_l ]] && do_strip=$do_strip_l
-[[ $prefix_l ]] && prefix=$prefix_l
-[[ $prefix = "/" ]] && unset prefix
[[ $hostonly_l ]] && hostonly=$hostonly_l
[[ $use_fstab_l ]] && use_fstab=$use_fstab_l
[[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
@@ -390,6 +393,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
[[ $compress_l ]] && compress=$compress_l
[[ $show_modules_l ]] && show_modules=$show_modules_l
[[ $nofscks_l ]] && nofscks="yes"
+[[ $prefix_mnt_l ]] && prefix_mnt="yes"
# eliminate IFS hackery when messing with fw_dir
fw_dir=${fw_dir//:/ }
@@ -428,6 +432,19 @@ fi
dracutfunctions=$dracutbasedir/dracut-functions
export dracutfunctions
+# sanitize and handle prefix.
+# If /run is the only component, or if $prefix_l doesn't start with /run, then
+# the path is assumed to be relative to /run, otherwise it's absolute.
+# Final prefix is always set as relative to /run
+if [[ "$prefix_l" =~ [[:alnum:]] ]]; then
+ prefix=$(normalize_path "/$prefix_l")
+ prefix=${prefix#/}
+ prefix=${prefix#run/}
+else
+ unset prefix
+ unset prefix_mnt
+fi
+
ddebug "Executing $0 $dracut_args"
[[ $do_list = yes ]] && {
@@ -494,6 +511,7 @@ readonly initdir=$(mktemp --tmpdir=/var/tmp/ -d -t initramfs.XXXXXX)
dfatal "mktemp failed."
exit 1
}
+readonly imgdir=/_img newroot=/sysroot
# clean up after ourselves no matter how we die.
trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || rm -rf "$initdir";exit $ret;' EXIT
@@ -508,48 +526,30 @@ export initdir dracutbasedir dracutmodules drivers \
add_drivers mdadmconf lvmconf filesystems \
use_fstab libdir usrlibdir fscks nofscks \
stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
- debug
-
-# Create some directory structure first
-[[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
-
-[[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
-[[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
-
-if [[ $prefix ]]; then
- for d in bin etc lib "$libdir" sbin tmp usr var; do
- ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
- done
-fi
+ debug imgdir prefix prefix_mnt newroot
+# initial directory layout + host safe symlinks
if [[ $kernel_only != yes ]]; then
- for d in bin etc lib "$libdir" sbin tmp usr var usr/bin usr/sbin; do
- [[ -e "${initdir}${prefix}/$d" ]] && continue
- if [ -h "/$d" ]; then
- inst "/$d" "${prefix}/$d"
- else
- mkdir -m 0755 -p "${initdir}${prefix}/$d"
- fi
- done
-
- for d in dev proc sys sysroot root run run/lock run/initramfs; do
- if [ -h "/$d" ]; then
- inst "/$d"
- else
- mkdir -m 0755 -p "$initdir/$d"
- fi
+ mkdir -m 0755 -p \
+ "${initdir}${imgdir}"/{bin,etc,lib,${libdir#/},sbin,var,usr/{bin,sbin}} \
+ "${initdir}"/{dev,proc,sys,${newroot#/},root,run/{lock,initramfs},tmp}
+
+ # host safe symlinks (will be adjusted later), needed during inst*() calls
+ ln -sfn "${initdir}"/tmp "${initdir}${imgdir}"/tmp
+ ln -sfn "${initdir}"/tmp "${initdir}${imgdir}"/var/tmp
+ ln -sfn "${initdir}"/run "${initdir}${imgdir}"/run
+ ln -sfn "${initdir}"/run "${initdir}${imgdir}"/var/run
+ ln -sfn "${initdir}"/run/lock "${initdir}${imgdir}"/var/lock
+ # initial sewing pass
+ for d in bin etc lib "${libdir#/}" sbin var usr; do
+ ln -sfn "${imgdir#/}/$d" "${initdir}/$d"
done
-
- ln -sfn /run "$initdir/var/run"
- ln -sfn /run/lock "$initdir/var/lock"
else
- for d in lib "$libdir"; do
- [[ -e "${initdir}${prefix}/$d" ]] && continue
- if [ -h "/$d" ]; then
- inst "/$d" "${prefix}/$d"
- else
- mkdir -m 0755 -p "${initdir}${prefix}/$d"
- fi
+ mkdir -m 0755 -p "${initdir}${imgdir}/"{lib,${libdir#/}}
+
+ # initial sewing pass
+ for d in lib "${libdir#/}"; do
+ ln -sfn "${imgdir#/}/$d" "${initdir}/$d"
done
fi
@@ -593,18 +593,20 @@ while pop include_src src && pop include_target tgt; do
inst $src $tgt
else
ddebug "Including directory: $src"
- mkdir -p "${initdir}/${tgt}"
+ mkdir -p "${initdir}${imgdir}/${tgt}"
# 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/}
+ s=${initdir}${imgdir}/${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"/*
+ pushd "$i" &>/dev/null
+ cp -a -t "$s" .
+ popd &>/dev/null
else
cp -a -t "$s" "$i"
fi
@@ -620,7 +622,6 @@ while pop install_items items; do
done
unset item
-
if [[ $kernel_only != yes ]]; then
# make sure that library links are correct and up to date
for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
@@ -672,6 +673,30 @@ if strstr "$modules_loaded" " fips " && command -v prelink >/dev/null; then
done
fi
+# final sewing pass
+# remove helper /run & /tmp links, set symlinks to match initramfs's root, link
+# remaining directories (if any)
+if [[ $kernel_only != yes ]]; then
+ rm -f "${initdir}${imgdir}"/{run,tmp}
+ ln -sfn /tmp "${initdir}${imgdir}"/var/tmp
+ ln -sfn /run "${initdir}${imgdir}"/var/run
+ ln -sfn /run/lock "${initdir}${imgdir}"/var/lock
+fi
+for d in "${initdir}${imgdir}"/*; do
+ s="${initdir}/${d##*/}"
+ if [[ -h ${s} ]]; then
+ # verify if everything is fine
+ t=$(readlink -e "${s}")
+ if [[ $t != $d ]]; then
+ dfatal "dracut: symlink mismatch ${d##*/} -/-> ${d#${initdir}/}"
+ exit 1
+ fi
+ else
+ ln -sfn "${imgdir#/}/${d##*/}" "${s}"
+ fi
+done
+
+# create the image
if ! ( cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet| \
$compress > "$outfile"; ); then
dfatal "dracut: creation of $outfile failed"
diff --git a/dracut-functions b/dracut-functions
index 1ef5269..3b971c7 100755
--- a/dracut-functions
+++ b/dracut-functions
@@ -269,13 +269,13 @@ check_vol_slaves() {
# Install a directory, keeping symlinks as on the original system.
# Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
-# will create ${initdir}/lib64, ${initdir}/lib64/file,
-# and a symlink ${initdir}/lib -> lib64.
+# will create ${initdir}${imgdir}/lib64, ${initdir}${imgdir}/lib64/file,
+# and a symlink ${initdir}${imgdir}/lib -> lib64.
inst_dir() {
- [[ -e ${initdir}"$1" ]] && return 0 # already there
+ [[ -e ${initdir}${imgdir}"$1" ]] && return 0 # already there
local _dir="$1" _part="${1%/*}" _file
- while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}${_part}" ]]; do
+ while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}${imgdir}${_part}" ]]; do
_dir="$_part $_dir"
_part=${_part%/*}
done
@@ -290,12 +290,12 @@ inst_dir() {
inst_dir "$target"
inst_symlink "$_file"
else
- [[ -h ${initdir}$_file ]] && _file=$(readlink "${initdir}$_file")
+ [[ -h ${initdir}${imgdir}$_file ]] && _file=$(readlink "${initdir}${imgdir}$_file")
# create directory
- mkdir -m 0755 -p "${initdir}$_file" || return 1
+ mkdir -m 0755 -p "${initdir}${imgdir}$_file" || return 1
if [[ -d "$_file" ]]; then
- chmod --reference="$_file" "${initdir}$_file"
- chmod u+w "${initdir}$_file"
+ chmod --reference="$_file" "${initdir}${imgdir}$_file"
+ chmod u+w "${initdir}${imgdir}$_file"
fi
fi
done
@@ -303,15 +303,15 @@ inst_dir() {
# $1 = file to copy to ramdisk
# $2 (optional) Name for the file on the ramdisk
-# Location of the image dir is assumed to be $initdir
+# Location of the image dir is assumed to be ${initdir}${imgdir}
# We never overwrite the target if it exists.
inst_simple() {
[[ -f $1 ]] || return 1
local _src=$1 target="${2:-$1}"
- if ! [[ -d ${initdir}$target ]]; then
- [[ -e ${initdir}$target ]] && return 0
- [[ -h ${initdir}$target ]] && return 0
+ if ! [[ -d ${initdir}${imgdir}$target ]]; then
+ [[ -e ${initdir}${imgdir}$target ]] && return 0
+ [[ -h ${initdir}${imgdir}$target ]] && return 0
inst_dir "${target%/*}"
fi
# install checksum files also
@@ -319,7 +319,7 @@ inst_simple() {
inst "${_src%/*}/.${_src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
fi
ddebug "Installing $_src"
- cp --sparse=always -pfL "$_src" "${initdir}$target"
+ cp --sparse=always -pfL "$_src" "${initdir}${imgdir}$target"
}
# find symlinks linked to given library file
@@ -352,7 +352,7 @@ rev_lib_symlinks() {
# is referenced.
inst_library() {
local _src=$1 _dest=${2:-$1} _lib _reallib _symlink
- [[ -e $initdir$_dest ]] && return 0
+ [[ -e ${initdir}${imgdir}$_dest ]] && return 0
if [[ -L $_src ]]; then
# install checksum files also
if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
@@ -361,14 +361,14 @@ inst_library() {
_reallib=$(readlink -f "$_src")
inst_simple "$_reallib" "$_reallib"
inst_dir "${_dest%/*}"
- ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}${_dest}"
+ ln -sfn $(convert_abs_rel "${_dest}" "${_reallib}") "${initdir}${imgdir}${_dest}"
else
inst_simple "$_src" "$_dest"
fi
# Create additional symlinks. See rev_symlinks description.
for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
- [[ ! -e $initdir$_symlink ]] && {
+ [[ ! -e ${initdir}${imgdir}$_symlink ]] && {
ddebug "Creating extra symlink: $_symlink"
inst_symlink $_symlink
}
@@ -396,7 +396,7 @@ inst_binary() {
_bin=$(find_binary "$1") || return 1
_target=${2:-$_bin}
inst_symlink $_bin $_target && return 0
- [[ -e $initdir$_target ]] && return 0
+ [[ -e ${initdir}${imgdir}$_target ]] && return 0
# If the binary being installed is also a library, add it to the loop.
_so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
@@ -414,7 +414,7 @@ inst_binary() {
fi
[[ $_line =~ $_so_regex ]] || continue
_file=${BASH_REMATCH[1]}
- [[ -e ${initdir}$_file ]] && continue
+ [[ -e ${initdir}${imgdir}$_file ]] && continue
# See if we are loading an optimized version of a shared lib.
if [[ $_file =~ $_lib_regex ]]; then
@@ -451,7 +451,7 @@ inst_script() {
# same as above, but specialized for symlinks
inst_symlink() {
- local _src=$1 _target=$initdir${2:-$1} _realsrc
+ local _src=$1 _target=${initdir}${imgdir}${2:-$1} _realsrc
[[ -L $1 ]] || return 1
[[ -L $_target ]] && return 0
_realsrc=$(readlink -f "$_src")
@@ -459,7 +459,7 @@ inst_symlink() {
if [[ -d $_realsrc ]]; then
inst_dir "$_realsrc"
else
- inst "$_realsrc" && mkdir -m 0755 -p "${_target%/*}"
+ inst "$_realsrc" && mkdir -m 0755 -p "${_target%/*}"
fi
if [[ -e "${_src}" ]]; then
ln -sfn $(convert_abs_rel "${_src}" "${_realsrc}") "$_target"
@@ -604,9 +604,9 @@ inst_decompress() {
_realsrc="$(readlink -f ${_src})" # symlink target with extension
_dst="${_src%.*}" # symlink without extension
_realdst="${_realsrc%.*}" # symlink target without extension
- mksubdirs "${initdir}/${_src}"
+ mksubdirs "${initdir}${imgdir}/${_src}"
# Create symlink without extension to target without extension.
- ln -sfn "${_realdst}" "${initdir}/${_dst}"
+ ln -sfn "${_realdst}" "${initdir}${imgdir}/${_dst}"
fi
# If the source is symlink we operate on its target.
@@ -614,7 +614,7 @@ inst_decompress() {
inst ${_src}
# Decompress with chosen tool. We assume that tool changes name e.g.
# from 'name.gz' to 'name'.
- ${_cmd} "${initdir}${_src}"
+ ${_cmd} "${initdir}${imgdir}${_src}"
done
}
@@ -787,7 +787,7 @@ check_module_dir() {
# $1 = full path to kernel module to install
install_kmod_with_fw() {
# no need to go further if the module is already installed
- [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
+ [[ -e "${initdir}${imgdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
&& return 0
inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" \
|| return $?
@@ -915,7 +915,7 @@ instmods() {
# if we are already installed, skip this module and go on
# to the next one.
- [[ -f $initdir/$1 ]] && return
+ [[ -f ${initdir}${imgdir}/$1 ]] && return
# If we are building a host-specific initramfs and this
# module is not already loaded, move on to the next one.
diff --git a/modules.d/99base/init b/modules.d/99base/init
index 06d61a8..0970a48 100755
--- a/modules.d/99base/init
+++ b/modules.d/99base/init
@@ -66,25 +66,31 @@ emergency_shell()
fi
}
-NEWROOT="/sysroot"
-[ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
-
trap "emergency_shell Signal caught!" 0
OLDPATH=$PATH
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
RD_DEBUG=""
+. /etc/dracut-init.conf
. /lib/dracut-lib.sh
[ -c /dev/null ] || mknod -m 0666 /dev/null c 1 3
-# mount some important things
-[ ! -d /proc/self ] && \
- mount -t proc -o nosuid,noexec,nodev proc /proc >/dev/null 2>&1
+# mount some important things; if something is already mounted,
+# we sanitize mount options by remounting
+# note: although -t would be ignored during remount, we play
+# it safe and make sure -t is not specified in such case
+# note: at this point, only /dev can be premounted by kernel, so
+# maybe just skip those checks altogether ?
+
+_opt="-o nosuid,noexec,nodev"; _fs="-t proc"
+[ -d /proc/self ] && { _opt="$_opt,remount"; unset _fs; }
+mount $_fs $_opt proc /proc >/dev/null 2>&1
-[ ! -d /sys/kernel ] && \
- mount -t sysfs -o nosuid,noexec,nodev sysfs /sys >/dev/null 2>&1
+_opt="-o nosuid,noexec,nodev"; _fs="-t sysfs"
+[ -d /sys/kernel ] && { _opt="$_opt,remount"; unset _fs; }
+mount $_fs $_opt sysfs /sys >/dev/null 2>&1
if [ -x /lib/systemd/systemd-timestamp ]; then
RD_TIMESTAMP=$(/lib/systemd/systemd-timestamp)
@@ -101,44 +107,50 @@ if [ "$RD_DEBUG" = "yes" ]; then
[ -n "$a" ] && [ $a -ge 8 ] && unset DRACUT_QUIET
fi
-if ! ismounted /dev; then
- # try to mount devtmpfs
- if ! mount -t devtmpfs -o mode=0755,nosuid devtmpfs /dev >/dev/null 2>&1; then
- # if it failed fall back to normal tmpfs
- mount -t tmpfs -o mode=0755,nosuid tmpfs /dev >/dev/null 2>&1
- # Make some basic devices first, let udev handle the rest
- mknod -m 0666 /dev/null c 1 3
- mknod -m 0666 /dev/ptmx c 5 2
- mknod -m 0600 /dev/console c 5 1
- mknod -m 0660 /dev/kmsg c 1 11
- fi
+_opt="-o mode=0755,nosuid,exec"; _fs="-t devtmpfs"
+ismounted /dev && { _opt="$_opt,remount"; unset _fs; }
+if ! mount $_fs $_opt devtmpfs /dev >/dev/null 2>&1; then
+ # if it failed (remount can't fail - no need to redo $_opt), fall back to
+ # normal tmpfs
+ mount -t tmpfs $_opt tmpfs /dev >/dev/null 2>&1
+ # Make some basic devices first, let udev handle the rest
+ mknod -m 0666 /dev/null c 1 3
+ mknod -m 0666 /dev/ptmx c 5 2
+ mknod -m 0600 /dev/console c 5 1
+ mknod -m 0660 /dev/kmsg c 1 11
fi
-# prepare the /dev directory
+# prepare the /dev directory (note: newer udevd takes care of it automatically)
[ ! -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
-
-[ -d /run/initramfs ] || mkdir -p -m 0755 /run/initramfs
+_opt="-o gid=5,mode=620,noexec,nosuid"; _fs="-t devpts"
+ismounted /dev/pts && { _opt="$_opt,remount"; unset _fs; } || mkdir -m 0755 /dev/pts
+mount $_fs $_opt devpts /dev/pts >/dev/null 2>&1
+
+_opt="-o mode=1777,nosuid,nodev"; _fs="-t tmpfs"
+ismounted /dev/shm && { _opt="$_opt,remount"; unset _fs; } || mkdir -m 0755 /dev/shm
+mount $_fs $_opt tmpfs /dev/shm >/dev/null 2>&1
+
+# Prepare proper tmpfs mount for /run:
+# - /run is just a symlink to real staging area. This allows us to be
+# independent from any mount place, with trivial symlink manipulation
+# - checking if /run is premounted, is pretty crazy in initramfs ...
+
+_opt="-o mode=0755,nosuid,nodev,exec"; _fs="-t tmpfs"
+RUNDIR=/_run
+ismounted /run && { _opt="$_opt,remount"; unset _fs; }
+mkdir -m 0755 -p $RUNDIR
+# move + remount or mount
+[ -z "$_fs" ] && mount --move /run $RUNDIR
+mount $_fs $_opt tmpfs $RUNDIR >/dev/null 2>&1
+# copy if mount
+[ -z "$_fs" ] || { cd /run; cp -a -t $RUNDIR .; cd /; }
+# set symlink
+rm -rf /run
+ln -sfn ${RUNDIR#/} /run
UDEVVERSION=$(udevadm --version)
if [ $UDEVVERSION -gt 166 ]; then
@@ -410,20 +422,43 @@ else
fi
[ "$RD_DEBUG" = "yes" ] && set -x
-if [ -d "$NEWROOT"/run ]; then
- NEWRUN="${NEWROOT}/run"
- mount --bind /run "$NEWRUN"
- NEWINITRAMFSROOT="$NEWRUN/initramfs"
+# /run move, udev adjustment (if applicable), prefix handling
+if [ -d "$NEWROOT/run" ]; then
+ NEWRUN="$NEWROOT/run"
+else
+ NEWRUN=/dev/.run
+ mkdir -p -m 0755 "$NEWRUN"
+ [ -n "$PREFIX" ] && ln -sfn .run/initramfs /dev/.initramfs
+ # if initramfs's udev uses /run by default, but the host is
+ # still /run-less, we should copy udev's data to legacy
+ # /dev/.udev, so the necessary info is available for the host
+ # (e.g. lvm db entries)
+ if [ -d /run/udev/data -o -d /run/udev/db ]; then
+ mkdir -p -m 0755 /dev/.udev
+ cd /run/udev
+ cp -a -t /dev/.udev .
+ cd /
+ rm -rf /run/udev
+ fi
+fi
- 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
+mount --move "$RUNDIR" "$NEWRUN"
+ln -sfn "${NEWRUN#/}" /run
+
+if [ -n "$PREFIX" ]; then
+ if [ -d "$NEWRUN/$PREFIX" ]; then
+ [ -n "$PREFIX_MNT" ] &&
+ warn "'$NEWRUN/$PREFIX' already exists, dracut files will be copied directly to this directory"
+ unset PREFIX_MNT
+ else
+ mkdir -p -m 0755 "$NEWRUN/$PREFIX"
fi
-else
- NEWRUN=/dev/.initramfs
- mkdir -m 0755 "$NEWRUN"
- mount --bind /run/initramfs "$NEWRUN"
+ if [ -n "$PREFIX_MNT" ]; then
+ mount -t tmpfs -o mode=0755,nosuid,nodev,exec tmpfs "$NEWRUN/$PREFIX"
+ fi
+ cd "$IMGDIR"
+ cp -a -t "$NEWRUN/$PREFIX" .
+ cd /
fi
wait_for_loginit
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
index f6dc920..2a9b643 100755
--- a/modules.d/99base/module-setup.sh
+++ b/modules.d/99base/module-setup.sh
@@ -12,7 +12,7 @@ depends() {
}
install() {
- local _d
+ local _d _x
dracut_install mount mknod mkdir modprobe pidof sleep chroot \
sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink
dracut_install -o less
@@ -25,7 +25,6 @@ install() {
inst "$moddir/initqueue" "/sbin/initqueue"
inst "$moddir/loginit" "/sbin/loginit"
- [ -e "${initdir}/lib" ] || mkdir -m 0755 -p ${initdir}/lib
mkdir -m 0755 -p ${initdir}/lib/dracut
mkdir -m 0755 -p ${initdir}/lib/dracut/hooks
for _d in $hookdirs emergency \
@@ -33,13 +32,17 @@ install() {
mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
done
- mkdir -p ${initdir}/tmp
-
dracut_install switch_root || dfatal "Failed to install switch_root"
inst "$moddir/dracut-lib.sh" "/lib/dracut-lib.sh"
inst_hook cmdline 10 "$moddir/parse-root-opts.sh"
- mkdir -p "${initdir}/var"
+
[ -x /lib/systemd/systemd-timestamp ] && inst /lib/systemd/systemd-timestamp
+
+ # export certain settings to init
+ for _d in newroot imgdir prefix prefix_mnt; do
+ _x=$(echo $_d | tr "a-z" "A-Z")
+ [ -n "$_d" ] && echo "${_x}=${!_d}" >>${initdir}/etc/dracut-init.conf
+ done
}
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 02/10] features: RUNDIR, imgdir, ... [update 1]
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
2011-10-18 18:33 ` [PATCH 01/10] features: RUNDIR, imgdir, prefix, prefix_mnt and related changes Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 03/10] minor changes Michal Soltys
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
Make sure we actually mimic host's structure to not end with duplicate
files (harmless but wasteful) on hosts, where lib and lib64 point to the
same place.
We detect symlink/dir presence in the creation loop, so we don't have to
worry about $[usr]libdir.
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
dracut | 30 ++++++++++++++++--------------
1 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/dracut b/dracut
index 1d5f2f4..191998a 100755
--- a/dracut
+++ b/dracut
@@ -530,9 +530,13 @@ export initdir dracutbasedir dracutmodules drivers \
# initial directory layout + host safe symlinks
if [[ $kernel_only != yes ]]; then
+ for d in /{bin,sbin,etc,lib{,64},var,usr{,/{bin,sbin,lib{,64}}}}; do
+ if [[ -h $d ]]; then inst_symlink $d
+ elif [[ -d $d ]]; then inst_dir $d; fi
+ done
+
mkdir -m 0755 -p \
- "${initdir}${imgdir}"/{bin,etc,lib,${libdir#/},sbin,var,usr/{bin,sbin}} \
- "${initdir}"/{dev,proc,sys,${newroot#/},root,run/{lock,initramfs},tmp}
+ "${initdir}"/{dev,proc,sys,${newroot#/},root,run{,/{lock,initramfs}},tmp}
# host safe symlinks (will be adjusted later), needed during inst*() calls
ln -sfn "${initdir}"/tmp "${initdir}${imgdir}"/tmp
@@ -540,18 +544,16 @@ if [[ $kernel_only != yes ]]; then
ln -sfn "${initdir}"/run "${initdir}${imgdir}"/run
ln -sfn "${initdir}"/run "${initdir}${imgdir}"/var/run
ln -sfn "${initdir}"/run/lock "${initdir}${imgdir}"/var/lock
- # initial sewing pass
- for d in bin etc lib "${libdir#/}" sbin var usr; do
- ln -sfn "${imgdir#/}/$d" "${initdir}/$d"
- done
else
- mkdir -m 0755 -p "${initdir}${imgdir}/"{lib,${libdir#/}}
-
- # initial sewing pass
- for d in lib "${libdir#/}"; do
- ln -sfn "${imgdir#/}/$d" "${initdir}/$d"
+ for d in /lib{,64}; do
+ if [[ -h $d ]]; then inst_symlink $d
+ elif [[ -d $d ]]; then inst_dir $d; fi
done
fi
+# initial sewing pass
+for d in "${initdir}${imgdir}"/*; do
+ ln -sfn "${imgdir#/}/${d##*/}" "${initdir}/${d##*/}"
+done
# check all our modules to see if they should be sourced.
# This builds a list of modules that we will install next.
@@ -686,13 +688,13 @@ for d in "${initdir}${imgdir}"/*; do
s="${initdir}/${d##*/}"
if [[ -h ${s} ]]; then
# verify if everything is fine
- t=$(readlink -e "${s}")
- if [[ $t != $d ]]; then
+ t=$(readlink "${s}")
+ if [[ $t != ${d#${initdir}/} ]]; then
dfatal "dracut: symlink mismatch ${d##*/} -/-> ${d#${initdir}/}"
exit 1
fi
else
- ln -sfn "${imgdir#/}/${d##*/}" "${s}"
+ ln -sfn "${d#${initdir}/}" "${s}"
fi
done
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 03/10] minor changes
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
2011-10-18 18:33 ` [PATCH 01/10] features: RUNDIR, imgdir, prefix, prefix_mnt and related changes Michal Soltys
2011-10-18 18:33 ` [PATCH 02/10] features: RUNDIR, imgdir, ... [update 1] Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 04/10] dracut: remove duplicate options Michal Soltys
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
- in 10i18n - do stty -iutf8 on non-utf8 consoles, for consistency with
iutf8 on utf8 ones
- vim modeline in xml file
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
dracut.kernel.7.xml | 1 +
modules.d/10i18n/console_init | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/dracut.kernel.7.xml b/dracut.kernel.7.xml
index 8d50d94..0571031 100644
--- a/dracut.kernel.7.xml
+++ b/dracut.kernel.7.xml
@@ -1,5 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" []>
+<!-- vim: set ts=8 sts=2 sw=2 et: -->
<refentry id="dracutkernel7">
<refentryinfo>
<title>dracut.kernel</title>
diff --git a/modules.d/10i18n/console_init b/modules.d/10i18n/console_init
index 110cb0a..b46046b 100755
--- a/modules.d/10i18n/console_init
+++ b/modules.d/10i18n/console_init
@@ -22,6 +22,7 @@ set_terminal() {
stty -F ${dev} iutf8
else
printf '\033%%@' >&7
+ stty -F ${dev} -iutf8
fi
}
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 04/10] dracut: remove duplicate options
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (2 preceding siblings ...)
2011-10-18 18:33 ` [PATCH 03/10] minor changes Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 05/10] dracut: detect lib paths more carefully Michal Soltys
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
'-I' and '--fwdir' were both read_arg and push_arg, and the latter has
priority.
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
dracut | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/dracut b/dracut
index 191998a..a93dade 100755
--- a/dracut
+++ b/dracut
@@ -216,8 +216,6 @@ while (($# > 0)); do
-c|--conf) read_arg conffile "$@" || shift;;
--confdir) read_arg confdir "$@" || shift;;
-L|--stdlog) read_arg stdloglvl_l "$@" || shift;;
- -I|--install) read_arg install_items "$@" || shift;;
- --fwdir) read_arg fw_dir_l "$@" || shift;;
--compress) read_arg compress_l "$@" || shift;;
--prefix) read_arg prefix_l "$@" || shift;;
-f|--force) force=yes;;
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 05/10] dracut: detect lib paths more carefully
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (3 preceding siblings ...)
2011-10-18 18:33 ` [PATCH 04/10] dracut: remove duplicate options Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 06/10] check root candidates " Michal Soltys
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
- consider that they can point to the same directory - in such case
ignore the one that is a symlink
- move the detection function to dracut-functions
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
dracut | 12 ++----------
dracut-functions | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/dracut b/dracut
index a93dade..115f1c4 100755
--- a/dracut
+++ b/dracut
@@ -456,16 +456,8 @@ ddebug "Executing $0 $dracut_args"
}
# Detect lib paths
-[[ $libdir ]] || for libdir in /lib64 /lib; do
- [[ -d $libdir ]] && break
-done || {
- dfatal 'No lib directory?!!!'
- exit 1
-}
-
-[[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
- [[ -d $usrlibdir ]] && break
-done || dwarn 'No usr/lib directory!'
+libdir="$(det_lib_paths)" || { dfatal 'No lib directory?!!!'; exit 1; }
+usrlibdir="$(det_lib_paths /usr)" || dwarn 'No usr/lib directory!'
# This is kinda legacy -- eventually it should go away.
case $dracutmodules in
diff --git a/dracut-functions b/dracut-functions
index 3b971c7..7b6aa5a 100755
--- a/dracut-functions
+++ b/dracut-functions
@@ -958,3 +958,24 @@ instmods() {
| egrep -v 'FATAL: Module .* not found.' | derror
return $?
}
+
+# determine lib paths in specified prefix
+# if they point to the same, ignore the one that is a symlink
+# prefer lib64 over lib
+function det_lib_paths() {
+ local _lib _d _d64
+ _d=$(readlink -e "$1/lib")
+ _d64=$(readlink -e "$1/lib64")
+ if [[ $_d = $_d64 ]]; then
+ [[ -h $1/lib ]] && unset _d
+ [[ -h $1/lib64 ]] && unset _d64
+ fi
+ if [[ -n $_d64 ]]; then
+ _lib=$1/lib64
+ elif [[ -n $_d ]]; then
+ _lib=$1/lib
+ else
+ return 1
+ fi
+ echo "$_lib"
+}
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 06/10] check root candidates more carefully
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (4 preceding siblings ...)
2011-10-18 18:33 ` [PATCH 05/10] dracut: detect lib paths more carefully Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 07/10] introduce optional job control Michal Soltys
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
This is from the following thread:
http://thread.gmane.org/gmane.linux.raid/35753/focus=35795
Additional tests + more specific info.
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
modules.d/99base/dracut-lib.sh | 11 +++++++++++
modules.d/99base/init | 12 ++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index 62c3bf5..cf5aae6 100755
--- a/modules.d/99base/dracut-lib.sh
+++ b/modules.d/99base/dracut-lib.sh
@@ -544,3 +544,14 @@ foreach_uuid_until() (
return 1
)
+
+usable_root() {
+ local _d
+ [ -d $1 ] || return 1
+ for _d in "$1"/{etc,proc,sys,dev,tmp,usr,var}; do
+ [ -e $_d ] || return 1
+ done
+ [ -e "$1/bin" -o -e "$1/sbin" ] || return 1
+ [ -e "$1/lib" -o -e "$1/lib64" ] || return 1
+ return 0
+}
diff --git a/modules.d/99base/init b/modules.d/99base/init
index 0970a48..bc5d2ba 100755
--- a/modules.d/99base/init
+++ b/modules.d/99base/init
@@ -298,10 +298,18 @@ getarg 'rd.break=mount' 'rdbreak=mount' && emergency_shell -n mount "Break mount
# be sourced any number of times. As soon as one suceeds, no more are sourced.
i=0
while :; do
- [ -d "$NEWROOT/proc" ] && break;
+ if ismounted "$NEWROOT"; then
+ usable_root "$NEWROOT" && break;
+ umount "$NEWROOT"
+ fi
for f in $hookdir/mount/*.sh; do
[ -f "$f" ] && . "$f"
- [ -d "$NEWROOT/proc" ] && break;
+ if ismounted "$NEWROOT"; then
+ usable_root "$NEWROOT" && break;
+ warn "$NEWROOT has no proper rootfs layout, ignoring and removing offending mount hook"
+ umount "$NEWROOT"
+ rm -f "$f"
+ fi
done
i=$(($i+1))
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 07/10] introduce optional job control
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (5 preceding siblings ...)
2011-10-18 18:33 ` [PATCH 06/10] check root candidates " Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 08/10] job control fixup Michal Soltys
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
Option --ctty will optionally add setsid binary to dracut's image.
During runtime, if rd.ctty is set and is a character device,
emergency shells will be spawned with job control.
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
dracut | 3 ++-
modules.d/99base/init | 10 ++++++++--
modules.d/99base/module-setup.sh | 1 +
modules.d/99shutdown/shutdown | 11 +++++++++--
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/dracut b/dracut
index 115f1c4..4cfcab8 100755
--- a/dracut
+++ b/dracut
@@ -231,6 +231,7 @@ while (($# > 0)); do
--nolvmconf) lvmconf_l="no";;
--debug) debug="yes";;
--profile) profile="yes";;
+ --ctty) cttyhack="yes";;
-v|--verbose) ((verbosity_mod_l++));;
-q|--quiet) ((verbosity_mod_l--));;
-l|--local) allowlocal="yes" ;;
@@ -514,7 +515,7 @@ chmod 755 "$initdir"
export initdir dracutbasedir dracutmodules drivers \
fw_dir drivers_dir debug no_kernel kernel_only \
add_drivers mdadmconf lvmconf filesystems \
- use_fstab libdir usrlibdir fscks nofscks \
+ use_fstab libdir usrlibdir fscks nofscks cttyhack \
stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
debug imgdir prefix prefix_mnt newroot
diff --git a/modules.d/99base/init b/modules.d/99base/init
index bc5d2ba..e532bfe 100755
--- a/modules.d/99base/init
+++ b/modules.d/99base/init
@@ -40,6 +40,7 @@ wait_for_loginit()
emergency_shell()
{
+ local _ctty
set +e
if [ "$1" = "-n" ]; then
_rdshell_name=$2
@@ -57,8 +58,13 @@ emergency_shell()
echo "Dropping to debug shell."
echo
export PS1="$_rdshell_name:\${PWD}# "
- [ -e /.profile ] || echo "exec 0<>/dev/console 1<>/dev/console 2<>/dev/console" > /.profile
- sh -i -l
+ [ -e /.profile ] || >/.profile
+ _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
+ if type setsid >/dev/null 2>&1 && [ -c "$_ctty" ] ; then
+ setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
+ else
+ sh -i -l
+ fi
else
warn "Boot has failed. To debug this issue add \"rdshell\" to the kernel command line."
# cause a kernel panic
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
index 2a9b643..4c64bca 100755
--- a/modules.d/99base/module-setup.sh
+++ b/modules.d/99base/module-setup.sh
@@ -16,6 +16,7 @@ install() {
dracut_install mount mknod mkdir modprobe pidof sleep chroot \
sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink
dracut_install -o less
+ [[ $cttyhack = yes ]] && dracut_install -o setsid
if [ ! -e "${initdir}/bin/sh" ]; then
dracut_install bash
(ln -s bash "${initdir}/bin/sh" || :)
diff --git a/modules.d/99shutdown/shutdown b/modules.d/99shutdown/shutdown
index a31a95d..9473b5b 100755
--- a/modules.d/99shutdown/shutdown
+++ b/modules.d/99shutdown/shutdown
@@ -13,6 +13,7 @@ export TERM=linux
emergency_shell()
{
+ local _ctty
set +e
if [ "$1" = "-n" ]; then
_rdshell_name=$2
@@ -29,8 +30,14 @@ emergency_shell()
echo "Dropping to debug shell."
echo
export PS1="$_rdshell_name:\${PWD}# "
- [ -e /.profile ] || echo "exec 0<>/dev/console 1<>/dev/console 2<>/dev/console" > /.profile
- sh -i -l
+ [ -e /.profile ] || >/.profile
+ _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
+ if type setsid >/dev/null 2>&1 && [ -c "$_ctty" ] ; then
+ _ctty=/dev/${_ctty##*/}
+ setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
+ else
+ sh -i -l
+ fi
else
exec /lib/systemd/systemd-shutdown "$@"
warn "Shutdown has failed. To debug this issue add \"rdshell\" to the kernel command line."
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 08/10] job control fixup
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (6 preceding siblings ...)
2011-10-18 18:33 ` [PATCH 07/10] introduce optional job control Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 09/10] prepare common emergency_shell function (1), shell job control fixups (2) Michal Soltys
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
- in case no ctty was provided, shell was spawned without caring about
/dev/console
Also, the ctty is more opportunistic. If the image was generated with
--ctty, we will fallback to /dev/tty1 if rc.ctty is invalid or missing.
Otherwise we spawn standard shell on /dev/console
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
modules.d/99base/init | 8 +++++---
modules.d/99shutdown/shutdown | 9 +++++----
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/modules.d/99base/init b/modules.d/99base/init
index e532bfe..3da6abd 100755
--- a/modules.d/99base/init
+++ b/modules.d/99base/init
@@ -59,11 +59,13 @@ emergency_shell()
echo
export PS1="$_rdshell_name:\${PWD}# "
[ -e /.profile ] || >/.profile
- _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
- if type setsid >/dev/null 2>&1 && [ -c "$_ctty" ] ; then
+ _ctty=/dev/console
+ if type setsid >/dev/null 2>&1; then
+ _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
+ [ -c "$_ctty" ] || _ctty=/dev/tty1
setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
else
- sh -i -l
+ sh -i -l 0<$_ctty 1>$_ctty 2>&1
fi
else
warn "Boot has failed. To debug this issue add \"rdshell\" to the kernel command line."
diff --git a/modules.d/99shutdown/shutdown b/modules.d/99shutdown/shutdown
index 9473b5b..21bb37f 100755
--- a/modules.d/99shutdown/shutdown
+++ b/modules.d/99shutdown/shutdown
@@ -31,12 +31,13 @@ emergency_shell()
echo
export PS1="$_rdshell_name:\${PWD}# "
[ -e /.profile ] || >/.profile
- _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
- if type setsid >/dev/null 2>&1 && [ -c "$_ctty" ] ; then
- _ctty=/dev/${_ctty##*/}
+ _ctty=/dev/console
+ if type setsid >/dev/null 2>&1; then
+ _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
+ [ -c "$_ctty" ] || _ctty=/dev/tty1
setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
else
- sh -i -l
+ sh -i -l 0<$_ctty 1>$_ctty 2>&1
fi
else
exec /lib/systemd/systemd-shutdown "$@"
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 09/10] prepare common emergency_shell function (1), shell job control fixups (2)
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (7 preceding siblings ...)
2011-10-18 18:33 ` [PATCH 08/10] job control fixup Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-18 18:33 ` [PATCH 10/10] optional shell job control - add documentation Michal Soltys
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
1) prepare common emergency_shell
emergency_shell functions from 99base/init and 99shutdown/shutdown were
very similar, which forced to do similar changes in both places
The core functionality was moved to 99base/dracut-lib.sh as
emergency_shell_core(), which is now called through wrapping
emergency_shell(), with two simple internal knobs (type and error
message). wait_for_loginit() was moved to the lib as well.
2) shell job control fixups
Terminal (the one provided to command line) is thoroughly checked if it
really is terminal. In case of any problems we fallback to /dev/tty1
(if --ctty was used) or if it doesn't exist for whatever reason (or no
--ctty was used), to /dev/console. Additionally, shell is never spawned
through setsid on /dev/console (little point to do so).
This should cover all possible corner cases.
---
modules.d/99base/dracut-lib.sh | 98 ++++++++++++++++++++++++++++++++++++++++
modules.d/99base/init | 64 --------------------------
modules.d/99shutdown/shutdown | 37 ++-------------
3 files changed, 102 insertions(+), 97 deletions(-)
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index cf5aae6..ff80eda 100755
--- a/modules.d/99base/dracut-lib.sh
+++ b/modules.d/99base/dracut-lib.sh
@@ -555,3 +555,101 @@ usable_root() {
[ -e "$1/lib" -o -e "$1/lib64" ] || return 1
return 0
}
+
+wait_for_loginit()
+{
+ set +x
+ [ "$RD_DEBUG" = "yes" ] || return
+ [ -e /run/initramfs/loginit.pipe ] || return
+ echo "DRACUT_LOG_END"
+ exec 0<>/dev/console 1<>/dev/console 2<>/dev/console
+ # wait for loginit
+ i=0
+ while [ $i -lt 10 ]; do
+ if [ ! -e /run/initramfs/loginit.pipe ]; then
+ j=$(jobs)
+ [ -z "$j" ] && break
+ [ -z "${j##*Running*}" ] || break
+ fi
+ sleep 0.1
+ i=$(($i+1))
+ done
+
+ if [ $i -eq 10 ]; then
+ kill %1 >/dev/null 2>&1
+ kill $(while read line;do echo $line;done</run/initramfs/loginit.pid)
+ fi
+
+ set -x
+ rm -f /run/initramfs/loginit.pipe /run/initramfs/loginit.pid
+}
+
+# meant only to be called through emergency_shell wrapper function;
+# standard version is defined below, shutdown override is in
+# 99shutdown/shutdown
+#
+# $1 - 's' or 'i', depending if it was called from shutdown or init
+# $2 - error message
+# $3 - "name", or:
+# $3, $4 - "-n" "name"
+# remaining arguments - remaining message passed to wrapper
+#
+emergency_shell_core()
+{
+ local _type; local _mesg
+ set +e
+
+ _type="$1"; _mesg="$2"; shift 2
+ if [ "$1" = "-n" ]; then
+ _rdshell_name=$2
+ shift 2
+ else
+ _rdshell_name=dracut
+ fi
+ echo ; echo
+ warn "$*"
+ echo
+ if [ $_type = i ]; then
+ source_hook emergency
+ wait_for_loginit
+ [ -e /run/initramfs/.die ] && exit 1
+ else
+ source_hook shutdown-emergency
+ fi
+ if getargbool 1 rd.shell -y rdshell || getarg rd.break rdbreak; then
+ local _tty; local _tmp
+
+ _tty=/dev/console
+ if type setsid >/dev/null 2>&1; then
+ [ -c /dev/tty1 ] && _tty=/dev/tty1
+ _tmp="$(getarg rd.ctty=)" && _tmp="/dev/${_tmp##*/}"
+ if [ -c "$_tmp" ] && exec 9<>$_tmp >/dev/null 2>&1; then
+ [ -t 9 ] && _tty=$_tmp
+ exec 9>&-
+ fi
+ fi
+ [ -x /lib/udev/console_init ] && /lib/udev/console_init $_tty
+
+ echo "Dropping to debug shell."
+ echo
+ export PS1="$_rdshell_name:\${PWD}# "
+ [ -e /.profile ] || >/.profile
+ if [ $_tty != /dev/console ]; then
+ setsid sh -i -l 0<$_tty 1>$_tty 2>&1
+ else
+ sh -i -l 0<$_tty 1>$_tty 2>&1
+ fi
+ else
+ [ $_type = s ] && exec /lib/systemd/systemd-shutdown "$@"
+ warn "$_mesg"
+ # cause a kernel panic
+ exit 1
+ fi
+}
+
+emergency_shell()
+{
+ emergency_shell_core i \
+ "Boot has failed. To debug this issue add \"rd.shell\" to the kernel command line." \
+ "$@"
+}
diff --git a/modules.d/99base/init b/modules.d/99base/init
index 3da6abd..16ed3fc 100755
--- a/modules.d/99base/init
+++ b/modules.d/99base/init
@@ -10,70 +10,6 @@
export -p > /tmp/export.orig
-wait_for_loginit()
-{
- set +x
- [ "$RD_DEBUG" = "yes" ] || return
- [ -e /run/initramfs/loginit.pipe ] || return
- echo "DRACUT_LOG_END"
- exec 0<>/dev/console 1<>/dev/console 2<>/dev/console
- # wait for loginit
- i=0
- while [ $i -lt 10 ]; do
- if [ ! -e /run/initramfs/loginit.pipe ]; then
- j=$(jobs)
- [ -z "$j" ] && break
- [ -z "${j##*Running*}" ] || break
- fi
- sleep 0.1
- i=$(($i+1))
- done
-
- if [ $i -eq 10 ]; then
- kill %1 >/dev/null 2>&1
- kill $(while read line;do echo $line;done</run/initramfs/loginit.pid)
- fi
-
- set -x
- rm -f /run/initramfs/loginit.pipe /run/initramfs/loginit.pid
-}
-
-emergency_shell()
-{
- local _ctty
- set +e
- if [ "$1" = "-n" ]; then
- _rdshell_name=$2
- shift 2
- else
- _rdshell_name=dracut
- fi
- echo ; echo
- warn $@
- source_hook emergency
- echo
- wait_for_loginit
- [ -e /run/initramfs/.die ] && exit 1
- if getargbool 1 rd.shell -y rdshell || getarg rd.break rdbreak; then
- echo "Dropping to debug shell."
- echo
- export PS1="$_rdshell_name:\${PWD}# "
- [ -e /.profile ] || >/.profile
- _ctty=/dev/console
- if type setsid >/dev/null 2>&1; then
- _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
- [ -c "$_ctty" ] || _ctty=/dev/tty1
- setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
- else
- sh -i -l 0<$_ctty 1>$_ctty 2>&1
- fi
- else
- warn "Boot has failed. To debug this issue add \"rdshell\" to the kernel command line."
- # cause a kernel panic
- exit 1
- fi
-}
-
trap "emergency_shell Signal caught!" 0
OLDPATH=$PATH
PATH=/usr/sbin:/usr/bin:/sbin:/bin
diff --git a/modules.d/99shutdown/shutdown b/modules.d/99shutdown/shutdown
index 21bb37f..8a44e8f 100755
--- a/modules.d/99shutdown/shutdown
+++ b/modules.d/99shutdown/shutdown
@@ -7,44 +7,15 @@
# Copyright 2011, Red Hat, Inc.
# Harald Hoyer <harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
-#!/bin/sh
. /lib/dracut-lib.sh
export TERM=linux
+# override standard function
emergency_shell()
{
- local _ctty
- set +e
- if [ "$1" = "-n" ]; then
- _rdshell_name=$2
- shift 2
- else
- _rdshell_name=dracut
- fi
- echo ; echo
- warn $@
- source_hook shutdown-emergency
- echo
- if getargbool 1 rd.shell -y rdshell || getarg rd.break rdbreak; then
- [ -x /lib/udev/console_init ] && /lib/udev/console_init /dev/console
- echo "Dropping to debug shell."
- echo
- export PS1="$_rdshell_name:\${PWD}# "
- [ -e /.profile ] || >/.profile
- _ctty=/dev/console
- if type setsid >/dev/null 2>&1; then
- _ctty="$(getarg rd.ctty=)" && _ctty="/dev/${_ctty##*/}"
- [ -c "$_ctty" ] || _ctty=/dev/tty1
- setsid sh -i -l 0<$_ctty 1>$_ctty 2>&1
- else
- sh -i -l 0<$_ctty 1>$_ctty 2>&1
- fi
- else
- exec /lib/systemd/systemd-shutdown "$@"
- warn "Shutdown has failed. To debug this issue add \"rdshell\" to the kernel command line."
- # cause a kernel panic
- exit 1
- fi
+ emergency_shell_core s \
+ "Shutdown has failed. To debug this issue add \"rd.shell\" to the kernel command line." \
+ "$@"
}
trap "emergency_shell Signal caught!" 0
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 10/10] optional shell job control - add documentation
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (8 preceding siblings ...)
2011-10-18 18:33 ` [PATCH 09/10] prepare common emergency_shell function (1), shell job control fixups (2) Michal Soltys
@ 2011-10-18 18:33 ` Michal Soltys
2011-10-21 21:19 ` [PATCH 11/10] dracut: sewing fixup Michal Soltys
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-18 18:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
dracut.8.xml | 9 +++++++++
dracut.kernel.7.xml | 14 ++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/dracut.8.xml b/dracut.8.xml
index d4689ee..8947780 100644
--- a/dracut.8.xml
+++ b/dracut.8.xml
@@ -297,6 +297,15 @@ include in the generic initramfs. This parameter can be specified multiple times
</varlistentry>
<varlistentry>
<term>
+ <option>--ctty</option>
+ </term>
+ <listitem>
+ <para>if possible, try to spawn an emergency shell on a terminal
+ with job control</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
<option>-h</option>
</term>
<term>
diff --git a/dracut.kernel.7.xml b/dracut.kernel.7.xml
index 0571031..08f1838 100644
--- a/dracut.kernel.7.xml
+++ b/dracut.kernel.7.xml
@@ -109,6 +109,20 @@ This parameter can be specified multiple times.</para>
<para>force loading kernel module <drivername> after all automatic loading modules have been loaded. This parameter can be specified multiple times.</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <envar>rd.ctty=<replaceable><terminal></replaceable></envar>
+ </term>
+ <listitem>
+ <para>
+ if the dracut image was generated with --ctty option, try to
+ spawn an emergency shell on the specified terminal; if
+ <envar>rd.ctty</envar> is specified without a value or not
+ provided at all, the default is /dev/tty1. The '/dev' prefix
+ can be omitted.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect2>
<refsect2 id="dracut-kernel-debug">
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 11/10] dracut: sewing fixup
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (9 preceding siblings ...)
2011-10-18 18:33 ` [PATCH 10/10] optional shell job control - add documentation Michal Soltys
@ 2011-10-21 21:19 ` Michal Soltys
2011-10-24 20:11 ` [PATCH 00/10] All recent patches linearly Michal Soltys
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-21 21:19 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
We accidentally tried to make upwards symlinks when directories existed.
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
dracut | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/dracut b/dracut
index 4cfcab8..72af2c0 100755
--- a/dracut
+++ b/dracut
@@ -543,7 +543,9 @@ else
fi
# initial sewing pass
for d in "${initdir}${imgdir}"/*; do
- ln -sfn "${imgdir#/}/${d##*/}" "${initdir}/${d##*/}"
+ if [[ ! -e "${initdir}/${d##*/}" ]]; then
+ ln -sfn "${imgdir#/}/${d##*/}" "${initdir}/${d##*/}"
+ fi
done
# check all our modules to see if they should be sourced.
@@ -684,7 +686,7 @@ for d in "${initdir}${imgdir}"/*; do
dfatal "dracut: symlink mismatch ${d##*/} -/-> ${d#${initdir}/}"
exit 1
fi
- else
+ elif [[ ! -e ${s} ]]; then
ln -sfn "${d#${initdir}/}" "${s}"
fi
done
--
1.7.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 00/10] All recent patches linearly
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (10 preceding siblings ...)
2011-10-21 21:19 ` [PATCH 11/10] dracut: sewing fixup Michal Soltys
@ 2011-10-24 20:11 ` Michal Soltys
2011-10-30 23:02 ` [PATCH] init: /dev/.initramfs symlink fixup Michal Soltys
2011-11-11 15:45 ` [PATCH 13/10] features: RUNDIR, imgdir, ... [update 2] Michal Soltys
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-24 20:11 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
Should I redo the set against latest HEAD ? There're few (trivial)
conflicts regarding first patch after latest upstream updates, and some
of the patches below were applied already. I have tiny one-liner patch
to add as well.
Everything is well tested at this point, at least I haven't experienced
any misbehaviour - both regarding /run treatment or ctty functionality.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] init: /dev/.initramfs symlink fixup
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (11 preceding siblings ...)
2011-10-24 20:11 ` [PATCH 00/10] All recent patches linearly Michal Soltys
@ 2011-10-30 23:02 ` Michal Soltys
2011-11-11 15:45 ` [PATCH 13/10] features: RUNDIR, imgdir, ... [update 2] Michal Soltys
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-10-30 23:02 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
It's not related to $PREFIX being set or not (anymore).
Signed-off-by: Michal Soltys <soltys-R61QfzASbfY@public.gmane.org>
---
modules.d/99base/init | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/modules.d/99base/init b/modules.d/99base/init
index c109ae4..0ce8ed8 100755
--- a/modules.d/99base/init
+++ b/modules.d/99base/init
@@ -380,7 +380,7 @@ if [ -d "$NEWROOT/run" ]; then
else
NEWRUN=/dev/.run
mkdir -p -m 0755 "$NEWRUN"
- [ -n "$PREFIX" ] && ln -sfn .run/initramfs /dev/.initramfs
+ ln -sfn .run/initramfs /dev/.initramfs
# if initramfs's udev uses /run by default, but the host is
# still /run-less, we should copy udev's data to legacy
# /dev/.udev, so the necessary info is available for the host
--
1.7.7.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 13/10] features: RUNDIR, imgdir, ... [update 2]
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
` (12 preceding siblings ...)
2011-10-30 23:02 ` [PATCH] init: /dev/.initramfs symlink fixup Michal Soltys
@ 2011-11-11 15:45 ` Michal Soltys
13 siblings, 0 replies; 15+ messages in thread
From: Michal Soltys @ 2011-11-11 15:45 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
- don't use cp -t (due to busybox's cp)
- add intermediate link to image's tree, to simplify life in init;
this allows us to switch whole image tree with single 'ln' manipulation,
instead of going in loop through all /bin, /sbin, ... symlinks;
we employ that early (see the next point) and before /run move (to not
lose access to binaries)
- create $prefix (and $prefix_mnt) early, so everything is de-facto
started from /run/$prefix
- keep /tmp and /var/tmp inside image tree
- simplify det_lib_paths() - make it essentially the same as before
an earlier patch, but keep it as a separate function
- add a few comments and corner cases fixups
---
dracut | 31 ++++++++++--------
dracut-functions | 29 ++++++----------
modules.d/99base/init | 64 ++++++++++++++++++++++---------------
modules.d/99base/module-setup.sh | 2 +-
4 files changed, 67 insertions(+), 59 deletions(-)
diff --git a/dracut b/dracut
index 72af2c0..e26e0c3 100755
--- a/dracut
+++ b/dracut
@@ -502,7 +502,7 @@ readonly initdir=$(mktemp --tmpdir=/var/tmp/ -d -t initramfs.XXXXXX)
dfatal "mktemp failed."
exit 1
}
-readonly imgdir=/_img newroot=/sysroot
+readonly imgdir=/_img imglnk=/__img newroot=/sysroot
# clean up after ourselves no matter how we die.
trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || rm -rf "$initdir";exit $ret;' EXIT
@@ -517,34 +517,38 @@ export initdir dracutbasedir dracutmodules drivers \
add_drivers mdadmconf lvmconf filesystems \
use_fstab libdir usrlibdir fscks nofscks cttyhack \
stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
- debug imgdir prefix prefix_mnt newroot
+ debug imgdir imglnk prefix prefix_mnt newroot
# initial directory layout + host safe symlinks
if [[ $kernel_only != yes ]]; then
- for d in /{bin,sbin,etc,lib{,64},var,usr{,/{bin,sbin,lib{,64}}}}; do
+ # directories inside ${initdir}${imgdir}
+ for d in /{bin,sbin,etc,lib{64,},var{,/tmp},usr{,/{bin,sbin,lib{64,}}},tmp}; do
if [[ -h $d ]]; then inst_symlink $d
elif [[ -d $d ]]; then inst_dir $d; fi
done
+ # directories inside ${initdir}
mkdir -m 0755 -p \
- "${initdir}"/{dev,proc,sys,${newroot#/},root,run{,/{lock,initramfs}},tmp}
+ "${initdir}"/{dev,proc,sys,run{,/{lock,initramfs}},root,${newroot#/}}
# host safe symlinks (will be adjusted later), needed during inst*() calls
- ln -sfn "${initdir}"/tmp "${initdir}${imgdir}"/tmp
- ln -sfn "${initdir}"/tmp "${initdir}${imgdir}"/var/tmp
ln -sfn "${initdir}"/run "${initdir}${imgdir}"/run
ln -sfn "${initdir}"/run "${initdir}${imgdir}"/var/run
ln -sfn "${initdir}"/run/lock "${initdir}${imgdir}"/var/lock
else
- for d in /lib{,64}; do
+ for d in /lib{64,}; do
if [[ -h $d ]]; then inst_symlink $d
elif [[ -d $d ]]; then inst_dir $d; fi
done
fi
+
# initial sewing pass
+# go through intermediate symlink (${imglnk}) - this greatly simplifies our life
+# inside init
+ln -sfn "${imgdir#/}" "${initdir}${imglnk}"
for d in "${initdir}${imgdir}"/*; do
if [[ ! -e "${initdir}/${d##*/}" ]]; then
- ln -sfn "${imgdir#/}/${d##*/}" "${initdir}/${d##*/}"
+ ln -sfn "${imglnk#/}/${d##*/}" "${initdir}/${d##*/}"
fi
done
@@ -669,11 +673,10 @@ if strstr "$modules_loaded" " fips " && command -v prelink >/dev/null; then
fi
# final sewing pass
-# remove helper /run & /tmp links, set symlinks to match initramfs's root, link
+# remove helper /run link, set symlinks to match initramfs's root, link
# remaining directories (if any)
if [[ $kernel_only != yes ]]; then
- rm -f "${initdir}${imgdir}"/{run,tmp}
- ln -sfn /tmp "${initdir}${imgdir}"/var/tmp
+ rm -f "${initdir}${imgdir}"/run
ln -sfn /run "${initdir}${imgdir}"/var/run
ln -sfn /run/lock "${initdir}${imgdir}"/var/lock
fi
@@ -682,12 +685,12 @@ for d in "${initdir}${imgdir}"/*; do
if [[ -h ${s} ]]; then
# verify if everything is fine
t=$(readlink "${s}")
- if [[ $t != ${d#${initdir}/} ]]; then
- dfatal "dracut: symlink mismatch ${d##*/} -/-> ${d#${initdir}/}"
+ if [[ $t != ${imglnk#/}/${d##*/} ]]; then
+ dfatal "dracut: symlink mismatch ${d##*/} -/-> ${imglnk#/}/${d##*/}"
exit 1
fi
elif [[ ! -e ${s} ]]; then
- ln -sfn "${d#${initdir}/}" "${s}"
+ ln -sfn "${imglnk#/}/${d##*/}" "${s}"
fi
done
diff --git a/dracut-functions b/dracut-functions
index 7b6aa5a..0298585 100755
--- a/dracut-functions
+++ b/dracut-functions
@@ -959,23 +959,16 @@ instmods() {
return $?
}
-# determine lib paths in specified prefix
-# if they point to the same, ignore the one that is a symlink
-# prefer lib64 over lib
+# determine lib paths in specified prefix ($1)
+# order of preference: lib64, lib, lib32
function det_lib_paths() {
- local _lib _d _d64
- _d=$(readlink -e "$1/lib")
- _d64=$(readlink -e "$1/lib64")
- if [[ $_d = $_d64 ]]; then
- [[ -h $1/lib ]] && unset _d
- [[ -h $1/lib64 ]] && unset _d64
- fi
- if [[ -n $_d64 ]]; then
- _lib=$1/lib64
- elif [[ -n $_d ]]; then
- _lib=$1/lib
- else
- return 1
- fi
- echo "$_lib"
+ local _lib
+
+ for _lib in "$1"/lib{64,}; do
+ if [[ -d $_lib ]]; then
+ echo "$_lib"
+ return 0
+ fi
+ done
+ return 1
}
diff --git a/modules.d/99base/init b/modules.d/99base/init
index 0397e36..00fcc27 100755
--- a/modules.d/99base/init
+++ b/modules.d/99base/init
@@ -81,20 +81,44 @@ mount $_fs $_opt tmpfs /dev/shm >/dev/null 2>&1
# Prepare proper tmpfs mount for /run:
# - /run is just a symlink to real staging area. This allows us to be
# independent from any mount place, with trivial symlink manipulation
-# - checking if /run is premounted, is pretty crazy in initramfs ...
-
+# - it handles both: if /run is present with content and/or if it's mounted
_opt="-o mode=0755,nosuid,nodev,exec"; _fs="-t tmpfs"
RUNDIR=/_run
ismounted /run && { _opt="$_opt,remount"; unset _fs; }
-mkdir -m 0755 -p $RUNDIR
+mkdir -m 0755 -p "$RUNDIR"
# move + remount or mount
-[ -z "$_fs" ] && mount --move /run $RUNDIR
-mount $_fs $_opt tmpfs $RUNDIR >/dev/null 2>&1
+[ -z "$_fs" ] && mount --move /run "$RUNDIR"
+mount $_fs $_opt tmpfs "$RUNDIR" >/dev/null 2>&1
# copy if mount
-[ -z "$_fs" ] || { cd /run; cp -a -t $RUNDIR .; cd /; }
+[ -n "$_fs" ] && { cd /run; cp -a . "$RUNDIR"; cd /; }
# set symlink
rm -rf /run
-ln -sfn ${RUNDIR#/} /run
+ln -sfn "${RUNDIR#/}" /run
+
+# Prepare (if applicable) image tree inside $PREFIX under /run; we do it
+# here, as we want to run everything de-facto from /run/$PREFIX/...
+if [ -n "$PREFIX" ]; then
+ mkdir -p -m 0755 "/run/.prefix"
+ cd "$IMGLNK"
+ cp -a . "/run/.prefix"
+ if [ -d "/run/$PREFIX" ]; then
+ cd "/run/$PREFIX"; cp -a . "/run/.prefix"; cd /
+ umount "/run/$PREFIX" >/dev/null 2>&1
+ rm -rf "/run/$PREFIX"
+ fi
+ if [ -n "$PREFIX_MNT" ]; then
+ mkdir -p -m 0755 "/run/$PREFIX"
+ mount -t tmpfs -o mode=0755,nosuid,nodev,exec tmpfs "/run/$PREFIX"
+ cd "/run/.prefix"; cp -a . "/run/$PREFIX"; cd /
+ rm -rf "/run/.prefix"
+ else
+ _tgt="/run/$PREFIX"
+ mkdir -p -m 0755 "${_tgt%/*}"
+ mv "/run/.prefix" "$_tgt"
+ fi
+ # switch intermediary link to the image tree we actually want to use
+ ln -sfn "run/$PREFIX" "$IMGLNK"
+fi
UDEVVERSION=$(udevadm --version)
if [ $UDEVVERSION -gt 166 ]; then
@@ -374,7 +398,7 @@ else
fi
[ "$RD_DEBUG" = "yes" ] && set -x
-# /run move, udev adjustment (if applicable), prefix handling
+# /run move, udev adjustment (if applicable)
if [ -d "$NEWROOT/run" ]; then
NEWRUN="$NEWROOT/run"
else
@@ -388,30 +412,18 @@ else
if [ -d /run/udev/data -o -d /run/udev/db ]; then
mkdir -p -m 0755 /dev/.udev
cd /run/udev
- cp -a -t /dev/.udev .
+ cp -a . /dev/.udev
cd /
rm -rf /run/udev
fi
fi
-mount --move "$RUNDIR" "$NEWRUN"
+# if we earlier moved away from IMGDIR, go back to it - or we lose access to
+# binaries briefly
+[ -n "$PREFIX" ] && ln -sfn "${IMGDIR#/}" "$IMGLNK"
ln -sfn "${NEWRUN#/}" /run
-
-if [ -n "$PREFIX" ]; then
- if [ -d "$NEWRUN/$PREFIX" ]; then
- [ -n "$PREFIX_MNT" ] &&
- warn "'$NEWRUN/$PREFIX' already exists, dracut files will be copied directly to this directory"
- unset PREFIX_MNT
- else
- mkdir -p -m 0755 "$NEWRUN/$PREFIX"
- fi
- if [ -n "$PREFIX_MNT" ]; then
- mount -t tmpfs -o mode=0755,nosuid,nodev,exec tmpfs "$NEWRUN/$PREFIX"
- fi
- cd "$IMGDIR"
- cp -a -t "$NEWRUN/$PREFIX" .
- cd /
-fi
+mount --move "$RUNDIR" "$NEWRUN"
+[ -n "$PREFIX" ] && ln -sfn "${NEWRUN#/}/$PREFIX" "$IMGLNK"
wait_for_loginit
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
index 4c64bca..2a59699 100755
--- a/modules.d/99base/module-setup.sh
+++ b/modules.d/99base/module-setup.sh
@@ -41,7 +41,7 @@ install() {
[ -x /lib/systemd/systemd-timestamp ] && inst /lib/systemd/systemd-timestamp
# export certain settings to init
- for _d in newroot imgdir prefix prefix_mnt; do
+ for _d in newroot imgdir imglnk prefix prefix_mnt; do
_x=$(echo $_d | tr "a-z" "A-Z")
[ -n "$_d" ] && echo "${_x}=${!_d}" >>${initdir}/etc/dracut-init.conf
done
--
1.7.7.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
end of thread, other threads:[~2011-11-11 15:45 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-18 18:33 [PATCH 00/10] All recent patches linearly Michal Soltys
[not found] ` <1318962806-24000-1-git-send-email-soltys-R61QfzASbfY@public.gmane.org>
2011-10-18 18:33 ` [PATCH 01/10] features: RUNDIR, imgdir, prefix, prefix_mnt and related changes Michal Soltys
2011-10-18 18:33 ` [PATCH 02/10] features: RUNDIR, imgdir, ... [update 1] Michal Soltys
2011-10-18 18:33 ` [PATCH 03/10] minor changes Michal Soltys
2011-10-18 18:33 ` [PATCH 04/10] dracut: remove duplicate options Michal Soltys
2011-10-18 18:33 ` [PATCH 05/10] dracut: detect lib paths more carefully Michal Soltys
2011-10-18 18:33 ` [PATCH 06/10] check root candidates " Michal Soltys
2011-10-18 18:33 ` [PATCH 07/10] introduce optional job control Michal Soltys
2011-10-18 18:33 ` [PATCH 08/10] job control fixup Michal Soltys
2011-10-18 18:33 ` [PATCH 09/10] prepare common emergency_shell function (1), shell job control fixups (2) Michal Soltys
2011-10-18 18:33 ` [PATCH 10/10] optional shell job control - add documentation Michal Soltys
2011-10-21 21:19 ` [PATCH 11/10] dracut: sewing fixup Michal Soltys
2011-10-24 20:11 ` [PATCH 00/10] All recent patches linearly Michal Soltys
2011-10-30 23:02 ` [PATCH] init: /dev/.initramfs symlink fixup Michal Soltys
2011-11-11 15:45 ` [PATCH 13/10] features: RUNDIR, imgdir, ... [update 2] Michal Soltys
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.