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
Modules
cp -va ./build_dir/target-*/linux-*/linux-4*/modules.builtin ./staging_dir/target-*/root-*/lib/modules/4*
# tar -C ./staging_dir/target-*/root-*/ -vcjf modules.tar.bz2 lib/modules
{{code}}
= Debian =
{{code}}
debootstrap --variant=minbase --include locales,sudo,sysvinit-core,sysvinit-utils,vim-nox,screen,wget,ntp,bridge-utils,ifupdown --exclude=nano,vim-tiny --foreign stretch $PWD
chroot $PWD debootstrap/debootstrap --second-stage
{{/code}}
{{code}}
qemu-debootstrap --include=locales,sudo,sysvinit-core,sysvinit-utils,vim-nox,screen,wget,ntp,bridge-utils,ifupdown --exclude=nano,vim-tiny,systemd,systemd-sysv --arch mipsel stretch /mnt/cdrom
{{/code}}
Do not install openssh-server during bootstrap otherwise it will bring in systemd!
Things to do after debootstrap:
* [[get rid of systemd>>http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_Stretch_installation]]
* set hostname
* set root password
* /etc/network/interfaces (TODO: swconfig while still in openwrt initramfs space?)
* apt-get install ~-~-no-install-recommends openssh-server (check that it is without libpam-systemd and systemd!!)
* apt-get install net-tools file ntp openssh-server gcc
** net-tools for ifconfig
** gcc for?
* echo vm.min_free_kbytes=16384 > /etc/sysctl.d/min_free_kbytes.conf
* kernel modules ( tar -C ./staging_dir/target-*/root-*/ -vcjf - lib/modules | ssh TARGET_IP tar -C / -vxjf - )
* read-only root
Needs CONFIG_DEVTMPFS=y in kernel.
{{code language="bash"}}
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
{{/code}}
{{code language="bash"}}
chroot /mnt /bin/bash
{{/code}}
{{code language="bash"}}
mount proc /proc -t proc
{{/code}}
{{code language="bash"}}
exec switch_root /mnt /sbin/init
{{/code}}
{{code language="bash"}}
ip addr add dev eth0 IP/NM
ip link set eth0 up
ip route add default via GW
{{/code}}
= Network =
{{code language="bash"}}
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
{{/code}}
= UBI =
{{code language="text"}}define Build/append-ubi
sh $(TOPDIR)/scripts/ubinize-image.sh \
$(if $(UBOOTENV_IN_UBI),--uboot-env) \
$(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
$(foreach part,$(UBINIZE_PARTS),--part $(part)) \
$(IMAGE_ROOTFS) \
$@.tmp \
-p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
$(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
$(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
$(UBINIZE_OPTS)
cat $@.tmp >> $@
rm $@.tmp
endef{{/code}}
~{~{/code}}
# tar -C ./staging_dir/target-*/root-*/ -vcjf modules.tar.bz2 lib/modules
{{code}}
= Debian =
{{code}}
debootstrap --variant=minbase --include locales,sudo,sysvinit-core,sysvinit-utils,vim-nox,screen,wget,ntp,bridge-utils,ifupdown --exclude=nano,vim-tiny --foreign stretch $PWD
chroot $PWD debootstrap/debootstrap --second-stage
{{/code}}
{{code}}
qemu-debootstrap --include=locales,sudo,sysvinit-core,sysvinit-utils,vim-nox,screen,wget,ntp,bridge-utils,ifupdown --exclude=nano,vim-tiny,systemd,systemd-sysv --arch mipsel stretch /mnt/cdrom
{{/code}}
Do not install openssh-server during bootstrap otherwise it will bring in systemd!
Things to do after debootstrap:
* [[get rid of systemd>>http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_Stretch_installation]]
* set hostname
* set root password
* /etc/network/interfaces (TODO: swconfig while still in openwrt initramfs space?)
* apt-get install ~-~-no-install-recommends openssh-server (check that it is without libpam-systemd and systemd!!)
* apt-get install net-tools file ntp openssh-server gcc
** net-tools for ifconfig
** gcc for?
* echo vm.min_free_kbytes=16384 > /etc/sysctl.d/min_free_kbytes.conf
* kernel modules ( tar -C ./staging_dir/target-*/root-*/ -vcjf - lib/modules | ssh TARGET_IP tar -C / -vxjf - )
* read-only root
Needs CONFIG_DEVTMPFS=y in kernel.
{{code language="bash"}}
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
{{/code}}
{{code language="bash"}}
chroot /mnt /bin/bash
{{/code}}
{{code language="bash"}}
mount proc /proc -t proc
{{/code}}
{{code language="bash"}}
exec switch_root /mnt /sbin/init
{{/code}}
{{code language="bash"}}
ip addr add dev eth0 IP/NM
ip link set eth0 up
ip route add default via GW
{{/code}}
= Network =
{{code language="bash"}}
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
{{/code}}
= UBI =
{{code language="text"}}define Build/append-ubi
sh $(TOPDIR)/scripts/ubinize-image.sh \
$(if $(UBOOTENV_IN_UBI),--uboot-env) \
$(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
$(foreach part,$(UBINIZE_PARTS),--part $(part)) \
$(IMAGE_ROOTFS) \
$@.tmp \
-p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
$(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
$(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
$(UBINIZE_OPTS)
cat $@.tmp >> $@
rm $@.tmp
endef{{/code}}
~{~{/code}}