4 phút đọc
luainkernel/lunatik: Lunatik is a framework for scripting the Linux kernel with Lua. – Repository luainkernel/lunatik. Mô tả: Lunatik is a framework for scripting the Linux kernel with Lua.. 599 stars, 63 forks, ngôn ngữ chính C, cập nhật 2026-09-03.
1. Repository làm gì?
Lunatik is a framework for scripting the Linux kernel with Lua. It is composed by the Lua interpreter modified to run in the kernel; a device driver (written in Lua =)) and a command line tool to load and run scripts and manage runtime environments from the user space; a C API to load and run scripts and manage runtime environments from the kernel; and Lua APIs for binding kernel facilities to Lua scripts.
Note: Lunatik supports Linux Kernel versions 5.15 and later
Feel free to join us on Matrix.
Here is an example of a character device driver written in Lua using Lunatik to generate random ASCII printable characters:
Install dependencies (here for Debian/Ubuntu, to be adapted to one's distribution):
Install dependencies (here for Arch Linux):
2. Dữ liệu và cấu trúc đáng chú ý
The lua-readline package is optional. When installed, the REPL gains line editing and command history:
Once done, the debian_kernel_postinst_lunatik.sh script from tools/ may be copied into /etc/kernel/postinst.d/: this ensures lunatik (and also the xdp needed libs) will get compiled on kernel upgrade.
Install Lunatik from our package feed.
Install and run the test suites:
lunatik test reloads the modules before the run and unloads them afterwards, so each invocation exercises the currently-installed kernel code. See tests/README.md for the full list of suites and individual tests.
Lunatik 4.4 is based on Lua 5.5 adapted to run in the kernel.
Lunatik does not support floating-point arithmetic, thus it does not support __div nor __pow metamethods and the type number has only the subtype integer.
3. Khả năng ứng dụng và giới hạn
Lunatik does not support the os library, floating-point arithmetic (__div, __pow), or debug.debug. The math library is present but all floating-point functions are absent — only integer operations are supported.
The io library is supported with the following limitations: there are no default streams (io.stdin, io.stdout, io.stderr), no default input/output (io.read, io.write, io.input, io.output), no process pipes (io.popen), no temporary files (io.tmpfile), and no buffering control (file:setvbuf). The available functions are io.open, io.lines, io.type, and the file handle methods read, write, lines, flush, seek, and close. On failure, error messages always read "I/O error" regardless of the underlying errno.
Lunatik modifies the following identifiers:
Lua APIs are documented with LDoc and can be browsed at luainkernel.github.io/lunatik.
The table below lists the available kernel Lua modules:
The C API allows kernel modules to create and manage Lunatik runtime environments, define new object classes, and expose kernel facilities to Lua scripts. See doc/capi.md for the full reference.
spyglass is a kernel script that implements a keylogger inspired by the spy kernel module. This kernel script logs the keysym of the pressed keys in a device (/dev/spyglass). If the keysym is a printable character, spyglass logs the keysym itself; otherwise, it logs a mnemonic of the ASCII code, (e.g., stands for 127).
The keyboard notifier fires in hardirq context, whereas the device requires process context; spyglass splits across two runtimes (device.lua in process and notifier.lua in hardirq) sharing captured chars via a fifo.
keylocker is a kernel script that implements Konami Code for locking and unlocking the console keyboard. When the user types ↑ ↑ ↓ ↓ ← → ← → LCTRL LALT, the keyboard will be locked; that is, the system will stop processing any key pressed until the user types the same key sequence again.
Số liệu repository có thể thay đổi; nên mở liên kết nguồn để kiểm tra README, giấy phép và trạng thái phát hành.
Nguồn tham khảo: Xem bài gốc