From patchwork Mon Nov 15 21:04:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Poiret X-Patchwork-Id: 34518 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 4D20327BBE1; Mon, 15 Nov 2021 21:05:16 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 1549527BBE3 for ; Mon, 15 Nov 2021 21:05:15 +0000 (GMT) Received: from localhost ([::1]:42194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmjAA-00013S-6U for patchwork@mira.cbaines.net; Mon, 15 Nov 2021 16:05:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmj9y-000137-QO for guix-patches@gnu.org; Mon, 15 Nov 2021 16:05:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44781) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmj9y-0007s6-Hh for guix-patches@gnu.org; Mon, 15 Nov 2021 16:05:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmj9y-0001B1-9v for guix-patches@gnu.org; Mon, 15 Nov 2021 16:05:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51878] [PATCH] installer: Rework installation device detection Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 15 Nov 2021 21:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51878 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51878@debbugs.gnu.org Cc: Josselin Poiret X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16370102684465 (code B ref -1); Mon, 15 Nov 2021 21:05:02 +0000 Received: (at submit) by debbugs.gnu.org; 15 Nov 2021 21:04:28 +0000 Received: from localhost ([127.0.0.1]:56327 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmj9P-00019x-U1 for submit@debbugs.gnu.org; Mon, 15 Nov 2021 16:04:28 -0500 Received: from lists.gnu.org ([209.51.188.17]:43836) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmj9N-00019p-NB for submit@debbugs.gnu.org; Mon, 15 Nov 2021 16:04:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmj9E-0000zY-FX for guix-patches@gnu.org; Mon, 15 Nov 2021 16:04:25 -0500 Received: from jpoiret.xyz ([206.189.101.64]:35916) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmj9C-0007nd-JE for guix-patches@gnu.org; Mon, 15 Nov 2021 16:04:16 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id E7856184D40; Mon, 15 Nov 2021 21:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637010252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=TXnTb3XJlY+soMLCf/Qsz2IIfjTRAAedI3PkeCfH+1A=; b=U6UeN+MZO8Ts7YsGIlBu6rpODUITx1cOE7LrmNw3igxZJi9854okuoJ4fKRIi31Pio3cnJ ZRk4dJkQtocRhlAqBqXp0UnIcQFtpvIVDL46jzVECTDu8+lr0O4/cR76dRZ0hAqMl9fIuy tm4s/3D6VGx7jF08V2trDpUvk8kND+42dJU3sU/hF7CsxXWPwCIDEfglufDb9T42cwSQgH GVizX8LhmlEPmfAN5U23bd0MRlFKs2jSTPO6X1izvWV/Xr1pmJs/O9Myovf8ieEVytM7JR cXXHL6aCF5BKEZTeaPmoNQ7/MHekgHvTK9B+laQJF3h9qn7GtTiGyU6mgGxNlg== Date: Mon, 15 Nov 2021 21:04:04 +0000 Message-Id: <20211115210404.10680-1-dev@jpoiret.xyz> MIME-Version: 1.0 X-Spamd-Bar: ++++ Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz Received-SPF: pass client-ip=206.189.101.64; envelope-from=dev@jpoiret.xyz; helo=jpoiret.xyz X-Spam_score_int: 3 X-Spam_score: 0.3 X-Spam_bar: / X-Spam_report: (0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FROM_SUSPICIOUS_NTLD=0.001, FROM_SUSPICIOUS_NTLD_FP=1.999, PDS_OTHER_BAD_TLD=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches X-Patchwork-Original-From: Josselin Poiret via Guix-patches via From: Josselin Poiret X-getmail-retrieved-from-mailbox: Patches Hello, While testing the installer to add LUKS2 support in a VM, the installer was having trouble detecting which device was the installation one, so I decided to rewrite that part using guile-parted. The old code could not properly detect the device as it was comparing a disk block device path (eg `/dev/sda`) with a partition block device path (`/dev/sda2`). Instead, this patch just iterates over all partitions of each device and tries to find if the root partition is among one of them. Best, Josselin Poiret -- >8 -- * gnu/installer/parted.scm (installation-device): Remove it. * gnu/installer/parted.scm (installer-root-partition-path): Add it. * gnu/installer/parted.scm (non-install-devices): Add installation-device? predicate. --- gnu/installer/parted.scm | 51 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/gnu/installer/parted.scm b/gnu/installer/parted.scm index 00de0a30fa..ea2e26ddad 100644 --- a/gnu/installer/parted.scm +++ b/gnu/installer/parted.scm @@ -26,6 +26,7 @@ (define-module (gnu installer parted) #:use-module ((gnu build file-systems) #:select (canonicalize-device-spec find-partition-by-label + find-partition-by-uuid read-partition-uuid read-luks-partition-uuid)) #:use-module ((gnu build linux-boot) @@ -345,35 +346,39 @@ (define (remove-logical-devices) (with-null-output-ports (invoke "dmsetup" "remove_all"))) -(define (installation-device) - "Return the installation device path." +(define (installer-root-partition-path) + "Return the root partition path, or #f if it could not be detected." (let* ((cmdline (linux-command-line)) (root (find-long-option "--root" cmdline))) (and root - (canonicalize-device-spec (uuid root))))) + (or (and (access? root F_OK) root) + (find-partition-by-label root) + (and=> (uuid root) + find-partition-by-uuid))))) (define (non-install-devices) "Return all the available devices, except the install device." - (define (read-only? device) - (dynamic-wind - (lambda () - (device-open device)) - (lambda () - (device-read-only? device)) - (lambda () - (device-close device)))) - - ;; If parted reports that a device is read-only it is probably the - ;; installation device. However, as this detection does not always work, - ;; compare the device path to the installation device path read from the - ;; command line. - (let ((install-device (installation-device))) - (remove (lambda (device) - (let ((file-name (device-path device))) - (or (read-only? device) - (and install-device - (string=? file-name install-device))))) - (devices)))) + + (define the-intaller-root-partition-path + (installer-root-partition-path)) + + ;; Read partition table of device and compare each path to the one + ;; we're booting from to determine if it is the installation + ;; device. + (define (installation-device? device) + (let ((disk (disk-new device))) + (and disk + (let loop ((partition #f)) + (let ((next-partition (disk-next-partition disk + #:partition + partition))) + (and next-partition + (or (string=? the-installer-root-partition-path + (partition-get-path + next-partition)) + (loop next-partition)))))))) + + (remove installation-device? (devices))) ;;