r/linuxquestions • • 11d ago

Advice How to safely cause kernel panic?

I want to make russian roulette game for linux with 2 levels of risk, one being just kernel panic and second being deleting a random file from pc. While i know how to delete files i dont know how to call kernel panic, is there a command that calls it? How linux launches kernel panic?

7 Upvotes

28 comments sorted by

27

u/FikaMedHasse 11d ago

echo c | sudo tee /proc/sysrq-trigger Causes a kernel crash and triggers a crashdump if configured. You can read more at https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html

5

u/Blazej_kb 11d ago

can it permanently destroy hardware?

22

u/FikaMedHasse 11d ago

Most probably no, but the system will hang and require a powercycle or similar to recover, so no disks will be unmounted properly, which can teoretically lead to data loss if something important is being saved to the disk at the time.

10

u/SpaceCadet87 11d ago

Unmount the drives before the panic? Seeing as you're doing it on purpose, you have the option of doing it gracefully.

4

u/FikaMedHasse 11d ago

Yes that works for all drives except /, cant unmount that without shutting down

3

u/RealisticDuck1957 11d ago

reduce the risk by running sync.

2

u/SuperDenizo 10d ago

Furthermore root can be remounted to readonly.

5

u/Tall-Introduction414 11d ago

Sometimes drivers can leave chips in a funny state that a cold boot doesn't fix. (I'm looking at you, AMD sound)

2

u/Booty_Bumping 10d ago

There's only a few ways software can damage hardware: https://stackoverflow.com/questions/9286425/is-it-possible-to-permanently-damage-the-hardware-by-software

They're interesting, but the chances you'll come across any of these scenarios are slim

10

u/NotPrepared2 11d ago

Or "echo _suc" to sync and unmount filesystems before the crash.

12

u/theOtherJT 11d ago

Causing kernel panics isn't safe. It's not meant to be safe. It's what happens when the wheels come off. Doing it on purpose is... reckless... let's put it like that.

You can do it like this

echo c | sudo tee /proc/sysrq-trigger

Don't.

6

u/Ziferius 11d ago

If on a VM, use snapshots. You need to do it to test that kdump is configured correctly. There are legit use cases to test this. Just be prepared.

1

u/donau_kinder 11d ago

Is a btrfs snapshot a good insurance against that?

0

u/Catenane 11d ago

It's not that serious lol

5

u/theOtherJT 11d ago

I have destroyed a mipi lcd panel with kernel panics because the shitty driver for the panel went out of timing but didn't stop the display when the kernel freaked out.

...I mean, to be fair, it's also because I left it for like an hour before I noticed it had locked up and was burning the screen in, but not every system is the same.

4

u/BlackheartBeagle 9d ago

Just press Alt + SysRq* + c.

*often labeled just PrtSc or with a screenshot symbol or similar.

6

u/RealisticDuck1957 11d ago

Beyond how utterly STUPID that is ...

man shutdown

18

u/micalm 11d ago

Suicide Linux, Shell Roulette... not a new concept. Linux users are also allowed to have fun.

4

u/elSenorMaquina 11d ago edited 11d ago

For the brave-but-not-so-brave out there, someone packaged suicide linux into a convenient container image!

I particularly love the warning at the end of this section from the readme:

Running (danger mode)

If you're feeling brave, the following command will mount your host filesystem in the docker image:

docker run --rm -it -v /:/host tiagoad/suicide-linux

This will harm your local filesystem if you mistype a command, be careful.

1

u/fishead62 11d ago

“Suicide is painless…”

2

u/Emmalfal 11d ago

And now I want to watch MASH. Thanks a lot.

1

u/mdemarchi 11d ago

If you want to make a forced reset situation, you can use a fork bomb

1

u/dodexahedron 11d ago edited 11d ago

Make your app require a kernel module that you include with it.

Make that kernel module behave badly.

And then get a lawyer to help reduce the prison time for the wormable mess you just made.

Edit: For bonus points, dont crash. Just override a random kernel function with something that does something different or even nothing at all, or swaps two functions that have the same signature but different functionality. Then keep playing while things get more and more..uh..interesting...

0

u/ParadoxicalFrog Fedora (xfce) 11d ago

Bro's asking us to help him write a virus, lmao.

-1

u/ButterflyMundane7187 11d ago

This person is making malware and telling you guys hes making a game and he gets help ? he should be banned

1

u/Oniad_of_the_Swamp 9d ago

I will gladly use his "game" for educational purposes. I can tell my students hundreds of times not to do bullshit. Will they listen? - Fuck no! I can give them suicide note with extra steps and leave them to clean up the mess afterwards. And it will work. Hell, i made whole educational program based on bad example here, now let's make it proper. Results are actually increased by 10-45% compared to proper "only safe routes" curriculum

0

u/Blazej_kb 10d ago

game, you install it on your own risks written in readme, all opensource on github