From d52b97cd255137b7abf72418eca1793826d9fa6d Mon Sep 17 00:00:00 2001 From: arstercz Date: Wed, 27 Apr 2022 04:46:02 +0000 Subject: [PATCH 1/2] fix disk readlink error which system boot by nfs mount --- disk/disk_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disk/disk_linux.go b/disk/disk_linux.go index f087b86..a64ff8e 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -349,7 +349,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro // /dev/root is not the real device name // so we get the real device name from its major/minor number - if d.Device == "/dev/root" { + if d.Device == "/dev/root" && d.Fstype != "nfs" { devpath, err := os.Readlink(common.HostSys("/dev/block/" + blockDeviceID)) if err != nil { return nil, err From f6dc96c30e5957e74a31347d19aa82e14a374e37 Mon Sep 17 00:00:00 2001 From: arstercz Date: Sun, 1 May 2022 02:33:09 +0000 Subject: [PATCH 2/2] follow the psutil principles, do nothing if can not find root device --- disk/disk_linux.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/disk/disk_linux.go b/disk/disk_linux.go index a64ff8e..3911af9 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -349,12 +349,11 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro // /dev/root is not the real device name // so we get the real device name from its major/minor number - if d.Device == "/dev/root" && d.Fstype != "nfs" { + if d.Device == "/dev/root" { devpath, err := os.Readlink(common.HostSys("/dev/block/" + blockDeviceID)) - if err != nil { - return nil, err + if err == nil { + d.Device = strings.Replace(d.Device, "root", filepath.Base(devpath), 1) } - d.Device = strings.Replace(d.Device, "root", filepath.Base(devpath), 1) } } ret = append(ret, d)