Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 453594 - >=sys-fs/lvm2-2.02.98: add systemd support
Summary: >=sys-fs/lvm2-2.02.98: add systemd support
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: Normal normal with 1 vote (vote)
Assignee: Robin Johnson
URL:
Whiteboard:
Keywords:
: 451452 (view as bug list)
Depends on:
Blocks: install-systemd-unit 465244 424637 systemd-love 479464
  Show dependency tree
 
Reported: 2013-01-22 21:59 UTC by Enrico Tagliavini
Modified: 2013-08-31 22:30 UTC (History)
17 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
add systemd support (add_systemd_support.patch,3.12 KB, patch)
2013-01-22 22:20 UTC, Enrico Tagliavini
Details | Diff
add systemd support (add_systemd_support.patch,3.35 KB, patch)
2013-01-30 19:41 UTC, Enrico Tagliavini
Details | Diff
add systemd support (add_systemd_support-v2.patch,3.29 KB, patch)
2013-04-02 18:30 UTC, Enrico Tagliavini
Details | Diff
add systemd support (add_systemd_support-v3.patch,2.30 KB, patch)
2013-04-16 16:07 UTC, Enrico Tagliavini
Details | Diff
add systemd support v2 (lvm2-2.02.98.ebuild.patch,5.80 KB, patch)
2013-06-04 20:01 UTC, Alexander Tsoy
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Enrico Tagliavini 2013-01-22 21:59:02 UTC
With systemd/udev 197 lvm /dev symlinks nodes are no more created automatically for me. I asked in #systemd IRC channel and also looked at how fedora 17 and fedora 18 are working. It turns out a systemd generator or a service unit is needed.

Reproducible: Always

Steps to Reproduce:
1. setup a gentoo box with systemd as init system
2. have an LVM volume marked to automount in fstab like
/dev/mapper/vg_schroedingers-lv_home      /home     ext4    defaults        0 1
3. boot and systemd will fail waiting for the named device
4. drop to a shell and ll /dev/mapper and /dev/VGNAME. the first is empty, the latter doesn't exist



I searched for a solution looking at how fedora handles the problem. Fedora 17 uses a systemd generator, included in the upstream lvm2 package. Fedora 18 uses lvmetad to autodiscover, and the systemd unit files are included by default in the upstream lvm2 package.

In my opinion the lvmetad solution is likely the better one, in the long term. The systemd generator might be discontinued since fedora/redhat will use lvmetad from now on. But for a short term solution the generator is probably a better idea.

I will upload a patch for the last ebuild to add this support.
Comment 1 Enrico Tagliavini 2013-01-22 22:20:39 UTC
Created attachment 336524 [details, diff]
add systemd support

A little disclaimer: this solution is not meant to be final. It is at most a request for comment level, and it is almost not tested given my limited time. It might even boot my system hopefully. 

This patch add systemd support for the last ~amd64 lvm2 ebuild, version 2.02.98 at the time of writing. It add 2 USE flags: systemd and lvmetad, with the latter masked by default for now. lvmetad USE should be set when the user want to use lvmetad by default with LVM. Setting systemd only will install the generator, setting also lvmetad will install lvmetad systemd unit files. You might ask why this is needed: while it should be technically possible to have both the generator and the lvmetad unit files at the same time, thus having the lvm scan 2 times at boot, this doesn't look good to me. You should have one or the other. Also for testing pourpose it is better to not have the generator, and see the fail if lvmetad doesn't work.

But as you can read in the patch, having lvmetad running is not enough. It must be enabled in the lvm.conf file too. Otherwise the boot will probably fail but keep in mind the boot should fail at mounting non root partitions, so you are able to drop to a shell, with your / already mounted in rw and fix this problem very easly (systemd automatically drop to a shell in this case). [The initrd mount / if it is on LVM, not systemd, so the / mount should not fail even if the config is wrong. This needs testing, since e.g. dracut can optionally include lvm.conf in the initramfs. Also genkernel must be checked].

The reason why I say to mask lvmetad for now is the openrc init script is missing, so there is no feature parity with the main gentoo init system, and it is still disabled by default unless enabled in the config file. Worth a bit of testing anyway. This is also the reason why I included the work for lvmetad in this bug instead of filling another one. Note my work for lvmetad is only for systemd support, not for openrc. I think this is the best long term solution, so it is not a separate issue.
Comment 2 Marcin Kowalski 2013-01-24 07:24:17 UTC
tested on ~amd64 box. 

Fixes booting on machine with /var and /home inside of encrypted lvm. 

Root partition is on separate device which is not part of that lvm setup.

Before using this modification, systemd would time out waiting for lvm volumes to appear. Upon entering the recovery shell, the device nodes would already be available. mount -a allowed to resume boot process, restarting mount services would stall and return to recovery shell.

Reinstalling lvm2 with aforementioned lvmetad use flag, enabling lvmetad as a systemd service and in lvm.conf fixes the boot process.
Comment 3 Enrico Tagliavini 2013-01-30 19:41:48 UTC
Created attachment 337336 [details, diff]
add systemd support

This corrects the generator. By default it calls the lvm executable from /usr/sbin but in gentoo it is in /sbin.
Comment 4 Enrico Tagliavini 2013-03-10 15:53:12 UTC
Well I think it is time to ask the opinion of the gentoo LVM2 package maintainers, if not even the inclusion in the main portage tree (probably with lvmetad USE masked). I don't see any major problem with this solution right now, but if you see them, please share :)
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2013-04-02 12:42:51 UTC
To be honest, I'd make all the systemd stuff unconditional. AFAICS it's nothing really big, and it doesn't have external deps. Installing the generator or the unit files does not hurt non-systemd systems, and people who really dislike them have INSTALL_MASK for the paths already.
Comment 6 Enrico Tagliavini 2013-04-02 18:30:52 UTC
Created attachment 344098 [details, diff]
add systemd support

Good point, simpler, less problems. This version does that. When USE lvmetad is not set systemd generator is installed in any case. Unit files are for lvmetad only.

I'm still not really sure if the generator can be installed even if you use lvmetad. In theory it is not a problem, but just to be sure I'm not enabling it for now.
Comment 7 Diego Elio Pettenò (RETIRED) gentoo-dev 2013-04-09 13:04:55 UTC
Hrm, here's my take on this, which I'd try to solve between tonight and tomorrow and then commit:

Introducing the lvmetad USE flag without an OpenRC script is a bad idea; I guess I'll need to set up a VM with LVM2 and test it myself (this cannot work with LXC, unfortunately).

The "use foo || use bar &&" form is tricky and I honestly don't like it — I'll change it to "{ use foo || use bar; } &&"
Comment 8 Enrico Tagliavini 2013-04-09 13:43:46 UTC
(In reply to comment #7)
> Introducing the lvmetad USE flag without an OpenRC script is a bad idea; I
> guess I'll need to set up a VM with LVM2 and test it myself (this cannot
> work with LXC, unfortunately).
> 
> The "use foo || use bar &&" form is tricky and I honestly don't like it —
> I'll change it to "{ use foo || use bar; } &&"

Yeah as I said lvmetad should be there just to start experiment with that, it might even be masked for now. But I think is worth to start introducing this stuff.

About the || && you are right. Better to be strict.

Thank you also for the lvmetad openrc init script
Comment 9 Alexander Tsoy 2013-04-16 14:38:57 UTC
(In reply to comment #6)
> I'm still not really sure if the generator can be installed even if you use
> lvmetad. In theory it is not a problem, but just to be sure I'm not enabling
> it for now.

http://www.redhat.com/archives/lvm-devel/2012-July/msg00072.html

"The lvm2 activation generator generates systemd units conditionally
based on the global/use_lvmetad lvm.conf setting.

If use_lvmetad=0, the lvm2-activation-early.service and lvm2-activation.service
units will be generated. These units are responsible for direct volume activation
by calling "vgchange -aay --sysinit" (this is actually the original on-boot
activation as it was used before). If use_lvmetad=1, no units will be generated
as we're relying on autoactivation."
Comment 10 Enrico Tagliavini 2013-04-16 16:07:27 UTC
Created attachment 345712 [details, diff]
add systemd support

Thank you very much Alexander. I was searching for that, since I was suspecting it. I never had the time to look into it since I was busy with other stuff.

This simplify everything: install systemd stuff in any case, the einfo message might be worded better, and the lvmetad init script for openrc is still missing.
Comment 11 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-18 06:08:51 UTC
Just FYI, I committed a patched ebuild to the systemd-love overlay. Thanks for that!
Comment 12 Enrico Tagliavini 2013-04-18 08:28:31 UTC
(In reply to comment #11)
> Just FYI, I committed a patched ebuild to the systemd-love overlay. Thanks
> for that!

Thank you Fabio
Comment 13 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-25 13:45:32 UTC
The only problem I have with this ebuild (well, the in-tree ebuild doesn't even work...) is that swap on LVM systemd unit activation times out.

apr 25 13:40:54 linux systemd[1]: Job dev-disk-by\x2duuid-eb64434e\x2d8bd8\x2d41ae\x2da235\x2d52a6fd91b909.device/start timed out.
apr 25 13:40:54 linux systemd[1]: Timed out waiting for device dev-disk-by\x2duuid-eb64434e\x2d8bd8\x2d41ae\x2da235\x2d52a6fd91b909.device.
apr 25 13:40:54 linux systemd[1]: Dependency failed for /dev/disk/by-uuid/eb64434e-8bd8-41ae-a235-52a6fd91b909.
apr 25 13:40:54 linux systemd[1]: Starting Swap.
apr 25 13:40:54 linux systemd[1]: Reached target Swap.

This is my fstab entry:
UUID=eb64434e-8bd8-41ae-a235-52a6fd91b909 swap swap defaults 0 0

I don't know (yet) if this is related to this bug or not though.
Comment 14 Enrico Tagliavini 2013-04-25 13:51:00 UTC
Weird, for me it works. I use an encrypted swap, no idea if this makes any difference

/dev/mapper/luks-swap   none            swap            sw              0 0

So I don't use UUIDs here since I use them in crypttab. Also for the rest of fstab I use labels and not UUID. Can you check if the problem happens only with UUIDs?
Comment 15 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-25 13:59:15 UTC
I tried UUIDs because this didn't work:
# /dev/mapper/vg_linux-lv_swap swap                    swap    defaults        0 0

I've seen that the /dev/disk/by-uuid/ (and by-id) symlinks are not generated by udev.
I am using a genkernel initramfs, I wonder if it's mdev messing up or we should move some files over to the final root...
Comment 16 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-25 14:17:21 UTC
On my system /dev/disk/by-* symlinks (by-uuid, by-label, by-id) are not populated for lvm swap partitions.
Comment 17 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-25 14:31:17 UTC
Output of blkid -p -o udev /dev/mapper/vg_linux-lv_swap:
ID_FS_LABEL=swappo
ID_FS_LABEL_ENC=swappo
ID_FS_UUID=eb64434e-8bd8-41ae-a235-52a6fd91b909
ID_FS_UUID_ENC=eb64434e-8bd8-41ae-a235-52a6fd91b909
ID_FS_VERSION=2
ID_FS_TYPE=swap
ID_FS_USAGE=other

Output of udevadm info -q all /dev/mapper/vg_linux-lv_swap:
P: /devices/virtual/block/dm-1
N: dm-1
E: DEVNAME=/dev/dm-1
E: DEVPATH=/devices/virtual/block/dm-1
E: DEVTYPE=disk
E: DM_UDEV_DISABLE_DISK_RULES_FLAG=1
E: DM_UDEV_DISABLE_OTHER_RULES_FLAG=1
E: DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG=1
E: MAJOR=251
E: MINOR=1
E: SUBSYSTEM=block
E: SYSTEMD_READY=0
E: TAGS=:systemd:
E: UDISKS_PRESENTATION_NOPOLICY=1
E: USEC_INITIALIZED=26344


Please note the "SYSTEMD_READY=0" environment variable, which is actually related to the effect I am seeing.
Comment 18 Enrico Tagliavini 2013-04-25 14:34:54 UTC
(In reply to comment #16)
> On my system /dev/disk/by-* symlinks (by-uuid, by-label, by-id) are not
> populated for lvm swap partitions.

On my system they are. I just remembered I have another swap partition. The one for my ubuntu system. The symlink is created:

schroedingherscat ~ # blkid | grep ubuntuswap
/dev/mapper/vg_schroedingers-lv_ubuntuswap: LABEL="ubuntuswap" UUID="cf5b8855-cfa0-4561-96cd-8fa4c72440d0" TYPE="swap" 
schroedingherscat ~ # ll /dev/disk/by-uuid/cf5b8855-cfa0-4561-96cd-8fa4c72440d0
lrwxrwxrwx 1 root root 10 Apr 25 10:15 /dev/disk/by-uuid/cf5b8855-cfa0-4561-96cd-8fa4c72440d0 -> ../../dm-4

Note: I use dracut as initramfs generator. I point this out since you mentioned genkernel, but I have no idea if this can make a difference or not since I don't know genkernel
Comment 19 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-25 15:34:55 UTC
So it looks like that mdev is not setting up the environment* for udev/systemd (*udev hwdb)... :S

Also see:
http://www.mail-archive.com/systemd-devel@lists.freedesktop.org/msg06402.html
Comment 20 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-25 15:36:09 UTC
To fix my issue I'd need to replace mdev with udev in the initramfs. :/
Comment 21 Nikoli 2013-04-25 17:13:56 UTC
Why you are not using dracut?
Comment 22 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-26 00:23:18 UTC
I confirm that migrating the initramfs to udev (from mdev) and moving /run/udev over to the final root fixes the issue.
I will post some patches tomorrow, but they'll be quite invasive.
Comment 23 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-26 13:04:51 UTC
I committed a working ebuild in the systemd-love overlay [1].
They are less painful that what I thought. I have been able to make possible to embed udev through --udev and eventually removed more cruft from the initramfs generation code:
- lvm is now copied from the system (including libs, using copy_binaries()), this because lvm must be compiled with udev support and its udev rules must be placed into the initramfs as well)
- dmraid needs lvm, so the above applies to it as well.

The only thing I am not happy about is that the initramfs generation code has udev rules.d paths hardcoded, and I wonder if it's possible to query the package manager from there.

[1] https://github.com/Sabayon/systemd-love/tree/master/sys-kernel/genkernel
Comment 24 Alexander Tsoy 2013-05-03 20:58:50 UTC
(In reply to comment #20)
> To fix my issue I'd need to replace mdev with udev in the initramfs. :/

Bug 330651 ?
Comment 25 Alexander Tsoy 2013-05-03 21:04:26 UTC
(In reply to comment #24)
> (In reply to comment #20)
> > To fix my issue I'd need to replace mdev with udev in the initramfs. :/
> 
> Bug 330651 ?

Ah.. Sorry, ignore my comment. :)
Comment 26 Alexander Tsoy 2013-06-04 20:01:19 UTC
Created attachment 350132 [details, diff]
add systemd support v2

Changes:
 - install tmpfiles.d config
 - add check for CONFIG_UEVENT_HELPER_PATH kernel config option (bug 451452)
 - remove most unconditional configure options from $myconf variable and append them to econf command
 - add configure option "--with-default-dm-run-dir=/run"
 - replace "--with-systemdsystemunitdir=$(systemd_get_unitdir)" with "$(systemd_with_unitdir)"
 - cleanup old patches


--

+       # when using systemd with lvmetad disabled
+       # a generator is needed for systemd to create /dev nodes
+       # note: this should be already build, but I am not sure
+       # if this is always, or just sometimes, better to force
+       emake -C scripts lvm2_activation_generator_systemd_red_hat

It looks like it always built if sources configured with --enable-applib. But I didn't test this and leave comment and emake as is.
Comment 27 Enrico Tagliavini 2013-06-05 19:49:56 UTC
marked my attachment as obsolete since Alexander's version is an improvement :).

Thank you for that
Comment 28 Pacho Ramos gentoo-dev 2013-07-05 17:08:59 UTC
Any problem with committing changes from systemd-love overlay in a week?
Comment 29 Pacho Ramos gentoo-dev 2013-07-20 13:16:27 UTC
As the changes are not trivial, I would like to see feedback from maintainer :/
Comment 30 Samuli Suominen (RETIRED) gentoo-dev 2013-07-28 10:05:38 UTC
*** Bug 451452 has been marked as a duplicate of this bug. ***
Comment 31 Samuli Suominen (RETIRED) gentoo-dev 2013-08-01 19:02:48 UTC
2.02.99 has upstream systemd files now, it's in portage
Comment 32 Samuli Suominen (RETIRED) gentoo-dev 2013-08-01 19:04:10 UTC
file new bugs if futher patches are required for the ebuild, thanks
Comment 33 Samuli Suominen (RETIRED) gentoo-dev 2013-08-02 06:59:59 UTC
I've just updated lvm2-2.02.99.ebuild again, so wait at least hour before it hits mirrors.
Once you see the latest version of it, modify it and create unified diff and file a new bug if futher changes are required.
Thank you.
Comment 34 Alexander Tsoy 2013-08-02 08:51:59 UTC
bug 451452 is not a dublicate and it is not fixed yet