From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 5lPsC1vSkmEkAgAAgWs5BA (envelope-from ) for ; Mon, 15 Nov 2021 22:34:19 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id oJLVBlvSkmEMLAAAbx9fmQ (envelope-from ) for ; Mon, 15 Nov 2021 21:34:19 +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 BE38F35999 for ; Mon, 15 Nov 2021 22:34:18 +0100 (CET) Received: from localhost ([::1]:58016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmjcH-0004wi-8t for larch@yhetil.org; Mon, 15 Nov 2021 16:34:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmjc2-0004hx-Jp for guix-patches@gnu.org; Mon, 15 Nov 2021 16:34:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44821) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmjc2-0003Cr-Bp for guix-patches@gnu.org; Mon, 15 Nov 2021 16:34:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmjc2-00020x-9n for guix-patches@gnu.org; Mon, 15 Nov 2021 16:34:02 -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: Mon, 15 Nov 2021 21:34:02 +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: Josselin Poiret Cc: 51878@debbugs.gnu.org Received: via spool by 51878-submit@debbugs.gnu.org id=B51878.16370120087672 (code B ref 51878); Mon, 15 Nov 2021 21:34:02 +0000 Received: (at 51878) by debbugs.gnu.org; 15 Nov 2021 21:33:28 +0000 Received: from localhost ([127.0.0.1]:56363 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmjbU-0001zg-7P for submit@debbugs.gnu.org; Mon, 15 Nov 2021 16:33:28 -0500 Received: from jpoiret.xyz ([206.189.101.64]:39056) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmjbR-0001zX-U9 for 51878@debbugs.gnu.org; Mon, 15 Nov 2021 16:33:26 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 9E0D8184F5D; Mon, 15 Nov 2021 21:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637012004; 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=TCTjsensS/MQ+qswBJfYSOva6SeiV6WJhLyMNpGYly0=; b=ig9zkialW0oJ6vd6ShKGvKhfr3t0ybhISQbxoc/t/yzFytOzp8g8APfYfvvGu5P8Cy/3Fl Pf/d/6mUpifG1yRA+4wq+Q1RVPHUA6ERv2ttUq3Xg4a4cfhZzZYeMoLckBWLw1Td5s/28k 8qeRFrsLIUCdbr2xYFzf7ge6RBe2bRsE7Dh9TCYyFiw8Tr4LRUl/Zaun4M4frEl3ma/O2F CC3K/4JTWzKHq1+wDcjTuq2WUUxWZRoQ6hce/GGMLOXGhebEoWUggdWtBPnPWcg/SWNm7j 2bYYZ1hQlGiTN1r/mW1IJIu7xcJbSZEUz8wPukFLAUGMIMwJP9nn3eihLF8iqQ== Date: Mon, 15 Nov 2021 21:32:32 +0000 Message-Id: <20211115213232.15112-1-dev@jpoiret.xyz> In-Reply-To: <20211115210404.10680-1-dev@jpoiret.xyz> References: <20211115210404.10680-1-dev@jpoiret.xyz> 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1637012058; 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=TCTjsensS/MQ+qswBJfYSOva6SeiV6WJhLyMNpGYly0=; b=pPw8/1DS+NxhQVTeHCbszbhnthsTO1jELE1vfkck4c0UP5E0GEAP0e24/cdUjYHsMy7YR1 UFwbLLPYU9K/XNZ7VXg/j0BEUWdws2d1uCqSlNUZVPGkEEyNljvzBTUxQpBacY3c52/8l2 CSMkK+B229Sm7Zwoz/snQo+xh42kFFNuOLsPkYBeI1Ez/GLv/Hwa12rBLzCC/q8nUmh4yU fzvuoSnOBu2UMJq0S71B1wXFiIVHmv7UBJaUaApfs5c/1+7H4Kcuq0SEAfHaZoOOCALRMO SFCrW4qJFFMImGm7bTj+3IyZnqMn1R9RFtWZT2RPRO0czICoC7gaqp4oKQxJ4Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637012058; a=rsa-sha256; cv=none; b=S5ThsKsgw1lA5EeqguOTbW1p+RKnoGUQk/M6ACs0FyHtwuU9TXyQjMbame38A347e2TMKb YoH8va76aXSZSlOiynTXLFJAqMlHfOMtoG4Mv+70Yuu9wYbAUvYX2kjDbJn/XCdSQ/da2O FfrEfr/pz3cR8BFPTQiwl1E3yB3L0Au/8zuD5nfQl5mLwNqRScF1PWr/+apx1uuvZqGTEV dHa/vEDcGbhHjpJVoGyDfeWofgySeeNTcFEegVpmIwQ4kQUS8rHW1soH+/eyxWZJ+rAGzu vFnE9y4HyJn8m9tElTZ+fzRfJJZu+1X39bdCToH3Erijg7KnJw1S4OLPxx2p1Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=ig9zkial; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 1.66 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=ig9zkial; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: BE38F35999 X-Spam-Score: 1.66 X-Migadu-Scanner: scn1.migadu.com X-TUID: 1qJj1+whG9/i Sorry for the noise, 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..42456a1d18 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-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) + (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