Browse Source

dracut: only use one tmpdir

also remove any partial written initramfs images
Harald Hoyer 9 years ago
parent
commit
b4ad021d34
  1. 3
      dracut-logger.sh
  2. 62
      dracut.sh

3
dracut-logger.sh

@ -150,8 +150,7 @@ dlog_init() {
&& type -P systemd-cat &>/dev/null \ && type -P systemd-cat &>/dev/null \
&& systemctl --quiet is-active systemd-journald.socket &>/dev/null \ && systemctl --quiet is-active systemd-journald.socket &>/dev/null \
&& { echo "dracut-$DRACUT_VERSION" | systemd-cat -t 'dracut' &>/dev/null; } ; then && { echo "dracut-$DRACUT_VERSION" | systemd-cat -t 'dracut' &>/dev/null; } ; then
readonly _dlogdir="$(mktemp --tmpdir="$TMPDIR/" -d -t dracut-log.XXXXXX)" readonly _systemdcatfile="$DRACUT_TMPDIR/systemd-cat"
readonly _systemdcatfile="$_dlogdir/systemd-cat"
mkfifo "$_systemdcatfile" mkfifo "$_systemdcatfile"
readonly _dlogfd=15 readonly _dlogfd=15
systemd-cat -t 'dracut' --level-prefix=true <"$_systemdcatfile" & systemd-cat -t 'dracut' --level-prefix=true <"$_systemdcatfile" &

62
dracut.sh

@ -813,24 +813,25 @@ fi
[[ $hostonly != "-h" ]] && unset hostonly [[ $hostonly != "-h" ]] && unset hostonly


readonly TMPDIR="$tmpdir" readonly TMPDIR="$tmpdir"
readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)" readonly DRACUT_TMPDIR="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
[ -d "$initdir" ] || { [ -d "$DRACUT_TMPDIR" ] || {
printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
exit 1 exit 1
} }


# clean up after ourselves no matter how we die. # clean up after ourselves no matter how we die.
trap ' trap '
ret=$?; ret=$?;
[[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; }; [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
[[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
[[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
exit $ret; exit $ret;
' EXIT ' EXIT


# clean up after ourselves no matter how we die. # clean up after ourselves no matter how we die.
trap 'exit 1;' SIGINT trap 'exit 1;' SIGINT


readonly initdir="${DRACUT_TMPDIR}/initramfs"
mkdir "$initdir"

export DRACUT_KERNEL_LAZY="1" export DRACUT_KERNEL_LAZY="1"
export DRACUT_RESOLVE_LAZY="1" export DRACUT_RESOLVE_LAZY="1"


@ -878,20 +879,18 @@ case "$(arch)" in
i686|x86_64) i686|x86_64)
;; ;;
*) *)
if [[ $early_microcode = yes ]]; then
early_microcode=no early_microcode=no
dinfo "Disabling early microcode for $(arch)" dinfo "Disabling early microcode for $(arch)"
fi
;; ;;
esac esac


if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
readonly early_cpio_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)" readonly early_cpio_dir="${DRACUT_TMPDIR}/earlycpio"
[ -d "$early_cpio_dir" ] || { mkdir "$early_cpio_dir"
printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t early_cpio.XXXXXX failed." >&2
exit 1
}
fi fi



if (( ${#drivers_l[@]} )); then if (( ${#drivers_l[@]} )); then
drivers='' drivers=''
while pop drivers_l val; do while pop drivers_l val; do
@ -1485,7 +1484,7 @@ if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
fi fi


if [[ $early_microcode = yes ]]; then if [[ $early_microcode = yes ]]; then
dinfo "*** Generating early-microcode cpio image ***" dinfo "*** Generating early-microcode cpio image contents ***"
ucode_dir=(amd-ucode intel-ucode) ucode_dir=(amd-ucode intel-ucode)
ucode_dest=(AuthenticAMD.bin GenuineIntel.bin) ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
_dest_dir="$early_cpio_dir/d/kernel/x86/microcode" _dest_dir="$early_cpio_dir/d/kernel/x86/microcode"
@ -1521,6 +1520,9 @@ if [[ $early_microcode = yes ]]; then
fi fi
done done
done done
if ! [[ $create_early_cpio = yes ]]; then
dinfo "*** No early-microcode cpio image needed ***"
fi
fi fi


if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
@ -1546,23 +1548,47 @@ dinfo "*** Creating image file ***"
[[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0" [[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0"


if [[ $create_early_cpio = yes ]]; then if [[ $create_early_cpio = yes ]]; then
dinfo "*** Creating microcode section ***"
echo 1 > "$early_cpio_dir/d/early_cpio" echo 1 > "$early_cpio_dir/d/early_cpio"
# The microcode blob is _before_ the initramfs blob, not after # The microcode blob is _before_ the initramfs blob, not after
(cd "$early_cpio_dir/d"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet > $outfile) if ! (
umask 077
cd "$early_cpio_dir/d"
find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
); then
dfatal "dracut: creation of $outfile failed"
exit 1
else
dinfo "*** Created microcode section ***"
fi fi
if ! ( umask 077; cd "$initdir"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \ fi
$compress >> "$outfile"; ); then
if ! (
umask 077
cd "$initdir"
find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \
$compress >> "${DRACUT_TMPDIR}/initramfs.img";
); then
dfatal "dracut: creation of $outfile failed" dfatal "dracut: creation of $outfile failed"
exit 1 exit 1
fi fi

dinfo "*** Creating image file done ***" dinfo "*** Creating image file done ***"


if (( maxloglvl >= 5 )); then if (( maxloglvl >= 5 )); then
if [[ $allowlocal ]]; then if [[ $allowlocal ]]; then
"$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img" | ddebug
else else
lsinitrd "$outfile"| ddebug lsinitrd "${DRACUT_TMPDIR}/initramfs.img" | ddebug
fi fi
fi fi


if cp --reflink=auto "${DRACUT_TMPDIR}/initramfs.img" "$outfile" |& derror ; then
dinfo "*** Creating initramfs image file '$outfile' done ***"
else
rm -f -- "$outfile"
dfatal "dracut: creation of $outfile failed"
exit 1
fi

exit 0 exit 0

Loading…
Cancel
Save