From 1a7eed303d76764f36eaaec5c6cce26a77b2a47e Mon Sep 17 00:00:00 2001 From: Michael Shigorin Date: Thu, 18 Sep 2014 22:33:19 +0400 Subject: [PATCH] pid1: initial "run as PID 1" feature This one has been inspired by these guys: http://www.informatimago.com/linux/emacs-on-user-mode-linux.html https://raymii.org/s/blog/Vim_as_PID_1_Boot_to_Vim.html It's aimed at building images running their main userspace piece instead of ramdisk's init, that means PID=1, UID=0. Mostly fun of course but it suddenly became interesting with kernel IP autoconfiguration and e.g. elinks running this way (NB: requires patched make-initrd 0.8.8 at the moment to get resolver configured). And startup times are way better than sysvinit and systemd combined! --- features.in/pid1/README | 15 ++++++++++++++ features.in/pid1/config.mk | 20 +++++++++++++++++++ .../pid1/stage1/scripts.d/11-initrd-pid1 | 4 ++++ .../pid1/stage1/scripts.d/82-gzip-initfs | 3 +++ features.in/syslinux/cfg.in/20pid1.cfg | 4 ++++ 5 files changed, 46 insertions(+) create mode 100644 features.in/pid1/README create mode 100644 features.in/pid1/config.mk create mode 100755 features.in/pid1/stage1/scripts.d/11-initrd-pid1 create mode 100755 features.in/pid1/stage1/scripts.d/82-gzip-initfs create mode 100644 features.in/syslinux/cfg.in/20pid1.cfg diff --git a/features.in/pid1/README b/features.in/pid1/README new file mode 100644 index 00000000..127962b2 --- /dev/null +++ b/features.in/pid1/README @@ -0,0 +1,15 @@ +Эта экспериментальная фича предназначена для обеспечения запуска +заданного приложения в моно^Wкачестве единственного, т.е. PID 1. + +Особенности результата: +- предельно быстрый запуск; +- работа под root; +- отсутствие какой бы то ни было инициализации окружения. + +Возможна настройка сетевых интерфейсов средствами ядра, условия: +- статически собранный модуль для используемого интерфейса; +- доступность DHCP/BOOTP/RARP в сегменте локальной сети. + +Пакет следует добавить в STAGE1_PACKAGES; путь к бинарнику +задаётся в PID1_BIN; PID1_PANIC позволяет указать время до +перезагрузки ядра при завершении работы приложения. diff --git a/features.in/pid1/config.mk b/features.in/pid1/config.mk new file mode 100644 index 00000000..e4e3cc3b --- /dev/null +++ b/features.in/pid1/config.mk @@ -0,0 +1,20 @@ +# choose the smallest suitable kernel +use/pid1: sub/stage1 use/syslinux/timeout/1 + @$(call add_feature) + @$(call add,STAGE1_PACKAGES,make-initrd) + @$(call add,STAGE2_BOOTARGS,quiet) + @$(call add,STAGE2_BOOTARGS,panic=$$(PID1_PANIC)) + @$(call add,STAGE2_BOOTARGS,rdinit=$$(PID1_BIN)) + @$(call add,SYSLINUX_CFG,pid1) + @$(call try,PID1_PANIC,3) + @$(call xport,PID1_PANIC) + @$(call xport,PID1_BIN) +ifeq (i586,$(ARCH)) + @$(call set,KFLAVOURS,ltsp-client) +endif + +# need a kernel with CONFIG_IP_PNP_DHCP +# NB: make-initrd must support resolver setup! +use/pid1/net: use/pid1 + @$(call add,STAGE2_BOOTARGS,ip=dhcp) + @$(call add,STAGE1_PACKAGES,chrooted-resolv) diff --git a/features.in/pid1/stage1/scripts.d/11-initrd-pid1 b/features.in/pid1/stage1/scripts.d/11-initrd-pid1 new file mode 100755 index 00000000..d3fbd71b --- /dev/null +++ b/features.in/pid1/stage1/scripts.d/11-initrd-pid1 @@ -0,0 +1,4 @@ +#!/bin/sh +# vi's +builtin_terms only cover ansi/xterm + +echo "PUT_FILES += /lib/terminfo/l/linux $GLOBAL_PID1_BIN" >> /etc/initrd.mk diff --git a/features.in/pid1/stage1/scripts.d/82-gzip-initfs b/features.in/pid1/stage1/scripts.d/82-gzip-initfs new file mode 100755 index 00000000..3f1bc9ec --- /dev/null +++ b/features.in/pid1/stage1/scripts.d/82-gzip-initfs @@ -0,0 +1,3 @@ +#!/bin/sh + +gzip < /boot/initrd.img > /boot/full.cz diff --git a/features.in/syslinux/cfg.in/20pid1.cfg b/features.in/syslinux/cfg.in/20pid1.cfg new file mode 100644 index 00000000..08c7341a --- /dev/null +++ b/features.in/syslinux/cfg.in/20pid1.cfg @@ -0,0 +1,4 @@ +label pid1 + menu label ^Just run as PID 1 + kernel alt0/vmlinuz + append initrd=alt0/full.cz @bootargs@