diff --git a/libpod/runtime.go b/libpod/runtime.go index c6a7f7e7b7..4483df99cd 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -624,6 +624,11 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) { } } + // Check current boot ID - will be written to the alive file. + if err := runtime.checkBootID(runtimeAliveFile); err != nil { + return err + } + runtime.startWorker() return nil diff --git a/libpod/runtime_freebsd.go b/libpod/runtime_freebsd.go index 38f77b56cf..7a9aea6c12 100644 --- a/libpod/runtime_freebsd.go +++ b/libpod/runtime_freebsd.go @@ -4,3 +4,7 @@ package libpod func checkCgroups2UnifiedMode(runtime *Runtime) { } + +func (r *Runtime) checkBootID(runtimeAliveFile string) error { + return nil +} diff --git a/libpod/runtime_linux.go b/libpod/runtime_linux.go index 729253addf..065a11959c 100644 --- a/libpod/runtime_linux.go +++ b/libpod/runtime_linux.go @@ -43,3 +43,25 @@ func checkCgroups2UnifiedMode(runtime *Runtime) { } } } + +// Check the current boot ID against the ID cached in the runtime alive file. +func (r *Runtime) checkBootID(runtimeAliveFile string) error { + systemBootID, err := os.ReadFile("/proc/sys/kernel/random/boot_id") + if err == nil { + podmanBootID, err := os.ReadFile(runtimeAliveFile) + if err != nil { + return fmt.Errorf("reading boot ID from runtime alive file: %w", err) + } + if len(podmanBootID) != 0 { + if string(systemBootID) != string(podmanBootID) { + return fmt.Errorf("current system boot ID differs from cached boot ID; an unhandled reboot has occurred. Please delete directories %q and %q and re-run Podman", r.storageConfig.RunRoot, r.config.Engine.TmpDir) + } + } else { + // Write the current boot ID to the alive file. + if err := os.WriteFile(runtimeAliveFile, systemBootID, 0644); err != nil { + return fmt.Errorf("writing boot ID to runtime alive file: %w", err) + } + } + } + return nil +}