|
|
18971c |
From b4ad021d34975f25f50024e3601354f75593837f Mon Sep 17 00:00:00 2001
|
|
|
18971c |
From: Harald Hoyer <harald@redhat.com>
|
|
|
18971c |
Date: Wed, 29 Jun 2016 11:25:12 +0200
|
|
|
18971c |
Subject: [PATCH] dracut: only use one tmpdir
|
|
|
18971c |
|
|
|
18971c |
also remove any partial written initramfs images
|
|
|
18971c |
---
|
|
|
18971c |
dracut-logger.sh | 3 +--
|
|
|
18971c |
dracut.sh | 66 +++++++++++++++++++++++++++++++++---------------
|
|
|
18971c |
2 files changed, 47 insertions(+), 22 deletions(-)
|
|
|
18971c |
|
|
|
18971c |
diff --git a/dracut-logger.sh b/dracut-logger.sh
|
|
|
18971c |
index ffa56167..53f74625 100755
|
|
|
18971c |
--- a/dracut-logger.sh
|
|
|
18971c |
+++ b/dracut-logger.sh
|
|
|
18971c |
@@ -150,8 +150,7 @@ dlog_init() {
|
|
|
18971c |
&& type -P systemd-cat &>/dev/null \
|
|
|
18971c |
&& systemctl --quiet is-active systemd-journald.socket &>/dev/null \
|
|
|
18971c |
&& { echo "dracut-$DRACUT_VERSION" | systemd-cat -t 'dracut' &>/dev/null; } ; then
|
|
|
18971c |
- readonly _dlogdir="$(mktemp --tmpdir="$TMPDIR/" -d -t dracut-log.XXXXXX)"
|
|
|
18971c |
- readonly _systemdcatfile="$_dlogdir/systemd-cat"
|
|
|
18971c |
+ readonly _systemdcatfile="$DRACUT_TMPDIR/systemd-cat"
|
|
|
18971c |
mkfifo "$_systemdcatfile"
|
|
|
18971c |
readonly _dlogfd=15
|
|
|
18971c |
systemd-cat -t 'dracut' --level-prefix=true <"$_systemdcatfile" &
|
|
|
18971c |
diff --git a/dracut.sh b/dracut.sh
|
|
|
18971c |
index b85d42dd..78976792 100755
|
|
|
18971c |
--- a/dracut.sh
|
|
|
18971c |
+++ b/dracut.sh
|
|
|
18971c |
@@ -813,24 +813,25 @@ fi
|
|
|
18971c |
[[ $hostonly != "-h" ]] && unset hostonly
|
|
|
18971c |
|
|
|
18971c |
readonly TMPDIR="$tmpdir"
|
|
|
18971c |
-readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
|
|
|
18971c |
-[ -d "$initdir" ] || {
|
|
|
18971c |
- printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
|
|
|
18971c |
+readonly DRACUT_TMPDIR="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
|
|
|
18971c |
+[ -d "$DRACUT_TMPDIR" ] || {
|
|
|
18971c |
+ printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
|
|
|
18971c |
exit 1
|
|
|
18971c |
}
|
|
|
18971c |
|
|
|
18971c |
# clean up after ourselves no matter how we die.
|
|
|
18971c |
trap '
|
|
|
18971c |
ret=$?;
|
|
|
18971c |
- [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
|
|
|
18971c |
- [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
|
|
|
18971c |
- [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
|
|
|
18971c |
+ [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
|
|
|
18971c |
exit $ret;
|
|
|
18971c |
' EXIT
|
|
|
18971c |
|
|
|
18971c |
# clean up after ourselves no matter how we die.
|
|
|
18971c |
trap 'exit 1;' SIGINT
|
|
|
18971c |
|
|
|
18971c |
+readonly initdir="${DRACUT_TMPDIR}/initramfs"
|
|
|
18971c |
+mkdir "$initdir"
|
|
|
18971c |
+
|
|
|
18971c |
export DRACUT_KERNEL_LAZY="1"
|
|
|
18971c |
export DRACUT_RESOLVE_LAZY="1"
|
|
|
18971c |
|
|
|
18971c |
@@ -878,20 +879,18 @@ case "$(arch)" in
|
|
|
18971c |
i686|x86_64)
|
|
|
18971c |
;;
|
|
|
18971c |
*)
|
|
|
18971c |
- early_microcode=no
|
|
|
18971c |
- dinfo "Disabling early microcode for $(arch)"
|
|
|
18971c |
+ if [[ $early_microcode = yes ]]; then
|
|
|
18971c |
+ early_microcode=no
|
|
|
18971c |
+ dinfo "Disabling early microcode for $(arch)"
|
|
|
18971c |
+ fi
|
|
|
18971c |
;;
|
|
|
18971c |
esac
|
|
|
18971c |
|
|
|
18971c |
if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
|
|
|
18971c |
- readonly early_cpio_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)"
|
|
|
18971c |
- [ -d "$early_cpio_dir" ] || {
|
|
|
18971c |
- printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t early_cpio.XXXXXX failed." >&2
|
|
|
18971c |
- exit 1
|
|
|
18971c |
- }
|
|
|
18971c |
+ readonly early_cpio_dir="${DRACUT_TMPDIR}/earlycpio"
|
|
|
18971c |
+ mkdir "$early_cpio_dir"
|
|
|
18971c |
fi
|
|
|
18971c |
|
|
|
18971c |
-
|
|
|
18971c |
if (( ${#drivers_l[@]} )); then
|
|
|
18971c |
drivers=''
|
|
|
18971c |
while pop drivers_l val; do
|
|
|
18971c |
@@ -1485,7 +1484,7 @@ if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
|
|
|
18971c |
fi
|
|
|
18971c |
|
|
|
18971c |
if [[ $early_microcode = yes ]]; then
|
|
|
18971c |
- dinfo "*** Generating early-microcode cpio image ***"
|
|
|
18971c |
+ dinfo "*** Generating early-microcode cpio image contents ***"
|
|
|
18971c |
ucode_dir=(amd-ucode intel-ucode)
|
|
|
18971c |
ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
|
|
|
18971c |
_dest_dir="$early_cpio_dir/d/kernel/x86/microcode"
|
|
|
18971c |
@@ -1521,6 +1520,9 @@ if [[ $early_microcode = yes ]]; then
|
|
|
18971c |
fi
|
|
|
18971c |
done
|
|
|
18971c |
done
|
|
|
18971c |
+ if ! [[ $create_early_cpio = yes ]]; then
|
|
|
18971c |
+ dinfo "*** No early-microcode cpio image needed ***"
|
|
|
18971c |
+ fi
|
|
|
18971c |
fi
|
|
|
18971c |
|
|
|
18971c |
if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
|
|
|
18971c |
@@ -1546,23 +1548,47 @@ dinfo "*** Creating image file ***"
|
|
|
18971c |
[[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0"
|
|
|
18971c |
|
|
|
18971c |
if [[ $create_early_cpio = yes ]]; then
|
|
|
18971c |
+ dinfo "*** Creating microcode section ***"
|
|
|
18971c |
echo 1 > "$early_cpio_dir/d/early_cpio"
|
|
|
18971c |
# The microcode blob is _before_ the initramfs blob, not after
|
|
|
18971c |
- (cd "$early_cpio_dir/d"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet > $outfile)
|
|
|
18971c |
+ if ! (
|
|
|
18971c |
+ umask 077
|
|
|
18971c |
+ cd "$early_cpio_dir/d"
|
|
|
18971c |
+ find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
|
|
|
18971c |
+ ); then
|
|
|
18971c |
+ dfatal "dracut: creation of $outfile failed"
|
|
|
18971c |
+ exit 1
|
|
|
18971c |
+ else
|
|
|
18971c |
+ dinfo "*** Created microcode section ***"
|
|
|
18971c |
+ fi
|
|
|
18971c |
fi
|
|
|
18971c |
-if ! ( umask 077; cd "$initdir"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \
|
|
|
18971c |
- $compress >> "$outfile"; ); then
|
|
|
18971c |
+
|
|
|
18971c |
+if ! (
|
|
|
18971c |
+ umask 077
|
|
|
18971c |
+ cd "$initdir"
|
|
|
18971c |
+ find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \
|
|
|
18971c |
+ $compress >> "${DRACUT_TMPDIR}/initramfs.img";
|
|
|
18971c |
+ ); then
|
|
|
18971c |
dfatal "dracut: creation of $outfile failed"
|
|
|
18971c |
exit 1
|
|
|
18971c |
fi
|
|
|
18971c |
+
|
|
|
18971c |
dinfo "*** Creating image file done ***"
|
|
|
18971c |
|
|
|
18971c |
if (( maxloglvl >= 5 )); then
|
|
|
18971c |
if [[ $allowlocal ]]; then
|
|
|
18971c |
- "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
|
|
|
18971c |
+ "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img" | ddebug
|
|
|
18971c |
else
|
|
|
18971c |
- lsinitrd "$outfile"| ddebug
|
|
|
18971c |
+ lsinitrd "${DRACUT_TMPDIR}/initramfs.img" | ddebug
|
|
|
18971c |
fi
|
|
|
18971c |
fi
|
|
|
18971c |
|
|
|
18971c |
+if cp --reflink=auto "${DRACUT_TMPDIR}/initramfs.img" "$outfile" |& derror ; then
|
|
|
18971c |
+ dinfo "*** Creating initramfs image file '$outfile' done ***"
|
|
|
18971c |
+else
|
|
|
18971c |
+ rm -f -- "$outfile"
|
|
|
18971c |
+ dfatal "dracut: creation of $outfile failed"
|
|
|
18971c |
+ exit 1
|
|
|
18971c |
+fi
|
|
|
18971c |
+
|
|
|
18971c |
exit 0
|