mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
kernel-install: add "$KERNEL_INSTALL_STAGING_AREA" directory
The general approach of kernel-install was that each plugin would drop in some files into the entry directory. But this doesn't scale well, because if we have multiple initrd generators, or multiple initrds, each generator would need to recreate the logic to put the generated files in the right place. Also, effective cleanup is impossible if anything goes wrong on the way, so we could end up with unused files in $BOOT. So let's invert the process: plugins drop files into $KERNEL_INSTALL_STAGING_AREA, and at the end 90-loaderentry.install DTRT with those files. This allow new plugins like 50-mkosi-initrd.install to be significantly simpler.
This commit is contained in:
parent
680cec6b4d
commit
367165a406
@ -180,6 +180,10 @@
|
|||||||
This should be configured as <varname>initrd_generator=</varname> in <filename>install.conf</filename>.
|
This should be configured as <varname>initrd_generator=</varname> in <filename>install.conf</filename>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para><varname>KERNEL_INSTALL_STAGING_AREA=...</varname> is set for plugins to a path to a directory.
|
||||||
|
Plugins may drop files in that directory, and they will be installed as part of the loader entry, based
|
||||||
|
on the file name and extension.</para>
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>bls</term>
|
<term>bls</term>
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
COMMAND="$1"
|
COMMAND="$1"
|
||||||
KERNEL_VERSION="$2"
|
KERNEL_VERSION="$2"
|
||||||
ENTRY_DIR_ABS="$3"
|
ENTRY_DIR_ABS="$3"
|
||||||
@ -88,7 +90,8 @@ install -g root -o root -m 0644 "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" || {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shift "$INITRD_OPTIONS_SHIFT"
|
shift "$INITRD_OPTIONS_SHIFT"
|
||||||
for initrd; do
|
# All files listed as arguments, and staged files called "initrd*" are installed as initrds.
|
||||||
|
for initrd in "$@" "${KERNEL_INSTALL_STAGING_AREA}"/initrd*; do
|
||||||
[ -f "$initrd" ] || {
|
[ -f "$initrd" ] || {
|
||||||
echo "Error: initrd '$initrd' not a file." >&2
|
echo "Error: initrd '$initrd' not a file." >&2
|
||||||
exit 1
|
exit 1
|
||||||
@ -114,11 +117,15 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
|
|||||||
echo "machine-id $MACHINE_ID"
|
echo "machine-id $MACHINE_ID"
|
||||||
echo "options $BOOT_OPTIONS"
|
echo "options $BOOT_OPTIONS"
|
||||||
echo "linux $ENTRY_DIR/linux"
|
echo "linux $ENTRY_DIR/linux"
|
||||||
for initrd; do
|
|
||||||
|
have_initrd=
|
||||||
|
for initrd in "${@}" "${KERNEL_INSTALL_STAGING_AREA}"/initrd*; do
|
||||||
echo "initrd $ENTRY_DIR/${initrd##*/}"
|
echo "initrd $ENTRY_DIR/${initrd##*/}"
|
||||||
|
have_initrd=yes
|
||||||
done
|
done
|
||||||
|
|
||||||
# Try "initrd", generated by dracut in its kernel-install hook, if no initrds were supplied
|
# Try "initrd", generated by dracut in its kernel-install hook, if no initrds were supplied
|
||||||
[ $# -eq 0 ] && [ -f "$ENTRY_DIR_ABS/initrd" ] && echo "initrd $ENTRY_DIR/initrd"
|
[ -z "$have_initrd" ] && [ -f "$ENTRY_DIR_ABS/initrd" ] && echo "initrd $ENTRY_DIR/initrd"
|
||||||
:
|
:
|
||||||
} >"$LOADER_ENTRY" || {
|
} >"$LOADER_ENTRY" || {
|
||||||
echo "Error: could not create loader entry '$LOADER_ENTRY'." >&2
|
echo "Error: could not create loader entry '$LOADER_ENTRY'." >&2
|
||||||
|
@ -128,10 +128,20 @@ fi
|
|||||||
|
|
||||||
ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
|
ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
|
||||||
|
|
||||||
|
# Provide a directory where to store generated initrds
|
||||||
|
cleanup() {
|
||||||
|
[ -n "$KERNEL_INSTALL_STAGING_AREA" ] && rm -rf "$KERNEL_INSTALL_STAGING_AREA"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
KERNEL_INSTALL_STAGING_AREA="$(mktemp -d -t -p /tmp kernel-install.staging.XXXXXXX)"
|
||||||
|
|
||||||
export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID"
|
export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID"
|
||||||
export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT"
|
export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT"
|
||||||
export KERNEL_INSTALL_LAYOUT="$layout"
|
export KERNEL_INSTALL_LAYOUT="$layout"
|
||||||
export KERNEL_INSTALL_INITRD_GENERATOR="$initrd_generator"
|
export KERNEL_INSTALL_INITRD_GENERATOR="$initrd_generator"
|
||||||
|
export KERNEL_INSTALL_STAGING_AREA
|
||||||
|
|
||||||
[ "$layout" = "bls" ]
|
[ "$layout" = "bls" ]
|
||||||
MAKE_ENTRY_DIR_ABS=$?
|
MAKE_ENTRY_DIR_ABS=$?
|
||||||
|
Loading…
Reference in New Issue
Block a user