5

WARNING!!!: The question asks for temporarily breaking Ubuntu. There shall be no safe answers. If you have important services running, important documents/files being edited, please note that you might not be able to recover/save your work. Please note that trying these answers is not recommended unless you know what and why you're doing it, and it is not answerer's (or asker's, FWIW) fault if you break something.

I need a way to make my Ubuntu become unresponsive. No running shutdown scripts, no recovery from hanging state. Just a quick and dirty way for the system to go into derp mode. Recovery should be only via powering off and on again.

Assume three things:

  • I am root
  • Non-bash solution ( so no fork bombs please, but command-line solution ok)
  • filesystem must remain intact

To address dobey's comment:

  • derp mode basically means "computer runs, but that's it"
  • "What you're actually trying to achieve". I think the title explains it pretty clearly. I want to make the OS unresponsive at will, where it won't be able to do anything. That's exactly what I'm trying to achieve. There's no debugging involved, there's no XY problem. I just need a way for system to lock up/crash/hang up where I can't do anything except hold the power down button.
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Could you please [edit] the question to be more clear about what you mean by derp mode here, and what you're actually trying to achieve? IE, what is your actual question? Triggering a kernel panic as root is trivial, and will meet your stated goals, but is basically useless if your goal isn't to debug the kernel. – dobey Nov 25 '17 at 01:30
  • @dobey see the update – Sergiy Kolodyazhnyy Nov 25 '17 at 01:42
  • @wjandrea nope, that's something I mentioned from the beginning when I posted the question, in one of the bullet points. Has to be a shell-agnostic solution. – Sergiy Kolodyazhnyy Nov 25 '17 at 02:12
  • 3
    This isn't a duplicate of that closed question. Besides how that question is so vague that we could hardly ever know anything is a duplicate of it, this one is clear, with specific requirements. Although this does warn that answers could be appropriate but result in data loss, this is merely asking how to make Ubuntu stop responding; it even says "temporarily breaking" and "filesystem must remain intact." It would be... bad if we sent people there and they thought they could recursively delete / to make their system stop responding until a reboot. – Eliah Kagan Dec 05 '17 at 20:43

3 Answers3

5

One definite way to make your system unusable is to crash it using:

sudo sh -c 'echo c > /proc/sysrq-trigger'

Or (if your /proc/sys/kernel/sysrq setting is set to something not so restrictive, like 1), press Alt + SysRq + C for the same effect.

These files are documented in the proc(5) manual:

/proc/sys/kernel/sysrq

This file controls the functions allowed to be invoked by the SysRq key. [..]

/proc/sysrq-trigger (since Linux 2.4.21)

Writing a character to this file triggers the same SysRq function as typing ALT-SysRq-<character> (see the description of /proc/sys/kernel/sysrq). This file is normally writable only by root. For further details see the Linux kernel source file Documentation/admin-guide/sysrq.rst (or Documentation/sysrq.txt before Linux 4.10).

For more information about this "sysrq" feature, see https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html

Lekensteyn
  • 174,277
  • Depending on the system you may need to enable SysRQ first with echo 1 >/proc/sys/kernel/sysrq though, see the bottom of my answer… – dessert Nov 25 '17 at 00:20
4

Please don't try unless you know exactly what you're doing!

  • changing /proc/sys/kernel settings related to kernel panic

    echo 1 >/proc/sys/kernel/hung_task_panic
    echo 1 >/proc/sys/kernel/panic_on_io_nmi
    echo 1 >/proc/sys/kernel/panic_on_oops
    echo 1 >/proc/sys/kernel/panic_on_stackoverflow
    

    This will set the kernel to panic immediately in case of a hung task(!), an NMI caused by an IO error, an oops or BUG and overflows of kernel, IRQ and exception stacks. While not causing a panic immediately, this should make it much easier to get to the point.

  • output the system's I/O ports

    cat /dev/port
    
  • overwrite the memory device with zeroes

    cp /dev/zero /dev/mem
    
  • flood system I/O ports with random numbers

    dd if=/dev/random of=/dev/port
    
  • using SysRq, perform a system crash by a NULL pointer dereference:

    echo 1 >/proc/sys/kernel/sysrq # make sure SysRQ is fully enabled
    echo c >/proc/sysrq-trigger    # pull the trigger
    

I didn't try any of these. (source 01, source 02, How to cause kernel panic with a single command?, source 04)

dessert
  • 39,982
0

Trying:

cd /proc

Followed by:

sudo kill *

Should do the trick

saltq
  • 11
  • 4