From a02892983cd88a0f4e9b451d0765f6e279fabab1 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 10 Jul 2021 18:54:25 -0700 Subject: INSTALLER:CLEANLY-INSTALLED-ONCE: handle /run using 'mount --move' Signed-off-by: Sean Whitton --- src/package.lisp | 2 ++ src/property/installer.lisp | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/package.lisp b/src/package.lisp index 1de47d8..07df631 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -31,6 +31,7 @@ #:file-exists-p #:directory-exists-p #:with-current-directory + #:delete-empty-directory #:delete-directory-tree #:safe-read-from-string #:compile-file* @@ -63,6 +64,7 @@ #:file-exists-p #:directory-exists-p #:with-current-directory + #:delete-empty-directory #:delete-directory-tree #:safe-read-from-string #:compile-file* diff --git a/src/property/installer.lisp b/src/property/installer.lisp index ba2e21f..097caef 100644 --- a/src/property/installer.lisp +++ b/src/property/installer.lisp @@ -174,19 +174,23 @@ using a combinator like ON-CHANGE, or applied manually with DEPLOY-THESE." (old-os (ensure-directories-exist (ensure-directory-pathname old-os))) (preserved-directories - '(;; These dirs can contain sockets, remote Lisp image output, - ;; etc.; avoid upsetting those. - #P"/run/" #P"/tmp/" + '(;; This can contain sockets, remote Lisp image output, etc.; + ;; avoid upsetting any of those. + #P"/tmp/" ;; Makes sense to keep /proc until we replace the running init, ;; and we want to retain all the systemd virtual filesystems ;; under /sys to avoid problems applying other properties. Both ;; are empty directories right after debootstrap, so nothing to ;; copy out. - #P"/proc/" #P"/sys/")) + #P"/proc/" #P"/sys/" + ;; This we make use of below. + #P"/old-run/")) efi-system-partition-mount-args) (flet ((preservedp (pathname) (member pathname preserved-directories :test #'pathname-equal))) (mount:assert-devtmpfs-udev-/dev) + (unless (zerop (mrun :for-exit "mountpoint" "-q" "/run")) + (failed-change "/run is not a mount point; don't know what to do.")) ;; If there's an EFI system partition, we need to store knowledge of ;; how to mount it so that we can restore the mount after doing the @@ -201,6 +205,17 @@ using a combinator like ON-CHANGE, or applied manually with DEPLOY-THESE." (setq efi-system-partition-mount-args `("-t" ,type "-o" ,options ,source "/boot/efi")))) + ;; /run is tricky because we want to retain the contents of the tmpfs + ;; mounted there until reboot, for similar reasons to wanting to retain + ;; /tmp, but unlike /tmp, /proc and /sys, a freshly debootstrapped + ;; system contains a few things under /run and we would like to move + ;; these out of /new-os. So we temporarily relocate the /run mount. + ;; + ;; If this causes problems we could reconsider -- there's usually a + ;; tmpfs mounted at /run, so those files underneath might not matter. + (mrun "mount" "--make-private" "/") + (system "mount" "--move" "/run" (ensure-directories-exist "/old-run/")) + ;; We are not killing any processes, so lazily unmount everything ;; before trying to perform any renames. (Present structure of this ;; loop assumes that each member of PRESERVED-DIRECTORIES is directly @@ -240,6 +255,10 @@ using a combinator like ON-CHANGE, or applied manually with DEPLOY-THESE." (signal c)))) (delete-directory-tree new-os :validate t) + ;; Restore /run and any submounts, like /run/lock. + (system "mount" "--move" "/old-run" "/run") + (delete-empty-directory "/old-run") + ;; For the freshly bootstrapped OS let's assume that HOME is /root and ;; XDG_CACHE_HOME is /root/.cache; we do want to try to read the old ;; OS's actual XDG_CACHE_HOME. Move cache & update environment. -- cgit v1.2.3