From patchwork Fri Oct 25 09:39:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janneke Nieuwenhuizen X-Patchwork-Id: 69444 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id A624427BBE9; Fri, 25 Oct 2024 10:41:51 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7A02D27BBEA for ; Fri, 25 Oct 2024 10:41:49 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t4Gp3-0002PG-3C; Fri, 25 Oct 2024 05:41:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t4Gp1-0002Or-NC for guix-patches@gnu.org; Fri, 25 Oct 2024 05:41:31 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t4Gp1-0003t3-Ee for guix-patches@gnu.org; Fri, 25 Oct 2024 05:41:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=iS7+3/AESJWRY83J3PsKmVkG2pCZUUpR5Nfk6jFjUR8=; b=elUiIhWu7yxjNJzmQQVUXCha9XNFyTBFMaJ8CBql+qrFHtmNUFfB++6PGlv+K3wZ7aJRBRwNC6y25Tanu1re0A6T2HRnJDgs6wvSkVma9VRuFTd7uOJV3kHexp3a9B9UpnHs19BZdlW6apXOuWDX7MpIvffffS1RFrotwBNbLV8ofWcH3+R/XmszqAOpNrvdw7FyqYKX76aTe6QCVpOBRIHfPMOde3oN6QZl2i6t6bqtTc0MJ1Mdjj+YwxRyBLB145rZbU9Pr9eKJaTxGx05cjvWpMJqABEnj5zoWYaexDIwz0Nspj3AHOf+ejhoALKm0HOjNG5hA8O/dn8Pi3QYpg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t4GpX-00025u-5l for guix-patches@gnu.org; Fri, 25 Oct 2024 05:42:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73927] [PATCH v3 03/17] bootloader: grub: Remove hardcoded partition number for the Hurd. Resent-From: Janneke Nieuwenhuizen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 25 Oct 2024 09:42:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73927 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73927@debbugs.gnu.org Received: via spool by 73927-submit@debbugs.gnu.org id=B73927.17298492787817 (code B ref 73927); Fri, 25 Oct 2024 09:42:03 +0000 Received: (at 73927) by debbugs.gnu.org; 25 Oct 2024 09:41:18 +0000 Received: from localhost ([127.0.0.1]:37305 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t4Gon-00021r-CK for submit@debbugs.gnu.org; Fri, 25 Oct 2024 05:41:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40720) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t4Gof-00020V-CA for 73927@debbugs.gnu.org; Fri, 25 Oct 2024 05:41:10 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t4Go4-0003mV-9C; Fri, 25 Oct 2024 05:40:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=iS7+3/AESJWRY83J3PsKmVkG2pCZUUpR5Nfk6jFjUR8=; b=oIB+PhG8pKSGlNPcZpM0 7hEWAYdylw/jAa+FUlsg/lFu+zSqSxdGtGR/cqmBHV3+kAxy+F6NCqhYhWukRwEUQ1JcKDAgUI4CD snFfPIvpC6HObjsXT8YdCyVJC3sAfhIG1QxkyIlugC86u+2MLT8XVdN4H3FkAQPXmZKOx1YM31bso U2FFVweOpczRuJHittd17QA4+zs3kbY0/9LFkY9VWbCZpnGWdLwZG94u3Kktm619q7UgOSJy3UdXP q7q8R3tC+rQu4LbeE9OTHa7ZRtsQv1ZS+LRiIZ+bgkbX7cLFc+v8A7j0OeKajLpGGUiVcutqCQCWs +1qkRiwWrNb21g==; From: Janneke Nieuwenhuizen Date: Fri, 25 Oct 2024 11:39:55 +0200 Message-ID: <20241025094011.8540-4-janneke@gnu.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025094011.8540-1-janneke@gnu.org> References: <20241025094011.8540-1-janneke@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This supports using another than the default DISK0 PART1 and using LABEL or UUID as root file-system specifier. It still defaults to DISK0 PART1 if the file-system cannot be found, i.e., lives only at the build side: A virtual machine/childhurd build. * gnu/bootloader/grub.scm (%device-spec-regexp): New variable. (string->device-spec, device-spec->hurd-device): Use it in new procedures. (device->hurd-device): New procedure. (make-grub-configuration): Use them to remove hardcoded partition number (root-index 1). Change-Id: I49fa93dacc09883dfb4d695402c5eac2e0e17286 --- gnu/bootloader/grub.scm | 42 +++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index 2723eda5f4..c929af691b 100644 --- a/gnu/bootloader/grub.scm +++ b/gnu/bootloader/grub.scm @@ -3,7 +3,7 @@ ;;; Copyright © 2016 Chris Marusich ;;; Copyright © 2017 Leo Famulari ;;; Copyright © 2017, 2020 Mathieu Othacehe -;;; Copyright © 2019, 2020, 2023 Janneke Nieuwenhuizen +;;; Copyright © 2019, 2020, 2023, 2024 Janneke Nieuwenhuizen ;;; Copyright © 2019, 2020 Miguel Ángel Arruga Vivas ;;; Copyright © 2020 Maxim Cournoyer ;;; Copyright © 2020 Stefan @@ -34,6 +34,7 @@ (define-module (gnu bootloader grub) #:use-module (guix gexp) #:use-module (gnu artwork) #:use-module (gnu bootloader) + #:use-module (gnu build file-systems) #:use-module (gnu system uuid) #:use-module (gnu system file-systems) #:use-module (gnu system keyboard) @@ -45,6 +46,7 @@ (define-module (gnu bootloader grub) #:use-module (ice-9 regex) #:use-module (srfi srfi-1) #:use-module (srfi srfi-2) + #:use-module (srfi srfi-26) #:export (grub-theme grub-theme? grub-theme-image @@ -355,6 +357,34 @@ (define (grub-root-search device file) ((or #f (? string?)) #~(format #f "search --file --set ~a" #$file))))) +(define %device-spec-regexp "/dev/[hsvw]d([abcd])([0-9]*)") +(define (string->device-spec str) + "Return device spec STR as /dev/XdYZ, also catering for uuid or label." + (cond ((string-match %device-spec-regexp str) + str) + ((string->uuid str) + => + find-partition-by-uuid) + (else + (find-partition-by-label str)))) + +(define* (device-spec->hurd-device device-spec #:key (disk "w")) + "Return DEVICE-SPEC as a Hurd device spec: + part:PART-NUMBER:device:DISKdDISK-INDEX +Default to part:1:device:DISKd0 if partition cannot be found." + (let* ((m (and=> device-spec (cute string-match %device-spec-regexp <>))) + (disk-char (and m (and=> (match:substring m 1) (compose car string->list)))) + (disk-index (or (and disk-char (- (char->integer disk-char) (char->integer #\a))) + 0)) + (partition-number (or (and m (and=> (match:substring m 2) string->number)) + 1))) + (format #f "part:~a:device:~ad~a" partition-number disk disk-index))) + +(define* (device->hurd-device device #:key (disk "w")) + "Return DEVICE as a Hurd device spec: part:PART-NUMBER:device:DISKdDISK-INDEX." + (let ((device-spec (canonicalize-device-spec device))) + (device-spec->hurd-device device-spec #:disk disk))) + (define* (make-grub-configuration grub config entries #:key (locale #f) @@ -413,16 +443,16 @@ (define (menu-entry->gexp entry) ;; IDE driver ("hdX") and those understood by rumpdisk ("wdX" ;; in the "noide" case). (disk (if (member "noide" arguments) "w" "h")) - (modules (menu-entry-multiboot-modules entry)) - (root-index 1)) ; XXX EFI will need root-index 2 + (device-string (file-system-device->string device)) + (device-spec (and=> device-string string->device-spec)) + (modules (menu-entry-multiboot-modules entry))) #~(format port " menuentry ~s { - multiboot ~a root=part:~a:device:~ad0~a~a + multiboot ~a root=~a~a~a }~%" #$label #$kernel - #$root-index - #$disk + #$(device-spec->hurd-device device-spec #:disk disk) (string-join (list #$@arguments) " " 'prefix) (string-join (map string-join '#$modules) "\n module " 'prefix))))