From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id um+XKxlpnWG7QwAAgWs5BA (envelope-from ) for ; Tue, 23 Nov 2021 23:20:09 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id qNKVJhlpnWH0KAAA1q6Kng (envelope-from ) for ; Tue, 23 Nov 2021 22:20:09 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 100432A1CE for ; Tue, 23 Nov 2021 23:20:09 +0100 (CET) Received: from localhost ([::1]:47542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpe91-0001gd-3U for larch@yhetil.org; Tue, 23 Nov 2021 17:20:07 -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 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++ 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches From: Josselin Poiret via Guix-patches via X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1637706009; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=t4ZGXHawdszxMRxUSfh8YWahLd0zlp2RrCKAk70qxv0=; b=QoVrPpGTozLZ0F2LM4JjsldOlOPTmTOi61xDh7SK2u8VSuhzawzri0nZU1GuyhDnDPmLLD wkfspMrj12iGajM8e3MacpKxS6X295OVParoFsCfo4MshaP4EwZFrOIuXSklaPKd5heM2f iI7643ExqrP/hM3QOvy+sdxSrUZpIqF1TFCnoktNbOtP7IA2oyvSc7xV296FmXJXkvr402 GAt69rb7YlQ/CMdRDd8mxbKPaRmchUB/k1Q3fF33zB3+CgajUuprieta+JoCHNiZjkh5hN +V65ds/3I5+rwlZISoI/7SH7i6ZuFVTMuG1I6fpzumkSvRGO0lfgz/a7PJGbdA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637706009; a=rsa-sha256; cv=none; b=tAhVYMso38ZHxEmWml5DPj3kpdl7/3HlPF7f6cGm/YShwJy/9U5+Xsa73z0qPDjdMztFA9 7yPeybOQL4Ulz5DC4LYeblmm/TMpyS43mMfAh2R0mmRzP9IsHnhXoLE3HVUl5+/Ya0Sw8A /249vxVoad2oNeBHSeAOfX36bd3p7VqSAF3JXgzrhMTlz/sXssDD+HFZLh5lzppDLR/3DH OICTeZO+N1Ye3XizFJSKpCewu4CAB0gv9bxp12MfscXeWtzKCo4VxnhtV/yB6bg7kol+l2 UbFUDrlt1lrRi0qHw0G4WhXclNRfAna1DQmNaXdMaLUk8iGaJrwk0XXfWW7MXw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=FeUTzE3O; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.89 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=FeUTzE3O; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 100432A1CE X-Spam-Score: -2.89 X-Migadu-Scanner: scn0.migadu.com X-TUID: Y68h+5mHBWep 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))) ;; -- 2.33.1