Add --entry-type=type1|type2 option to kernel-install.
Both kernel-core and kernel-uki-virt call kernel-install upon removal. Need an additional argument to avoid complete removal for both traditional kernel and UKI. Signed-off-by: Li Tian <litian@redhat.com>
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
33a5cc768c
commit
b6d4997683
@@ -33,6 +33,11 @@ case "$COMMAND" in
|
||||
exec depmod -a "$KERNEL_VERSION"
|
||||
;;
|
||||
remove)
|
||||
[ "$KERNEL_INSTALL_BOOT_ENTRY_TYPE" = "type2" ] || \
|
||||
[ "$KERNEL_INSTALL_BOOT_ENTRY_TYPE" = "type1" ] && \
|
||||
[ -d "/lib/modules/$KERNEL_VERSION/kernel" ] && \
|
||||
echo "Multiple entry types exist, not removing modules.dep or associated files." && \
|
||||
exit 0
|
||||
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
|
||||
echo "Removing /lib/modules/${KERNEL_VERSION}/modules.dep and associated files"
|
||||
exec rm -f \
|
||||
|
||||
@@ -49,6 +49,11 @@ LOADER_ENTRY="$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION.conf"
|
||||
|
||||
case "$COMMAND" in
|
||||
remove)
|
||||
if [ -f "/lib/modules/$KERNEL_VERSION/vmlinuz" ] && [ "$KERNEL_INSTALL_BOOT_ENTRY_TYPE" = "type2" ]; then
|
||||
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
|
||||
echo "BOOT_ENTRY_TYPE=type2, not removing loader entries."
|
||||
exit 0
|
||||
fi
|
||||
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
|
||||
echo "Removing ${LOADER_ENTRY%.conf}*.conf"
|
||||
exec rm -f \
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "boot-entry.h"
|
||||
#include "bootspec.h"
|
||||
#include "build.h"
|
||||
#include "chase.h"
|
||||
#include "conf-files.h"
|
||||
@@ -88,6 +89,7 @@ typedef struct Context {
|
||||
Action action;
|
||||
sd_id128_t machine_id;
|
||||
bool machine_id_is_random;
|
||||
BootEntryType entry_type;
|
||||
KernelImageType kernel_image_type;
|
||||
Layout layout;
|
||||
char *layout_other;
|
||||
@@ -427,6 +429,20 @@ static int context_set_initrds(Context *c, char* const* strv) {
|
||||
return context_set_path_strv(c, strv, "command line", "initrds", &c->initrds);
|
||||
}
|
||||
|
||||
static int context_set_entry_type(Context *c, const char *s) {
|
||||
assert(c);
|
||||
BootEntryType e;
|
||||
if (isempty(s) || streq(s, "all")) {
|
||||
c->entry_type = _BOOT_ENTRY_TYPE_INVALID;
|
||||
return 0;
|
||||
}
|
||||
e = boot_entry_type_from_string(s);
|
||||
if (e < 0)
|
||||
return log_error_errno(e, "Invalid entry type: %s", s);
|
||||
c->entry_type = e;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int context_load_environment(Context *c) {
|
||||
assert(c);
|
||||
|
||||
@@ -983,6 +999,7 @@ static int context_build_environment(Context *c) {
|
||||
"KERNEL_INSTALL_LAYOUT", context_get_layout(c),
|
||||
"KERNEL_INSTALL_INITRD_GENERATOR", strempty(c->initrd_generator),
|
||||
"KERNEL_INSTALL_UKI_GENERATOR", strempty(c->uki_generator),
|
||||
"KERNEL_INSTALL_BOOT_ENTRY_TYPE", boot_entry_type_to_string(c->entry_type),
|
||||
"KERNEL_INSTALL_STAGING_AREA", c->staging_area);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build environment variables for plugins: %m");
|
||||
@@ -1487,6 +1504,9 @@ static int help(void) {
|
||||
" --root=PATH Operate on an alternate filesystem root\n"
|
||||
" --image=PATH Operate on disk image as filesystem root\n"
|
||||
" --image-policy=POLICY Specify disk image dissection policy\n"
|
||||
" --entry-type=type1|type2|all\n"
|
||||
" Operate only on the specified bootloader\n"
|
||||
" entry type\n"
|
||||
"\n"
|
||||
"This program may also be invoked as 'installkernel':\n"
|
||||
" installkernel [OPTIONS...] VERSION VMLINUZ [MAP] [INSTALLATION-DIR]\n"
|
||||
@@ -1516,6 +1536,7 @@ static int parse_argv(int argc, char *argv[], Context *c) {
|
||||
ARG_ROOT,
|
||||
ARG_IMAGE,
|
||||
ARG_IMAGE_POLICY,
|
||||
ARG_BOOT_ENTRY_TYPE,
|
||||
};
|
||||
static const struct option options[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
@@ -1531,6 +1552,7 @@ static int parse_argv(int argc, char *argv[], Context *c) {
|
||||
{ "image", required_argument, NULL, ARG_IMAGE },
|
||||
{ "image-policy", required_argument, NULL, ARG_IMAGE_POLICY },
|
||||
{ "no-legend", no_argument, NULL, ARG_NO_LEGEND },
|
||||
{ "entry-type", required_argument, NULL, ARG_BOOT_ENTRY_TYPE },
|
||||
{}
|
||||
};
|
||||
int t, r;
|
||||
@@ -1614,6 +1636,12 @@ static int parse_argv(int argc, char *argv[], Context *c) {
|
||||
return r;
|
||||
break;
|
||||
|
||||
case ARG_BOOT_ENTRY_TYPE:
|
||||
r = context_set_entry_type(c, optarg);
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
return -EINVAL;
|
||||
|
||||
@@ -1641,6 +1669,7 @@ static int run(int argc, char* argv[]) {
|
||||
.action = _ACTION_INVALID,
|
||||
.kernel_image_type = KERNEL_IMAGE_TYPE_UNKNOWN,
|
||||
.layout = _LAYOUT_INVALID,
|
||||
.entry_type = _BOOT_ENTRY_TYPE_INVALID,
|
||||
.entry_token_type = BOOT_ENTRY_TOKEN_AUTO,
|
||||
};
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
|
||||
@@ -97,6 +97,13 @@ test ! -e "$entry"
|
||||
test ! -e "$BOOT_ROOT/the-token/1.1.1/linux"
|
||||
test ! -e "$BOOT_ROOT/the-token/1.1.1/initrd"
|
||||
|
||||
# Test --entry-type options
|
||||
"$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd"
|
||||
"$kernel_install" -v remove 1.1.1 --entry-type=type1
|
||||
test ! -e "$entry"
|
||||
test ! -e "$BOOT_ROOT/the-token/1.1.1/linux"
|
||||
test ! -e "$BOOT_ROOT/the-token/1.1.1/initrd"
|
||||
|
||||
# Invoke kernel-install as installkernel
|
||||
ln -s --relative -v "$kernel_install" "$D/sources/installkernel"
|
||||
"$D/sources/installkernel" -v 1.1.2 "$D/sources/linux" System.map /somedirignored
|
||||
|
||||
Reference in New Issue
Block a user