Slashdot Mirror


Logging Unexpected Shutdowns/Crashes w/ Linux?

sweede asks: "I have a dedicated server that seems to reboot more often than it should. In Windows 2000/XP (maybe NT4.0?), if your computer or server crashes it will leave an event message in the Event Viewer for you to review on what went wrong. Is it possible to do something similar in Linux? Where a power outage or an unexpected kernel panic will leave a message in /var/log/event (or whatever) Searching Google for 'kernel trapping' doesn't give me a whole lot of info on the subject."

42 of 86 comments (clear)

  1. I'm pretty sure.. by Creepy+Crawler · · Score: 3, Informative

    That the reason Linux doenst write anything to the HD after Panic si so that it doesnt mangle/destroy the FS.

    And if I'm correct, if you turn on serial console, you'll get a Panic output on serial. Add a serial2IP box and you're set.

    --
    1. Re:I'm pretty sure.. by Chester+K · · Score: 3, Interesting

      That the reason Linux doenst write anything to the HD after Panic si so that it doesnt mangle/destroy the FS.

      Why not reserve a set place on the hard drive and write out error trap information there? There's no reason the filesystem needs to be involved at all. I'm going to guess that's what Windows does.

      --

      NO CARRIER
    2. Re:I'm pretty sure.. by bobthemonkey13 · · Score: 2, Informative

      Or a dot-matrix printer. Seriously, I did this for a while; you can turn on console-on-LPT support in your kernel config, and pass a parameter with your bootloader. It takes a while for the stupid thing to display all the kernel messages at boot, but the sound is priceless. Sadly, the 20-some-year-old printer decided to kick the bucket (still lasted longer than my HP DeskJet, thank you very much), so I switched to a 286 laptop running Minix 1.5 and term, which might be a cheap way to implement the serial2IP idea.

    3. Re:I'm pretty sure.. by Creepy+Crawler · · Score: 3, Interesting

      OK. Then how do you guarantee the state of the kernel? If you use bios calls, it screws up the memmap even more. Thats assuming you can even pass something like that.

      100$ question: How do you break out of code inserted that might have had a bug? How do you determine what code had that bug?

      Answer those, and then I'll trust Write_after_system_crash api

      --
    4. Re:I'm pretty sure.. by Creepy+Crawler · · Score: 2, Insightful

      Too true. I knew about those options too, but if he wants logging, he can make a cheap logserver that archives these problems across the whole network.
      If it's only 1 computer, I'd probably use a real terminal or a cheapie like your minix box or printer.

      --
    5. Re:I'm pretty sure.. by Anonymous Coward · · Score: 2, Informative

      Why not reserve a set place on the hard drive and write out error trap information there?

      The IDE/SCSI driver could still corrupt your data. How would you know where to write the info anyway? The kernel could easily calculate and store a block number, but could it trust the stored number after panic() is called? Maybe somebody overwrote that variable, or maybe some bad RAM caused it to spontaneously change.

      Kernel panics are generally used as a last resort, when something goes really wrong and there's no sane way to handle it (at least in theory). Deciding whether it's safe to write to disk would be difficult.

      Anyway, there are kernel patches that save crash dumps to your swap space or even your video RAM (search for something like "linux crash dump"). I wouldn't use them all the time, but they might be useful if you know your RAM is OK and don't suspect disk/IDE problems. A serial console is safer, but not always practical.

    6. Re:I'm pretty sure.. by FueledByRamen · · Score: 2, Interesting

      OK, I've got an idea. When it panics, it reruns the bootloader (use BIOS calls to read the first HD sector and go from there) and passes it some special flags which basically say "I did a bad thing, clean up after me." The bootloader will unpack another set of routines (checksummed for quality) in the same way it loads the Linux kernel off of the HD, and place them into an area of RAM that's hopefully not used by anything kernel related (app space). It will then read in the pagetables and other info still resident in RAM (use the Linux kernel on the HD for reference / symbol tables, or rebuild the crashdump app at the same time as the kernel with the same memory offsets and values), and formulate a meaningful crashdump. It'll then read in the partition table / slicetable / disk label / whatever, and find and write over the swap partition with the dump (making sure that the swap partiton actually is a swap partition - read its header and such, just in case the partition table was mangled). It will then reboot the computer. Upon reboot, Linux will pick up on the swap partition containing a crash dump (changed magic number?) and copy it to a file on the HD, then reformat the swap partition and mount it as normal, making a note in the syslogs that it crashed and the crashdump can be found at $LOCATION. (And maybe pass control to a different rc file, for a limited or debugging sysinit.)

      --
      Every cloud has a silver lining (except for the mushroom shaped ones, which have a lining of Iridium & Strontium 90)
    7. Re:I'm pretty sure.. by anthony_dipierro · · Score: 2, Insightful

      What's the reason that just about every other unix does write to the HD after panic?

    8. Re:I'm pretty sure.. by You're+All+Wrong · · Score: 2, Insightful

      Why do you trust a kernel that has got its knickers in a twist to be able to know where the swap partition is?

      I'd be happier with it writing to a floppy, serial, or other isolated subsystem. The difference between your swap partition and your root directory structure might be just 0x10000 in one of the register values, and that's considered too close to be worth risking.

      YAW.

      --
      Your head of state is a corrupt weasel, I hope you're happy.
    9. Re:I'm pretty sure.. by Tux2000 · · Score: 2, Interesting

      When it panics, it reruns the bootloader (use BIOS calls to read the first HD sector and go from there) [...]

      When Linux panics, it usually has a good reason to do so. Something like a damaged descriptor table, overwritten kernel code, hardware that works wrong, and various other catastrophes. Panic means a real panic: You can not reliably use any hardware. So you can not rerun the bootloader, and you can not access the BIOS. You can only hope that a hardware watchdog card notices that the kernel has paniced (because its timeout counter is no longer reset) and reboots the machine.

      (BTW: to access the boot loader and the BIOS, you probably would have to drop out of protected mode back into the ugly world of real mode (or V86 mode), causing even more P.I.T.A.)

      --
      Denken hilft.
  2. Easy... by icemax · · Score: 3, Informative

    'last reboot' should show you all the recent boots

    --


    __________
    Love conquers all... except CANCER
    1. Re:Easy... by Big+Jason · · Score: 4, Funny

      Not to be confused with last | reboot, which I've done before. Doh!

  3. Logging Unexpected Shutdowns/Crashes w/ Linux? by krishnaD · · Score: 3, Informative

    /var/log/messages, /var/log/syslog should give you enough info about kernel . Also there are lots of tools to enable various kind of accouting check sa.

    1. Re:Logging Unexpected Shutdowns/Crashes w/ Linux? by Creepy+Crawler · · Score: 2, Insightful

      Its not enough if you're trying to determine whats throwing the system out to lunch.

      Id be apt to turn on hangcheck with 1min restart + email on my servers. But better is to know what they failed by..

      --
    2. Re:Logging Unexpected Shutdowns/Crashes w/ Linux? by Tux2000 · · Score: 2, Informative

      Add a serial or parallel console that writes to paper, i.e. a printer. Disable syslogd and klogd and let all log output go to the console.

      --
      Denken hilft.
  4. Flag it. by slittle · · Score: 2, Interesting

    Same way they know to fsck/chkdsk the drives: if a 'dirty bit' (or file, in your case) exists during boot, shutdown was unclean - log it. Otherwise create it. Only clear it as the last step of a clean shutdown.

    --
    Opportunity knocks. Karma hunts you down.
    1. Re:Flag it. by Creepy+Crawler · · Score: 3, Interesting

      You fail to understand what happens to create the "Dirty Bit".

      1: System starts up (say clean).
      2: It marks a bit on the partition that system has been started up.
      3: Usage Usage Usage
      4: Send shutdown
      5: System umounts cleanly. Undoes "dirty bit"
      6: Power == 0

      On a dirty FS, stage #5 is never hit so when system comes back on, it checks the bit and detects unclean shutdown. The bit is never wrote during the unclean shutdown.

      In the similar problem, I see problems when NTkern crashes. How exactly does it manage to:

      1: Read the partitiom
      2: Read the program on the partition
      3: Run the insert log program to add log entry
      4: Still have the "blue screen"

      I smell nasty data corruption waiting to happen. After all, if you cant guarantee the state of the kernel, does it really justify reading, writing, and executing on a crashed kernel????

      --
  5. Kernel Panic on Linux? Sounds like hardware prob. by Radical+Rad · · Score: 2, Informative

    After 10 years without ever needing to apply the knowledge I forgot how.Would the magic sysrq key help? I bet it is a hardware problem though. And what about logging power outages? That is easy to do. APC probably has Linux software already to do this. For other logging there is ample facilities on Linux. Start a syslog server. Point everything to the loopback address.

  6. Re:Kernel Panic on Linux? Sounds like hardware pro by Drakon · · Score: 4, Funny

    If you run 2.6.0-test6 with -mm15 and some home brewed patches, you can have crashes without hardware failure

    (one who speaks from experiance) :-)

  7. Other OSes by menscher · · Score: 5, Informative
    This will probably be modded down as flame bait, but I can't resist pointing out what some other OSes have done when crashing:

    IRIX will core dump to the swap partition. On the next boot it analyzes this core file, which includes various system logs, etc, and saves useful output in /var/adm/crash. You know you've done a good job when the kernel panic causes a panic, called a double panic. I used to be able to trigger those at will. Hrmm, I should test that on the current release.

    AIX summarizes the likely causes of failure (power failure, someone pressed the power switch, or power supply died, etc). I've seen (but do not personally use) a similar thing with IRIX that actually assigns a percentage confidence level to its guess.

    Of course, usually you know there was a power failure because your UPS told you so.... I did have one case where we had a very brief outage (or maybe just a brownout). Every machine in the building had rebooted.... except one. That RS/6000 had an eerie log message like "power failure detected". And no, it was not on a UPS. I was rather impressed.

    Sadly, I don't know how to get any useful information out of linux. And don't give me crap about it never crashing. I can prove otherwise. Too bad I can't figure out why.... Maybe a kernel developer will read this and copy some ideas from the commercial Unix vendors.

    1. Re:Other OSes by FueledByRamen · · Score: 3, Interesting
      f course, usually you know there was a power failure because your UPS told you so.... I did have one case where we had a very brief outage (or maybe just a brownout). Every machine in the building had rebooted.... except one. That RS/6000 had an eerie log message like "power failure detected". And no, it was not on a UPS. I was rather impressed.
      I had a similar interesting experience with an SGI Indy (Irix 6.5.13, or thereabouts). I was booting it up after it'd been sitting for a while, just to see what I had running on there. While it was going, and I was fumbling around for an ethernet cable for it (it takes several minutes at boot to wait for a cable instead of noting its absence and moving on), I kicked the power strip that it was on and the plug wiggled around in the wall socket. I heard a spark jump in the socket, and the monitor it was on (Dell/Sony Trinitron 19") went to half-height mode for a few seconds, spitting and clicking, turning the screen on and off and varying the vertical height randomly.

      I expected the Indy to kernel panic or turn off. Instead, below the complaints about the missing ethernet cable ("en0: link carrier not detected" or similar), there was a lone status message: "Power failure detected."

      No UPS, no power saving devices of any kind, only the filter caps in the power supply between the logic board and the unreliable, crufty power system of a 70 year old house at the mercy of a power strip first used on my (brand new at the time) Atari 800. The other computer on the power strip (350 P2 running RH 7.1) rebooted hard, right in the middle of heavy FS activity. I had to hit the reset button before it would come back up again, too - the brownout hung the POST.
      --
      Every cloud has a silver lining (except for the mushroom shaped ones, which have a lining of Iridium & Strontium 90)
    2. Re:Other OSes by Ster · · Score: 3, Informative

      Mac OS X writes a crash dump to the non-volitile RAM in the event of a panic. Then, after the next successful boot, it reads out the dump and adds it to /Library/Logs/panic.log. If, for some reason, the machine won't come back up, you can probably read the dump from OpenFirmware.

      -Ster

    3. Re:Other OSes by kinema · · Score: 3, Interesting

      I wonder if /dev/nvram (the small amount of NVRAM availible on the RTC) is large enough to store such a dump.

    4. Re:Other OSes by anthony_dipierro · · Score: 4, Informative

      IRIX will core dump to the swap partition.

      FreeBSD does this. HP/UX does this. I always assumed Linux did it too, it just wasn't turned on by default. I guess I was wrong.

      As a side note, my first job out of college was to analyze core dumps from HP/UX. There's an awful lot you can learn from these things. Not just stack traces, the entire memory of the system is contained in the dump. It's time consuming, but a large portion of the time you can find out *exactly* what went wrong.

    5. Re:Other OSes by cookd · · Score: 2, Interesting

      Windows does something like this too.

      At Blue Screen, it will make a dump in the swap partition if so configured. The dump can be a 64k error summary (MiniDump), kernel memory dump, or a full physical memory dump (if swap > physical memory). While there is a slim possibility that doing this might make things worse (if the code to write the dump is corrupted, or the disk driver is corrupted), it is MUCH more likely that the information written will be useful. Also, the swap partition driver is pretty stable and simple, so chances are very good that it won't mess up anything that wasn't already messed up. If you're paranoid, you can turn off this feature.

      At clean shutdown, it writes an event to the event log indicating clean shutdown.

      At boot, if there is no "clean shutdown" event, it writes an "unexpected shutdown" event to the event log. It estimates the time of the crash based on the last events in the event log. Since Windows has periodic "I am running ok" events recorded to the event log, it can use the last "I am ok" event to guess at the crash time.

      At boot, if there is a crash dump in the swap partition, it is recovered and copied to a file for subsequent analysis.

      --
      Time flies like an arrow. Fruit flies like a banana.
    6. Re:Other OSes by isorox · · Score: 3, Funny

      Nah, if kernel developers read slashdot, nothing would get done!

    7. Re:Other OSes by Tux2000 · · Score: 2, Informative

      Nope. RTC memory is something between 128 Bytes (IBM AT) and 2 KBytes (IBM PS/2 series). And each bit of it is used for the BIOS and some hardware stuff (Microchannel requires a lot of memory). Perhaps, some machines have a few unused bits. But you can't stuff all your memory into them. You can't compress several megabytes or gigabytes into 10 to 20 Bits (at least not lossless). With a lot of luck and deep knowledge of the used machine and BIOS, you may be able to store a dirty-or-clean shutdown flag. But as I said, it depends very much on the machine and the BIOS.

      --
      Denken hilft.
  8. Try the Linux Kernel Crash Dump (LKCD) patches by bigsteve@dstc · · Score: 5, Informative

    If you are adventurous, you could try applying the LKCD patches to your kernel. Start looking here

    1. Re:Try the Linux Kernel Crash Dump (LKCD) patches by Anonymous Coward · · Score: 2, Informative

      Its located here for the unitiated.

      I took a look at it a while back and it looked interesting. Just checked back at the site and there is a reasonable howto provided by IBM in the doc section which should give you some idea of what/how it works.

      Its worth a look, but honestly, it sounds a LOT more like a hardware issue than software. Is the server on an UPS? If not, get it on one. Reseat all your cards and ram etc then see if it crashes as regularly.

  9. rc.local by bobbozzo · · Score: 2, Informative
    As others have mentioned, there are various ways to see when the system rebooted.

    If you want to be emailed if the system reboots, put something at the end of /etc/rc.d/rc.local, if you're using something like RedHat (SYSV init, IIRC).

    Logwatch will probably let you know if the system rebooted also.

    If you want a log of the kernel panic, or something else, that's a lot more complicated, as others ahve mentioned

    --
    Nothing to see here; Move along.
  10. "Linux crashes" are probably contact failure. by Futurepower(R) · · Score: 3, Interesting


    As others have said, the "Linux crash" is probably hardware failure.

    The most common cause of serious failure, if the software has been installed correctly and tested, is bad contacts. To fix the problem, just loosen the screws that hold the adapter cards, pull the cards out about 1 millimeter or 1/32 of an inch, push the cards back in fully, and re-tighten the screws. Also, pull all connectors off a similar amount, and push them back on. Do the same with the memory modules. That's all.

    The scraping caused by moving the contact points a tiny amount is actually very violent on a micro scale. The scraping removes oxide that causes a contact to lose electrical conduction.

    This is reliable information. I've been selling and occasionally repairing PCs since before IBM sold PCs, back in the days when personal computers cost $2300, had two diskette drives and no hard drive, and ran the CP/M operating system.

    My guess is that, if you had a penny for every real crash of a stable distribution of Linux, after a few years you might still have to borrow money from your little brother to buy a piece of bubble gum.

  11. It'll never catch the things you want... by Bazman · · Score: 2, Interesting

    Murphy's law will apply and the thing that causes your system to crash wont be trapped by whatever magic you try to log it with! We recently had a machine that would just power-down without warning. I eventually discovered it happened after intensive CPU load for about 20 mins, figured maybe it was some heating problem, kicked up the sensors package and spotted the CPU temp heading into egg-frying temperatures. It seems the BIOS would just protect its motherboard by shutting down. The kernel had no chance to report anything.

  12. Depends on what it's doing by Sits · · Score: 3, Informative

    To the best of my knowledge linux doesn't automatically reboot after a kernel crash unless you have told it to. If the crash was that severe this means you can walk up to the crashed machine and read the oops off the screen. If the machine isn't oopsing before the reboot this suggests some sort of hardware fault (e.g. your CPU is overheating). If it is hardware resetting the machine it is very unlikely that Linux can tell you what the fault is by itself (e.g. if it was the CPU overheating you will have to find someway to log the temperature to a file and observe the graph up to crash yourself).

    Oh and here's a useful way of working out whether there was a crash or not:
    last -x | grep "shutdown\|reboot"
    Every reboot that doesn't have a matching shutdown was probably a crash (other than the last line).

  13. Here's how: by samjam · · Score: 4, Informative

    1) First disable console blanking, that way when you get to the crashed box and plug the monitor in you can see the kernel panic message. /usr/sbin/setterm -blank 0 -powersave off -powerdown 0

    We had some early kernel 2.4 redhat boxes crashing like the dickens for a while, it was a kernel problem and only when it happened on a local machine under our eyes did we get to realise what had happened.

    2) Network syslog;
    If you syslog to a central machine not only does it make error spotting centralised and easier but it means you have the last gasps of the crashed machine logged on a machine that is still up.

    Sam

  14. serial console by treat · · Score: 3, Informative

    A serial console (make sure you enable the magic sysrq key! for some reason RedHat disables it by default) is an essential tool for any Linux server you care about. If you don't have the money for a console server, just plug servers into each other.

    If your machine crashes without a panic message, however, you're out of luck. Wait until crash dumps are available - I'm surprised this isn't a 2.6 feature. Until we get crash dumps that work 99% of the time (like on Sparc-Solaris), Linux will continue to suck. At least it sucks less than the alternatives.

  15. The cleaning team by Tux2000 · · Score: 3, Funny

    "Now, where was the power outlet for the vaccuum cleaner? Hell, I'll tear out that red cable and plug the vaccuum cleaner there."

    --
    Denken hilft.
  16. Yes! by twistedcubic · · Score: 4, Funny


    Is it possible to do something similar in Linux?

    Yeah, but we have to wait until our SCO insider funnels us the code.

  17. Linux Trace Toolkit by bendl · · Score: 2, Interesting
    I'm working on a project called Linux Trace Toolkit (LTT) that is suitable for an automatic logging.

    LTT log every system call at a ns precision in a RAM buffer and then on disk. The events include, for instance, read/write/open operations, system call, interuptions, process state, disk and internet interface operations and so on. You can add specific event by modifying your application and recompile with the LTT library.

    LTT is not yet included in the kernel and was not choosen after the "Halloween Freeze" however, the new infrastructure can operate in a "flight recorder" mode that will, for instance, log the last 5 Mb of events that happens on the system.

    Of course, when there is a kernel crash, you can not be certain to have those events on disk but this is chicken and egg problem.

    Anyway, I believe this king of functionality is in demande by most critical applications. This is very important in the embedded market too where debugging and optimization is very painful.

  18. Some ideas by Gudlyf · · Score: 4, Informative
    Mission Critical Linux does this.

    There's also the LKCD (Linux Kernel Crash Dumps) package:

    KCD contains kernel and user level code designed to:

    • Save the kernel memory image when the system dies due to a software failure;
    • Recover the kernel memory image when the system is rebooted;
    • Analyze the memory image to determine what happened when the failure occurred.
    --
    Trolls lurk everywhere. Mod them down.
  19. Re:Linux is VERY reliable. by Vlad_the_Inhaler · · Score: 2, Insightful

    I built the machine I am writing this on around 18 months ago. After a few months it became totally unstable (after a software upgrade to SuSE 8.0, I think). Now it runs SuSE 8.2 with absolutely no hardware changes and has not died on me for months.
    Other people had no problems with that level.
    The driver for the Realtek 8139 that came with the early 2.4 kernels used to kill the machine I first ran it on. Kill it stone dead, I had to hit reset to restart. The machine is dual-boot and worked fine under Win95. That problem was fixed in a kernel that came out in late 2001 (?) and that nic has always worked just fine in this machine since I built it, as did the old 3com card I replaced it with in the older machine..

    Linux is not impervious to quality problems. No OS is.

    --
    Mielipiteet omiani - Opinions personal, facts suspect.
  20. A few hints by kasperd · · Score: 2, Interesting

    You can use a serial console or try out some version of the netconsole patch to get the messages on another computer. (Notice that netconsole over the internet is probably possible, but it is sent in clear and can be snooped or modified). I also recall reading about some patch to keep a new kernel ready in memory that could be booted with arguments telling it where to find the log from the old kernel, I even think it included a checksum to prevent booting the new kernel if it had been corrupted.

    --

    Do you care about the security of your wireless mouse?
  21. You must be mistaken. by Viqsi · · Score: 2, Funny

    Unexpected shutdowns? Crashes? You must be mistaken. Linux does not crash. Ever.

    Now, what was your name and address again?

    --

    --
    viqsi - See "vixen"
    If we do not change our direction we are likely to end up where we are headed.