An initramfs PID-1 for those in a pinch

Related tags

Cryptography pinch
Overview

pinch

A fast initramfs PID-1 written in Rust and driven by Lua.

[    0.440249] Run /init as init process
[Starting Pinch]
-- Initializing Lua environment
-- Running script: init.env.lua
-- Running script: /usr/share/pinch/device-qemu-amd64-init.lua
-- Running script: init.lua
[LUA] Pinch starting up on QEMU amd64 (Sun Mar 17 02:23:56 2024)
[LUA] Framebuffer disabled: false
[LUA] Kernel modules: 
[RUST]: probing modules: {"libcomposite", "vfat", "virtio-gpu", "virtio_input", "virtio_pci", "virtio_blk", "evdev"}
$ modprobe libcomposite
$ modprobe vfat
$ modprobe virtio-gpu
[    0.478948] ACPI: bus type drm_connector registered
$ modprobe virtio_input
$ modprobe virtio_pci
[    0.506230] ACPI: \_SB_.LNKB: Enabled at IRQ 10
[    0.508777] input: QEMU Virtio Mouse as /devices/pci0000:00/0000:00:02.0/virtio0/input/input2
[    0.519092] ACPI: \_SB_.LNKC: Enabled at IRQ 11
[    0.521646] input: QEMU Virtio Keyboard as /devices/pci0000:00/0000:00:03.0/virtio1/input/input3
[    0.530380] ACPI: \_SB_.LNKD: Enabled at IRQ 11
[    0.540925] ACPI: \_SB_.LNKA: Enabled at IRQ 10
[    0.546178] [drm] pci: virtio-vga detected at 0000:00:05.0
[    0.547478] Console: switching to colour dummy device 80x25
[    0.548359] virtio-pci 0000:00:05.0: vgaarb: deactivate vga console
[    0.550564] [drm] features: +virgl +edid -resource_blob -host_visible
[    0.550565] [drm] features: -context_init
[    0.553883] [drm] number of scanouts: 1
[    0.554524] [drm] number of cap sets: 2
[    0.566724] [drm] cap set 0: id 1, max-version 1, max-size 308
[    0.568695] [drm] cap set 1: id 2, max-version 2, max-size 1384
[    0.570799] [drm] Initialized virtio_gpu 0.1.0 0 for 0000:00:05.0 on minor 0
[    0.572532] fbcon: virtio_gpudrmfb (fb0) is primary device
[    0.574948] Console: switching to colour frame buffer device 80x30
[    0.581496] virtio-pci 0000:00:05.0: [drm] fb0: virtio_gpudrmfb frame buffer device
$ modprobe virtio_blk
[    0.601218] virtio_blk virtio4: 32/0/0 default/read/poll queues
[    0.609238] virtio_blk virtio4: [vda] 8388608 512-byte logical blocks (4.29 GB/4.00 GiB)
[    0.615545] GPT:Primary header thinks Alt. header is not at the end of the disk.
[    0.617434] GPT:3692543 != 8388607
[    0.618935] GPT:Alternate GPT header not at the end of the disk.
[    0.621391] GPT:3692543 != 8388607
[    0.622624] GPT: Use GNU Parted to correct GPT errors.
[    0.624082]  vda: vda1 vda2
$ modprobe evdev
$ /sbin/udevd -d --resolve-names=never
[    0.629269] udevd[805]: starting version 3.2.14
[    0.631439] udevd[806]: starting eudev-3.2.14
-- /sys/module/firmware_class/parameters/path > /lib/firmware/postmarketos
[RUST]: udev: matching subsystem: block
[RUST]: udev: matching subsystem: input
[RUST]: udev: matching subsystem: graphics
[RUST]: udev: scanning devices
[LUA] found device: /dev/input/event1
[LUA] found device: /dev/input/event2
[LUA] found device: /dev/fb0
[LUA] found device: /dev/vda
[LUA] found device: /dev/vda1
[LUA] found device: /dev/vda2
[LUA] found device: /dev/input/event0

Building

Small release builds:

RUSTFLAGS="-Zlocation-detail=none -C strip=symbols" \
    cargo +nightly build --release \
    -Z build-std=std,panic_abort \
    -Z build-std-features=panic_immediate_abort \
    --target x86_64-unknown-linux-gnu

Size analysis

With following modules: 756k

anyhow = { version = "1.0.81", features = [] }
mlua = { version = "0.9.6", features = ["luau", "vendored"] }

Removing anyhow brings us down to 716k (saves 40k), so not a worthwhile tradeoff.

Switching from luau to lua54 brings it down to 384k (saves 382k). Bah!

pmOS ramdisk stats

Ignoring kernel modules which vary per kernel package/arch/device.

Initramfs for qemu-amd64 is 2.6M

/tmp/extract # ls -lh lib/
total 1M
-rwxr-xr-x    1 root     root      634.6K Mar 14 22:02 ld-musl-x86_64.so.1
lrwxrwxrwx    1 root     root          17 Mar 14 22:02 libblkid.so.1 -> libblkid.so.1.1.0
-rwxr-xr-x    1 root     root      186.8K Mar 14 22:02 libblkid.so.1.1.0
lrwxrwxrwx    1 root     root          19 Mar 14 22:02 libc.musl-x86_64.so.1 -> ld-musl-x86_64.so.1
-r-xr-xr-x    1 root     root      287.4K Mar 14 22:02 libdevmapper.so.1.02
/tmp/extract # ls -lah bin
total 904K
drwxr-xr-x    2 root     root        4.0K Mar 14 22:02 .
drwxr-xr-x   14 root     root        4.0K Mar 14 22:02 ..
-rwxr-xr-x    1 root     root      789.8K Mar 14 22:02 busybox
-rwxr-xr-x    1 root     root      101.7K Mar 14 22:02 busybox-extras
lrwxrwxrwx    1 root     root          12 Mar 14 22:02 sh -> /bin/busybox
/tmp/extract # ls -lh usr/bin/
total 116K
-rwxr-xr-x    1 root     root       98.2K Mar 14 22:02 pbsplash
-rwxr-xr-x    1 root     root       13.9K Mar 14 22:02 unudhcpd
/tmp/extract # ls -lh usr/sbin
total 44K
-rwxr-xr-x    1 root     root       42.1K Mar 14 22:02 kpartx
/tmp/extract # ls -lh sbin
total 48K
-rwxr-xr-x    1 root     root       46.1K Mar 14 22:02 blkid

Replacing busybox would obviously be awesome, and maybe even feasible. We would lose debug shell capabilities, but on devices that have the ability to choose between ramdisks we could just have a debug variant.

Next biggest things are libblkid and libdevmapper. Given that libblkid was just used to let mdev properly configure /dev/disk/by-partlabel we can probably get rid of it.

You might also like...
rust cli project.el clone for those leaving emacs

R-Ject I was a longtime Emacs user and really miss the project management that came with projectile.el and project.el at the same time I was looking f

Owner
Caleb Connolly
they/them | Kernel hacker
Caleb Connolly
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
Tiny PID loop for `no_std` targets

pid-loop ?? PID loop for no_std targets. License Licensed under either of Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/license

Vitaly Domnikov 3 Dec 16, 2021
wait-for-pid -- Wait for processes to exit

wait-for-pid -- Wait for processes to exit wait-for-pid PID is similar to the bash built-in command wait, except it works even when the processes star

Tv 2 Feb 2, 2022
A simple /proc//{mem,maps} library for Rust

Summary A very simple library that wraps around /proc/pid/mem and /proc/pid/maps to read memory out of a running process on Linux. Usage Basic usage l

null 6 Jul 27, 2022
A cli utility written in Rust that allows fetching all the labels of a project, save those as a YAML file

A cli utility written in Rust that allows fetching all the labels of a project, save those as a YAML file that you can easily edit or save as backup and apply a saved preset to new repositories.

Chevdor 4 May 5, 2022
"Crates for Cheese" is a Rust collection library of those crates I consider a useful "extended standard".

cfc The purpose of this library is to provide a minimal list of currated crates which enhance the std library. In addition, most or all crates in this

null 0 Dec 23, 2021
The library for those who need a little extra from their windows. ™

WinEx The library for those who need a little extra from their windows. ™ WinEx - Short for Window Extended - is a library whose goal is to implement

Matheus Branco Borella 2 Mar 27, 2022
Allow raw pointer access without those pesky unsafe blocks everywhere!

Allow raw pointer access without those pesky unsafe blocks everywhere!

null 1 Jan 23, 2022
Project Masterpass is a deterministic databaseless key management algorithm, aimed to help those who cannot protect their encryption keys in storage

Project Masterpass (working title) Attention! This project is still under heavy development, and SHOULD NOT be used in practice, as the algorithms cou

Gyorgy Wang 2 Sep 11, 2022