How to check if not clean shutdown?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to check if not clean shutdown?

Johannes Lundberg
Hi

In the boot process on my test machines I'd like to do different things
depending on the last run was a clean shutdown or kernel panic. Where/How
can I get this information?

Thanks!
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: How to check if not clean shutdown?

Warner Losh
You can't, in general. By the time the boot loader starts, all knowledge of
past boots is gone, unless specific counter-measures were put in place.

However, if root is UFS and read/write in your box, it will be unclean on
anything but a clean shutdown/reboot. If it's read-only, ZFS or NFS
mounted, then you can't use this method.

If you have UEFI, you can set a UEFI variable on shutdown and clear it on
boot. If it's not there on boot, you had an unclean shutdown. You could do
the same with a file in a r/w filesystem that doesn't record clean/unclean
(like ZFS or NFS).

Locally, we have hacks to IPMI to record kernel crashes in the IPMI log,
but that's kinda specific to the BMC we have on our boards...

Warner


On Tue, May 22, 2018 at 7:57 AM, Johannes Lundberg <[hidden email]>
wrote:

> Hi
>
> In the boot process on my test machines I'd like to do different things
> depending on the last run was a clean shutdown or kernel panic. Where/How
> can I get this information?
>
> Thanks!
> _______________________________________________
> [hidden email] mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "[hidden email]"
>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: How to check if not clean shutdown?

Johannes Lundberg
On Tue, May 22, 2018 at 3:30 PM, Warner Losh <[hidden email]> wrote:

> You can't, in general. By the time the boot loader starts, all knowledge
> of past boots is gone, unless specific counter-measures were put in place.
>
> However, if root is UFS and read/write in your box, it will be unclean on
> anything but a clean shutdown/reboot. If it's read-only, ZFS or NFS
> mounted, then you can't use this method.
>
> If you have UEFI, you can set a UEFI variable on shutdown and clear it on
> boot. If it's not there on boot, you had an unclean shutdown. You could do
> the same with a file in a r/w filesystem that doesn't record clean/unclean
> (like ZFS or NFS).
>
> Locally, we have hacks to IPMI to record kernel crashes in the IPMI log,
> but that's kinda specific to the BMC we have on our boards...
>
> Warner
>

I see. Thanks for the quick reply.
I guess I can add a dummy file somewhere that I delete in a shutdown hook.


>
>
> On Tue, May 22, 2018 at 7:57 AM, Johannes Lundberg <[hidden email]>
> wrote:
>
>> Hi
>>
>> In the boot process on my test machines I'd like to do different things
>> depending on the last run was a clean shutdown or kernel panic. Where/How
>> can I get this information?
>>
>> Thanks!
>> _______________________________________________
>> [hidden email] mailing list
>> https://lists.freebsd.org/mailman/listinfo/freebsd-current
>> To unsubscribe, send any mail to "[hidden email]
>> "
>>
>
>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: How to check if not clean shutdown?

Rodney W. Grimes-4
> On Tue, May 22, 2018 at 3:30 PM, Warner Losh <[hidden email]> wrote:
>
> > You can't, in general. By the time the boot loader starts, all knowledge
> > of past boots is gone, unless specific counter-measures were put in place.
> >
> > However, if root is UFS and read/write in your box, it will be unclean on
> > anything but a clean shutdown/reboot. If it's read-only, ZFS or NFS
> > mounted, then you can't use this method.
> >
> > If you have UEFI, you can set a UEFI variable on shutdown and clear it on
> > boot. If it's not there on boot, you had an unclean shutdown. You could do
> > the same with a file in a r/w filesystem that doesn't record clean/unclean
> > (like ZFS or NFS).
> >
> > Locally, we have hacks to IPMI to record kernel crashes in the IPMI log,
> > but that's kinda specific to the BMC we have on our boards...
> >
> > Warner
> >
>
> I see. Thanks for the quick reply.
> I guess I can add a dummy file somewhere that I delete in a shutdown hook.

utmp has one attempt at keeping track of this by recording a shutdown record.


> > On Tue, May 22, 2018 at 7:57 AM, Johannes Lundberg <[hidden email]>
> > wrote:
> >
> >> Hi
> >>
> >> In the boot process on my test machines I'd like to do different things
> >> depending on the last run was a clean shutdown or kernel panic. Where/How
> >> can I get this information?
> >>
> >> Thanks!
> >> _______________________________________________
> >> [hidden email] mailing list
> >> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> >> To unsubscribe, send any mail to "[hidden email]
> >> "
> >>
> >
> >
> _______________________________________________
> [hidden email] mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "[hidden email]"
>

--
Rod Grimes                                                 [hidden email]
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "[hidden email]"