From patchwork Tue Nov 23 22:19:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Poiret X-Patchwork-Id: 34776 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 136C527BBEA; Tue, 23 Nov 2021 22:20:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=no 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 8B65627BBE9 for ; Tue, 23 Nov 2021 22:20:10 +0000 (GMT) Received: from localhost ([::1]:47542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpe93-0001gd-Nv for patchwork@mira.cbaines.net; Tue, 23 Nov 2021 17:20:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpe8w-0001f2-1Q for guix-patches@gnu.org; Tue, 23 Nov 2021 17:20:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:40885) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mpe8v-0000IP-P4 for guix-patches@gnu.org; Tue, 23 Nov 2021 17:20:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mpe8v-00085K-IP for guix-patches@gnu.org; Tue, 23 Nov 2021 17:20:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51878] [PATCH v2] installer: Rework installation device detection Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 23 Nov 2021 22:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51878 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Mathieu Othacehe Cc: Josselin Poiret , 51878@debbugs.gnu.org Received: via spool by 51878-submit@debbugs.gnu.org id=B51878.163770596931023 (code B ref 51878); Tue, 23 Nov 2021 22:20:01 +0000 Received: (at 51878) by debbugs.gnu.org; 23 Nov 2021 22:19:29 +0000 Received: from localhost ([127.0.0.1]:52431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mpe8O-00084J-K5 for submit@debbugs.gnu.org; Tue, 23 Nov 2021 17:19:28 -0500 Received: from jpoiret.xyz ([206.189.101.64]:39814) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mpe8M-000848-2p for 51878@debbugs.gnu.org; Tue, 23 Nov 2021 17:19:27 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 5FAA2184F2B; Tue, 23 Nov 2021 22:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637705964; 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: in-reply-to:in-reply-to:references:references; bh=t4ZGXHawdszxMRxUSfh8YWahLd0zlp2RrCKAk70qxv0=; b=FeUTzE3OzCZCUhu1oKZb9T5nuOdyrKtWDsiLS9RtX6ec3lN+16a6jt7A9dG1XGgH0iIvGq ye1sbxQoid9MvnJHzr4Y2xdZ6GBHDFB/SJ3aNZeVj5cwwn05+K4yOsRBo1ldLv1n9Er68t cwNpvdtaExvda095uUSApaqKGcNQgZj2RYMvfspsbKq8IPG0PGWfbXkeJJa6EvVxn5HSxW ip/K3RVz4489ysZ73Yt74DQuG/dl0riBl1bsf8exekqYHK3lD0mgHlkoNpl2pnsjYsfT8a 3x85O3gS6sHyH0sNvGPj1BvKhOca+sAY/PHyFRSJwqzjtdMoDX+Q3rRGpJmwYQ== Date: Tue, 23 Nov 2021 22:19:09 +0000 Message-Id: <20211123221909.11142-1-dev@jpoiret.xyz> In-Reply-To: <87lf1mhmgw.fsf@gnu.org> References: <87lf1mhmgw.fsf@gnu.org> MIME-Version: 1.0 X-Spamd-Bar: ++++ Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz 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, You're right, I didn't take CDs into account. Here is a new version which compares the device path itself to the --root argument as well, which is the case for CDs. I checked both iso9660 and qcow2 in qemu, and both only list other devices. I didn't quite get your comment about filtering the `(devices)` list. In both cases, we use `remove`, but here I've factored out the predicate used for it. Best, Josselin -- >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 | 53 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/gnu/installer/parted.scm b/gnu/installer/parted.scm index 00de0a30fa..f665e67b35 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,41 @@ (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-installer-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) + (or (string=? the-installer-root-partition-path + (device-path 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))) ;;