GNU bug report logs - #73494
[PATCH 0/2] tmpfs /run.

Previous Next

Package: guix-patches;

Reported by: Hilton Chain <hako <at> ultrarare.space>

Date: Thu, 26 Sep 2024 07:03:02 UTC

Severity: normal

Tags: patch

Full log


View this message in rfc822 format

From: Hilton Chain <hako <at> ultrarare.space>
To: 73494 <at> debbugs.gnu.org
Cc: Hilton Chain <hako <at> ultrarare.space>, Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, Hilton Chain <hako <at> ultrarare.space>, Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, Ludovic Courtès <ludo <at> gnu.org>, Vagrant Cascadian <vagrant <at> debian.org>, Z572 <zhengjunjie <at> iscas.ac.cn>, Gabriel Wicki <gabriel <at> erlikon.ch>
Subject: [bug#73494] [PATCH v5 2/3] services: cleanup: Bind mount /var/run to /run.
Date: Sat,  3 May 2025 22:22:56 +0800
* gnu/system/file-systems.scm (%runtime-variable-data)
(%runtime-variable-data/bind-mount): New variables.
* gnu/system/file-systems.scm (%base-file-systems): Register
%runtime-variable-data.
* gnu/services.scm (cleanup-gexp): Bind mount /var/run to /run.  Remove now
extraneous cleanups.
* doc/guix.texi (File Systems): Document it.

Change-Id: Ie462347935569acddfba68441cf58815a5087cff
Modified-by: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
---
 doc/guix.texi               |  7 +++++++
 gnu/services.scm            | 21 +++++++++++++--------
 gnu/services/dbus.scm       | 31 -------------------------------
 gnu/system/file-systems.scm | 29 +++++++++++++++++++++++++++--
 4 files changed, 47 insertions(+), 41 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 0537cae87d..eb8dd39c89 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -18383,6 +18383,13 @@ File Systems
 read-write in its own ``name space.''
 @end defvar
 
+@defvar %runtime-variable-data
+This file system is mounted as @file{/run} and contains system
+information data describing the system since it was booted.
+@file{/var/run} is bind mounted to @file{/run}, for backward
+compatibility.
+@end defvar
+
 @defvar %binary-format-file-system
 The @code{binfmt_misc} file system, which allows handling of arbitrary
 executable file types to be delegated to user space.  This requires the
diff --git a/gnu/services.scm b/gnu/services.scm
index 6865c7560f..700966c4c2 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -628,9 +628,14 @@ (define (system-provenance system)
 
 (define (cleanup-gexp _)
   "Return a gexp to clean up /tmp and similar places upon boot."
-  (with-imported-modules '((guix build utils))
+  (with-imported-modules (source-module-closure
+                          '((guix build utils)
+                            (gnu build file-systems)
+                            (gnu system file-systems)))
     #~(begin
-        (use-modules (guix build utils))
+        (use-modules (guix build utils)
+                     (gnu build file-systems)
+                     (gnu system file-systems))
 
         ;; Clean out /tmp, /var/run, and /run.
         ;;
@@ -662,17 +667,17 @@ (define (cleanup-gexp _)
                       "/lib/locale"))
            (setlocale LC_CTYPE "en_US.utf8")
            (delete-file-recursively "/tmp")
-           (delete-file-recursively "/var/run")
-           (delete-file-recursively "/run")
 
            ;; Note: The second argument to 'mkdir' is and'ed with umask,
            ;; hence the 'chmod' calls.
            (mkdir "/tmp" #o1777)
            (chmod "/tmp" #o1777)
-           (mkdir "/var/run" #o755)
-           (chmod "/var/run" #o755)
-           (mkdir "/run" #o755)
-           (chmod "/var/run" #o755))))))
+
+           ;; XXX: It'd be cleaner if we could simply register
+           ;; %runtime-variable-data/bind-mount in %base-file-systems, that
+           ;; fails with: 'statfs-raw: No such file or directory' when
+           ;; checking for "/run".
+           (mount-file-system %runtime-variable-data/bind-mount #:root "/"))))))
 
 (define cleanup-service-type
   ;; Service that cleans things up in /tmp and similar.
diff --git a/gnu/services/dbus.scm b/gnu/services/dbus.scm
index 76e04bf221..9292172e01 100644
--- a/gnu/services/dbus.scm
+++ b/gnu/services/dbus.scm
@@ -190,37 +190,6 @@ (define (dbus-activation config)
           ;; world-readable.
           (mkdir-p/perms "/run/dbus" user #o755))
 
-        (catch 'system-error
-          (lambda ()
-            (symlink "/run/dbus" "/var/run/dbus"))
-          (lambda args
-            (let ((errno (system-error-errno args)))
-              (cond
-               ((= errno EEXIST)
-                (let ((existing-name
-                       (false-if-exception
-                        (readlink "/var/run/dbus"))))
-                  (unless (equal? existing-name "/run/dbus")
-                    ;; Move the content of /var/run/dbus to /run/dbus, and
-                    ;; retry.
-                    (let ((dir (opendir "/var/run/dbus")))
-                      (let loop ((next (readdir dir)))
-                        (cond
-                         ((eof-object? next) (closedir dir))
-                         ((member next '("." "..")) (loop (readdir dir)))
-                         (else
-                          (begin
-                            (rename-file (string-append "/var/run/dbus/" next)
-                                         (string-append "/run/dbus/" next))
-                            (loop (readdir dir)))))))
-                    (rmdir "/var/run/dbus")
-                    (symlink "/run/dbus" "/var/run/dbus"))))
-               (else
-                (format (current-error-port)
-                        "Failed to symlink /run/dbus to /var/run/dbus: ~s~%"
-                        (strerror errno))
-                (error "cannot create /var/run/dbus"))))))
-
         (unless (file-exists? "/etc/machine-id")
           (format #t "creating /etc/machine-id...~%")
           (invoke (string-append #$(dbus-configuration-dbus config)
diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm
index 4ea8237c70..c75ef39377 100644
--- a/gnu/system/file-systems.scm
+++ b/gnu/system/file-systems.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2013-2022 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2020 Google LLC
 ;;; Copyright © 2020 Jakub Kądziołka <kuba <at> kadziolka.net>
-;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
+;;; Copyright © 2020, 2021, 2025 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
 ;;; Copyright © 2021 Tobias Geerinckx-Rice <me <at> tobias.gr>
 ;;; Copyright © 2022 Oleg Pykhalov <go.wigust <at> gmail.com>
 ;;;
@@ -82,6 +82,8 @@ (define-module (gnu system file-systems)
             %pseudo-terminal-file-system
             %tty-gid
             %immutable-store
+            %runtime-variable-data
+            %runtime-variable-data/bind-mount
             %control-groups
             %elogind-file-systems
 
@@ -448,6 +450,28 @@ (define %immutable-store
     (check? #f)
     (flags '(read-only bind-mount no-atime))))
 
+(define %runtime-variable-data
+  (file-system
+    (type "tmpfs")
+    (mount-point "/run")
+    (device "tmpfs")
+    ;; Don't use no-suid here as /run/privileged/bin may contain SUID
+    ;; executables.
+    (flags '(no-dev strict-atime))
+    (options "mode=0755,nr_inodes=800k,size=20%")
+    (needed-for-boot? #t)
+    (check? #f)
+    (create-mount-point? #t)))
+
+(define %runtime-variable-data/bind-mount
+  (file-system
+    (device "/run")
+    (mount-point "/var/run")
+    (type "tmpfs")
+    (flags '(bind-mount))
+    (check? #f)
+    (create-mount-point? #t)))
+
 (define %control-groups
   ;; The cgroup2 file system.
   (list (file-system
@@ -497,7 +521,8 @@ (define %base-file-systems
         %debug-file-system
         %shared-memory-file-system
         %efivars-file-system
-        %immutable-store))
+        %immutable-store
+        %runtime-variable-data))
 
 (define %base-live-file-systems
   ;; This is the bare minimum to use live file-systems.
-- 
2.49.0





This bug report was last modified 34 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.