From: "Ludovic Courtès" <ludo@gnu.org>
To: 28377@debbugs.gnu.org
Subject: [bug#28377] [PATCH 10/10] vm: Generate a UUID to identify the root file system.
Date: Thu, 7 Sep 2017 00:17:56 +0200 [thread overview]
Message-ID: <20170906221756.17024-10-ludo@gnu.org> (raw)
In-Reply-To: <20170906221756.17024-1-ludo@gnu.org>
This makes collisions less likely than when using a label to look up the
partition. See <https://bugs.gnu.org/27735>.
* gnu/system/vm.scm (operating-system-uuid): New procedure.
(system-disk-image): Define 'root-uuid' and use it for the root file
system. Pass it to 'iso9660-image' and 'qemu-image'.
---
gnu/system/vm.scm | 51 +++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 45 insertions(+), 6 deletions(-)
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 73d830bf0..d947fd605 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -61,6 +61,7 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
+ #:use-module (rnrs bytevectors)
#:use-module (ice-9 match)
#:export (expression->derivation-in-linux-vm
@@ -342,6 +343,35 @@ the image."
;;; VM and disk images.
;;;
+(define* (operating-system-uuid os #:optional (type 'dce))
+ "Compute UUID object with a deterministic \"UUID\" for OS, of the given
+TYPE (one of 'iso9660 or 'dce). Return a UUID object."
+ (if (eq? type 'iso9660)
+ (let ((pad (compose (cut string-pad <> 2 #\0)
+ number->string))
+ (h (hash (operating-system-services os) 3600)))
+ (bytevector->uuid
+ (string->iso9660-uuid
+ (string-append "1970-01-01-"
+ (pad (hash (operating-system-host-name os) 24)) "-"
+ (pad (quotient h 60)) "-"
+ (pad (modulo h 60)) "-"
+ (pad (hash (operating-system-file-systems os) 100))))
+ 'iso9660))
+ (bytevector->uuid
+ (uint-list->bytevector
+ (list (hash file-system-type
+ (expt 2 32))
+ (hash (operating-system-host-name os)
+ (expt 2 32))
+ (hash (operating-system-services os)
+ (expt 2 32))
+ (hash (operating-system-file-systems os)
+ (expt 2 32)))
+ (endianness little)
+ 4)
+ type)))
+
(define* (system-disk-image os
#:key
(name "disk-image")
@@ -358,12 +388,20 @@ to USB sticks meant to be read-only."
(if (string=? "iso9660" file-system-type)
string-upcase
identity))
+
(define root-label
- ;; Volume name of the root file system. Since we don't know which device
- ;; will hold it, we use the volume name to find it (using the UUID would
- ;; be even better, but somewhat less convenient.)
+ ;; Volume name of the root file system.
(normalize-label "GuixSD_image"))
+ (define root-uuid
+ ;; UUID of the root file system, computed in a deterministic fashion.
+ ;; This is what we use to locate the root file system so it has to be
+ ;; different from the user's own file system UUIDs.
+ (operating-system-uuid os
+ (if (string=? file-system-type "iso9660")
+ 'iso9660
+ 'dce)))
+
(define file-systems-to-keep
(remove (lambda (fs)
(string=? (file-system-mount-point fs) "/"))
@@ -387,8 +425,8 @@ to USB sticks meant to be read-only."
;; Force our own root file system.
(file-systems (cons (file-system
(mount-point "/")
- (device root-label)
- (title 'label)
+ (device root-uuid)
+ (title 'uuid)
(type file-system-type))
file-systems-to-keep)))))
@@ -397,7 +435,7 @@ to USB sticks meant to be read-only."
(if (string=? "iso9660" file-system-type)
(iso9660-image #:name name
#:file-system-label root-label
- #:file-system-uuid #f
+ #:file-system-uuid root-uuid
#:os-drv os-drv
#:bootcfg-drv bootcfg
#:bootloader (bootloader-configuration-bootloader
@@ -413,6 +451,7 @@ to USB sticks meant to be read-only."
#:disk-image-format "raw"
#:file-system-type file-system-type
#:file-system-label root-label
+ #:file-system-uuid root-uuid
#:copy-inputs? #t
#:register-closures? #t
#:inputs `(("system" ,os-drv)
--
2.14.1
next prev parent reply other threads:[~2017-09-06 22:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-06 21:51 [bug#28377] [PATCH 00/10] Allow users to specify the UUID of disk images Ludovic Courtès
2017-09-06 22:17 ` [bug#28377] [PATCH 01/10] vm: Allow partitions to be initialized with a given UUID Ludovic Courtès
2017-09-06 22:17 ` [bug#28377] [PATCH 02/10] file-systems: Add UUID type dictionaries Ludovic Courtès
2017-09-11 15:50 ` Danny Milosavljevic
2017-09-11 16:04 ` Ludovic Courtès
2017-09-06 22:17 ` [bug#28377] [PATCH 03/10] services: base: Import the closure of (gnu build file-systems) Ludovic Courtès
2017-09-11 15:52 ` Danny Milosavljevic
2017-09-06 22:17 ` [bug#28377] [PATCH 04/10] file-systems: Introduce (gnu system uuid) Ludovic Courtès
2017-09-11 15:54 ` Danny Milosavljevic
2017-09-06 22:17 ` [bug#28377] [PATCH 05/10] services: file-system: Use 'file-system->spec' Ludovic Courtès
2017-09-11 15:55 ` Danny Milosavljevic
2017-09-06 22:17 ` [bug#28377] [PATCH 06/10] system: Introduce a disjoint UUID type Ludovic Courtès
2017-09-11 16:01 ` Danny Milosavljevic
2017-09-06 22:17 ` [bug#28377] [PATCH 07/10] system: Serialize the UUID type in the "parameters" file Ludovic Courtès
2017-09-11 16:02 ` Danny Milosavljevic
2017-09-06 22:17 ` [bug#28377] [PATCH 08/10] uuid: 'uuid' macro supports more UUID types Ludovic Courtès
2017-09-06 22:17 ` [bug#28377] [PATCH 09/10] vm: Allow users to specify a UUID for the root partition Ludovic Courtès
2017-09-11 16:10 ` Danny Milosavljevic
2017-09-11 20:53 ` bug#28377: " Ludovic Courtès
2017-09-06 22:17 ` Ludovic Courtès [this message]
2017-09-11 16:50 ` [bug#28377] [PATCH 10/10] vm: Generate a UUID to identify the root file system 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170906221756.17024-10-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=28377@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 external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.