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 ms11 with LMTPS id ADYYORkcpV/JfgAA0tVLHw (envelope-from ) for ; Fri, 06 Nov 2020 09:49:13 +0000 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 mD36NBkcpV/zQAAAbx9fmQ (envelope-from ) for ; Fri, 06 Nov 2020 09:49:13 +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 95A0E9402A0 for ; Fri, 6 Nov 2020 09:49:13 +0000 (UTC) Received: from localhost ([::1]:52406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kayMp-0006AL-DV for larch@yhetil.org; Fri, 06 Nov 2020 04:49:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kayLi-0005o9-G4 for guix-patches@gnu.org; Fri, 06 Nov 2020 04:48:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:43588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kayLi-0002fG-6J for guix-patches@gnu.org; Fri, 06 Nov 2020 04:48:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kayLi-0002L4-4Z for guix-patches@gnu.org; Fri, 06 Nov 2020 04:48:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#41143] [PATCH v3 2/2] mapped-devices: Add 'lvm-device-mapping'. Resent-From: Mikhail Tsykalov Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 06 Nov 2020 09:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41143 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: ludo@gnu.org Cc: 41143@debbugs.gnu.org, Mikhail Tsykalov Received: via spool by 41143-submit@debbugs.gnu.org id=B41143.16046560698962 (code B ref 41143); Fri, 06 Nov 2020 09:48:02 +0000 Received: (at 41143) by debbugs.gnu.org; 6 Nov 2020 09:47:49 +0000 Received: from localhost ([127.0.0.1]:55132 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kayLV-0002KT-9d for submit@debbugs.gnu.org; Fri, 06 Nov 2020 04:47:49 -0500 Received: from mail-lj1-f174.google.com ([209.85.208.174]:35774) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kayLS-0002KA-PU for 41143@debbugs.gnu.org; Fri, 06 Nov 2020 04:47:47 -0500 Received: by mail-lj1-f174.google.com with SMTP id 11so730877ljf.2 for <41143@debbugs.gnu.org>; Fri, 06 Nov 2020 01:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=maxqnBOxb+eyJTUPUEz7CfiQdAxY0gIvpmOMXnfgrT0=; b=RBRhyAKIdmqDaIexnj7qphzb/8DendwqDe9BO9vu0z4g8rqBzDUM3311mqDAQps8GX M/1BA18UeRLbOsv3NrRvXzDsRUGbvcDXOJMmiV6Q3DqGD5wiM1JsNO5N55CY9Iqhl6Or W+XaRdImYOSqzbgKBI2ec0521SkWDR4avtmcFp8sKMQP9rgdvPy3oIdbZmF5KJDmx4uk KSesDtyCJPFhI+WRvDAz9hL1oZDXeC6M4GoUN/s7OLf76aAaaD+umopdOcCSFg4yEihU 6ZuaiLqDRB+YUuBcCOq/ZWNeCRI1XQ/haSjfgHYqUlKp9ctQtTjB5yuM5inC8Md4EwDh wdAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=maxqnBOxb+eyJTUPUEz7CfiQdAxY0gIvpmOMXnfgrT0=; b=S2OsjnrSbE3yAWBTZYkhpcLByZNXa2/JLtCVM1sLM/s7J08BscdhfgrRTUZL3HP3ov 9A6VBAdu9G17B/HlCx7mHLDkvUyrIhybCqYX6M+kncEheVN5K22LJM0wN/v4xLT5g2Yx Z4TsgeBo+m3Z3GO2uKeji7BPs2eye8GIQHqmUBFPGWhWLJoVinxdbLu1mmKaKKXLFmvN JZHkhK+QvPm6T7l5QA7yDJIkOsGLzFLpn2X/ng/wUXbUOAWn+Pqo6R9ZQxBgYXkmnKLd HGDbWRPJFkuPH8jBhFdy9HY5ta2KSEE9Awt55XMRm+hymtaqb1BwTvIeGwPNAUcLWsiP 633g== X-Gm-Message-State: AOAM5317NmZfbu5XzG+G0GfhvDQu1rWTTlR2OS2MbAWcRgy9OvP4RbfU MFXDjYH/C/dXC2FFYtk5c2g= X-Google-Smtp-Source: ABdhPJwz7E3gOs3W09UQI/p9sQBM1boD/aOmgfCbo75u5wcvKwOx7jr0b+LFWz60wxy9sgy+1pCs5A== X-Received: by 2002:a2e:b04e:: with SMTP id d14mr432765ljl.38.1604656060967; Fri, 06 Nov 2020 01:47:40 -0800 (PST) Received: from akiha.sknt.ru ([88.201.200.148]) by smtp.googlemail.com with ESMTPSA id f9sm88496ljg.53.2020.11.06.01.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 01:47:40 -0800 (PST) From: Mikhail Tsykalov Date: Fri, 6 Nov 2020 12:47:38 +0300 Message-Id: <20201106094738.132011-2-tsymsh@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201106094738.132011-1-tsymsh@gmail.com> References: <87o8kc5e2w.fsf@gnu.org> <20201106094738.132011-1-tsymsh@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -1.0 (-) 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" X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=RBRhyAKI; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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-Spam-Score: 5.09 X-TUID: A4bLReIy5D3V * gnu/system/mapped-devices.scm (lvm-device-mapping, open-lvm-device, close-lvm-device): New variables. * gnu/tests/install.scm (%lvm-separate-home-os, %lvm-separate-home-os-source, %lvm-separate-home-installation-script, %test-lvm-separate-home-os): New variables. * gnu/system/linux-initrd.scm (raw-initrd): Add (srfi srfi-1) to initrd expression. --- doc/guix.texi | 25 +++++++++- gnu/system/linux-initrd.scm | 1 + gnu/system/mapped-devices.scm | 25 +++++++++- gnu/tests/install.scm | 87 +++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 02b92a9b69..acb6453165 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12713,7 +12713,6 @@ Guix extends this notion by considering any device or set of devices that are @dfn{transformed} in some way to create a new device; for instance, RAID devices are obtained by @dfn{assembling} several other devices, such as hard disks or partitions, into a new one that behaves as one partition. -Other examples, not yet implemented, are LVM logical volumes. Mapped devices are declared using the @code{mapped-device} form, defined as follows; for examples, see below. @@ -12726,7 +12725,8 @@ the system boots up. @item source This is either a string specifying the name of the block device to be mapped, such as @code{"/dev/sda3"}, or a list of such strings when several devices -need to be assembled for creating a new one. +need to be assembled for creating a new one. In case of LVM this is a +string specifying name of the volume group to be mapped. @item target This string specifies the name of the resulting mapped device. For @@ -12735,6 +12735,9 @@ specifying @code{"my-partition"} leads to the creation of the @code{"/dev/mapper/my-partition"} device. For RAID devices of type @code{raid-device-mapping}, the full device name such as @code{"/dev/md0"} needs to be given. +LVM logical volumes of type @code{lvm-device-mapping} need to +be specified as @code{"VGNAME-LVNAME"}. + @item targets This list of strings specifies names of the resulting mapped devices in case there are several. The format is identical to @var{target}. @@ -12758,6 +12761,11 @@ module for the appropriate RAID level to be loaded, such as @code{raid456} for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10. @end defvr +@defvr {Scheme Variable} lvm-device-mapping +This defines LVM logical volume(s). Volume group is activated by +@command{vgchange} command from the package @code{lvm2}. +@end defvr + @cindex disk encryption @cindex LUKS The following example specifies a mapping from @file{/dev/sda3} to @@ -12815,6 +12823,19 @@ Note that the RAID level need not be given; it is chosen during the initial creation and formatting of the RAID device and is determined automatically later. +LVM logical volumes ``alpha'' and ``beta'' from volume group ``vg0'' can +be declared as follows: + +@lisp +(mapped-device + (source "vg0") + (target (list "vg0-alpha" "vg0-beta")) + (type lvm-device-mapping)) +@end lisp + +Devices @file{/dev/mapper/vg0-alpha} and @file{/dev/mapper/vg0-beta} can +then be used as the @code{device} of a @code{file-system} declaration +(@pxref{File Systems}). @node User Accounts @section User Accounts diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index 3e2f1282cc..85e493fecb 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -217,6 +217,7 @@ upon error." (gnu system file-systems) ((guix build utils) #:hide (delete)) (guix build bournish) ;add the 'bournish' meta-command + (srfi srfi-1) ;for lvm-device-mapping (srfi srfi-26) ;; FIXME: The following modules are for diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm index 8b5aec983d..559c27bb28 100644 --- a/gnu/system/mapped-devices.scm +++ b/gnu/system/mapped-devices.scm @@ -36,7 +36,7 @@ #:autoload (gnu build linux-modules) (missing-modules) #:autoload (gnu packages cryptsetup) (cryptsetup-static) - #:autoload (gnu packages linux) (mdadm-static) + #:autoload (gnu packages linux) (mdadm-static lvm2-static) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) @@ -64,7 +64,8 @@ check-device-initrd-modules ;XXX: needs a better place luks-device-mapping - raid-device-mapping)) + raid-device-mapping + lvm-device-mapping)) ;;; Commentary: ;;; @@ -304,4 +305,24 @@ TARGET (e.g., \"/dev/md0\"), using 'mdadm'." (open open-raid-device) (close close-raid-device))) +(define (open-lvm-device source targets) + #~(and + (zero? (system* #$(file-append lvm2-static "/sbin/lvm") + "vgchange" "--activate" "ay" #$source)) + ; /dev/mapper nodes are usually created by udev, but udev may be unavailable at the time we run this. So we create them here. + (zero? (system* #$(file-append lvm2-static "/sbin/lvm") + "vgscan" "--mknodes")) + (every file-exists? (map (lambda (file) (string-append "/dev/mapper/" file)) + '#$targets)))) + + +(define (close-lvm-device source targets) + #~(zero? (system* #$(file-append lvm2-static "/sbin/lvm") + "vgchange" "--activate" "n" #$source))) + +(define lvm-device-mapping + (mapped-device-kind + (open open-lvm-device) + (close close-lvm-device))) + ;;; mapped-devices.scm ends here diff --git a/gnu/tests/install.scm b/gnu/tests/install.scm index dee2b870e8..2d99638ecc 100644 --- a/gnu/tests/install.scm +++ b/gnu/tests/install.scm @@ -65,6 +65,7 @@ %test-btrfs-root-on-subvolume-os %test-jfs-root-os %test-f2fs-root-os + %test-lvm-separate-home-os %test-gui-installed-os %test-gui-installed-os-encrypted @@ -795,6 +796,92 @@ build (current-guix) and then store a couple of full system images.") #:initialization enter-luks-passphrase))))) +;;; +;;; Separate /home on LVM +;;; + +;; Since LVM support in guix currently doesn't allow root-on-LVM we use /home on LVM +(define-os-with-source (%lvm-separate-home-os %lvm-separate-home-os-source) + (use-modules (gnu) (gnu tests)) + + (operating-system + (host-name "separate-home-on-lvm") + (timezone "Europe/Paris") + (locale "en_US.utf8") + + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "/dev/vdb"))) + (kernel-arguments '("console=ttyS0")) + + (mapped-devices (list (mapped-device + (source "vg0") + (target "vg0-home") + (type lvm-device-mapping)))) + (file-systems (cons* (file-system + (device (file-system-label "root-fs")) + (mount-point "/") + (type "ext4")) + (file-system + (device "/dev/mapper/vg0-home") + (mount-point "/home") + (type "ext4") + (dependencies mapped-devices)) + %base-file-systems)) + (users %base-user-accounts) + (services (cons (service marionette-service-type + (marionette-configuration + (imported-modules '((gnu services herd) + (guix combinators))))) + %base-services)))) + +(define %lvm-separate-home-installation-script + "\ +. /etc/profile +set -e -x +guix --version + +export GUIX_BUILD_OPTIONS=--no-grafts +parted --script /dev/vdb mklabel gpt \\ + mkpart primary ext2 1M 3M \\ + mkpart primary ext2 3M 1.6G \\ + mkpart primary 1.6G 3.2G \\ + set 1 boot on \\ + set 1 bios_grub on +pvcreate /dev/vdb3 +vgcreate vg0 /dev/vdb3 +lvcreate -L 1.6G -n home vg0 +vgchange -ay +mkfs.ext4 -L root-fs /dev/vdb2 +mkfs.ext4 /dev/mapper/vg0-home +mount /dev/vdb2 /mnt +mkdir /mnt/home +mount /dev/mapper/vg0-home /mnt/home +df -h /mnt /mnt/home +herd start cow-store /mnt +mkdir /mnt/etc +cp /etc/target-config.scm /mnt/etc/config.scm +guix system init /mnt/etc/config.scm /mnt --no-substitutes +sync +reboot\n") + +(define %test-lvm-separate-home-os + (system-test + (name "lvm-separate-home-os") + (description + "Test functionality of an OS installed with a LVM /home partition") + (value + (mlet* %store-monad ((image (run-install %lvm-separate-home-os + %lvm-separate-home-os-source + #:script + %lvm-separate-home-installation-script + #:packages (list lvm2-static) + #:target-size (* 3200 MiB))) + (command (qemu-command/writable-image image))) + (run-basic-test %lvm-separate-home-os + `(,@command) "lvm-separate-home-os"))))) + + ;;; ;;; Btrfs root file system. ;;; -- 2.20.1