From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: LVM support Date: Tue, 21 Apr 2015 17:52:33 +0200 Message-ID: <87h9s9h41q.fsf@gnu.org> References: <20150415050756.GC6648@venom> <878udt1sj5.fsf@gnu.org> <20150416062401.GD6648@venom> <87twwgxmrr.fsf@gnu.org> <20150417010911.GA610@venom> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkaTX-00045W-4U for guix-devel@gnu.org; Tue, 21 Apr 2015 11:52:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YkaTU-0000Xs-E0 for guix-devel@gnu.org; Tue, 21 Apr 2015 11:52:39 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:36713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkaTU-0000Xo-Aa for guix-devel@gnu.org; Tue, 21 Apr 2015 11:52:36 -0400 Received: from pluto.bordeaux.inria.fr ([193.50.110.57]:38634 helo=pluto) by fencepost.gnu.org with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1YkaTT-0000bS-Ok for guix-devel@gnu.org; Tue, 21 Apr 2015 11:52:36 -0400 In-Reply-To: <20150417010911.GA610@venom> (=?utf-8?B?IlRvbcOhxaEgxIxlY2gi?= =?utf-8?B?J3M=?= message of "Fri, 17 Apr 2015 03:09:11 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org Tom=C3=A1=C5=A1 =C4=8Cech skribis: > On Thu, Apr 16, 2015 at 02:47:52PM +0200, Ludovic Court=C3=A8s wrote: >>Tom=C3=A1=C5=A1 =C4=8Cech skribis: >> >>> On Wed, Apr 15, 2015 at 02:32:14PM +0200, Ludovic Court=C3=A8s wrote: >> >>[...] >> >>>>Sorry I=E2=80=99m not really familiar with LVM. >>> >>> It's implemented using device mapper but instead of mapping one block >>> device to another you map one block device to whole group (like >>> playground where you can do anything). >> >>What do you mean by =E2=80=9Cwhole group=E2=80=9D? A tree under /dev/map= per? > > From device node POV it generates > /dev// and it also creates > /dev/mapper/- and > /dev/dm-. OK. > From block device perspective it adds another level of "partitioning" > to "physical volume" partitions. You gather block devices (can be > partitions, disks, anything), create volume group to join the space > into one entity and then create logical volumes without caring where > it really is. Logical volumes are useful for resizing, adding and > removing filesystems - it has always the same device node. Yes, that part I knew. ;-) [...] > --- 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 >=20=20 > - luks-device-mapping)) > + luks-device-mapping > + lvm-mapping > + lvm-mapping-used?)) >=20=20 > ;;; Commentary: > ;;; > @@ -208,6 +211,27 @@ file." > (open open-luks-device) > (close close-luks-device))) >=20=20 > +(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))) This looks good to me! So I would declare (mapped-device (source "/dev/sda") (target "volume_group_name-logical_volume_name") (kind lvm-device-mapping)) and that would give me /dev/mapper/volume_group_name-logical_volume_name, right? > (define (other-file-system-services os) > "Return file system services for the file systems of OS that are not m= arked > 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))) I don=E2=80=99t think it=E2=80=99s necessary: if a =E2=80=98file-system=E2= =80=99 object has "/dev/mapper/volume_group_name-logical_volume_name" has its =E2=80=98device= =E2=80=99 field, then this device mapping will automatically be recognized as needed-for-boot, won=E2=80=99t it? > --- 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 appea= r." >=20=20 > (boot-system #:mounts '#$(map file-system->spec file-systems) > #:pre-mount (lambda () > - (and #$@device-mapping-commands)) > + (and #$@device-mapping-commands > + ;; If we activated any volume g= roup, we > + ;; need to ensure that device n= odes are > + ;; created. Add code here to c= all it > + ;; once for all activations. > + #$(when (lvm-mapping-used? mapp= ed-devices) > + #~(zero? > + (system* (string-append > + #$lvm2/static > + "/sbin/lvm.sta= tic") > + "vgscan" > + "--mknodes"))))) So =E2=80=98lvm vgchange --activate y=E2=80=99 does not create /dev nodes? = Would it be possible to change the command returned by =E2=80=98logical-volume-group-activate=E2=80=99 to somehow create the nodes= ? That would be ideal. Thanks! Ludo=E2=80=99.