Re: How to properly reboot the system from a service specified by `systemd.unit=` boot option?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mi, 01.01.25 17:25, Qu Wenruo (wqu@xxxxxxxx) wrote:

> [BACKGROUND]
> I'm trying to implement a super simple kdump service(s) for Archlinux.
>
> The idea is super simple, just use the default linux kernel installed as
> kernel/initramfs for the kexec environment.
>
> So there is a kexec.service to setup the environment, with extra systemd
> options to disable th kexec.service itself, and start the kdump.service:
>
> ```
> [Unit]
> Description=Setup kexec environment
> After=local-fs.target
>
> [Service]
> Type=oneshot
> RemainAfterExit=true
> ExecStart=/usr/bin/kexec -p /boot/vmlinuz-linux
> --initrd=/boot/initramfs-linux.img --append="root=/dev/os/root rw
> console=ttyS0 nr_cpus=1 reset_devices systemd.mask=kexec.service
> systemd.unit=kdump.service"
> ExecStop=/usr/bin/kexec -p -u
>
> [Install]
> WantedBy=multi-user.target
> ```
>
> So that after a crash we can boot into the same kernel/initramfs combo and
> do whatever to collect the vmcore.
>
> The kdump.service will just call makedumpfile and exit (hopefully also
> reboot the system):
>
> ```
> [Unit]
> Description=Save the kernel crash dump after a crash
> After=multi-user.target

why so late?

>
> [Service]
> Type=idle
> ExecStart=/bin/sh -c 'mkdir -p /var/crash/ && /usr/bin/makedumpfile
> -z -d 31

It's kinda weird this is placed in /var/cras rather than
/var/lib/crash?

If you use the latter you can use StateDirectory=crash instead.

> /proc/vmcore "/var/crash/crashdump-$$(date +%%F-%%T)"'
> ExecStartPost=reboot

Note that "reboot" is actually a sysv legacy command. The most elegant
way to reboot after the service is complete is via
SuccessAction=reboot in the [Unit] section. See systemd.unit(5) man
page for more info.

Lennart

--
Lennart Poettering, Berlin



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux