Openwrt Notes

Version 19.1 by Leon Poon on 2019/01/06 13:28

 

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)
  • 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
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

Network

sed -re 's/^boot_run_hook/#\0/g' -i /etc/preinit
PREINIT=1 . /etc/preinit
for pi_ifname in eth0.1 eth0.2; do preinit_ip; done