Skip to content

Commit 17af112

Browse files
committed
Comments addressed.
1 parent 6f9e345 commit 17af112

7 files changed

Lines changed: 88 additions & 12 deletions

File tree

toolkit/tools/internal/osinfo/osinfo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package osinfo
22

33
import (
4+
"errors"
5+
"io/fs"
46
"os"
57
"path/filepath"
68
"strings"
@@ -10,6 +12,9 @@ import (
1012
func GetDistroAndVersion(rootDir string) (string, string) {
1113
output, err := os.ReadFile(filepath.Join(rootDir, "etc/os-release"))
1214
if err != nil {
15+
if !errors.Is(err, fs.ErrNotExist) {
16+
return "Unknown Distro", "Unknown Version"
17+
}
1318
// Fall back to /usr/lib/os-release per the os-release(5) spec.
1419
output, err = os.ReadFile(filepath.Join(rootDir, "usr/lib/os-release"))
1520
if err != nil {

toolkit/tools/internal/targetos/targetos.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package targetos
55

66
import (
7+
"errors"
78
"fmt"
9+
"io/fs"
810
"path/filepath"
911
"strings"
1012

@@ -26,6 +28,9 @@ func GetInstalledTargetOs(rootfs string) (TargetOs, error) {
2628
// Try /etc/os-release first, then fall back to /usr/lib/os-release.
2729
fields, err := envfile.ParseEnvFile(filepath.Join(rootfs, "etc/os-release"))
2830
if err != nil {
31+
if !errors.Is(err, fs.ErrNotExist) {
32+
return "", fmt.Errorf("failed to read /etc/os-release:\n%w", err)
33+
}
2934
fields, err = envfile.ParseEnvFile(filepath.Join(rootfs, "usr/lib/os-release"))
3035
if err != nil {
3136
return "", fmt.Errorf("failed to read os-release (tried /etc/os-release and /usr/lib/os-release):\n%w", err)
@@ -42,7 +47,7 @@ func GetInstalledTargetOs(rootfs string) (TargetOs, error) {
4247
return TargetOsAzureLinux2, nil
4348

4449
default:
45-
return "", fmt.Errorf("unknown VERSION_ID (%s) for CBL-Mariner in /etc/os-release", versionId)
50+
return "", fmt.Errorf("unknown VERSION_ID (%s) for CBL-Mariner in os-release", versionId)
4651
}
4752

4853
case "azurelinux":
@@ -53,7 +58,7 @@ func GetInstalledTargetOs(rootfs string) (TargetOs, error) {
5358
// ACL uses VERSION_ID like "3.0.YYYYMMDD" (e.g. "3.0.20260421").
5459
// Accept any version that starts with "3.0".
5560
if !strings.HasPrefix(versionId, "3.0") {
56-
return "", fmt.Errorf("unknown VERSION_ID (%s) for Azure Container Linux in /etc/os-release", versionId)
61+
return "", fmt.Errorf("unknown VERSION_ID (%s) for Azure Container Linux in os-release", versionId)
5762
}
5863
return TargetOsAcl, nil
5964

@@ -64,11 +69,11 @@ func GetInstalledTargetOs(rootfs string) (TargetOs, error) {
6469
return TargetOsAzureLinux3, nil
6570

6671
default:
67-
return "", fmt.Errorf("unknown VERSION_ID (%s) for Azure Linux in /etc/os-release", versionId)
72+
return "", fmt.Errorf("unknown VERSION_ID (%s) for Azure Linux in os-release", versionId)
6873
}
6974

7075
default:
71-
return "", fmt.Errorf("unknown VARIANT_ID (%s) for Azure Linux in /etc/os-release", variantId)
76+
return "", fmt.Errorf("unknown VARIANT_ID (%s) for Azure Linux in os-release", variantId)
7277
}
7378

7479
case "fedora":
@@ -77,7 +82,7 @@ func GetInstalledTargetOs(rootfs string) (TargetOs, error) {
7782
return TargetOsFedora42, nil
7883

7984
default:
80-
return "", fmt.Errorf("unknown VERSION_ID (%s) for Fedora in /etc/os-release", versionId)
85+
return "", fmt.Errorf("unknown VERSION_ID (%s) for Fedora in os-release", versionId)
8186
}
8287

8388
case "ubuntu":
@@ -89,10 +94,10 @@ func GetInstalledTargetOs(rootfs string) (TargetOs, error) {
8994
return TargetOsUbuntu2404, nil
9095

9196
default:
92-
return "", fmt.Errorf("unknown VERSION_ID (%s) for Ubuntu in /etc/os-release", versionId)
97+
return "", fmt.Errorf("unknown VERSION_ID (%s) for Ubuntu in os-release", versionId)
9398
}
9499

95100
default:
96-
return "", fmt.Errorf("unknown ID (%s) in /etc/os-release", distroId)
101+
return "", fmt.Errorf("unknown ID (%s) in os-release", distroId)
97102
}
98103
}

toolkit/tools/pkg/imagecustomizerlib/cosicommon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func extractUkiEntriesIfPresent(chrootDir, buildDir string, distroHandler Distro
429429

430430
var entries []SystemDBootEntry
431431
for kernelName, cmdline := range cmdlines {
432-
efiPath := filepath.Join("/"+distroHandler.GetEspDir(), "EFI/Linux", fmt.Sprintf("%s.efi", kernelName))
432+
efiPath := filepath.Join("/", distroHandler.GetEspDir(), "EFI/Linux", fmt.Sprintf("%s.efi", kernelName))
433433
kernelVersion, err := getKernelVersion(kernelName)
434434
if err != nil {
435435
return nil, fmt.Errorf("invalid kernel name in UKI file (%s):\n%w", kernelName, err)

toolkit/tools/pkg/imagecustomizerlib/customizeuki_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,45 @@ func getUkiAddonFiles(espPath string) ([]string, error) {
566566

567567
return addonFiles, nil
568568
}
569+
570+
func TestGetKernelNameFromUki(t *testing.T) {
571+
tests := []struct {
572+
name string
573+
ukiPath string
574+
expected string
575+
expectError bool
576+
}{
577+
{
578+
name: "standard vmlinuz naming",
579+
ukiPath: "/boot/efi/EFI/Linux/vmlinuz-6.6.51.1-5.azl3.efi",
580+
expected: "vmlinuz-6.6.51.1-5.azl3",
581+
},
582+
{
583+
name: "non-standard naming (ACL)",
584+
ukiPath: "/boot/EFI/Linux/acl.efi",
585+
expected: "acl",
586+
},
587+
{
588+
name: "non-standard naming with path",
589+
ukiPath: "/some/path/custom-kernel.efi",
590+
expected: "custom-kernel",
591+
},
592+
{
593+
name: "no .efi extension",
594+
ukiPath: "/boot/EFI/Linux/vmlinuz-6.6.51",
595+
expectError: true,
596+
},
597+
}
598+
599+
for _, tt := range tests {
600+
t.Run(tt.name, func(t *testing.T) {
601+
result, err := getKernelNameFromUki(tt.ukiPath)
602+
if tt.expectError {
603+
assert.Error(t, err)
604+
} else {
605+
assert.NoError(t, err)
606+
assert.Equal(t, tt.expected, result)
607+
}
608+
})
609+
}
610+
}

toolkit/tools/pkg/imagecustomizerlib/distrohandler_acl.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,25 @@ func (d *aclDistroHandler) GetTargetOs() targetos.TargetOs {
3131
}
3232

3333
func (d *aclDistroHandler) ValidateConfig(rc *ResolvedConfig) error {
34-
// TODO: Block unsupported operations (repartitioning, GRUB, initramfs regen, etc.)
34+
// ACL Phase 0: only mount/recognize/passthrough is supported.
35+
// Block operations that would fail with confusing errors later.
36+
37+
if rc.Storage.CustomizePartitions() {
38+
return fmt.Errorf("storage repartitioning is not yet supported for ACL")
39+
}
40+
41+
if rc.BootLoader.ResetType == imagecustomizerapi.ResetBootLoaderTypeHard {
42+
return fmt.Errorf("bootloader hard-reset is not supported on ACL (ACL uses systemd-boot, not GRUB)")
43+
}
44+
45+
if rc.Uki != nil && rc.Uki.Mode != imagecustomizerapi.UkiModePassthrough {
46+
return fmt.Errorf("only UKI passthrough mode is currently supported for ACL (got %q)", rc.Uki.Mode)
47+
}
48+
49+
if len(rc.OsKernelCommandLine.ExtraCommandLine) > 0 {
50+
return fmt.Errorf("kernel command line modification is not yet supported for ACL")
51+
}
52+
3553
return nil
3654
}
3755

toolkit/tools/pkg/imagecustomizerlib/imageutils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ func extractOSRelease(imageConnection *imageconnection.ImageConnection) (string,
391391
osReleasePath := filepath.Join(imageConnection.Chroot().RootDir(), "etc/os-release")
392392
data, err := file.Read(osReleasePath)
393393
if err != nil {
394+
if !errors.Is(err, fs.ErrNotExist) {
395+
return "", fmt.Errorf("failed to read /etc/os-release:\n%w", err)
396+
}
394397
osReleasePath = filepath.Join(imageConnection.Chroot().RootDir(), "usr/lib/os-release")
395398
data, err = file.Read(osReleasePath)
396399
if err != nil {
@@ -418,9 +421,10 @@ func clearBtrfsReadOnlyProperties(imageConnection *imageconnection.ImageConnecti
418421
mountPath := filepath.Join(imageConnection.Chroot().RootDir(), mp.GetTarget())
419422

420423
// Check if the subvolume is read-only.
421-
stdout, _, err := shell.Execute("btrfs", "property", "get", "-ts", mountPath, "ro")
424+
stdout, stderr, err := shell.Execute("btrfs", "property", "get", "-ts", mountPath, "ro")
422425
if err != nil {
423426
// Not all btrfs mounts have subvolumes; skip on error.
427+
logger.Log.Debugf("Skipping btrfs property check on %s: %v: %s", mp.GetTarget(), err, stderr)
424428
continue
425429
}
426430

toolkit/tools/pkg/imagecustomizerlib/partitionutils.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ func findFstabInRoot(diskPartition diskutils.PartitionInfo, tmpDir string) ([]st
203203
matchingPaths = append(matchingPaths, "")
204204
}
205205

206-
// ACL places an fstab at /usr/share/ic/etc/fstab on the USR partition. This
207-
// path is outside the /etc overlay.
206+
// Check for IC-specific fstab.
207+
// ACL places an fstab at /usr/share/ic/etc/fstab on the USR partition so
208+
// that IC can discover the partition layout without /etc being available.
209+
// The path is unique enough to avoid false matches on non-ACL distros.
208210
fstabIcPath := filepath.Join(tmpDir, "share/ic/etc/fstab")
209211
exists, err = file.PathExists(fstabIcPath)
210212
if err != nil {

0 commit comments

Comments
 (0)