You are not logged in.

#1 2022-11-21 03:51:37

osteichthyes
Member
Registered: 2016-04-20
Posts: 38

Issue with systemd when setting up decrypt on login

I'm building out a new laptop (a framework -- I'm quite impressed -- but I digress).

I've contributed to/used the auto-mount at login setup on the wiki a half dozen or more times, under a variety of distros (including two Arch laptops). I've never seen this issue before.

On the framework laptop, I'm having an issue with the final systemd unit script:

[Unit]
DefaultDependencies=no
BindsTo=dev-PARTITION.device
After=dev-PARTITION.device
BindsTo=dev-mapper-home\x2dusername.device
Requires=home-username.mount
Before=home-username.mount
Conflicts=umount.target
Before=umount.target

[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutSec=0
ExecStop=/usr/bin/cryptsetup close home-username

[Install]
RequiredBy=dev-mapper-home\x2dusername.device

This unit should lock/close the device on logout.

I've written the script, but when I go to install/enable it, I get the following error:

Unit /etc/systemd/system/cryptsetup-homeusername.service is added as a dependency to a non-existent unit dev-mapper-homeusername.device.

I understand the script hyphenates the mapper differently, I've just copy/pasted from the script in the wiki. Everything is consistently hyphenated/named

however, despite this error, /dev/mapper/homeusername exists.
When I use systemctl status dev-mapper-homeusername, I get the following:

● dev-mapper-homeusername.device - /dev/mapper/homeusername
    Follows: unit currently follows state of sys-devices-virtual-block-dm\x2d0.device
     Loaded: loaded
     Active: active (plugged) since Sun 2022-11-20 21:25:36 CST; 22min ago
      Until: Sun 2022-11-20 21:25:36 CST; 22min ago
     Device: /sys/devices/virtual/block/dm-0

Nov 20 21:25:36 frameWork systemd[1]: Condition check resulted in /dev/mapper/homeusername being skipped.

So, why is it showing up as an active device unit, but the unit appears non-existent on installation of a dependent unit?
Any ideas/guidance?

Last edited by osteichthyes (2022-11-21 15:45:41)

Offline

#2 2022-11-21 03:54:59

osteichthyes
Member
Registered: 2016-04-20
Posts: 38

Re: Issue with systemd when setting up decrypt on login

I've also tried changing the installation to block to:

RequiredBy=sys-devices-virtual-block-dm\x2d0.device

This also resulted in the same error.

Offline

#3 2022-11-21 15:29:29

osteichthyes
Member
Registered: 2016-04-20
Posts: 38

Re: Issue with systemd when setting up decrypt on login

This probably belongs in NC, my mistake, if someone could move it.

Thanks!

Offline

#4 2022-11-21 17:06:23

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: Issue with systemd when setting up decrypt on login

Moved. by request.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2022-11-22 17:49:17

osteichthyes
Member
Registered: 2016-04-20
Posts: 38

Re: Issue with systemd when setting up decrypt on login

I have a hunch that by posting this in the wrong forum, it was lost in the shuffle, so I hope a comment will get it noticed in NC.

I'm thinking this is a udev issue or something? Why would a device unit have an active status and yet yield an error when making dependents upon it?

Offline

#6 2022-11-23 02:19:30

osteichthyes
Member
Registered: 2016-04-20
Posts: 38

Re: Issue with systemd when setting up decrypt on login

It occurred to me today that this is the first time I've used luks2 with these scripts.

Offline

#7 2022-11-23 03:01:54

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: Issue with systemd when setting up decrypt on login

Your thread will be noticed just about anywhere on the forums.  The best way to get more attention is to add more relevant information about what you have learned or discovered in your search for an answer.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#8 2022-11-23 03:42:02

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,130

Re: Issue with systemd when setting up decrypt on login

Why is it interested in dev-mapper-homeusername.device when you specified dev-mapper-home\x2dusername.device? Isn't that the difference between /dev/mapper/homeusername and /dev/mapper/home-username? Is it correct that

Requires=home-username.mount
Before=home-username.mount

aren't escaped?

Last edited by cfr (2022-11-23 03:46:58)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#9 2022-11-23 17:21:57

osteichthyes
Member
Registered: 2016-04-20
Posts: 38

Re: Issue with systemd when setting up decrypt on login

cfr wrote:

Why is it interested in dev-mapper-homeusername.device when you specified dev-mapper-home\x2dusername.device? Isn't that the difference between /dev/mapper/homeusername and /dev/mapper/home-username? Is it correct that

Requires=home-username.mount
Before=home-username.mount

aren't escaped?


I apologize for the confusion, I used homeusername instead of home-username. All of the files are consistently hyphenated, but I copied the codeblock from the wiki, even though the actual used names are obviously specific to my system. In short, they both are homeusername. Sorry.

I believe because those are unit names, they aren't escaped, but device units are escaped. Honestly, I'm not really clear on when/why the escaping happens. But, this is how they are written in the wiki. I've had success with it in the past.

I think the escapes are correct.

The hyphenation issue is also consistent on the actual system (I didn't yet have internet on that system when I was writing this so I mostly copy/pasted).

The bigger question I have is why systemd claims a device unit that definitely exists is claimed not to exist.

Offline

#10 2022-11-23 23:22:45

osteichthyes
Member
Registered: 2016-04-20
Posts: 38

Re: Issue with systemd when setting up decrypt on login

In an effort to clear up the confusion, here's the actual unit file:

[Unit]
DefaultDependencies=no
BindsTo=dev-disk-by\x2dpartlabel-homeScott.device
After=dev-disk-by\x2dpartlabel-homeScott.device
BindsTo=dev-mapper-homescott.device
Requires=home-scott.mount
Before=home-scott.mount
Conflicts=umount.target
Before=umount.target

[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutSec=0
ExecStop=/usr/bin/cryptsetup close homescott

[Install]
RequiredBy=dev-mapper-homescott.device

Which, when enabled, yields the following error:

Unit /etc/systemd/system/cryptsetup-scott.service is added as a dependency to a non-existent unit dev-mapper-homescott.device.

But once installed, I can check the status:

● cryptsetup-scott.service
     Loaded: loaded (/etc/systemd/system/cryptsetup-scott.service; enabled; preset: disabled)
     Active: active (exited) since Wed 2022-11-23 16:59:16 CST; 21min ago

Nov 23 16:59:16 frameWork systemd[1]: Finished cryptsetup-scott.service.

and

 dev-mapper-homescott.device - /dev/mapper/homescott
    Follows: unit currently follows state of sys-devices-virtual-block-dm\x2d0.device
     Loaded: loaded
     Active: active (plugged) since Wed 2022-11-23 16:59:16 CST; 22min ago
      Until: Wed 2022-11-23 16:59:16 CST; 22min ago
     Device: /sys/devices/virtual/block/dm-0

Nov 23 16:59:16 frameWork systemd[1]: Condition check resulted in /dev/mapper/homescott being skipped.

Offline

#11 2022-11-24 00:01:34

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,425

Re: Issue with systemd when setting up decrypt on login

Are you sure it's homescott and not homeScott as well on the dev mapper? Did you run the paths you are referring to through

systemd-escape -p

as recommended to get the correct escape sequences?

Offline

#12 2022-11-24 00:18:30

osteichthyes
Member
Registered: 2016-04-20
Posts: 38

Re: Issue with systemd when setting up decrypt on login

V1del wrote:

Are you sure it's homescott and not homeScott as well on the dev mapper? Did you run the paths you are referring to through

systemd-escape -p

as recommended to get the correct escape sequences?


I did.

Ok, so I did some more playing. It seems to work, despite the error. I think device units appear to be treated uniquely by systemd as they do not have unit files. I'm confused, this seems to be resolved in that it seems to work, but I believe the warning is erroneous.

Last edited by osteichthyes (2022-11-24 00:18:54)

Offline

Board footer

Powered by FluxBB