diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm index caec80f..18d1f06 100644 --- a/gnu/packages/linux.scm +++ b/gnu/packages/linux.scm @@ -1638,6 +1638,33 @@ mapper. Kernel components are part of Linux-libre.") ;; Command-line tools are GPLv2. (license (list gpl2 lgpl2.1)))) +(define-public lvm2/static + (package + (name "lvm2-static") + (version (package-version lvm2)) + (build-system trivial-build-system) + (source #f) + (arguments + `(#:modules ((guix build utils)) + #:builder + (begin + (use-modules (guix build utils)) + (let ((source (string-append (assoc-ref %build-inputs "lvm2") "/sbin")) + (bin (string-append (assoc-ref %outputs "out") "/sbin"))) + (mkdir-p bin) + (for-each (lambda (file) + (copy-file (string-append source "/" file) + (string-append bin "/" file))) + '("lvm.static" "dmsetup.static")))))) + + (native-inputs `(("lvm2" ,lvm2 "static"))) + (synopsis "Statically-linked commands from lvm2") + (description + "This package provides statically-linked binaries dmsetup and lvm taken +from lvm2 package. It is meant to be used in initrds.") + (home-page (package-home-page lvm2)) + (license (package-license lvm2)))) + (define-public wireless-tools (package (name "wireless-tools") diff --git a/gnu/system.scm b/gnu/system.scm index 6cf12df..7c1e67c 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -41,6 +41,7 @@ #:use-module (gnu packages compression) #:use-module (gnu packages firmware) #:autoload (gnu packages cryptsetup) (cryptsetup) + #:autoload (gnu packages linux) (lvm2/static) #:use-module (gnu services) #:use-module (gnu services dmd) #:use-module (gnu services base) @@ -86,7 +87,9 @@ %base-packages %base-firmware - luks-device-mapping)) + luks-device-mapping + lvm-mapping + lvm-mapping-used?)) ;;; Commentary: ;;; @@ -208,6 +211,27 @@ file." (open open-luks-device) (close close-luks-device))) +(define (logical-volume-group-activate source target) + #~(zero? (system* (string-append #$lvm2/static "/sbin/lvm.static") + "vgchange" "--activate" "y" #$target))) + +(define (logical-volume-group-deactivate source target) + #~(zero? (system* (string-append #$lvm2/static "/sbin/lvm.static") + "vgchange" "--activate" "n" #$target))) + +(define (lvm-mapping-used? devices) + (not + (null? (filter + (lambda (md) + (eq? (mapped-device-type md) + lvm-mapping)) + devices)))) + +(define lvm-mapping + (mapped-device-kind + (open logical-volume-group-activate) + (close logical-volume-group-deactivate))) + (define (other-file-system-services os) "Return file system services for the file systems of OS that are not marked as 'needed-for-boot'." @@ -267,7 +291,10 @@ from the initrd." (file-systems (operating-system-file-systems os))) (filter (lambda (md) (let ((user (mapped-device-user md file-systems))) - (and user (file-system-needed-for-boot? user)))) + (or + (and user (file-system-needed-for-boot? user)) + (and (eq? (mapped-device-type md) + lvm-mapping))))) devices))) (define (device-mapping-services os) diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index 83685ad..fc8bbd3 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -25,6 +25,7 @@ #:select (%store-prefix)) #:use-module ((guix derivations) #:select (derivation->output-path)) + #:use-module (gnu system) #:use-module (gnu packages cpio) #:use-module (gnu packages compression) #:use-module (gnu packages linux) @@ -212,6 +213,9 @@ loaded at boot time in the order in which they appear." file-systems) (list e2fsck/static) '()) + ,@(if (lvm-mapping-used? mapped-devices) + (list lvm2/static) + '()) ,@(if volatile-root? (list unionfs-fuse/static) '()))) @@ -241,7 +245,19 @@ loaded at boot time in the order in which they appear." (boot-system #:mounts '#$(map file-system->spec file-systems) #:pre-mount (lambda () - (and address@hidden)) + (and address@hidden + ;; If we activated any volume group, we + ;; need to ensure that device nodes are + ;; created. Add code here to call it + ;; once for all activations. + #$(when (lvm-mapping-used? mapped-devices) + #~(zero? + (system* (string-append + #$lvm2/static + "/sbin/lvm.static") + "vgscan" + "--mknodes"))))) + #:linux-modules '#$linux-modules #:linux-module-directory '#$kodir #:qemu-guest-networking? #$qemu-networking?