2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-21 01:42:15 +00:00

fix(genimage): publish the EL kernel and ramdisks together

The Red Hat-family genimage staged and published the boot files only
for openEuler. For the other releases, it copied the kernel into the
image directory before it built the initial ramdisks, and it ignored a
failed kernel copy and a failed move of a ramdisk. When dracut failed,
the new kernel stayed next to the ramdisks of the earlier build. On
images without dracut, a failed cpio replaced the ramdisks with empty
archives.

genimage now builds the kernel and both ramdisks in a temporary
directory inside the image directory for every release, and publishes
them with publish_staged_boot_files after both ramdisks are built. It
stops when the kernel copy, dracut, the move of a ramdisk or any command
of the cpio pipeline fails. openEuler keeps its single stateless
ramdisk.
This commit is contained in:
Vinícius Ferrão
2026-11-06 14:54:46 -03:00
parent 1f6f56e559
commit 876ff7bfe0
2 changed files with 17 additions and 48 deletions
@@ -7,7 +7,7 @@ use strict;
use warnings "all";
use File::Basename;
use File::Copy qw(move);
use File::Copy ();
use File::Find;
use File::Path;
use Cwd qw(realpath);
@@ -151,13 +151,6 @@ sub pack_initrd {
return 1;
}
sub publish_boot_files {
my ($native_bootdir, $destdir, $initrd, $mode) = @_;
move($initrd, "$native_bootdir/initrd-$mode.gz")
or die("Error: failed to move the initial ramdisk for $mode: $!\n");
return publish_staged_boot_files($native_bootdir, $destdir, $mode);
}
# nodeset copies the kernel and the initial ramdisks as one set, so a failure puts back every file already replaced.
sub publish_staged_boot_files {
my ($native_bootdir, $destdir, @modes) = @_;
+16 -40
View File
@@ -72,11 +72,11 @@ my $lock;
my $envar;
my $gpgcheck;
my $native_bootdir;
my $stateless_uftp_receiver;
sub xdie {
unlink("$rootimg_dir/tmp/initrd.$$.gz")
if $rootimg_dir && defined(imgutils::openeuler_release_version($osver));
unlink("$rootimg_dir/tmp/initrd.$$.gz") if $rootimg_dir;
system("rm -rf /tmp/xcatinitrd.$$");
umount_chroot($rootimg_dir);
die @_;
@@ -719,26 +719,9 @@ chomp($kernelver);
#$updates{'kernelver'} = $kernelver if ($tempfile);
# copy the kernel to $destdir
my $kernel_output = "$destdir/kernel";
if (defined(imgutils::openeuler_release_version($osver))) {
$native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1);
$kernel_output = "$native_bootdir/kernel";
}
my $kernel_copy;
if (-e "$rootimg_dir/boot/vmlinux-$kernelver") {
$kernel_copy = cp("$rootimg_dir/boot/vmlinux-$kernelver", $kernel_output);
} elsif (-e "$rootimg_dir/boot/vmlinuz-$kernelver") {
$kernel_copy = cp("$rootimg_dir/boot/vmlinuz-$kernelver", $kernel_output);
} elsif (-e "$rootimg_dir/boot/image-$kernelver") {
$kernel_copy = cp("$rootimg_dir/boot/image-$kernelver", $kernel_output);
} elsif (-e "$rootimg_dir/lib/modules/$kernelver/vmlinuz") {
$kernel_copy = cp("$rootimg_dir/lib/modules/$kernelver/vmlinuz", $kernel_output);
} else {
xdie("couldn't find the kernel file matched $kernelver in $rootimg_dir/boot");
}
xdie("Error: failed to copy the kernel to $kernel_output: $!\n")
if $native_bootdir && !$kernel_copy;
# The kernel and the initial ramdisks wait here until genimage publishes them together.
$native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1);
eval { imgutils::copy_kernel($rootimg_dir, $kernelver, $native_bootdir) } or xdie($@);
# Load driver update disk, and copy them to the root image
my @dd_drivers = &load_dd();
@@ -818,7 +801,7 @@ if ((-d "$rootimg_dir/usr/share/dracut") or (-d "$rootimg_dir/usr/lib/dracut"))
print "Enter the dracut mode. Dracut version: $dracutver. Dracut directory: $dracutdir.\n";
}
xdie("Error: failed to generate the initial ramdisk: native image has no dracut installation\n")
if $native_bootdir && !$dracutmode;
if !$dracutmode && defined(imgutils::openeuler_release_version($osver));
imgutils::disable_vendor_repositories($rootimg_dir);
imgutils::skip_kdump_without_dump_memory($rootimg_dir);
@@ -1014,6 +997,12 @@ if ($dracutmode) {
mkinitrd("statelite");
mkinitrd("stateless");
}
my @initrd_modes = defined(imgutils::openeuler_release_version($osver)) ? ('stateless') : ('statelite', 'stateless');
eval { imgutils::publish_staged_boot_files($native_bootdir, $destdir, @initrd_modes) } or xdie($@);
if ($dracutmode) {
mark_rootimg_check('stateless');
mark_uftp_receiver('stateless', $stateless_uftp_receiver);
}
sub getlibs {
my $file = shift;
@@ -1305,22 +1294,10 @@ sub mkinitrd_dracut {
or xdie("Error: failed to generate the initial ramdisk for $mode.\n");
umount_chroot($rootimg_dir);
eval { imgutils::check_uftp_initrd($rootimg_dir, "/tmp/initrd.$$.gz", $mode) } or xdie($@) if $uftp_receiver;
if ($native_bootdir) {
eval {
imgutils::publish_boot_files($native_bootdir, $destdir,
"$rootimg_dir/tmp/initrd.$$.gz", $mode);
} or xdie($@);
print "the initial ramdisk for $mode is generated successfully.\n";
mark_rootimg_check($mode);
mark_uftp_receiver($mode, $uftp_receiver);
return;
}
move("$rootimg_dir/tmp/initrd.$$.gz", "$native_bootdir/initrd-$mode.gz")
or xdie("Error: failed to move the initial ramdisk for $mode: $!\n");
print "the initial ramdisk for $mode is generated successfully.\n";
print("Move $rootimg_dir/tmp/initrd.$$.gz -> $destdir/initrd-$mode.gz\n");
if (move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz")) {
mark_rootimg_check($mode);
mark_uftp_receiver($mode, $uftp_receiver);
}
$stateless_uftp_receiver = $uftp_receiver if $mode eq 'stateless';
}
# nodeset warns unless this marker says that the stateless initial ramdisk checks the root image checksum.
@@ -2058,8 +2035,7 @@ EOMS
system("mkdir -p /tmp/xcatinitrd.$$/var/run/netreport");
#copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd-$mode.gz");
system("rm -rf /tmp/xcatinitrd.$$");
eval { imgutils::pack_initrd("/tmp/xcatinitrd.$$", "$native_bootdir/initrd-$mode.gz", 'gzip', $mode) } or xdie($@);
}