summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Tsykalov <tsymsh@gmail.com>2020-11-06 12:47:38 +0300
committerLudovic Courtès <ludo@gnu.org>2020-11-26 00:05:39 +0100
commita9a2fdaabcc78e7a54d9a6bcfa4ee3de308e9a90 (patch)
tree1852c17d33cc33ce572810f8042fe5c24a7ef235
parent788df2ecd62d5c2fc0d94928f45c947e6393e20b (diff)
mapped-devices: Add 'lvm-device-mapping'.
* 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. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r--doc/guix.texi25
-rw-r--r--gnu/system/linux-initrd.scm1
-rw-r--r--gnu/system/mapped-devices.scm25
-rw-r--r--gnu/tests/install.scm87
4 files changed, 134 insertions, 4 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 13fb4b15315..22102972a33 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -13758,7 +13758,6 @@ Guix extends this notion by considering any device or set of devices that
13758are @dfn{transformed} in some way to create a new device; for instance, 13758are @dfn{transformed} in some way to create a new device; for instance,
13759RAID devices are obtained by @dfn{assembling} several other devices, such 13759RAID devices are obtained by @dfn{assembling} several other devices, such
13760as hard disks or partitions, into a new one that behaves as one partition. 13760as hard disks or partitions, into a new one that behaves as one partition.
13761Other examples, not yet implemented, are LVM logical volumes.
13762 13761
13763Mapped devices are declared using the @code{mapped-device} form, 13762Mapped devices are declared using the @code{mapped-device} form,
13764defined as follows; for examples, see below. 13763defined as follows; for examples, see below.
@@ -13771,7 +13770,8 @@ the system boots up.
13771@item source 13770@item source
13772This is either a string specifying the name of the block device to be mapped, 13771This is either a string specifying the name of the block device to be mapped,
13773such as @code{"/dev/sda3"}, or a list of such strings when several devices 13772such as @code{"/dev/sda3"}, or a list of such strings when several devices
13774need to be assembled for creating a new one. 13773need to be assembled for creating a new one. In case of LVM this is a
13774string specifying name of the volume group to be mapped.
13775 13775
13776@item target 13776@item target
13777This string specifies the name of the resulting mapped device. For 13777This string specifies the name of the resulting mapped device. For
@@ -13780,6 +13780,9 @@ specifying @code{"my-partition"} leads to the creation of
13780the @code{"/dev/mapper/my-partition"} device. 13780the @code{"/dev/mapper/my-partition"} device.
13781For RAID devices of type @code{raid-device-mapping}, the full device name 13781For RAID devices of type @code{raid-device-mapping}, the full device name
13782such as @code{"/dev/md0"} needs to be given. 13782such as @code{"/dev/md0"} needs to be given.
13783LVM logical volumes of type @code{lvm-device-mapping} need to
13784be specified as @code{"VGNAME-LVNAME"}.
13785
13783@item targets 13786@item targets
13784This list of strings specifies names of the resulting mapped devices in case 13787This list of strings specifies names of the resulting mapped devices in case
13785there are several. The format is identical to @var{target}. 13788there are several. The format is identical to @var{target}.
@@ -13803,6 +13806,11 @@ module for the appropriate RAID level to be loaded, such as @code{raid456}
13803for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10. 13806for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10.
13804@end defvr 13807@end defvr
13805 13808
13809@defvr {Scheme Variable} lvm-device-mapping
13810This defines LVM logical volume(s). Volume group is activated by
13811@command{vgchange} command from the package @code{lvm2}.
13812@end defvr
13813
13806@cindex disk encryption 13814@cindex disk encryption
13807@cindex LUKS 13815@cindex LUKS
13808The following example specifies a mapping from @file{/dev/sda3} to 13816The following example specifies a mapping from @file{/dev/sda3} to
@@ -13860,6 +13868,19 @@ Note that the RAID level need not be given; it is chosen during the
13860initial creation and formatting of the RAID device and is determined 13868initial creation and formatting of the RAID device and is determined
13861automatically later. 13869automatically later.
13862 13870
13871LVM logical volumes ``alpha'' and ``beta'' from volume group ``vg0'' can
13872be declared as follows:
13873
13874@lisp
13875(mapped-device
13876 (source "vg0")
13877 (target (list "vg0-alpha" "vg0-beta"))
13878 (type lvm-device-mapping))
13879@end lisp
13880
13881Devices @file{/dev/mapper/vg0-alpha} and @file{/dev/mapper/vg0-beta} can
13882then be used as the @code{device} of a @code{file-system} declaration
13883(@pxref{File Systems}).
13863 13884
13864@node User Accounts 13885@node User Accounts
13865@section User Accounts 13886@section User Accounts
diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 3e2f1282ccc..85e493fecb9 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -217,6 +217,7 @@ upon error."
217 (gnu system file-systems) 217 (gnu system file-systems)
218 ((guix build utils) #:hide (delete)) 218 ((guix build utils) #:hide (delete))
219 (guix build bournish) ;add the 'bournish' meta-command 219 (guix build bournish) ;add the 'bournish' meta-command
220 (srfi srfi-1) ;for lvm-device-mapping
220 (srfi srfi-26) 221 (srfi srfi-26)
221 222
222 ;; FIXME: The following modules are for 223 ;; FIXME: The following modules are for
diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm
index 8b5aec983d1..559c27bb28c 100644
--- a/gnu/system/mapped-devices.scm
+++ b/gnu/system/mapped-devices.scm
@@ -36,7 +36,7 @@
36 #:autoload (gnu build linux-modules) 36 #:autoload (gnu build linux-modules)
37 (missing-modules) 37 (missing-modules)
38 #:autoload (gnu packages cryptsetup) (cryptsetup-static) 38 #:autoload (gnu packages cryptsetup) (cryptsetup-static)
39 #:autoload (gnu packages linux) (mdadm-static) 39 #:autoload (gnu packages linux) (mdadm-static lvm2-static)
40 #:use-module (srfi srfi-1) 40 #:use-module (srfi srfi-1)
41 #:use-module (srfi srfi-26) 41 #:use-module (srfi srfi-26)
42 #:use-module (srfi srfi-34) 42 #:use-module (srfi srfi-34)
@@ -64,7 +64,8 @@
64 check-device-initrd-modules ;XXX: needs a better place 64 check-device-initrd-modules ;XXX: needs a better place
65 65
66 luks-device-mapping 66 luks-device-mapping
67 raid-device-mapping)) 67 raid-device-mapping
68 lvm-device-mapping))
68 69
69;;; Commentary: 70;;; Commentary:
70;;; 71;;;
@@ -304,4 +305,24 @@ TARGET (e.g., \"/dev/md0\"), using 'mdadm'."
304 (open open-raid-device) 305 (open open-raid-device)
305 (close close-raid-device))) 306 (close close-raid-device)))
306 307
308(define (open-lvm-device source targets)
309 #~(and
310 (zero? (system* #$(file-append lvm2-static "/sbin/lvm")
311 "vgchange" "--activate" "ay" #$source))
312 ; /dev/mapper nodes are usually created by udev, but udev may be unavailable at the time we run this. So we create them here.
313 (zero? (system* #$(file-append lvm2-static "/sbin/lvm")
314 "vgscan" "--mknodes"))
315 (every file-exists? (map (lambda (file) (string-append "/dev/mapper/" file))
316 '#$targets))))
317
318
319(define (close-lvm-device source targets)
320 #~(zero? (system* #$(file-append lvm2-static "/sbin/lvm")
321 "vgchange" "--activate" "n" #$source)))
322
323(define lvm-device-mapping
324 (mapped-device-kind
325 (open open-lvm-device)
326 (close close-lvm-device)))
327
307;;; mapped-devices.scm ends here 328;;; mapped-devices.scm ends here
diff --git a/gnu/tests/install.scm b/gnu/tests/install.scm
index 2d62a873ca8..71caa3a4930 100644
--- a/gnu/tests/install.scm
+++ b/gnu/tests/install.scm
@@ -67,6 +67,7 @@
67 %test-btrfs-root-on-subvolume-os 67 %test-btrfs-root-on-subvolume-os
68 %test-jfs-root-os 68 %test-jfs-root-os
69 %test-f2fs-root-os 69 %test-f2fs-root-os
70 %test-lvm-separate-home-os
70 71
71 %test-gui-installed-os 72 %test-gui-installed-os
72 %test-gui-installed-os-encrypted 73 %test-gui-installed-os-encrypted
@@ -798,6 +799,92 @@ build (current-guix) and then store a couple of full system images.")
798 799
799 800
800;;; 801;;;
802;;; Separate /home on LVM
803;;;
804
805;; Since LVM support in guix currently doesn't allow root-on-LVM we use /home on LVM
806(define-os-with-source (%lvm-separate-home-os %lvm-separate-home-os-source)
807 (use-modules (gnu) (gnu tests))
808
809 (operating-system
810 (host-name "separate-home-on-lvm")
811 (timezone "Europe/Paris")
812 (locale "en_US.utf8")
813
814 (bootloader (bootloader-configuration
815 (bootloader grub-bootloader)
816 (target "/dev/vdb")))
817 (kernel-arguments '("console=ttyS0"))
818
819 (mapped-devices (list (mapped-device
820 (source "vg0")
821 (target "vg0-home")
822 (type lvm-device-mapping))))
823 (file-systems (cons* (file-system
824 (device (file-system-label "root-fs"))
825 (mount-point "/")
826 (type "ext4"))
827 (file-system
828 (device "/dev/mapper/vg0-home")
829 (mount-point "/home")
830 (type "ext4")
831 (dependencies mapped-devices))
832 %base-file-systems))
833 (users %base-user-accounts)
834 (services (cons (service marionette-service-type
835 (marionette-configuration
836 (imported-modules '((gnu services herd)
837 (guix combinators)))))
838 %base-services))))
839
840(define %lvm-separate-home-installation-script
841 "\
842. /etc/profile
843set -e -x
844guix --version
845
846export GUIX_BUILD_OPTIONS=--no-grafts
847parted --script /dev/vdb mklabel gpt \\
848 mkpart primary ext2 1M 3M \\
849 mkpart primary ext2 3M 1.6G \\
850 mkpart primary 1.6G 3.2G \\
851 set 1 boot on \\
852 set 1 bios_grub on
853pvcreate /dev/vdb3
854vgcreate vg0 /dev/vdb3
855lvcreate -L 1.6G -n home vg0
856vgchange -ay
857mkfs.ext4 -L root-fs /dev/vdb2
858mkfs.ext4 /dev/mapper/vg0-home
859mount /dev/vdb2 /mnt
860mkdir /mnt/home
861mount /dev/mapper/vg0-home /mnt/home
862df -h /mnt /mnt/home
863herd start cow-store /mnt
864mkdir /mnt/etc
865cp /etc/target-config.scm /mnt/etc/config.scm
866guix system init /mnt/etc/config.scm /mnt --no-substitutes
867sync
868reboot\n")
869
870(define %test-lvm-separate-home-os
871 (system-test
872 (name "lvm-separate-home-os")
873 (description
874 "Test functionality of an OS installed with a LVM /home partition")
875 (value
876 (mlet* %store-monad ((image (run-install %lvm-separate-home-os
877 %lvm-separate-home-os-source
878 #:script
879 %lvm-separate-home-installation-script
880 #:packages (list lvm2-static)
881 #:target-size (* 3200 MiB)))
882 (command (qemu-command/writable-image image)))
883 (run-basic-test %lvm-separate-home-os
884 `(,@command) "lvm-separate-home-os")))))
885
886
887;;;
801;;; Btrfs root file system. 888;;; Btrfs root file system.
802;;; 889;;;
803 890