On 2024-01-26, Nicolas George <geo...@nsup.org> wrote:
> Curt (12024-01-26):
>> A play-sound.timer unit file in /usr/lib/systemd/system-generators/initrd
>> directory.
>
> I see no mention of this directory on the web. Where did yo find the
> idea of using it, I want to check the doc.

I guess that path should've been /usr/local/lib/systemd/system-generators/*.

https://manpages.debian.org/testing/systemd/systemd.generator.7.en.html

> And what should I put in the timer file to express “when a password is
> asked”?

> In fact, what relation do you see between a timer and cryptsetup asking
> for a password?
>


**Step 1: Create the Timer Unit File**

1. Create a timer unit file named `play-sound-cryptsetup.timer` in the
`/usr/local/lib/systemd/system-generators/initrd` directory.

2. Add the following content to the `play-sound-cryptsetup.timer` file:

```
[Unit]
Description=Play sound when cryptsetup prompts for a password

[Timer]
OnBootSec=0

[Install]
WantedBy=initrd.target
```
This timer will be triggered immediately after the initrd is loaded, ensuring
the sound is played at the very beginning of the boot process.

**Step 2: Create the Service Unit File**

1. Create a service unit file named `play-sound-cryptsetup.service` in the same
directory as the timer unit file 
(`/usr/local/lib/systemd/system-generators/initrd`).

2. Add the following content to the `play-sound-cryptsetup.service` file:

```
[Unit]
Description=Play sound when cryptsetup prompts for a password

[Service]
Type=oneshot
ExecStart=/usr/bin/cryptsetup --key-file /dev/null open-dialog cryptluks
ExecStartPost=/bin/play -q /path/to/your/sound.wav
```

Replace `cryptluks` with the actual device name of your encrypted partition.

**Step 3: Create the Initrd Image**

1. Build the initrd image using the `mkinitrd` tool:

```
mkinitrd -f /boot/initramfs-$(uname -r).img -v
```

2. Update the initrd image to be used by systemd:

```
sudo update-initramfs -u
```

**Step 4: Enable and Start the Timer**

1. Enable the timer to ensure it runs every time the system boots:

```
sudo systemctl enable play-sound-cryptsetup.timer
```

2. Start the timer to play the sound immediately:

```
sudo systemctl start play-sound-cryptsetup.timer
```

Now, every time you boot your system and cryptsetup prompts for a password, the
specified sound file (`/path/to/your/sound.wav`) will play. 

(Anyway, this is what my personal robot explained to me and may be subject to
imperfection and error.)

Reply via email to