From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 28 17:40:17 2019 Received: (at 36876) by debbugs.gnu.org; 28 Aug 2019 21:40:17 +0000 Received: from localhost ([127.0.0.1]:51344 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i35fs-0005NM-HP for submit@debbugs.gnu.org; Wed, 28 Aug 2019 17:40:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54809) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i35fo-0005Mz-QF for 36876@debbugs.gnu.org; Wed, 28 Aug 2019 17:40:14 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:56968) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1i35fg-0002mz-M4; Wed, 28 Aug 2019 17:40:04 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=48176 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1i35fb-0000QU-Gt; Wed, 28 Aug 2019 17:40:00 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: zerodaysfordays@sdf.lonestar.org (Jakob L. Kreuze) Subject: Re: bug#36876: guix system delete-generations removes custom boot menu entries References: <20190731094857.28829b11@gmail.com> <8736ifzjfe.fsf@sdf.lonestar.org> <87sgps6p6c.fsf@gnu.org> <87lfvdpaey.fsf@sdf.lonestar.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 11 Fructidor an 227 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Wed, 28 Aug 2019 23:39:55 +0200 In-Reply-To: <87lfvdpaey.fsf@sdf.lonestar.org> (Jakob L. Kreuze's message of "Wed, 28 Aug 2019 11:38:45 -0400") Message-ID: <87r255dl5g.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 36876 Cc: 36876@debbugs.gnu.org, Jesse Gibbons , Danny Milosavljevic X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, zerodaysfordays@sdf.lonestar.org (Jakob L. Kreuze) skribis: > Ludovic Court=C3=A8s writes: > >> I agree with Danny here that parsing the GRUB config wouldn=E2=80=99t be= great. >> >> We have information about the user=E2=80=99s extra menu entries. The is= sue, as >> I see it, as that this information is lost once the system is >> instantiated. >> >> But! We have the structure, that gets serialized with >> the system, and which we could extend with those extra menu entries. >> That way, the info would be preserved, and we can restore them upon >> =E2=80=98delete-generations=E2=80=99. records are bootload= er-independent, >> which is good. >> >> How does that sound? > > Would that involve appending an additional field to > for storing the previous entries? I think that would have the pleasant > side-effect of making the code for deployment/reconfiguration simpler :) Oh that=E2=80=99d be nice. The attached patches should fix this. I=E2=80=99ve successfully deleted a generation on my system. :-) I don=E2=80=99t have extra menu entries thoug= h, so it=E2=80=99d be great if you could give it a try. Thanks, Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-system-Add-bootloader-menu-entries-field-to-boot-par.patch Content-Transfer-Encoding: quoted-printable From 0735c71707a5ea14e43e9adf6125801afa7db1ce Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Ludovic=3D20Court=3DC3=3DA8s?=3D Date: Wed, 28 Aug 2019 23:27:20 +0200 Subject: [PATCH 1/2] system: Add 'bootloader-menu-entries' field to . This allows us to keep track of the extra menu entries specified in the OS configuration. * gnu/system.scm ()[bootloader-menu-entries]: New field. (read-boot-parameters): Initialize it. (operating-system-boot-parameters): Likewise. (operating-system-boot-parameters-file): Serialize it. * gnu/bootloader.scm (menu-entry->sexp, sexp->menu-entry): New procedures. --- gnu/bootloader.scm | 34 ++++++++++++++++++++++++++++++++++ gnu/system.scm | 15 +++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm index a381f67145..03616c12ab 100644 --- a/gnu/bootloader.scm +++ b/gnu/bootloader.scm @@ -2,6 +2,7 @@ ;;; Copyright =C2=A9 2017 David Craven ;;; Copyright =C2=A9 2017 Mathieu Othacehe ;;; Copyright =C2=A9 2017 Leo Famulari +;;; Copyright =C2=A9 2019 Ludovic Court=C3=A8s ;;; ;;; This file is part of GNU Guix. ;;; @@ -23,6 +24,7 @@ #:use-module (guix records) #:use-module (guix ui) #:use-module (srfi srfi-1) + #:use-module (ice-9 match) #:export (menu-entry menu-entry? menu-entry-label @@ -32,6 +34,9 @@ menu-entry-initrd menu-entry-device-mount-point =20 + menu-entry->sexp + sexp->menu-entry + bootloader bootloader? bootloader-name @@ -76,6 +81,35 @@ (default '())) ; list of string-valued gexps (initrd menu-entry-initrd)) ; file name of the initrd as a = gexp =20 +(define (menu-entry->sexp entry) + "Return ENTRY serialized as an sexp." + (match entry + (($ label device mount-point linux linux-arguments initrd) + `(menu-entry (version 0) + (label ,label) + (device ,device) + (device-mount-point ,mount-point) + (linux ,linux) + (linux-arguments ,linux-arguments) + (initrd ,initrd))))) + +(define (sexp->menu-entry sexp) + "Turn SEXP, an sexp as returned by 'menu-entry->sexp', into a +record." + (match sexp + (('menu-entry ('version 0) + ('label label) ('device device) + ('device-mount-point mount-point) + ('linux linux) ('linux-arguments linux-arguments) + ('initrd initrd) _ ...) + (menu-entry + (label label) + (device device) + (device-mount-point mount-point) + (linux linux) + (linux-arguments linux-arguments) + (initrd initrd))))) + ;;; ;;; Bootloader record. diff --git a/gnu/system.scm b/gnu/system.scm index 01be1243fe..a599ba2750 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -116,6 +116,7 @@ boot-parameters-label boot-parameters-root-device boot-parameters-bootloader-name + boot-parameters-bootloader-menu-entries boot-parameters-store-device boot-parameters-store-mount-point boot-parameters-kernel @@ -251,6 +252,8 @@ directly by the user." ;; OS's root file system, so it might be a device path like "/dev/sda3". (root-device boot-parameters-root-device) (bootloader-name boot-parameters-bootloader-name) + (bootloader-menu-entries ;list of + boot-parameters-bootloader-menu-entries) (store-device boot-parameters-store-device) (store-mount-point boot-parameters-store-mount-point) (kernel boot-parameters-kernel) @@ -297,6 +300,11 @@ file system labels." ((_ args) args) (#f 'grub))) ; for compatibility reasons. =20 + (bootloader-menu-entries + (match (assq 'bootloader-menu-entries rest) + ((_ . entries) (map sexp->menu-entry entries)) + (#f '()))) + ;; In the past, we would store the directory name of the kernel inst= ead ;; of the absolute file name of its image. Detect that and correct = it. (kernel (if (string=3D? linux (direct-store-path linux)) @@ -1005,6 +1013,8 @@ such as '--root' and '--load' to ." (operating-system-user-kernel-arguments os))) (initrd initrd) (bootloader-name bootloader-name) + (bootloader-menu-entries + (bootloader-configuration-menu-entries (operating-system-bootloader = os))) (store-device (ensure-not-/dev (file-system-device store))) (store-mount-point (file-system-mount-point store))))) =20 @@ -1046,6 +1056,11 @@ being stored into the \"parameters\" file)." #$(boot-parameters-kernel-arguments params)) (initrd #$(boot-parameters-initrd params)) (bootloader-name #$(boot-parameters-bootloader-name pa= rams)) + (bootloader-menu-entries + #$(map menu-entry->sexp + (or (and=3D> (operating-system-bootloader os) + bootloader-configuration-menu-entri= es) + '()))) (store (device #$(device->sexp (boot-parameters-store-device params= ))) --=20 2.23.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-guix-system-Reinstalling-the-bootloader-preserves-ex.patch From f0c5d8f1479d899ce5e646f7a157c571c9b6d80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Wed, 28 Aug 2019 23:31:28 +0200 Subject: [PATCH 2/2] guix system: Reinstalling the bootloader preserves extra menu entries. Fixes . Reported by Jesse Gibbons . Previously 'guix system delete-generations' or 'switch-generation' would lose the extra bootloader menu entries specified in the current system's configuration. This fixes that. * guix/scripts/system.scm (reinstall-bootloader): Turn PARAMS into a single . Adjust ENTRIES to include extra menu entries specified in PARAMS. --- guix/scripts/system.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 9fc3a10e98..27b014db68 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -384,12 +384,14 @@ STORE is an open connection to the store." (bootloader bootloader))) ;; Make the specified system generation the default entry. - (params (profile-boot-parameters %system-profile (list number))) + (params (first (profile-boot-parameters %system-profile + (list number)))) (old-generations (delv number (reverse (generation-numbers %system-profile)))) (old-params (profile-boot-parameters %system-profile old-generations)) - (entries (map boot-parameters->menu-entry params)) + (entries (cons (boot-parameters->menu-entry params) + (boot-parameters-bootloader-menu-entries params))) (old-entries (map boot-parameters->menu-entry old-params))) (run-with-store store (mlet* %store-monad -- 2.23.0 --=-=-=--