>From fc2d8dc30c04677ebf553b02227dc10b0be49665 Mon Sep 17 00:00:00 2001 From: Andreas Enge Date: Thu, 14 Jul 2016 15:51:59 +0200 Subject: [PATCH] system: Add mapped devices for RAID. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/system/mapped-devices.scm (raid-device-mapping, open-raid-device, close-raid-device): New variables. * doc/guix.texi (Mapped Devices): Add documentation for RAID devices, reorganize documentation for LUKS devices. Co-authored-by: Ludovic Courtès --- doc/guix.texi | 113 +++++++++++++++++++++++++++--------------- gnu/system/mapped-devices.scm | 29 ++++++++++- 2 files changed, 102 insertions(+), 40 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 393efab..ddeeb71 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6946,6 +6946,7 @@ and unmount user-space FUSE file systems. This requires the @cindex mapped devices The Linux kernel has a notion of @dfn{device mapping}: a block device, such as a hard disk partition, can be @dfn{mapped} into another device, +usually in @code{/dev/mapper/}, with additional processing over the data that flows through address@hidden that the address@hidden makes no difference between the concept of a ``mapped device'' and that of a file system: both boil down @@ -6955,42 +6956,14 @@ devices, like file systems, using the generic @dfn{translator} mechanism (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A typical example is encryption device mapping: all writes to the mapped device are encrypted, and all reads are deciphered, transparently. +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: - address@hidden -(mapped-device - (source "/dev/sda3") - (target "home") - (type luks-device-mapping)) address@hidden example - -Or, better yet, like this: - address@hidden -(mapped-device - (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44")) - (target "home") - (type luks-device-mapping)) address@hidden example - address@hidden disk encryption address@hidden LUKS -This example specifies a mapping from @file{/dev/sda3} to address@hidden/dev/mapper/home} using LUKS---the address@hidden://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a -standard mechanism for disk encryption. In the second example, the UUID -(unique identifier) is the LUKS UUID returned for the device by a -command like: - address@hidden -cryptsetup luksUUID /dev/sdx9 address@hidden example - -The @file{/dev/mapper/home} -device can then be used as the @code{device} of a @code{file-system} -declaration (@pxref{File Systems}). The @code{mapped-device} form is -detailed below. +Mapped devices are declared using the @code{mapped-device} form, +defined as follows; for examples, see below. @deftp {Data Type} mapped-device Objects of this type represent device mappings that will be made when @@ -6998,13 +6971,17 @@ the system boots up. @table @code @item source -This string specifies the name of the block device to be mapped, such as address@hidden"/dev/sda3"}. +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. @item target -This string specifies the name of the mapping to be established. For -example, specifying @code{"my-partition"} will lead to the creation of +This string specifies the name of the resulting mapped device. For +kernel mappers such as encrypted devices of type @code{luks-device-mapping}, +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. @item type This must be a @code{mapped-device-kind} object, which specifies how @@ -7018,6 +6995,64 @@ command from the package with the same name. It relies on the @code{dm-crypt} Linux kernel module. @end defvr address@hidden {Scheme Variable} raid-device-mapping +This defines a RAID device, which is assembled using the @code{mdadm} +command from the package with the same name. It requires a Linux kernel +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. address@hidden defvr + address@hidden disk encryption address@hidden LUKS +The following example specifies a mapping from @file{/dev/sda3} to address@hidden/dev/mapper/home} using LUKS---the address@hidden://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a +standard mechanism for disk encryption. +The @file{/dev/mapper/home} +device can then be used as the @code{device} of a @code{file-system} +declaration (@pxref{File Systems}). + address@hidden +(mapped-device + (source "/dev/sda3") + (target "home") + (type luks-device-mapping)) address@hidden example + +Alternatively, to become independent of device numbering, one may obtain +the LUKS UUID (@dfn{unique identifier}) of the source device by a +command like: + address@hidden +cryptsetup luksUUID /dev/sda3 address@hidden example + +and use it as follows: + address@hidden +(mapped-device + (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44")) + (target "home") + (type luks-device-mapping)) address@hidden example + +A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1} +may be declared as follows: + address@hidden +(mapped-device + (source (list "/dev/sda1" "/dev/sdb1")) + (target "/dev/md0") + (type raid-device-mapping)) address@hidden example + +The @file{/dev/md0} device can then be used as the @code{device} of a address@hidden declaration (@pxref{File Systems}). +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. + + @node User Accounts @subsection User Accounts diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm index 732f73c..d0a9f02 100644 --- a/gnu/system/mapped-devices.scm +++ b/gnu/system/mapped-devices.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès +;;; Copyright © 2016 Andreas Enge ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,6 +23,7 @@ #:use-module (gnu services) #:use-module (gnu services shepherd) #:autoload (gnu packages cryptsetup) (cryptsetup) + #:autoload (gnu packages linux) (mdadm) #:use-module (srfi srfi-1) #:use-module (ice-9 match) #:export (mapped-device @@ -38,7 +40,8 @@ device-mapping-service-type device-mapping-service - luks-device-mapping)) + luks-device-mapping + raid-device-mapping)) ;;; Commentary: ;;; @@ -127,4 +130,28 @@ (open open-luks-device) (close close-luks-device))) +(define (open-raid-device source target) + "Return a gexp that assembles SOURCE (a list of devices) to the RAID device +TARGET, using 'mdadm'." + #~(let ((every (@ (srfi srfi-1) every))) + (let loop () + (unless (every file-exists? '#$source) + (format #t "waiting a bit...~%") + (sleep 1) + (loop))) + (zero? (system* (string-append #$mdadm "/sbin/mdadm") + "--assemble" #$target + address@hidden)))) + +(define (close-raid-device source target) + "Return a gexp that stops the RAID device TARGET." + #~(zero? (system* (string-append #$mdadm "/sbin/mdadm") + "--stop" #$target))) + +(define raid-device-mapping + ;; The type of RAID mapped devices. + (mapped-device-kind + (open open-raid-device) + (close close-raid-device))) + ;;; mapped-devices.scm ends here -- 2.9.0