Categorygithub.com/mlafeldt/sysrq
modulepackage
0.0.0-20171106101645-38dd78d6e663
Repository: https://github.com/mlafeldt/sysrq.git
Documentation: pkg.go.dev

# README

sysrq

Go client to perform low-level commands via the Linux SysRq interface (accessible at /proc/sysrq-trigger).

Among other things, SysRq can crash the system by forcing a NULL pointer dereference, which makes it a good fit for Chaos Engineering experiments.

CLI

In addition to the Go library, there's a sysrq command-line tool you can install from source:

go get -u github.com/mlafeldt/sysrq/cmd/sysrq

Use the tool to trigger one or more commands:

sudo sysrq <cmd>...

This will print a list of all available commands:

sysrq -list

Vagrant playground

Here's how to run SysRq commands against a local Vagrant machine:

# Start Vagrant machine
vagrant up

# Trigger crash command
make trigger CMD=crash

# Show system logs
make log
...
ubuntu-xenial login: [   94.116848] sysrq: SysRq : Trigger a crash
[   94.152571] BUG: unable to handle kernel NULL pointer dereference at           (null)
[   94.263679] IP: [<ffffffff81504df6>] sysrq_handle_crash+0x16/0x20
...

# Fix Vagrant machine
vagrant reload

Docker

Since Docker mounts /proc/sysrq-trigger as read-only, you cannot run commands against other containers, but you can still affect the host system:

docker run --rm -v /proc/sysrq-trigger:/sysrq -e TRIGGER_FILE=/sysrq mlafeldt/sysrq <cmd>...

Author

This project is being developed by Mathias Lafeldt.

# Packages

No description provided by the author

# Functions

FromString creates a Command from a string.
Trigger performs one or more commands via the Linux SysRq interface.

# Constants

Crash performs a system crash by a NULL pointer dereference.
DefaultTriggerFile is the location of the file where SysRq commands are written to by default.
DumpFtraceBuffer dumps the ftrace buffer.
Help displays help (actually any other key than those listed here will display help.).
KillAllTasks sends a SIGKILL to all processes, except for init.
Loglevel0 sets the console log level to 0.
Loglevel1 sets the console log level to 1.
Loglevel2 sets the console log level to 2.
Loglevel3 sets the console log level to 3.
Loglevel4 sets the console log level to 4.
Loglevel5 sets the console log level to 5.
Loglevel6 sets the console log level to 6.
Loglevel7 sets the console log level to 7.
Loglevel8 sets the console log level to 8.
Loglevel9 sets the console log level to 9, the most verbose level.
MemoryFullOOMKill calls the OOM killer to kill a memory hog process, but doesn't panic if nothing can be killed.
NiceAllRTTasks will make RT tasks nice-able.
Poweroff shuts your system off (if configured and supported).
Reboot immediately reboots the system without syncing or unmounting your disks.
SAK (Secure Access Key) kills all programs on the current virtual console.
ShowAllTimers dumps per CPU lists of all armed hrtimers (but NOT regular timer_list timers) and detailed information about all clockevent devices.
ShowBacktraceAllActiveCPUs shows a stack backtrace for all active CPUs.
ShowBlockedTasks dumps tasks that are in uninterruptable (blocked) state.
ShowMemoryUsage dumps current memory info to your console.
ShowRegisters dumps the current registers and flags to your console.
ShowTaskStates dumps a list of current tasks and their information to your console.
Sync attempts to sync all mounted filesystems.
TerminateAllTasks sends a SIGTERM to all processes, except for init.
ThawFilesystems forcibly "Just thaw it" - filesystems frozen by the FIFREEZE ioctl.
Unmount attempts to remount all mounted filesystems read-only.
Unraw turns off keyboard raw mode and sets it to XLATE.

# Variables

Commands is a list of supported SysRq commands.

# Structs

SysRq is used to configure access to the Linux SysRq interface.

# Type aliases

Command is a SysRq command.