diff --git a/xCAT-server/lib/perl/xCAT/SvrUtils.pm b/xCAT-server/lib/perl/xCAT/SvrUtils.pm index fe8ca1fdbb..7417f4c653 100644 --- a/xCAT-server/lib/perl/xCAT/SvrUtils.pm +++ b/xCAT-server/lib/perl/xCAT/SvrUtils.pm @@ -2613,8 +2613,14 @@ sub build_statelite_nfsroot_parameter { my ($additional_mount_options, $error) = _parse_statelite_nfsroot_options($additional_options); return (undef, $error) if $error; + # root=nfs: separates the server, the directory and the options with colons, so an IPv6 + # server has to be bracketed or the directory cannot be told from the address. dracut and + # mount.nfs both read the bracketed form. All three netboot plugins build it here. + my $authority = xCAT::NetworkUtils->format_uri_host($server); + return (undef, "Unable to render the NFS root server $server") unless defined($authority); + my @mount_options = ('ro', @{$additional_mount_options}); - return ('root=nfs:' . $server . ':' . $rootdir . ':' . join(',', @mount_options), undef); + return ('root=nfs:' . $authority . ':' . $rootdir . ':' . join(',', @mount_options), undef); } #-------------------------------------------------------------------------------------------------------- diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 47a7e92c49..8b547cf475 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -2243,7 +2243,8 @@ sub mksysclone $kcmdline .= "n8r"; } } - $kcmdline .= " XCAT=$xcatmaster:$xcatdport xcatd=$xcatmaster:$xcatdport SCRIPTNAME=$imagename"; + my $xcat_endpoint = xCAT::NetworkUtils::xcatd_cmdline_address($xcatmaster, $xcatdport); + $kcmdline .= " XCAT=$xcat_endpoint xcatd=$xcat_endpoint SCRIPTNAME=$imagename"; my $k; my $i; diff --git a/xCAT-server/lib/xcat/plugins/debian.pm b/xCAT-server/lib/xcat/plugins/debian.pm index a18aa0021f..4536619c47 100644 --- a/xCAT-server/lib/xcat/plugins/debian.pm +++ b/xCAT-server/lib/xcat/plugins/debian.pm @@ -1830,7 +1830,8 @@ sub mknetboot $kcmdline = "NFSROOT=$nfssrv:$nfsdir STATEMNT="; } } else { - $kcmdline = "imgurl=http://$imgsrv:$httpport/$rootimgdir/rootimg-statelite.gz STATEMNT="; + $kcmdline = "imgurl=http://" . xCAT::NetworkUtils->format_host_port($imgsrv, $httpport) + . "/$rootimgdir/rootimg-statelite.gz STATEMNT="; $kcmdline = $checksum_arg . $kcmdline; } @@ -1859,7 +1860,7 @@ sub mknetboot } $kcmdline .= $statemnt . " "; $kcmdline .= - "XCAT=$xcatmaster:$xcatdport "; + "XCAT=" . xCAT::NetworkUtils::xcatd_cmdline_address($xcatmaster, $xcatdport) . " "; $kcmdline .= "NODE=$node "; @@ -1887,10 +1888,10 @@ sub mknetboot else { $kcmdline = - "imgurl=http://$imgsrv:$httpport/$rootimgdir/$compressedrootimg "; + "imgurl=http://" . xCAT::NetworkUtils->format_host_port($imgsrv, $httpport) . "/$rootimgdir/$compressedrootimg "; $kcmdline .= $checksum_arg; $kcmdline .= $uftp_args; - $kcmdline .= "XCAT=$xcatmaster:$xcatdport "; + $kcmdline .= "XCAT=" . xCAT::NetworkUtils::xcatd_cmdline_address($xcatmaster, $xcatdport) . " "; } diff --git a/xCAT-server/lib/xcat/plugins/destiny.pm b/xCAT-server/lib/xcat/plugins/destiny.pm index c637a19cd6..12f2819dfd 100644 --- a/xCAT-server/lib/xcat/plugins/destiny.pm +++ b/xCAT-server/lib/xcat/plugins/destiny.pm @@ -701,7 +701,8 @@ sub setdestiny { if (-r "$tftpdir/xcat/nbk.$arch") { $bphash->{$_}->[0]->{kernel} = "xcat/nbk.$arch"; $bphash->{$_}->[0]->{initrd} = "xcat/nkfs.$arch.gz"; - $bphash->{$_}->[0]->{kcmdline} = $kcmdline . "xcatd=$master:$xcatdport"; + $bphash->{$_}->[0]->{kcmdline} = $kcmdline . "xcatd=" + . xCAT::NetworkUtils::xcatd_cmdline_address($master, $xcatdport); $callback->({ warning => ["No genesis.kernel.$arch file found. Defaulting to legacy nbk.$arch"]}); } else { # can not find genesis.kernel or nbk file $callback->({ error => ["Could not find genesis.kernel.$arch or legacy nbk.$arch files"], errorcode => [1] }); diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index a2b43a9af2..ba51533831 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -579,7 +579,7 @@ sub mknetboot $kcmdline .= $checksum_arg; $kcmdline .= $uftp_args; } - $kcmdline .= "XCAT=$xcatmaster:$xcatdport "; + $kcmdline .= "XCAT=" . xCAT::NetworkUtils::xcatd_cmdline_address($xcatmaster, $xcatdport) . " "; $kcmdline .= " XCATHTTPPORT=$httpport "; #if site.nodestatus="n", append "nonodestatus" to kcmdline @@ -1537,7 +1537,8 @@ sub mksysclone } } } - $kcmdline .= " XCAT=$xcatmaster:$xcatdport xcatd=$xcatmaster:$xcatdport SCRIPTNAME=$imagename"; + my $xcat_endpoint = xCAT::NetworkUtils::xcatd_cmdline_address($xcatmaster, $xcatdport); + $kcmdline .= " XCAT=$xcat_endpoint xcatd=$xcat_endpoint SCRIPTNAME=$imagename"; $bootparams->{$node}->[0]->{kernel} = "xcat/$genesis_kernel"; $bootparams->{$node}->[0]->{initrd} = "xcat/$genesis_initrd"; diff --git a/xCAT-test/unit/nfs_root_options.t b/xCAT-test/unit/nfs_root_options.t index 4e7df2762a..d2912c1809 100644 --- a/xCAT-test/unit/nfs_root_options.t +++ b/xCAT-test/unit/nfs_root_options.t @@ -159,6 +159,33 @@ for my $owner ([anaconda => 'rhels8'], [debian => 'ubuntu24.04'], [sles => 'sles } } +# root=nfs: separates the server, the directory and the options with colons, so an IPv6 server +# has to be bracketed. All three netboot plugins build the parameter here, so one test covers EL, +# Ubuntu and SUSE. +{ + my ($nfsroot, $error) = xCAT::SvrUtils->build_statelite_nfsroot_parameter( + '2001:db8::1', '/install/netboot/rhels10.0/x86_64/compute/rootimg', undef); + is($error, undef, 'an IPv6 NFS root server is accepted'); + is($nfsroot, 'root=nfs:[2001:db8::1]:/install/netboot/rhels10.0/x86_64/compute/rootimg:ro', + 'and is bracketed, so the directory can be told from the address'); + + ($nfsroot, $error) = xCAT::SvrUtils->build_statelite_nfsroot_parameter( + '192.0.2.1', '/install/netboot/rhels10.0/x86_64/compute/rootimg', undef); + is($nfsroot, 'root=nfs:192.0.2.1:/install/netboot/rhels10.0/x86_64/compute/rootimg:ro', + 'an IPv4 server is left as it was'); + + ($nfsroot, $error) = xCAT::SvrUtils->build_statelite_nfsroot_parameter( + 'mn.cluster', '/install/netboot/rhels10.0/x86_64/compute/rootimg', undef); + is($nfsroot, 'root=nfs:mn.cluster:/install/netboot/rhels10.0/x86_64/compute/rootimg:ro', + 'and so is a name, which the resolver in the image handles'); + + # The options still follow the directory, which is what the colons have to keep apart. + ($nfsroot, $error) = xCAT::SvrUtils->build_statelite_nfsroot_parameter( + '2001:db8::1', '/rootimg', 'nolock,vers=3'); + is($nfsroot, 'root=nfs:[2001:db8::1]:/rootimg:ro,nolock,vers=3', + 'the mount options are still readable after a bracketed address'); +} + done_testing(); sub set_row {