sysinstall: Look for valid kernel image before installing
Instead of failing the installation after creating the partitions and doing almost the entire installation, and then failing if we don't have a kernel image. Look for it before we start doing modifications to the disk. This way we tell the user as soon as possible that we can't install the OS because of the missing kernel image.
This commit is contained in:
+23
-20
@@ -930,12 +930,16 @@ static int invoke_bootctl_link(
|
||||
sd_varlink **link,
|
||||
const char *root_dir,
|
||||
int root_fd,
|
||||
const char *kernel_filename,
|
||||
int kernel_fd,
|
||||
char **encrypted_credentials) {
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(root_dir);
|
||||
assert(root_fd >= 0);
|
||||
assert(kernel_filename);
|
||||
assert(kernel_fd >= 0);
|
||||
|
||||
r = connect_to_bootctl(link);
|
||||
if (r < 0)
|
||||
@@ -959,25 +963,6 @@ static int invoke_bootctl_link(
|
||||
if (root_fd_idx < 0)
|
||||
return log_error_errno(root_fd_idx, "Failed to submit root fd onto Varlink connection: %m");
|
||||
|
||||
_cleanup_free_ char *kernel_filename = NULL;
|
||||
_cleanup_close_ int kernel_fd = -EBADF;
|
||||
if (arg_kernel_image) {
|
||||
r = path_extract_filename(arg_kernel_image, &kernel_filename);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to extract filename from kernel path '%s': %m", arg_kernel_image);
|
||||
if (r == O_DIRECTORY)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EISDIR), "Kernel path '%s' refers to directory, must be regular file, refusing.", arg_kernel_image);
|
||||
|
||||
kernel_fd = xopenat_full(XAT_FDROOT, arg_kernel_image, O_RDONLY|O_CLOEXEC, XO_REGULAR, MODE_INVALID);
|
||||
if (kernel_fd < 0)
|
||||
return log_error_errno(kernel_fd, "Failed to open kernel image '%s': %m", arg_kernel_image);
|
||||
|
||||
} else {
|
||||
r = find_current_kernel(&kernel_filename, &kernel_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
int kernel_fd_idx = sd_varlink_push_dup_fd(*link, kernel_fd);
|
||||
if (kernel_fd_idx < 0)
|
||||
return log_error_errno(kernel_fd_idx, "Failed to submit kernel fd onto Varlink connection: %m");
|
||||
@@ -1259,6 +1244,8 @@ static void end_marker(void) {
|
||||
}
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_free_ char *kernel_filename = NULL;
|
||||
_cleanup_close_ int kernel_fd = -EBADF;
|
||||
int r;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
@@ -1341,6 +1328,22 @@ static int run(int argc, char *argv[]) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (arg_kernel_image) {
|
||||
r = path_extract_filename(arg_kernel_image, &kernel_filename);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to extract filename from kernel path '%s': %m", arg_kernel_image);
|
||||
if (r == O_DIRECTORY)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EISDIR), "Kernel path '%s' refers to directory, must be regular file, refusing.", arg_kernel_image);
|
||||
|
||||
kernel_fd = xopenat_full(XAT_FDROOT, arg_kernel_image, O_RDONLY|O_CLOEXEC, XO_REGULAR, MODE_INVALID);
|
||||
if (kernel_fd < 0)
|
||||
return log_error_errno(kernel_fd, "Failed to open kernel image '%s': %m", arg_kernel_image);
|
||||
} else {
|
||||
r = find_current_kernel(&kernel_filename, &kernel_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Verify we have everything we need */
|
||||
assert(arg_node);
|
||||
assert(arg_erase >= 0);
|
||||
@@ -1408,7 +1411,7 @@ static int run(int argc, char *argv[]) {
|
||||
emoji_enabled() ? glyph(GLYPH_COMPUTER_DISK) : "", emoji_enabled() ? " " : "");
|
||||
|
||||
_cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *bootctl_link = NULL;
|
||||
r = invoke_bootctl_link(&bootctl_link, root_dir, root_fd, encrypted_credentials);
|
||||
r = invoke_bootctl_link(&bootctl_link, root_dir, root_fd, kernel_filename, kernel_fd, encrypted_credentials);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user