mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
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>
This commit is contained in:
parent
788df2ecd6
commit
a9a2fdaabc
4 changed files with 134 additions and 4 deletions
|
@ -13758,7 +13758,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.
|
||||
|
@ -13771,7 +13770,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
|
||||
|
@ -13780,6 +13780,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}.
|
||||
|
@ -13803,6 +13806,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
|
||||
|
@ -13860,6 +13868,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
|
||||
|
|
|
@ -217,6 +217,7 @@ (define kodir
|
|||
(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
|
||||
|
|
|
@ -36,7 +36,7 @@ (define-module (gnu system mapped-devices)
|
|||
#: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 @@ (define-module (gnu system mapped-devices)
|
|||
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 @@ (define raid-device-mapping
|
|||
(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
|
||||
|
|
|
@ -67,6 +67,7 @@ (define-module (gnu tests install)
|
|||
%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
|
||||
|
@ -796,6 +797,92 @@ (define %test-encrypted-root-os
|
|||
(run-basic-test %encrypted-root-os command "encrypted-root-os"
|
||||
#: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.
|
||||
|
|
Loading…
Reference in a new issue