From: "Ludovic Courtès" <ludo@gnu.org>
To: 28706@debbugs.gnu.org
Subject: [bug#28706] [PATCH 3/3] guix system: Error out when passed a wrong file system UUID/label.
Date: Wed, 4 Oct 2017 21:51:45 +0200 [thread overview]
Message-ID: <20171004195145.4743-3-ludo@gnu.org> (raw)
In-Reply-To: <20171004195145.4743-1-ludo@gnu.org>
* guix/scripts/system.scm (check-file-system-availability): New
procedure.
(perform-action): Use it.
---
guix/scripts/system.scm | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 567d8bb64..e50f1d8ac 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -37,6 +37,8 @@
#:use-module (guix scripts graph)
#:use-module (guix build utils)
#:use-module (gnu build install)
+ #:autoload (gnu build file-systems)
+ (find-partition-by-label find-partition-by-uuid)
#:use-module (gnu system)
#:use-module (gnu bootloader)
#:use-module (gnu system file-systems)
@@ -404,6 +406,7 @@ NUMBERS, which is a list of generation numbers."
"Roll back the system profile to its previous generation. STORE is an open
connection to the store."
(switch-to-system-generation store "-1"))
+
\f
;;;
;;; Switch generations.
@@ -555,6 +558,61 @@ PATTERN, a string. When PATTERN is #f, display all the system generations."
(leave (G_ "invalid syntax: ~a~%") pattern))))
\f
+;;;
+;;; File system declaration checks.
+;;;
+
+(define (check-file-system-availability file-systems)
+ "Check whether the UUIDs or partition labels that FILE-SYSTEMS refer to, if
+any, are available. Raise an error if they're not."
+ (define relevant
+ (filter (lambda (fs)
+ (and (file-system-mount? fs)
+ (not (string=? "tmpfs" (file-system-type fs)))
+ (not (memq 'bind-mount (file-system-flags fs)))))
+ file-systems))
+
+ (define labeled
+ (filter (lambda (fs)
+ (eq? (file-system-title fs) 'label))
+ relevant))
+
+ (define uuid
+ (filter (lambda (fs)
+ (eq? (file-system-title fs) 'uuid))
+ relevant))
+
+ (define fail? #f)
+
+ (define (file-system-location* fs)
+ (location->string
+ (source-properties->location
+ (file-system-location fs))))
+
+ (let-syntax ((error (syntax-rules ()
+ ((_ args ...)
+ (begin
+ (set! fail? #t)
+ (format (current-error-port)
+ args ...))))))
+ (for-each (lambda (fs)
+ (unless (find-partition-by-label (file-system-device fs))
+ (error (G_ "~a: error: file system with label '~a' not found~%")
+ (file-system-location* fs)
+ (file-system-device fs))))
+ labeled)
+ (for-each (lambda (fs)
+ (unless (find-partition-by-uuid (file-system-device fs))
+ (error (G_ "~a: error: file system with UUID '~a' not found~%")
+ (file-system-location* fs)
+ (uuid->string (file-system-device fs)))))
+ uuid)
+
+ (when fail?
+ ;; Better be safe than sorry.
+ (exit 1))))
+
+\f
;;;
;;; Action.
;;;
@@ -637,6 +695,13 @@ output when building a system derivation, such as a disk image."
(when (eq? action 'reconfigure)
(maybe-suggest-running-guix-pull))
+ ;; Check whether the declared file systems exist. This is better than
+ ;; instantiating a broken configuration. Assume that we can only check if
+ ;; running as root.
+ (when (and (memq action '(init reconfigure))
+ (zero? (getuid)))
+ (check-file-system-availability (operating-system-file-systems os)))
+
(mlet* %store-monad
((sys (system-derivation-for-action os action
#:file-system-type file-system-type
--
2.14.2
next prev parent reply other threads:[~2017-10-04 19:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-04 19:48 [bug#28706] [PATCH 0/3] Detect wrong UUIDs/labels in 'guix system init/reconfigure' Ludovic Courtès
2017-10-04 19:51 ` [bug#28706] [PATCH 1/3] uuid: Add 'uuid=?' and use it Ludovic Courtès
2017-10-04 19:51 ` [bug#28706] [PATCH 2/3] file-systems: Add a 'location' field to <file-system> Ludovic Courtès
2017-10-05 6:11 ` Danny Milosavljevic
2017-10-04 19:51 ` Ludovic Courtès [this message]
2017-10-05 6:12 ` [bug#28706] [PATCH 3/3] guix system: Error out when passed a wrong file system UUID/label Danny Milosavljevic
2017-10-05 10:12 ` bug#28706: " Ludovic Courtès
2017-10-05 6:11 ` [bug#28706] [PATCH 1/3] uuid: Add 'uuid=?' and use it Danny Milosavljevic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171004195145.4743-3-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=28706@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).