diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 903baf453..5ef767964 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -11,6 +11,42 @@ use File::Path; use Cwd qw(realpath); use xCAT::SvrUtils; +sub el_major_version { + my $version = shift; + + return if !defined($version); + + my ($os_family, $os_major) = xCAT::SvrUtils::parseosver($version); + return + if !defined($os_family) + || $os_family !~ /^(?:rhels?|rhelc|rhelhpc|centos(?:-stream)?|rocky|alma(?:linux)?|ol)$/; + + return $os_major if length($os_major); + return; +} + +sub rpm_installroot_command { + my ( $osver, $rootimg_dir, $non_interactive, $dnf_available ) = @_; + $non_interactive ||= ""; + $dnf_available = -x "/usr/bin/dnf" unless defined($dnf_available); + my $majorrel = el_major_version($osver); + my $pkgmgr = "yum"; + + # EL8 and newer are dnf-native. Keep yum as the fallback for legacy + # systems and minimal environments that still provide only yum. + if (defined($majorrel) && $majorrel > 7 && $dnf_available) { + $pkgmgr = "dnf"; + } + + my $cmd = "$pkgmgr $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* "; + if (defined($majorrel) && $majorrel > 7) { + $cmd .= "--releasever=" . $majorrel . " "; + $cmd .= "--setopt=module_platform_id=platform:el" . $majorrel . " "; + } + + return $cmd; +} + sub varsubinline{ my $line=shift; my $refvardict=shift; diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 9e3ba2409..a648e65d8 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -92,38 +92,6 @@ sub majversion { return $majorrel; } -sub el_major_version { - my $version = shift; - - if (defined($version) - && $version =~ /^(?:rhels?|centos|rocky|alma(?:linux)?|ol)\D*(\d+)/) - { - return $1; - } - - return; -} - -sub rpm_installroot_command { - my $non_interactive = shift || ""; - my $majorrel = el_major_version($osver); - my $pkgmgr = "yum"; - - # EL8 and newer are dnf-native. Keep yum as the fallback for legacy - # systems and minimal environments that still provide only yum. - if (defined($majorrel) && $majorrel > 7 && -x "/usr/bin/dnf") { - $pkgmgr = "dnf"; - } - - my $cmd = "$pkgmgr $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* "; - if (defined($majorrel) && $majorrel > 7) { - $cmd .= "--releasever=" . $majorrel . " "; - $cmd .= "--setopt=module_platform_id=platform:el" . $majorrel . " "; - } - - return $cmd; -} - sub mount_chroot { my $rootimage_dir = shift; @@ -406,7 +374,9 @@ if($onlyinitrd){ my $non_interactive; if (!$prompt) { $non_interactive = "-y"; } - my $yumcmd = rpm_installroot_command($non_interactive); + my $yumcmd = imgutils::rpm_installroot_command( + $osver, $rootimg_dir, $non_interactive + ); foreach (0 .. $repnum) { $yumcmd .= "--enablerepo=$osver-$arch-$_ "; @@ -572,7 +542,9 @@ if($onlyinitrd){ } close($yumconfig); $index--; - my $yumcmd_base = rpm_installroot_command($non_interactive); + my $yumcmd_base = imgutils::rpm_installroot_command( + $osver, $rootimg_dir, $non_interactive + ); #yum/rpm/zypper has defect on calculating diskspace usage when installing rpm on a NFS mounted installroot if (isNFSdir("$rootimg_dir")) {