From 1f990063f5d37f7f8124bbb2ccae6258cb8e7b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:08:54 -0300 Subject: [PATCH 1/9] fix(ubuntu): apply partitionfile entries on Subiquity installs linuximage.partitionfile had no effect on Ubuntu 20.04 and later installs. The Subiquity pre-install script decodes each entry with base64decode, which uses read -n, and Subiquity runs the script under dash, which has no read -n. A layout file decoded to an empty storage config, which stops the install, and a layout script or disk script decoded to nothing. The d: and s:d: disk step also ran after the script had written the storage config, so a disk file could not change the disk that getinstdisk chose, which prefers a disk that already holds an operating system. Decode with coreutils base64, which the live system ships, and run the disk step before the storage config is written. The storage config uses the first disk the disk file names, because the layout uses one disk, and names it by its device node: Subiquity matches the path literally and finds no disk for a /dev/disk/by-id link. --- .../xcat/install/scripts/pre.ubuntu.subiquity | 67 +++---------------- 1 file changed, 11 insertions(+), 56 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity index 92707fb716..be79dbe1c7 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity +++ b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity @@ -139,63 +139,15 @@ chmod 755 /tmp/foo.sh /tmp/foo.sh >/tmp/foo.log 2>&1 & +# Subiquity runs this script under dash, which has no read -n, and its live system ships coreutils. base64decode() { - h0="0"; h1="1"; h2="2"; h3="3"; h4="4"; h5="5"; h6="6"; h7="7"; - h8="8"; h9="9"; h10="A"; h11="B"; h12="C"; h13="D"; h14="E"; h15="F"; - - while : - do - i=0 - while [ "$i" -lt 4 ] - do - read -n 1 c || return - - case "${c}" in - "A") d=0 ;; "B") d=1 ;; "C") d=2 ;; "D") d=3 ;; - "E") d=4 ;; "F") d=5 ;; "G") d=6 ;; "H") d=7 ;; - "I") d=8 ;; "J") d=9 ;; "K") d=10 ;; "L") d=11 ;; - "M") d=12 ;; "N") d=13 ;; "O") d=14 ;; "P") d=15 ;; - "Q") d=16 ;; "R") d=17 ;; "S") d=18 ;; "T") d=19 ;; - "U") d=20 ;; "V") d=21 ;; "W") d=22 ;; "X") d=23 ;; - "Y") d=24 ;; "Z") d=25 ;; "a") d=26 ;; "b") d=27 ;; - "c") d=28 ;; "d") d=29 ;; "e") d=30 ;; "f") d=31 ;; - "g") d=32 ;; "h") d=33 ;; "i") d=34 ;; "j") d=35 ;; - "k") d=36 ;; "l") d=37 ;; "m") d=38 ;; "n") d=39 ;; - "o") d=40 ;; "p") d=41 ;; "q") d=42 ;; "r") d=43 ;; - "s") d=44 ;; "t") d=45 ;; "u") d=46 ;; "v") d=47 ;; - "w") d=48 ;; "x") d=49 ;; "y") d=50 ;; "z") d=51 ;; - "0") d=52 ;; "1") d=53 ;; "2") d=54 ;; "3") d=55 ;; - "4") d=56 ;; "5") d=57 ;; "6") d=58 ;; "7") d=59 ;; - "8") d=60 ;; "9") d=61 ;; "+") d=62 ;; "/") d=63 ;; - "=") d=0 ;; - *) continue ;; - esac - - eval "a${i}=${c}" - eval "b${i}=${d}" - - i=$(( i + 1 )) - done - - o0=$(( ((b0 << 2) | (b1 >> 4)) & 0xff )) - o1=$(( ((b1 << 4) | (b2 >> 2)) & 0xff )) - o2=$(( ((b2 << 6) | b3) & 0xff )) - - [ "${a2}" == "=" ] && - eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 - ))}\"" && - return - [ "${a3}" == "=" ] && - eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 - ))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16 - ))}\"" && - return - eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 - ))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16 - ))}\\x\${h$(( o2 / 16 ))}\${h$(( o2 % 16 ))}\"" - done + base64 -d } + +# A d: or s:d: entry in linuximage.partitionfile replaces the disk getinstdisk chose. +#XCA_PARTMAN_DISK_SCRIPT# + # Note that the subiquity/curtin installation config is fairly picky about # the order in which things are specified - you have to specify all the # partitions before you can specify any filesystems, which means this is @@ -211,7 +163,10 @@ base64decode() # to this unwrapped file and must start at column 0. logger -t $log_label -p "info" "Generate partition file..." if [ -e /tmp/xcat.install_disk ]; then - INSTALL_DISK=$(cat /tmp/xcat.install_disk) + # The layout uses one disk, the first one the disk file names. + INSTALL_DISK=$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk) + # Subiquity matches the disk path literally, so resolve a link such as /dev/disk/by-id/. + INSTALL_DISK=$(readlink -f "$INSTALL_DISK" || echo "$INSTALL_DISK") else logger -t $log_label -p "err" "Failed to find partition file - getinstdisk must be run first" logger -t $log_label -p "err" "Using fallback default disk /dev/sda" @@ -385,8 +340,8 @@ storage: EOF fi +# A partitionfile layout or s: script must come after the default layout, which it replaces. #XCA_PARTMAN_RECIPE_SCRIPT# -#XCA_PARTMAN_DISK_SCRIPT# #XCA_PARTMAN_ADDITIONAL_CONFIG_SCRIPT# exit 0 From 94fb370ee4e30d50b45598fe7f009ed92f08e9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:08:55 -0300 Subject: [PATCH 2/9] test(ubuntu): cover partitionfile entries on Subiquity installs Render the node's pre-install script through the Template entry point and run its partitioning under dash. Without a partitionfile the storage config keeps the disk getinstdisk chose. A disk file puts its first disk there, resolved when it is a link, a disk script puts the disk it writes there, and a layout file or layout script replaces the default storage config. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/README.md | 7 +- .../native/ubuntu_subiquity_install_disk.t | 85 +++++++++++++++++++ 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 xCAT-test/native/ubuntu_subiquity_install_disk.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index a61196daa7..2fb86641ef 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -104,7 +104,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index e875373802..8d03a9db8b 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -422,13 +422,14 @@ prove xCAT-test/native/install_profile_riscv64.t \ xCAT-test/native/netboot_profile_riscv64.t \ xCAT-test/native/netboot_profile_postinstall.t \ xCAT-test/native/builddebs_riscv64.t \ - xCAT-test/native/ubuntu_subiquity_template.t + xCAT-test/native/ubuntu_subiquity_template.t \ + xCAT-test/native/ubuntu_subiquity_install_disk.t ``` The renderers need the system Perl with the xCAT dependencies, XML::Simple, DBD::SQLite, Capture::Tiny, and File::Slurper. The sandbox clears the environment -and does not mount perlbrew or local::lib directories. The Subiquity case also -needs /usr/bin/python3 with PyYAML; on EL8, install python36 for that path. +and does not mount perlbrew or local::lib directories. The Subiquity cases also +need /usr/bin/python3 with PyYAML; on EL8, install python36 for that path. The Debian case needs debhelper, devscripts, fakeroot, and reprepro, and skips on non-Debian hosts. Each case creates its own temporary files and database. The temporary directory must allow execution; set TMPDIR if /tmp is noexec. diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t new file mode 100644 index 0000000000..3a5c19480a --- /dev/null +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -0,0 +1,85 @@ +#!/usr/bin/env perl +# The storage config a Subiquity install receives for each linuximage.partitionfile form. +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use Test::More; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); +use XCAT::Test::Template qw(template_database render_template); + +plan skip_all => 'installer execution requires Linux namespaces' unless $^O eq 'linux'; +my $database = template_database(); +# Subiquity runs its early commands under dash. +my ($shell) = grep { -x $_ } qw(/usr/bin/dash /bin/dash /bin/sh); +my $sequence = 0; + +sub render_part { + my ($script, $pattern, @entries) = @_; + my $dir = "$database/case-" . ++$sequence; + make_path($dir); + my @partitionfile; + for my $n (0 .. $#entries) { + my ($prefix, $contents) = @{ $entries[$n] }; + write_text("$dir/partition-$n", $contents); + push @partitionfile, "$prefix$dir/partition-$n"; + } + render_template($database, repo_path("xCAT-server/share/xcat/install/scripts/$script"), "$dir/node.pre", + 'node', '', '', '', join(',', @partitionfile), {xcatmaster => '192.0.2.1'}); + my ($part) = read_text("$dir/node.pre") =~ $pattern; + return $part; +} + +# getinstdisk has already chosen /dev/sdz. +sub installer_root { + my $root = sandbox_root(); + make_path("$root/efi", "$root/by-id"); + write_text("$root/bin/logger", "#!/bin/sh\nexit 0\n"); + chmod 0755, "$root/bin/logger" or die $!; + write_text("$root/tmp/xcat.install_disk", "/dev/sdz\n"); + write_text("$root/nvme7n1", ''); + symlink('../../nvme7n1', "$root/by-id/nvme-link") or die $!; + return $root; +} + +sub storage_config { + my ($root) = @_; + return -e "$root/tmp/partitionfile" ? read_text("$root/tmp/partitionfile") : ''; +} + +# Written as PyYAML writes it, so it reads the same before and after the pre-script rewrites it. +my $layout = "storage:\n version: 1\n config:\n - id: custom-disk\n type: disk\n path: /dev/disk/by-id/custom\n"; +my $writer = "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n${layout}EOF\n"; +my $diskscript = "#!/bin/sh\necho /dev/disk/by-id/scripted >/tmp/xcat.install_disk\n"; + +# Each case: label, the partitionfile entries as [prefix, file contents], and the disk the storage +# config must name. +my @cases = ( + ['no partitionfile', [], '/dev/sdz'], + ['a disk file', [['d:', "/dev/disk/by-id/nvme-pinned /dev/sdb\n"]], '/dev/disk/by-id/nvme-pinned'], + ['a disk file naming a link', [['d:', "/dev/disk/by-id/nvme-link\n"]], '/dev/nvme7n1'], + ['a disk script', [['s:d:', $diskscript]], '/dev/disk/by-id/scripted'], + ['a layout file', [['', $layout]], '/dev/disk/by-id/custom'], + ['a layout script', [['s:', $writer]], '/dev/disk/by-id/custom'], +); +for my $case (@cases) { + my ($label, $entries, $expected) = @$case; + subtest $label => sub { + my $part = render_part('pre.ubuntu.subiquity', qr/(^base64decode\(\)\n.*^exit 0$)/ms, @$entries); + ok($part, 'the rendered script defines base64decode before the partitioning') or return; + my $root = installer_root(); + write_text("$root/part.sh", $part); + my ($rc, $output) = sandbox_run($root, {read_only => {"$root/efi" => '/sys/firmware/efi', + "$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1'}}, $shell, '/fixture/part.sh'); + is($rc, 0, "the partitioning runs under $shell") or diag($output); + my $config = storage_config($root); + my ($disk) = $config =~ /^\s+type: disk\n(?:\s+\S+:.*\n)*?\s+path: (\S+)$/m; + is($disk, $expected, "the storage config partitions $expected"); + is($config, $layout, 'the administrator layout replaces the default one') if $expected eq '/dev/disk/by-id/custom'; + }; +} +done_testing(); From e87c72c38d6ed9331fd1d08ac85536e79fcc70ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:42:40 -0300 Subject: [PATCH 3/9] fix(template): read each partitionfile entry with its own s: prefix linuximage.partitionfile takes a comma-separated list of layout, d: disk and c: configuration entries, any of them prefixed with s: for a script. The Ubuntu layout step chose between decoding a layout file and running a layout script by the s: prefix of the last entry in the whole list, so a layout file followed by an s:d: disk script was run as a script, and a layout script followed by a d: disk file was copied into the layout as text. The parser also kept a script flag set by an earlier entry of the same kind after a later entry replaced it. Give each kind the prefix of the entry that is used, the last one of that kind, and decode the Ubuntu layout by it. --- xCAT-server/lib/perl/xCAT/Template.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 747ba01e04..d332a91f5e 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -224,15 +224,16 @@ sub subvars { $filepath = $1; } + # The last entry of each kind wins, with its own s: prefix. if ($filepath =~ /^d:(.*)/) { - $diskfile = $1; - if ($scriptflag) { $diskscriptflag = 1; } + $diskfile = $1; + $diskscriptflag = $scriptflag; } elsif ($filepath =~ /^c:(.*)/) { - $configfile = $1; - if ($scriptflag) { $configscriptflag = 1; } + $configfile = $1; + $configscriptflag = $scriptflag; } elsif ($filepath) { - $partitionfile = $filepath; - if ($scriptflag) { $partscriptflag = 1; } + $partitionfile = $filepath; + $partscriptflag = $scriptflag; } } @@ -483,7 +484,7 @@ sub subvars { # Put the base64 coded partitionfile into %pre part $partcontent = "cat > /tmp/partscript.enc << EOFEOF\n" . $partcontent . "\nEOFEOF\n"; - if ($scriptflag) { + if ($partscriptflag) { # Put the code to decode preseed script and run it to generate pressed recipe file #$partcontent .= "python -c 'import base64; print base64.b64decode(open(\"/tmp/partscript.enc\",\"rb\").read())' >/tmp/partscript\n"; From ff870a0723a010bea7ec28a704264b8684ff4387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:42:41 -0300 Subject: [PATCH 4/9] test(template): cover partitionfile entries read with their own s: prefix A layout file followed by a disk script and a layout script followed by a disk file each replace the default storage config with the administrator layout. A layout file after a layout script and a disk file after a disk script are read as files, on Subiquity and in the debian-installer recipe step. --- .../native/ubuntu_subiquity_install_disk.t | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t index 3a5c19480a..84de4aa2e5 100644 --- a/xCAT-test/native/ubuntu_subiquity_install_disk.t +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -65,6 +65,11 @@ my @cases = ( ['a disk script', [['s:d:', $diskscript]], '/dev/disk/by-id/scripted'], ['a layout file', [['', $layout]], '/dev/disk/by-id/custom'], ['a layout script', [['s:', $writer]], '/dev/disk/by-id/custom'], + ['a layout file after a layout script', [['s:', "#!/bin/sh\nexit 0\n"], ['', $layout]], '/dev/disk/by-id/custom'], + ['a disk file after a disk script', [['s:d:', "#!/bin/sh\nexit 0\n"], ['d:', "/dev/disk/by-id/nvme-pinned\n"]], + '/dev/disk/by-id/nvme-pinned'], + ['a layout file before a disk script', [['', $layout], ['s:d:', $diskscript]], '/dev/disk/by-id/custom'], + ['a layout script before a disk file', [['s:', $writer], ['d:', "/dev/disk/by-id/nvme-pinned\n"]], '/dev/disk/by-id/custom'], ); for my $case (@cases) { my ($label, $entries, $expected) = @$case; @@ -82,4 +87,16 @@ for my $case (@cases) { is($config, $layout, 'the administrator layout replaces the default one') if $expected eq '/dev/disk/by-id/custom'; }; } + +# The debian-installer path renders the same entries into pre.ubuntu, under a shell with read -n. +subtest 'a debian-installer recipe file after a recipe script' => sub { + my $part = render_part('pre.ubuntu', qr/(^base64decode\(\)\n.*?^exit 0$)/ms, + ['s:', "#!/bin/sh\nexit 0\n"], ['', "recipe ::\n .\n"]); + ok($part, 'the rendered script defines base64decode before the recipe') or return; + my $root = installer_root(); + write_text("$root/part.sh", $part); + my ($rc, $output) = sandbox_run($root, '/bin/bash', '/fixture/part.sh'); + is($rc, 0, 'the recipe step runs') or diag($output); + is(storage_config($root), "recipe ::\n .\n", 'the later recipe file replaces the default recipe'); +}; done_testing(); From 45546220be063025b445d282af3d6a0391c30cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 23:06:05 -0300 Subject: [PATCH 5/9] fix(ubuntu): stop a Subiquity install when a partitionfile entry fails A disk script or layout script that failed, or a disk or layout entry that held nothing usable, left the disk getinstdisk chose or the default layout in place, and the install went on to wipe that disk. A layout whose storage section is missing or empty is worse: Subiquity then puts LVM on the largest disk. The entry exists to keep the install off some disks, so these fallbacks can destroy the disk it protects. A valid layout that started a YAML document also broke the install, because it was appended to autoinstall.yaml as a second document. When a disk or layout entry is configured, require it to succeed and to write a disk name, or a storage section with a config or a layout, and stop the pre-install script with an error otherwise. Subiquity then stops before it partitions. Rewrite an accepted layout as a YAML fragment that holds only the storage section. Without an entry, the detected disk and the default layout are used as before. --- .../xcat/install/scripts/pre.ubuntu.subiquity | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity index be79dbe1c7..cddbed7d89 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity +++ b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity @@ -146,7 +146,19 @@ base64decode() } # A d: or s:d: entry in linuximage.partitionfile replaces the disk getinstdisk chose. +rm -f /tmp/diskscript.enc +[ -e /tmp/xcat.install_disk ] && mv /tmp/xcat.install_disk /tmp/xcat.install_disk.detected #XCA_PARTMAN_DISK_SCRIPT# +override_rc=$? +if [ -e /tmp/diskscript.enc ]; then + # Falling back to the detected disk could wipe the disk the entry protects. + if [ "$override_rc" -ne 0 ] || [ -z "$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk 2>/dev/null)" ]; then + logger -t $log_label -p "err" "The partitionfile disk entry selected no disk, stopping the install" + exit 1 + fi +elif [ -e /tmp/xcat.install_disk.detected ]; then + mv /tmp/xcat.install_disk.detected /tmp/xcat.install_disk +fi # Note that the subiquity/curtin installation config is fairly picky about # the order in which things are specified - you have to specify all the @@ -340,8 +352,33 @@ storage: EOF fi +# Keep only a storage section that holds a config or a layout, rewritten as one YAML fragment +# for autoinstall.yaml. Subiquity puts LVM on the largest disk when that section is missing. +normalize_storage_layout() +{ + python3 -c 'import sys, yaml +s = yaml.safe_load(open(sys.argv[1])) +t = s.get("storage") if isinstance(s, dict) else None +if not (isinstance(t, dict) and (t.get("config") or t.get("layout"))): + sys.exit(1) +open(sys.argv[1], "w").write(yaml.safe_dump({"storage": t}, default_flow_style=False, sort_keys=False))' "$1" 2>/dev/null +} + # A partitionfile layout or s: script must come after the default layout, which it replaces. +rm -f /tmp/partscript.enc +mv /tmp/partitionfile /tmp/partitionfile.default #XCA_PARTMAN_RECIPE_SCRIPT# +override_rc=$? +if [ -e /tmp/partscript.enc ]; then + # Keeping the default layout could wipe a disk the administrator layout protects. + if [ "$override_rc" -ne 0 ] || ! normalize_storage_layout /tmp/partitionfile; then + logger -t $log_label -p "err" "The partitionfile layout entry wrote no layout, stopping the install" + rm -f /tmp/partitionfile + exit 1 + fi +else + mv /tmp/partitionfile.default /tmp/partitionfile +fi #XCA_PARTMAN_ADDITIONAL_CONFIG_SCRIPT# exit 0 From 1d378818dd822731527e667beb9ef540f3c95785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 23:06:20 -0300 Subject: [PATCH 6/9] test(ubuntu): cover a failed partitionfile entry on Subiquity installs A disk script or layout script that fails, or that writes no disk or layout, and a disk file or layout file that holds only blank lines, comments or an empty storage section each stop the pre-install script and leave no storage config for Subiquity. A layout file that starts a YAML document still leaves autoinstall.yaml one document. --- .../native/ubuntu_subiquity_install_disk.t | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t index 84de4aa2e5..dbcf016365 100644 --- a/xCAT-test/native/ubuntu_subiquity_install_disk.t +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -57,7 +57,7 @@ my $writer = "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n${layout}EOF\n"; my $diskscript = "#!/bin/sh\necho /dev/disk/by-id/scripted >/tmp/xcat.install_disk\n"; # Each case: label, the partitionfile entries as [prefix, file contents], and the disk the storage -# config must name. +# config must name, or undef when the install must stop before a storage config exists. my @cases = ( ['no partitionfile', [], '/dev/sdz'], ['a disk file', [['d:', "/dev/disk/by-id/nvme-pinned /dev/sdb\n"]], '/dev/disk/by-id/nvme-pinned'], @@ -70,6 +70,16 @@ my @cases = ( '/dev/disk/by-id/nvme-pinned'], ['a layout file before a disk script', [['', $layout], ['s:d:', $diskscript]], '/dev/disk/by-id/custom'], ['a layout script before a disk file', [['s:', $writer], ['d:', "/dev/disk/by-id/nvme-pinned\n"]], '/dev/disk/by-id/custom'], + ['a disk script that fails', [['s:d:', "#!/bin/sh\nexit 42\n"]], undef], + ['a disk script that selects no disk', [['s:d:', "#!/bin/sh\nexit 0\n"]], undef], + ['a layout script that fails', [['s:', "#!/bin/sh\nexit 42\n"]], undef], + ['a layout script that writes no layout', [['s:', "#!/bin/sh\nexit 0\n"]], undef], + ['a layout file with only blank lines', [['', "\n \n"]], undef], + ['a layout file with only comments', [['', "# no layout yet\n"]], undef], + ['a disk file with only blank lines', [['d:', " \n\n"]], undef], + ['a layout file with an empty storage section', [['', "storage:\n"]], undef], + ['a layout file with a null storage section', [['', "storage: null\n"]], undef], + ['a layout file that starts a YAML document', [['', "---\n$layout"]], '/dev/disk/by-id/custom'], ); for my $case (@cases) { my ($label, $entries, $expected) = @$case; @@ -80,11 +90,20 @@ for my $case (@cases) { write_text("$root/part.sh", $part); my ($rc, $output) = sandbox_run($root, {read_only => {"$root/efi" => '/sys/firmware/efi', "$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1'}}, $shell, '/fixture/part.sh'); + if (!defined $expected) { + isnt($rc, 0, "the pre-install script fails under $shell"); + ok(!-e "$root/tmp/partitionfile", 'and leaves no storage config to inject'); + return; + } is($rc, 0, "the partitioning runs under $shell") or diag($output); my $config = storage_config($root); my ($disk) = $config =~ /^\s+type: disk\n(?:\s+\S+:.*\n)*?\s+path: (\S+)$/m; is($disk, $expected, "the storage config partitions $expected"); is($config, $layout, 'the administrator layout replaces the default one') if $expected eq '/dev/disk/by-id/custom'; + # The early command appends the storage config to Subiquity's autoinstall.yaml. + write_text("$root/autoinstall.yaml", "version: 1\nidentity:\n hostname: node\n$config"); + is(system('/usr/bin/python3', '-I', '-c', 'import sys, yaml; sys.exit("storage" not in yaml.safe_load(open(sys.argv[1])))', + "$root/autoinstall.yaml"), 0, 'autoinstall.yaml stays one YAML document with a storage section'); }; } From f1d8641672330f3266aa77bacbc8ef93ca31c1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:15:59 -0300 Subject: [PATCH 7/9] fix(ubuntu): keep a partitionfile layout on the partitionfile disk A Subiquity layout written with "layout:" and no "match" goes to the largest disk. With a d: or s:d: entry in linuximage.partitionfile, that disk need not be the one the entry selected, so the install could wipe a disk the entry was meant to keep it off. When a disk entry is configured, give such a layout a match on the selected disk. Refuse a use_gap layout in that case, because some Subiquity releases ignore match in use_gap mode and would install into free space on another disk. A layout with its own match, a "config:" layout and a layout without a disk entry are kept as written. --- .../xcat/install/scripts/pre.ubuntu.subiquity | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity index cddbed7d89..90b3e363b1 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity +++ b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity @@ -150,7 +150,9 @@ rm -f /tmp/diskscript.enc [ -e /tmp/xcat.install_disk ] && mv /tmp/xcat.install_disk /tmp/xcat.install_disk.detected #XCA_PARTMAN_DISK_SCRIPT# override_rc=$? +disk_entry="" if [ -e /tmp/diskscript.enc ]; then + disk_entry=1 # Falling back to the detected disk could wipe the disk the entry protects. if [ "$override_rc" -ne 0 ] || [ -z "$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk 2>/dev/null)" ]; then logger -t $log_label -p "err" "The partitionfile disk entry selected no disk, stopping the install" @@ -353,7 +355,9 @@ EOF fi # Keep only a storage section that holds a config or a layout, rewritten as one YAML fragment -# for autoinstall.yaml. Subiquity puts LVM on the largest disk when that section is missing. +# for autoinstall.yaml. Subiquity puts LVM on the largest disk when that section is missing, +# and a layout without a match goes to the largest disk too, so it gets the disk in $2, if any. +# Some Subiquity releases ignore match in use_gap mode, so such a layout is refused with $2. normalize_storage_layout() { python3 -c 'import sys, yaml @@ -361,7 +365,12 @@ s = yaml.safe_load(open(sys.argv[1])) t = s.get("storage") if isinstance(s, dict) else None if not (isinstance(t, dict) and (t.get("config") or t.get("layout"))): sys.exit(1) -open(sys.argv[1], "w").write(yaml.safe_dump({"storage": t}, default_flow_style=False, sort_keys=False))' "$1" 2>/dev/null +l = t.get("layout") +if sys.argv[2] and isinstance(l, dict): + if l.get("mode") == "use_gap": + sys.exit(1) + l.setdefault("match", {"path": sys.argv[2]}) +open(sys.argv[1], "w").write(yaml.safe_dump({"storage": t}, default_flow_style=False, sort_keys=False))' "$1" "$2" 2>/dev/null } # A partitionfile layout or s: script must come after the default layout, which it replaces. @@ -371,8 +380,8 @@ mv /tmp/partitionfile /tmp/partitionfile.default override_rc=$? if [ -e /tmp/partscript.enc ]; then # Keeping the default layout could wipe a disk the administrator layout protects. - if [ "$override_rc" -ne 0 ] || ! normalize_storage_layout /tmp/partitionfile; then - logger -t $log_label -p "err" "The partitionfile layout entry wrote no layout, stopping the install" + if [ "$override_rc" -ne 0 ] || ! normalize_storage_layout /tmp/partitionfile "${disk_entry:+$INSTALL_DISK}"; then + logger -t $log_label -p "err" "The partitionfile layout entry wrote no usable layout, stopping the install" rm -f /tmp/partitionfile exit 1 fi From 75c874ebadd4aac99d92b142ebdd60789b335f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:15:59 -0300 Subject: [PATCH 8/9] test(ubuntu): cover a partitionfile layout on the partitionfile disk A layout without a match that follows a disk file gets a match on the disk the file selects, resolved when it is a link, and a use_gap layout that follows a disk file stops the install. A layout with its own match and a layout without a disk entry are kept as written. --- .../native/ubuntu_subiquity_install_disk.t | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t index dbcf016365..1131c30629 100644 --- a/xCAT-test/native/ubuntu_subiquity_install_disk.t +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -57,7 +57,8 @@ my $writer = "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n${layout}EOF\n"; my $diskscript = "#!/bin/sh\necho /dev/disk/by-id/scripted >/tmp/xcat.install_disk\n"; # Each case: label, the partitionfile entries as [prefix, file contents], and the disk the storage -# config must name, or undef when the install must stop before a storage config exists. +# config must name, or undef when the install must stop before a storage config exists. A fourth +# value is the whole storage config of a layout. my @cases = ( ['no partitionfile', [], '/dev/sdz'], ['a disk file', [['d:', "/dev/disk/by-id/nvme-pinned /dev/sdb\n"]], '/dev/disk/by-id/nvme-pinned'], @@ -80,9 +81,19 @@ my @cases = ( ['a layout file with an empty storage section', [['', "storage:\n"]], undef], ['a layout file with a null storage section', [['', "storage: null\n"]], undef], ['a layout file that starts a YAML document', [['', "---\n$layout"]], '/dev/disk/by-id/custom'], + ['a layout without a match after a disk file', [['', "storage:\n layout:\n name: direct\n"], + ['d:', "/dev/disk/by-id/nvme-link\n"]], undef, + "storage:\n layout:\n name: direct\n match:\n path: /dev/nvme7n1\n"], + ['a layout with its own match after a disk file', [['', "storage:\n layout:\n name: direct\n match:\n ssd: true\n"], + ['d:', "/dev/disk/by-id/nvme-link\n"]], undef, + "storage:\n layout:\n name: direct\n match:\n ssd: true\n"], + ['a layout without a match and no disk entry', [['', "storage:\n layout:\n name: direct\n"]], undef, + "storage:\n layout:\n name: direct\n"], + ['a use_gap layout after a disk file', [['', "storage:\n layout:\n name: direct\n mode: use_gap\n"], + ['d:', "/dev/disk/by-id/nvme-link\n"]], undef], ); for my $case (@cases) { - my ($label, $entries, $expected) = @$case; + my ($label, $entries, $expected, $expected_layout) = @$case; subtest $label => sub { my $part = render_part('pre.ubuntu.subiquity', qr/(^base64decode\(\)\n.*^exit 0$)/ms, @$entries); ok($part, 'the rendered script defines base64decode before the partitioning') or return; @@ -90,6 +101,11 @@ for my $case (@cases) { write_text("$root/part.sh", $part); my ($rc, $output) = sandbox_run($root, {read_only => {"$root/efi" => '/sys/firmware/efi', "$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1'}}, $shell, '/fixture/part.sh'); + if (defined $expected_layout) { + is($rc, 0, "the partitioning runs under $shell") or diag($output); + is(storage_config($root), $expected_layout, 'the storage config is the expected layout'); + return; + } if (!defined $expected) { isnt($rc, 0, "the pre-install script fails under $shell"); ok(!-e "$root/tmp/partitionfile", 'and leaves no storage config to inject'); From 00fb5843cff281f063bad553a0f9bc662c054176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:11:42 -0300 Subject: [PATCH 9/9] docs(ubuntu): describe partitionfile on Subiquity installs State that on Subiquity installs the partition definition file or script provides a curtin storage section that replaces the default layout, that a layout without a match is restricted to the disk a disk entry selects, that a failed layout or disk entry stops the install, that the first disk of a disk file is used, and that a disk script runs in the live installer under dash. Name the file that the disk file and the disk script write as /tmp/xcat.install_disk, which both Ubuntu installers read, instead of /tmp/install_disk. --- .../common/deployment/cfg_partition.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/source/guides/admin-guides/manage_clusters/common/deployment/cfg_partition.rst b/docs/source/guides/admin-guides/manage_clusters/common/deployment/cfg_partition.rst index 82767e6d5e..fe5a2090df 100644 --- a/docs/source/guides/admin-guides/manage_clusters/common/deployment/cfg_partition.rst +++ b/docs/source/guides/admin-guides/manage_clusters/common/deployment/cfg_partition.rst @@ -9,6 +9,8 @@ By default, xCAT will attempt to determine the first physical disk and use a gen .. warning:: **partition definition script** has only been verified on RedHat and Ubuntu, use at your own risk for SLES. +.. note:: Ubuntu 20.04 and later install with Subiquity. There the partition definition file, or the file the partition definition script writes to ``/tmp/partitionfile``, holds a curtin ``storage:`` section with a ``config`` or ``layout`` entry instead of a partman recipe. The installer keeps only that section, and it replaces the default layout. With a partition disk file or script as well, a ``layout`` without a ``match`` is restricted to the disk it selects, and a ``use_gap`` layout is refused. A layout or disk entry that fails, or that writes no layout or disk, stops the install before it partitions. The additional preseed configuration applies to the debian-installer only. + .. END_Overview @@ -480,13 +482,14 @@ If not specified, the default value will be used. nodeset osimage= - the ``d:`` preceding the filename tells nodeset that this is a partition disk file. -- For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, it will generate a script to write the content of the partition disk file to ``/tmp/install_disk``, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/.pre``. +- For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, it will generate a script to write the content of the partition disk file to ``/tmp/xcat.install_disk``, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/.pre``. +- A Subiquity install partitions only the first disk the file names. Use a ``/dev/disk/by-id/`` name when the kernel can enumerate the disks in a different order at each boot. .. END_Partition_Disk_File_ubuntu_only .. BEGIN_Partition_Disk_Script_ubuntu_only -The disk script contains a script to generate a partitioning disk file named ``/tmp/install_disk``. for example: :: +The disk script contains a script to generate a partitioning disk file named ``/tmp/xcat.install_disk``. for example: :: rm /tmp/devs-with-boot 2>/dev/null || true; for d in $(list-devices partition); do @@ -499,12 +502,12 @@ The disk script contains a script to generate a partitioning disk file named ``/ fi done; if [[ -e /tmp/devs-with-boot ]]; then - head -n1 /tmp/devs-with-boot | egrep -o '\S+[^0-9]' > /tmp/install_disk; + head -n1 /tmp/devs-with-boot | egrep -o '\S+[^0-9]' > /tmp/xcat.install_disk; rm /tmp/devs-with-boot 2>/dev/null || true; else DEV=`ls /dev/disk/by-path/* -l | egrep -o '/dev.*[s|h|v]d[^0-9]$' | sort -t : -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -g | head -n1 | egrep -o '[s|h|v]d.*$'`; if [[ "$DEV" == "" ]]; then DEV="sda"; fi; - echo "/dev/$DEV" > /tmp/install_disk; + echo "/dev/$DEV" > /tmp/xcat.install_disk; fi; If not specified, the default value will be used. @@ -516,6 +519,7 @@ If not specified, the default value will be used. - the ``s:`` prefix tells ``nodeset`` that is a script, the ``s:d:`` preceding the filename tells ``nodeset`` that this is a script to generate the partition disk file. - For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/.pre``. +- A Subiquity install runs the script in the live installer system, under ``dash`` unless its first line names another interpreter. ``list-devices``, which the example uses, exists only in the debian-installer. .. END_Partition_Disk_Script_ubuntu_only