linuxinitrdinitramfs

Execute an interactive script in systemd-based initramfs


I want to start an interactive script in a systemd-based initramfs. I use mkinitcpio with the systemd-hook to create it. My problem is, that there is no input supplied to the script started as a service. The script is started and I see his output, until it waits for input.

my_service.service:

[Unit]
Requires=systemd-vconsole-setup.service
# Requires=getty@tty2.service
After=systemd-vconsole-setup.service
Before=initrd-switch-root.service
Conflicts=multi-user.target
DefaultDependencies=no

[Service]
Type=oneshot
# ExecStartPre=/usr/bin/chvt 2
ExecStart=/usr/bin/sh /myscript
# ExecStartPost=/usr/bin/chvt 1
# StandardInput=tty
StandardInput=tty-force
StandardOutput=tty
TTYPath=/dev/tty1
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes

[Install]
WantedBy=sysinit.target

I appended Requires=otpboot.service to initrd-switch-root.service, so it waits until my script finishes (which does not happen, since there is no input supplied). I also tried to move my script to tty2 (which would be totally fine for my use case), the chvt commands succeeds, but the output of my_service is still on tty1. Since I can't change to tty2 with Ctrl+Alt+F2 I think tty is not setup already. So I added the getty@ service and the agetty binary and required it, but tty2 still does not work.

I appreciate any hint in any direction.


Solution

  • Ok, my bad. I tought thought the sd-vconsole hook replaces the keyboard hook, but it did not. So my keyboard drivers were missing. (That's why changing to tty2 manually did not work - should have given me a clue).

    If somebody has problems, removing TTYVTDisallocate makes debugging a bit easier.