From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?B?VG9tw6HFoSDEjGVjaA==?= Subject: Re: LVM support Date: Fri, 17 Apr 2015 03:09:11 +0200 Message-ID: <20150417010911.GA610@venom> References: <20150415050756.GC6648@venom> <878udt1sj5.fsf@gnu.org> <20150416062401.GD6648@venom> <87twwgxmrr.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Fba/0zbH8Xs+Fj9o" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiumV-0000T1-UQ for guix-devel@gnu.org; Thu, 16 Apr 2015 21:09:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YiumQ-0006V3-Or for guix-devel@gnu.org; Thu, 16 Apr 2015 21:09:19 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53612 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiumQ-0006Uz-ED for guix-devel@gnu.org; Thu, 16 Apr 2015 21:09:14 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 50E72ACBA for ; Fri, 17 Apr 2015 01:09:13 +0000 (UTC) Content-Disposition: inline In-Reply-To: <87twwgxmrr.fsf@gnu.org> 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 --Fba/0zbH8Xs+Fj9o Content-Type: multipart/mixed; boundary="wac7ysb48OaltWcw" Content-Disposition: inline --wac7ysb48OaltWcw Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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/mapp= er? =46rom device node POV it generates /dev// and it also creates /dev/mapper/- and /dev/dm-. =46rom 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. > >>>Technically, if LVM volumes are mapped devices, the best would be to >>>define a structure for them, as discussed on IRC >>>(like =E2=80=98luks-device-mapping=E2=80=99 in (gnu system).) >> >> I didn't like the idea first because it felt confusing and >> unatural. Words like `mapping' and `source' and `target' are >> misleading. But from programming POV it seems to be the easisest >> approach in the end. > >I would think the terms are pretty descriptive, esp. when looking at the >corresponding section of the manual, but I=E2=80=99m biased. ;-) I meant in LVM context of course. >Now, my understanding of your message is not so much that the terms are >misleading, but rather that the abstraction is bogus (which appears to >be the case based on what you say.) > >> On the other hand problem starts with need-for-boot?. Device mapped >> device will be activated during the boot (which is desirable for LVM) >> only if there is filesystem which uses such device and has >> `need-for-boot?' set to #t. > >Right. I was hesitant about this approach actually, see 9cb426b8. Ah, OK, I didn't updated since I started to work on LVM. >> I needed to tweak operating-system-boot-mapped-devices to not filter >> mappings of the new type at all. Now it seems to generate initrd >> capable of booting root filesystem from LVM :) > >Nice! Could you post your working version of the patch, just to make >things more concrete? I attach patch to this mail. >> The thing is that this design is not nice. I always admired Scheme's >> power in expressing things naturally. mapped-device interface is for >> mapping 1 block device to 1 block device which will contain 1 >> filesystem. > >Understood. This has nothing to do with Scheme, really. :-) > >> Design I'm thinking about would follow file-system structure. For >> device property (I'm not sure if this is proper word in Scheme for >> item of record type) to define functions like `partition' (disk, >> number), `mapped-device' (source, target, type), `logical-volume' (group, >> volume) and whatever would be needed further. You could then express >> your mount in more powerful way like: >> >> (partition "sda" 1) >> >> (mapped-device >> (partition "sda" 2) >> "encrypted_swap" >> luks-mapping-type) >> >> (logical-volume >> "system_group" >> "root") >> >> >> (mapped-device >> (logical-volume "some_group" "some_volume") >> "encrypted data" >> luks-mapping-type) >> >> etc. > >I see. Looks good! > >Does the volume some_group/some_volume have an associated /dev node or >tree? What does it look like? Yes, it does, I described above. >Really a detail, but I think "/dev/sda2" or (partition "/dev/sda2") is >enough; no need to abstract it, IMO, since device node name is up to the >user. Well, I faced situations where such freedom of expression would be handy, but there were rare. sda says that it is the first found scsi device in the system but it doesn't say anything about accessibility of the device (`local-disk' should be introduced as well I think). >> Of course, it would lead to more complicated code to handle such >> configuration, but it would definitely feel more natural. >> >> When other block device type (like iSCSI) would be required, just >> another function (or whatever it is) would be implemented. > >Anything special about iSCSI? I would expect iSCSI partitions/disks to >just have block devices as usual, no? Yes, but when you have root filesystem on iSCSI, you need to perform other actions to make that block device available as with device mapping or LVM... (You need to configure and establish connection to iSCSI target.) Ad the progress - current state of the patch is that it should work for filesystems mounted from initrd. And is ugly. As I understand the problem, created device nodes are missing after switch-root and it seems it tried to mount filesystems before starting eudev. I'll have a look on that again after some sleep. Thank you for your comments. S_W --wac7ysb48OaltWcw Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="lvm.patch" Content-Transfer-Encoding: quoted-printable 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)))) =20 +(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") "/s= bin")) + (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 ta= ken +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 =20 - luks-device-mapping)) + luks-device-mapping + lvm-mapping + lvm-mapping-used?)) =20 ;;; Commentary: ;;; @@ -208,6 +211,27 @@ file." (open open-luks-device) (close close-luks-device))) =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))) + (define (other-file-system-services os) "Return file system services for the file systems of OS that are not mar= ked 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))) =20 (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." =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 gro= up, we + ;; need to ensure that device nod= es are + ;; created. Add code here to cal= l it + ;; once for all activations. + #$(when (lvm-mapping-used? mapped= -devices) + #~(zero? + (system* (string-append + #$lvm2/static + "/sbin/lvm.stati= c") + "vgscan" + "--mknodes"))))) + #:linux-modules '#$linux-modules #:linux-module-directory '#$kodir #:qemu-guest-networking? #$qemu-networking? --wac7ysb48OaltWcw-- --Fba/0zbH8Xs+Fj9o Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlUwXTQACgkQ37XrCapiVCP0RgCgploXlgAokFaKh/FqO8AxL7WG uXMAnimlXM8TaS7U+W7AxKu9KH2ThYL9 =V6ol -----END PGP SIGNATURE----- --Fba/0zbH8Xs+Fj9o--