Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction to krOS

krOS is a semi-realistic operating system developed and maintained on the Roblox platform. It features a Process Manager, File System, Graphics output, a syscall interface, built in libraries and applications, etc.
Through the chapters you will learn how the OS learn, how to interact with it, its ABI and API, and more.

The structure of krOS

1. The FS (File System)

krOS is coded in Luau. The FS is, through the lifetime of the OS, a Virtual File System. Each file is stored inside of the hierarchy dictionary. On shutdown, the OS convers that entire dictionary into JSON, which is then compressed down by ZLib, then saved into 512KB buffer chunks. On startup, the 512KB buffer chunks are converted into the ZLib compressed format, decompressed back into JSON, then decoded back into the original dictionary that lives on to be the FS.
Not the most realistic approach, definitely, but it is a very usable one that causes little issues and allows a lot of control.
File system operations retrieve/write data to the dictionary/entries from the dictionary.

2. The PM (Process Manager)

The PM stores each process in a Luau table, with the key being its PID. It contains a lot of information about the process and references to its resources so they can be freed when the process gets shut down. Processes are scheduled using Roblox’s native task.spawn(), which has worked fine so far and multitasking hasn’t been an issue.
The PM acts more as a JIT compiler. Applications are stored as Lua 5.1 source code, which the PM passes to vLua, which will compile to bytecode that will be run by the VM.

3. The VGA

VGA is usually a low resolution way to display text, but in krOS VGA is the first, primitive text output. If you’ve ever done OSDev, the address 0xB8000 may closely represent what this does. Its only job is to display text to the screen, nothing else.

4. The AGO (Advanced Graphics Output)

The AGO’s job is to display more advanced objects to the screen. It does not however offer pixel-level control like a real OS would, just a lot of Roblox GUI. It NEVER returns the GUI itself, only an ID that can be used to manipulate the GUI through controlled functions.

5. The WM (Window Manager)

The WM is NOT made over the AGO. This was done to improve performance of the overall OS while keeping maximum control at the kernel level. Its job is to create windows, return IDs, and offer basic window manipulation functions.

5. The GM (Graphics Manager)

The GM displays objects inside of windows created with the window manager. It also only returns IDs, not real Roblox objects, with functions to manipulate those IDs.

Note

None of the graphics APIs return actual Roblox objects because that would allow escaping from the virtual Luau environment using the .Parent property, which would allow direct access to all Roblox Local services.

6. The environment itself

The environment for each process is, under normal circumstances with no intrusive exploits used, fully blocked. You can not get to the Roblox services. You can only use the functions that are given to you. Some Roblox DataTypes are given, but they are primitives that do not lead anywhere, such as Vector2, etc.

7. Structure of krOS fs

krOS’s root folder isn’t the usual / from Linux. It is the simple phrase root that is the first folder in the entire hierarchy. The entire OS root/ hierarchy looks like this:

root/
├── assets
├── bin
├── lib
├── sys
└── user

assets

Contains core assets, such as images (the rbxassetid://), etc.

bin

Contains valid files that can be run

lib

Contains libraries that are meant to be imported

sys

Contains core system files

user

Contains user files

The purpose of krOS

krOS was made mostly for being a fun project, but also to prove a point. That a limited platform can still do so much. Roblox does not have any low level functions, only high level functions, but put together they can simulate a low level environment very well. Could even simulate an actual Emulator, but the nature of the Luau language would limit the project quite significantly.

Builtin programs

You will learn how to use the builtin programs of krOS. These programs do not include self-made or installed programs.

console.exe

console.exe is the krOS builtin terminal.
A terminal is a text-based user interface that lets you type commands to interact with an operating system.

Program information

  • Location: root/bin/console.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: yes
  • Interacts with any graphics API (directly): yes
  • Uses keyboard for advanced interaction: yes
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin

Help with console.exe

To use console.exe, you can run it from the start menu or from the start bar. Once you are in, you have a basic terminal in which you can type commands. The builtin commands are:

clear
# Clears the console (removes all text)
echo {text}
# Outputs back to the console whatever text was given
help
# Get help with the available commands and programs
pwd
# Prints the current working directory
cd
# Changes the current working directory
shutdown
# Shuts down the system
expand_storage
# Prompts +8MB storage expansion

cat.exe

cat.exe outputs the content of a file.

Program information

  • Location: root/bin/cat.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/cat.exe

Help with cat.exe

You can run cat from your console program (such as root/bin/console.exe).
You must provide a flag to cat.exe or else it will not work.

--help
# Get help with the available flags of cat.exe
{file_to_read}
# The path of the file whose contents should be displayed.

ls.exe

ls.exe outputs all the children of a directory.

Program information

  • Location: root/bin/ls.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/ls.exe

Help with ls.exe

You can run ls from your console program (such as root/bin/console.exe).
If you do not provide any flag to ls, the children of the CWD will be displayed.

--help
# Get help with the available flags of ls.exe
{dir_to_list_children_of}
# The path of the directory whose children should be displayed.

mkdir.exe

mkdir.exe creates a directory.

Program information

  • Location: root/bin/mkdir.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/mkdir.exe

Help with mkdir.exe

You can run mkdir from your console program (such as root/bin/console.exe).

--help
# Get help with the available flags of mkdir.exe
{location}
# Create a directory at location

rmdir.exe

rmdir.exe removes a directory.

Program information

  • Location: root/bin/rmdir.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/rmdir.exe

Help with rmdir.exe

You can run rmdir from your console program (such as root/bin/console.exe).
Unlike the GNU Coreutils rmdir, you use rmdir to remove any directory, even if it’s full, even if it isn’t.

--help
# Get help with the available flags of rmdir.exe
{location}
# Remove directory at location

touch.exe

touch.exe creates an empty file.

Program information

  • Location: root/bin/touch.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/touch.exe

Help with rmdir.exe

You can run touch from your console program (such as root/bin/console.exe).

--help
# Get help with the available flags of touch.exe
{location}
# Create empty file at location

rm.exe

rm.exe removes a file.

Program information

  • Location: root/bin/rm.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/rm.exe

Help with rm.exe

You can run rm from your console program (such as root/bin/console.exe).
Unlike the GNU Coreutils rm, you use rm to remove EXCLUSIVELY files.

--help
# Get help with the available flags of rm.exe
{location}
# Remove file at location

df.exe

df.exe displays disk information.

Program information

  • Location: root/bin/df.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/df.exe

Help with df.exe

You can run df from your console program (such as root/bin/console.exe).
If you pass no arguments, the information will be shown in Bytes (B)

--help
# Get help with the available flags of df.exe
--kb
# Get information in Kilobytes (KB)
--mb
# Get information in Megabytes (MB)
--gb
# Get information in Gigabytes (GB)

ps.exe

ps.exe displays process information.

Program information

  • Location: root/bin/ps.exe
  • Permissions: r-x-
  • Interacts with file system: no
  • Interacts with process manager: yes
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/ps.exe

Help with ps.exe

You can run ps from your console program (such as root/bin/console.exe).

--help
# Get help with the available flags of ps.exe
--advanced
# Get advanced information about all processes

cp.exe

cp.exe copies a file.

Program information

  • Location: root/bin/cp.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/cp.exe

Help with cp.exe

You can run cp from your console program (such as root/bin/console.exe).
Unlike the GNU Coreutils cp, you cannot copy directories using cp.

--help
# Get help with the available flags of cp.exe
{file} {path}
# Copy file to path

mv.exe

mv.exe moves a file.

Program information

  • Location: root/bin/mv.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/mv.exe

Help with mv.exe

You can run mv from your console program (such as root/bin/console.exe).
Unlike the GNU Coreutils mv, you cannot move directories using mv.

--help
# Get help with the available flags of mv.exe
{file} {path}
# Move file to path

zip.exe

zip.exe zips a file or directory.

Program information

  • Location: root/bin/zip.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/zip.exe

Help with zip.exe

You can run zip from your console program (such as root/bin/console.exe).

--help
# Get help with the available flags of zip.exe
{source} {dest}
# Zip source into dest

unzip.exe

unzip.exe unzips a zip file into a directory.

Program information

  • Location: root/bin/unzip.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: no
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/unzip.exe

Help with unzip.exe

You can run unzip from your console program (such as root/bin/console.exe).

--help
# Get help with the available flags of unzip.exe
{source} {dest}
# Unzip source into dest

editor.exe

editor.exe lets you modify contents of files / create new files.

Program information

  • Location: root/bin/editor.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): yes
  • Uses keyboard for advanced interaction: yes
  • Uses mouse for advanced interaction: yes
  • Initial working directory: root/bin/editor.exe

Help with editor.exe

You can run editor from your console program (such as root/bin/console.exe).

--help
# Get help with the available flags of editor.exe
{source}
# Open source in editor

appstore.exe

appstore.exe lets you upload/download files.

Program information

  • Location: root/bin/appstore.exe
  • Permissions: r-x-
  • Interacts with file system: yes
  • Interacts with process manager: no
  • Interacts with any graphics API (directly): no
  • Uses keyboard for advanced interaction: yes
  • Uses mouse for advanced interaction: no
  • Initial working directory: root/bin/appstore.exe

Help with appstore.exe

You can run appstore from your console program (such as root/bin/console.exe).

--help
# Get help with the available flags of appstore.exe
upload {path} {appname} {description}
# Upload to appstore the file at {path}, with the app name {appname}, and the description {description}
download {path} {appname}
# Download from appstore into {path} the app with the app name {appname}
# If multiple apps under the same appname exist the program will prompt you to choose one
remove {appname}
# Remove app {appname} from appstore
# Only works with your own apps
listuser {username}
# List apps of an user

Builtin programs

You will learn how to use the libraries in root/lib

stdio.lib

stdio.lib is responsible for standard input/output (the parent process decides the callbacks)


Importing

local stdio = import("stdio.lib")

Methods

out

function stdio.out(data)
  • Outputs to stdout the data
  • Example usage:
local stdio = import("stdio.lib")

stdio.out("Hello world!") -- if ran by root/bin/console.exe this will output "Hello world" to the screen

inp

function stdio.inp(): string
  • Returns stdin data
  • Example usage:
local stdio = import("stdio.lib")

stdio.out("What is your name > ")
local name = stdio.inp()
stdio.out("Hello, "..name)

-- if ran by root/bin/console.exe this will output "Hello, " + the given data to the screen

fs.lib

fs.lib communicates with the FS (File System) using syscalls and wraps those functions


Importing

local fs = import("fs.lib")

Methods

write

dir

function fs.write.dir(path: string): number
  • Creates a directory at specified path
  • Returns a return code:
Return CodeNumerical ValueMeaning
SUCCESS0The operation has completed successfully
INVALID_PATH1The specified path is invalid
INVALID_PARENT_TYPE2The parent is a file and not a directory
DIR_EXISTS3The directory already exists
NO_PERMS4No permission to write directory at the specified path
STORAGE_OVERFLOW5The operation would cause the storage to fill up
  • Example usage:
local fs = import("fs.lib")

local success = fs.write.dir("root/user/Hello")
if success == 0 then
    -- the operation completed successfully
end

file

function fs.write.file(path: string, content: string): number
  • Creates a new file at specified path
  • File will contain given content
  • Returns a return code:
Return CodeNumerical ValueMeaning
SUCCESS0The operation has completed successfully
INVALID_PATH1The specified path is invalid
INVALID_PARENT_TYPE2The parent is a file and not a directory
OVERWRITE_DIR3fs.write.file() can not overwrite a directory
NO_PERMS4No permission to write file at the specified path
STORAGE_OVERFLOW5The operation would cause the storage to fill up
  • Example usage:
local fs = import("fs.lib")

local success = fs.write.file("root/user/hello.lua", "Hello World!")
if success = 0 then
    -- the operation completed successfully
end

read

function fs.read(path: string): (number, string)
  • Reads the content of a file at specified path
  • Returns the return code (ret1) and the content (ret2)
Return CodeNumerical ValueMeaning
SUCCESS0The operation has completed successfully
INVALID_FILE1The file that was attempted to be read is invalid
ATTEMPT_READ_DIR2fs.read() can not read a directory
NO_PERMS3No permission to read the file
  • Example usage:
local fs = import("fs.lib")

local success, content = fs.read("root/user/hello.lua")
if success = 0 then
    -- the operation completed successfully
end

remove

dir

function fs.remove.dir(path: string): number
  • Removes a directory and its children
  • Returns a return code:
Return CodeNumerical ValueMeaning
SUCCESS0The operation completed successfully
INVALID_DIR1The folder that should’ve been removed was not found
NO_PERMS2No permission to remove directory
FAILED3The operation has failed on the directory children - Data loss is possible
INVALID_FS_STATE0xDEADBEEFAn invalid file system state. The system will panic when this is returned
  • Example usage:
local fs = import("fs.lib")

local success = fs.remove.dir("root/user")
if success = 0 then
    -- the operation completed successfully
    -- this operation will not cause there are no permissions to remove root/user
end

file

function fs.remove.file(path: string): number
  • Removes a file
  • Returns a return code:
Return CodeNumerical ValueMeaning
SUCCESS0The operation completed successfully
INVALID_FILE1The specified file is invalid
NO_PERMS2No permission to complete operation
  • Example usage:
local fs = import("fs.lib")

local success = fs.remove.file("root/bin/console.exe")
if success = 0 then
    -- the operation completed successfully
    -- this operation will not cause there are no permissions to remove root/bin/console.exe
end

dir_children

function fs.remove.dir_children(path: string): number
  • Removes children of a directory excluding the directory

  • Returns a return code: | Return Code | Numerical Value | Meaning | | :———: | :———––: | :—–: | | SUCCESS | 0 | The operation completed successfully | | INVALID_DIR | 1 | The folder whose children should’ve been removed was not found | | NO_PERMS | 2 | No permission to remove children of directory | | FAILED | 3 | The operation has failed on the directory children - Data loss is possible | | INVALID_FS_STATE | 0xDEADBEEF | An invalid file system state. The system will panic when this is returned |

  • Example usage:

local fs = import("fs.lib")

local success = fs.remove.dir_children("root")
if success = 0 then
    -- the operation completed successfully
    -- this operation will not cause there are no permissions to remove root
end

get_dir_children

function fs.get_dir_children(path: string): (number, {string})
  • Gets all children of a directory
  • Returns a return code (ret1) and the children (ret2) | Return Code | Numerical Value | Meaning | | :———: | :———––: | :—–: | | SUCCESS | 0 | The operation completed successfully | | INVALID_PATH | 1 | The directory to get children of is invalid | | INVALID_PROP | 2 | This should never be returned as it is logically impossible to achieve |

get_ext

function fs.get_ext(path_or_fname: string): string
  • Returns the extension of a path or filename
  • Returns "" (an empty string) if filename has no extension

get_basename

function fs.get_basename(path_or_fname: string): string
  • Returns only the name, strips the extension and the path expression from earlier

get_name

function fs.get_name(path_or_fname: string): string
  • Returns the filename, removes previous slashes and keeps the name and extension

get_path_breakdown

function fs.get_path_breakdown(path_or_fname: string): {string}
  • Returns the path breakdown, a table of all elements from the path

get_parent

function fs.get_parent(path_or_fname: string): string
  • Returns the parent of a path

exists

function fs.exists(path): boolean
  • Returns whether the object exists or not in the filesystem

get_used_storage

function fs.get_used_storage(): number
  • Returns the used storage

get_max_storage

function fs.get_max_storage(): number
  • Returns the whole available storage

get_final_path

function fs.get_final_path(path, optional_start): string
  • Starts in the working directory or optional_start, then normalizes the given path and returns it
  • Example usage:
local fs = import("fs.lib")

local normalized = fs.get_final_path("../lib/../bin", "root/bin")
--[[
normalized is now "root/bin", because:
1. we start in root/bin
2. we go back (..) into root
3. we go in root/lib
4. we go back (..) into root
5. we go in root/bin
]]

get_final_path_ignore_existence

function fs.get_final_path_ignore_existence(path, optional_start): string
  • Starts in the working directory or optional_start, then normalizes the given path and returns it
  • Can go one file deeper (inexistent)
  • Example usage:
local fs = import("fs.lib")

local normalized = fs.get_final_path("../lib/../bin/inexistent_file.exe", "root/bin")
--[[
normalized is now "root/bin/inexistent_file.exe", because:
1. we start in root/bin
2. we go back (..) into root
3. we go in root/lib
4. we go back (..) into root
5. we go in root/bin
6. we go in root/bin/inexistent_file.exe
this is useful for programs such as mkdir or touch

keyboard.lib

keyboard.lib offers basic keyboard functions


Importing

local keyboard = import("keyboard.lib")

Methods

register_event

function keyboard.register_event(
    on_press: (key: string) -> nil, 
    on_release: (key: string) -> nil
): number?
  • Registers an event
  • Whenever the key is pressed, on_press is called with the name of the key (Roblox Enum key name)
  • Whenever the key is released, on_release is called with the name of the key (Roblox Enum key name)
  • Returns an ID to the keyboard listener

unregister_event

function keyboard.unregister_event(id: number)
  • Unregisters an event
  • Example usage:
local keyboard = import("keyboard.lib")

local enter_pressed = false

local id = keyboard.register_event(function(key: string)
    if key == "Return" then enter_pressed = true end
end, nil)

while true do
    if enter_pressed then
        keyboard.unregister_event(id)
        break
    end
    wait(0.1)
end

is_key_pressed

function is_key_pressed(key: string): boolean
  • Returns whether a key is pressed or not
  • Pass Roblox Enum key name
  • Example usage:
local keyboard = import("keyboard.lib")
local stdio = import("stdio.lib")

if keyboard.is_key_down("X") then
    stdio.out("X is down!")
end

await_key_press

function await_key_press(key: string)
  • Waits for the specified key to be pressed
  • Pass Roblox Enum key name
  • Example usage:
local keyboard = import("keyboard.lib")
local stdio = import("stdio.lib")

keyboard.await_key_press("Space")

stdio.out("Space was pressed!")

sysinfo.lib

sysinfo.lib returns useful system information


Importing

local sysinfo = import("sysinfo.lib")

Methods

get_kernel_ver

function sysinfo.get_kernel_ver(): string
  • Returns the kernel version

get_fs_ver

function sysinfo.get_fs_ver(): string
  • Returns the filesystem version

get_pm_ver

function sysinfo.get_pm_ver(): string
  • Returns the process manager version

get_screen_size

function sysinfo.get_screen_size(): {x: number, y: number}
  • Returns the screen size