Giter Site home page Giter Site logo

slashinit's Introduction

/init

Minimal PID 1 for initramfs.

This is used for diskless servers with only two stages: /etc/boot and /etc/reboot.

For all spawned processes:

  • inputs from stdin are dropped.
  • outputs from stdout are redirected to /dev/console.
  • logs from stderr are redirected to /dev/kmsg.

Build & Install

The binary must be installed as /init and nothing else.

$ make install DESTDIR=<PATH>

Update & reboot

When your system is running with /init you don't need any extra tool to do an update. Just put the new kernel at /kernel and /init will automatically kexec it after the /etc/reboot stage.

If you want to update your system in the usual way (pxe, efi,...) you need a cold reboot:

$ touch /reboot
$ reboot

With reboot a script that stops your supervisor. For example with runit:

$ cat /bin/reboot
#!/bin/sh

exec pkill -HUP runsvdir

Configuration

Only two files are needed, for example:

$ cat /etc/boot
#!/bin/sh

# your personal stuff..

exec runsvdir -P /run/service

and

$ cat /etc/reboot
#!/bin/sh

# your personal stuff..

# you can still use kexec-tools for old kernels or unsupported arch.
kexec -l /kernel --reuse-cmdline && kexec -e

File system

/init will create a minimal file system that should look like this if all goes well:

# cat /proc/mounts
none / rootfs rw,nosuid 0 0
none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
none /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime 0 0
none /dev devtmpfs rw,nosuid,noexec 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0

Note that /init mounts cgroup2 as /sys/fs/cgroup and not the old cgroup.

Kernel configuration

A minimal kernel configuration to enable all features of /init would look like this:

CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE=<PATH>  # root directory with <PATH>/init
CONFIG_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y
CONFIG_DEVTMPFS=y
CONFIG_PROC_FS=y
CONFIG_SYSFS=y

Since all logs go into the kernel, it's a good idea to increase the size of the log buffer:

CONFIG_LOG_BUF_SHIFT=24

Required for updates:

CONFIG_RELOCATABLE=y
CONFIG_CRYPTO=y
CONFIG_CRYPTO_SHA256=y
CONFIG_KEXEC_FILE=y

Not mandatory but useful to see what's going on :)

CONFIG_PRINTK=y
CONFIG_TTY=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y

For feature requests and bug reports, please create an issue.

slashinit's People

Contributors

angt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.