From 79adfd2c0df1de8a42255bfdca5f169471f9306d Mon Sep 17 00:00:00 2001 From: Arush Wadhawan <142635726+SoulSniper1212@users.noreply.github.com> Date: Fri, 14 Nov 2025 14:03:26 -0500 Subject: [PATCH] fix: detect and handle immutable filesystems like Fedora Silverblue (#1405) --- agent/agent.go | 37 +++++++++++++++++++++++++++++++++++++ agent/disk.go | 9 ++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 75f51cbc..d6bbae1e 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -229,3 +229,40 @@ func (a *Agent) getFingerprint() string { return fingerprint } + +// getRootMountPoint returns the appropriate root mount point for the system +// For immutable systems like Fedora Silverblue, it returns /sysroot instead of / +func (a *Agent) getRootMountPoint() string { + // Check for typical immutable system indicators + // 1. Check if /etc/os-release contains indicators of an immutable system + if osReleaseContent, err := os.ReadFile("/etc/os-release"); err == nil { + content := string(osReleaseContent) + // Look for indicators of atomic/immutable systems + if strings.Contains(content, "fedora") && strings.Contains(content, "silverblue") || + strings.Contains(content, "coreos") || + strings.Contains(content, "flatcar") || + strings.Contains(content, "rhel-atomic") || + strings.Contains(content, "centos-atomic") { + // Verify that /sysroot exists before returning it + if _, err := os.Stat("/sysroot"); err == nil { + return "/sysroot" + } + } + } + + // 2. Check if /run/ostree is present (ostree-based systems like Silverblue) + if _, err := os.Stat("/run/ostree"); err == nil { + // Verify that /sysroot exists before returning it + if _, err := os.Stat("/sysroot"); err == nil { + return "/sysroot" + } + } + + return "/" +} + +// isImmutableSystem detects if the system is likely an immutable system like Fedora Silverblue +// where the real root filesystem is mounted at /sysroot instead of / +func (a *Agent) isImmutableSystem() bool { + return a.getRootMountPoint() != "/" +} diff --git a/agent/disk.go b/agent/disk.go index 88567979..4900311c 100644 --- a/agent/disk.go +++ b/agent/disk.go @@ -95,6 +95,9 @@ func (a *Agent) initializeDiskInfo() { } } + // Get the appropriate root mount point for this system + rootMountPoint := a.getRootMountPoint() + // Use FILESYSTEM env var to find root filesystem if filesystem != "" { for _, p := range partitions { @@ -138,7 +141,7 @@ func (a *Agent) initializeDiskInfo() { for _, p := range partitions { // fmt.Println(p.Device, p.Mountpoint) // Binary root fallback or docker root fallback - if !hasRoot && (p.Mountpoint == "/" || (p.Mountpoint == "/etc/hosts" && strings.HasPrefix(p.Device, "/dev"))) { + if !hasRoot && (p.Mountpoint == rootMountPoint || (p.Mountpoint == "/etc/hosts" && strings.HasPrefix(p.Device, "/dev"))) { fs, match := findIoDevice(filepath.Base(p.Device), diskIoCounters, a.fsStats) if match { addFsStat(fs, p.Mountpoint, true) @@ -174,8 +177,8 @@ func (a *Agent) initializeDiskInfo() { // If no root filesystem set, use fallback if !hasRoot { rootDevice, _ := findIoDevice(filepath.Base(filesystem), diskIoCounters, a.fsStats) - slog.Info("Root disk", "mountpoint", "/", "io", rootDevice) - a.fsStats[rootDevice] = &system.FsStats{Root: true, Mountpoint: "/"} + slog.Info("Root disk", "mountpoint", rootMountPoint, "io", rootDevice) + a.fsStats[rootDevice] = &system.FsStats{Root: true, Mountpoint: rootMountPoint} } a.initializeDiskIoStats(diskIoCounters)