From f4194731df1a6847a1724360e163b4a2b57fba28 Mon Sep 17 00:00:00 2001 From: hys Date: Wed, 17 Jun 2026 12:42:57 +0800 Subject: [PATCH] fix: lsblk command add sysroot in container --- collector/lsblk_linux.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/collector/lsblk_linux.go b/collector/lsblk_linux.go index fd63dabcc7..03ada9b869 100644 --- a/collector/lsblk_linux.go +++ b/collector/lsblk_linux.go @@ -111,6 +111,14 @@ func (c *lsblkCollector) Update(ch chan<- prometheus.Metric) error { } args := []string{"--json", "-b", "-o", "NAME,SIZE,FSTYPE,MOUNTPOINT,FSUSED,FSUSE%"} + // When running inside a container with the host rootfs mounted under + // --path.rootfs (e.g. /host/root), the in-container lsblk cannot see the + // host's device-mapper/LVM topology or filesystem usage. Pointing lsblk at + // the host root via --sysroot makes it read the host's sysfs, udev and + // mountinfo, so LVM volumes and their FSUSED/FSUSE% are reported correctly. + if *rootfsPath != "" && *rootfsPath != "/" { + args = append(args, "--sysroot", *rootfsPath) + } cmd := execCommand(path, args...) out, err := CombinedOutputTimeout(cmd, *lsblkTimeout) if err != nil {