initramfs-kernel
kernel runs /init.
/init is a script which sets INITRAMFS=1 and then execs /sbin/init.
/sbin/init is ELF comes from procd package. What it does (as pid=1):
- early (different from procd early):
- mount /proc, /sysfs, and create /dev nodes, create /tmp subdirs etc
- set PATH
- kmodloader in subprocess (waits until done)
- preinit
- plugd in subprocess (seem to deal with firmware)
- /etc/preinit in subprocess
- when /etc/preinit is done then it execvp the "real" /sbin/procd
procd states:
- early (first state):
- coldplug (remount /dev, etc)
- start udevtrigger in subproc
- when udevtrigger completes, hotplug
- when hotplug completes, next state (ubus)
- coldplug (remount /dev, etc)
- ubus:
- start attempts to connect to ubs
- start ubus as service
- once connection's done then next state (init)
- init - read /etc/inittab and run:
- respawn - things that need to keep rerunning once quitted
- askconsole
- askfirst - the "Press Enter to activate this console" message
- sysinit - (usually /etc/init.d/rcS with S) and then next state (running)
- running - waits for shutdown signal (usr1/usr2) or reboot (int/term)
- shutdown
- runs shutdown command per inittab (also /etc/init.d/rcS but with K)
- when done next state (halt)
- halt - kill everything and either enter sleep loop or reboots
Debian
Things to do after debootstrap:
- get rid of systemd
- set hostname
- set root password
- /etc/network/interfaces (TODO: swconfig while still in openwrt initramfs space?)
- apt-get install net-tools file ntp openssh-server gcc
- net-tools for ifconfig
- gcc for?
- read-only root
Needs CONFIG_DEVTMPFS=y in kernel.
mkdir -pv /mnt &&
mknod /dev/sda b 8 0 &&
cryptsetup open /dev/sda usb &&
vgchange -ay vol_grp1 &&
mount /dev/vol_grp1/logical_vol1 /mnt -o ro
mknod /dev/sda b 8 0 &&
cryptsetup open /dev/sda usb &&
vgchange -ay vol_grp1 &&
mount /dev/vol_grp1/logical_vol1 /mnt -o ro
chroot /mnt /bin/bash
mount proc /proc -t proc
exec switch_root /mnt /sbin/init
ip addr add dev eth0 IP/NM
ip link set eth0 up
ip route add default via GW
ip link set eth0 up
ip route add default via GW
Network
sed -re 's/^boot_run_hook/#\0/g' -i /etc/preinit
PREINIT=1 . /etc/preinit
preinit_config_board # set up the switch and lan ports on eth0.2, and create ip link
json_select switch
json_select switch0
json_add_boolean reset 0 # do not reset when setting up wan ports on eth0.1
json_select ..
json_select ..
preinit_config_switch switch0 eth0.1 # set up wan ports
preinit_ip_config eth0.1 # create ip link
ip address flush dev eth0 # del default address
for pi_ifname in eth0.1 eth0.2; do
ip -4 address flush dev $pi_ifname # del default address
ip link set dev $pi_ifname down
done
PREINIT=1 . /etc/preinit
preinit_config_board # set up the switch and lan ports on eth0.2, and create ip link
json_select switch
json_select switch0
json_add_boolean reset 0 # do not reset when setting up wan ports on eth0.1
json_select ..
json_select ..
preinit_config_switch switch0 eth0.1 # set up wan ports
preinit_ip_config eth0.1 # create ip link
ip address flush dev eth0 # del default address
for pi_ifname in eth0.1 eth0.2; do
ip -4 address flush dev $pi_ifname # del default address
ip link set dev $pi_ifname down
done