From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id IM1jJ4jLkmHKcQEAgWs5BA (envelope-from ) for ; Mon, 15 Nov 2021 22:05:12 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id yCcVI4jLkmHVFAAA1q6Kng (envelope-from ) for ; Mon, 15 Nov 2021 21:05:12 +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 5BA4935380 for ; Mon, 15 Nov 2021 22:05:12 +0100 (CET) Received: from localhost ([::1]:42194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmjA7-00013S-GW for larch@yhetil.org; Mon, 15 Nov 2021 16:05:11 -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 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++ 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+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=1637010312; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=TXnTb3XJlY+soMLCf/Qsz2IIfjTRAAedI3PkeCfH+1A=; b=X+aRDcrzK7YlRMLF/Fev4AC+3GcC/i5AfDnAJKI2T4+xl4L6BV4Niw2O1YOlrFl53xXpQL gmd726p8exFlW6Kre4mXVBUnzLQoVLGCdvsBGzUBKyXyz9bGTX3+2ESfhvB8TLCD51lSg7 ZocbKG7mxMV8A8KD2Ud3/VVOMbVfdoT4xxVc7Q52fUGe9sxcWmCHunwg1kJwR9MUIl3Gxc OZomH9DKAF3+mGxYMUm+u+TolqOJrPl8vhB/Sy3WUVDVjwGK7MsmIAwose1xBulpPspxEC 3Zx1qgQJB6M4wjSvo9IrZAN3Ra9lVhAfhe69Elc1stIVIFCJNGq3OZYJIjVZ+A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637010312; a=rsa-sha256; cv=none; b=Z8zCsT67MtdUNtGJ3pktaYKwZwfU8RG5QF0j/SLtNooY+zOZjJJCSItyTYP/nVNdTJOfyB b7hU/rlWhgew5/8pW4zfcfdA2cqRcZ8Auk9YOgkDKYbiHDRoIevZ9jiPAhtXu0bs7/mgyi g+/aA7SmXUdXeDLGnU1NXnAQ46XbceE0qyDM4qc1ittIktxoR6gARhF4vkv96bxfetA5wQ SeZxUVdiVB6hKhPDfAPeyPBEKNZZsxHFZQJaxzIPKDOczXHTofJC5h+Ys2EzWI2QnJRGOg gujotVgKIPYajdW+0VSCMW1DnlupSP9BayW9y7/s5LXdi9PQKczn3/I0gC6MKw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=U6UeN+MZ; 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: 0.46 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=U6UeN+MZ; 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: 5BA4935380 X-Spam-Score: 0.46 X-Migadu-Scanner: scn1.migadu.com X-TUID: EtHrZ+uDR1jg 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))) ;; -- 2.33.1