Wiki source code of Openwrt Notes

Version 47.1 by Leon Poon on 2019/11/02 06:35

Hide last authors
Leon Poon 1.1 1
2
3 = initramfs-kernel =
4
5 kernel runs /init.
6
7 /init is a script which sets INITRAMFS=1 and then execs /sbin/init.
8
Leon Poon 2.1 9 /sbin/init is ELF comes from procd package. What it does (as pid=1):
Leon Poon 1.1 10
Leon Poon 4.1 11 * early (different from procd early):
Leon Poon 1.1 12 ** mount /proc, /sysfs, and create /dev nodes, create /tmp subdirs etc
13 ** set PATH
Leon Poon 3.1 14 * kmodloader in subprocess (waits until done)
Leon Poon 1.1 15 * preinit
16 ** plugd in subprocess (seem to deal with firmware)
17 ** /etc/preinit in subprocess
Leon Poon 2.1 18 * when /etc/preinit is done then it execvp the "real" /sbin/procd
Leon Poon 1.1 19
Leon Poon 4.1 20 procd states:
21
22 * early (first state):
23 ** coldplug (remount /dev, etc)
24 *** start udevtrigger in subproc
25 *** when udevtrigger completes, hotplug
26 *** when hotplug completes, next state (ubus)
27 * ubus:
28 ** start attempts to connect to ubs
29 ** start ubus as service
30 ** once connection's done then next state (init)
31 * init - read /etc/inittab and run:
32 ** respawn - things that need to keep rerunning once quitted
33 ** askconsole
34 ** askfirst - the "Press Enter to activate this console" message
35 ** sysinit - (usually /etc/init.d/rcS with S) and then next state (running)
36 * running - waits for shutdown signal (usr1/usr2) or reboot (int/term)
37 * shutdown
38 ** runs shutdown command per inittab (also /etc/init.d/rcS but with K)
39 ** when done next state (halt)
40 * halt - kill everything and either enter sleep loop or reboots
41
Leon Poon 38.1 42 = Modules =
43
44 {{code}}
45 cp -va ./build_dir/target-*/linux-*/linux-4*/modules.builtin ./staging_dir/target-*/root-*/lib/modules/4*
46 # tar -C ./staging_dir/target-*/root-*/ -vcjf modules.tar.bz2 lib/modules
Leon Poon 39.1 47 {{/code}}
Leon Poon 38.1 48
Leon Poon 5.1 49 = Debian =
50
Leon Poon 30.1 51 {{code}}
Leon Poon 35.1 52 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
Leon Poon 33.1 53 chroot $PWD debootstrap/debootstrap --second-stage
Leon Poon 32.1 54 {{/code}}
55
56 {{code}}
Leon Poon 40.1 57 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 $PWD
Leon Poon 30.1 58 {{/code}}
59
Leon Poon 35.1 60 Do not install openssh-server during bootstrap otherwise it will bring in systemd!
61
Leon Poon 11.1 62 Things to do after debootstrap:
Leon Poon 5.1 63
Leon Poon 11.1 64 * [[get rid of systemd>>http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_Stretch_installation]]
Leon Poon 44.1 65 * dpkg-reconfigure locales
Leon Poon 13.1 66 * set hostname
Leon Poon 11.1 67 * set root password
68 * /etc/network/interfaces (TODO: swconfig while still in openwrt initramfs space?)
Leon Poon 36.1 69 * apt-get install ~-~-no-install-recommends openssh-server (check that it is without libpam-systemd and systemd!!)
Leon Poon 44.1 70 * apt-get install net-tools file ntp openssh-server gcc lvm2
Leon Poon 15.1 71 ** net-tools for ifconfig
Leon Poon 14.1 72 ** gcc for?
Leon Poon 37.1 73 * echo vm.min_free_kbytes=16384 > /etc/sysctl.d/min_free_kbytes.conf
Leon Poon 41.1 74 * apt-get install kmod (depmod, etc)
Leon Poon 43.1 75 * kernel modules ( tar ~-~-owner=0 ~-~-group=0  -C ./staging_dir/target-*/root-*/ -vcjf - lib/modules | ssh TARGET_IP tar -C /chroot -vxjf - )
Leon Poon 42.1 76 * depmod
Leon Poon 11.1 77 * read-only root
78
79 Needs CONFIG_DEVTMPFS=y in kernel.
80
Leon Poon 9.1 81 {{code language="bash"}}
Leon Poon 19.1 82 mkdir -pv /mnt &&
83 mknod /dev/sda b 8 0 &&
84 cryptsetup open /dev/sda usb &&
85 vgchange -ay vol_grp1 &&
86 mount /dev/vol_grp1/logical_vol1 /mnt -o ro
Leon Poon 10.1 87 {{/code}}
88
89 {{code language="bash"}}
Leon Poon 13.1 90 chroot /mnt /bin/bash
Leon Poon 10.1 91 {{/code}}
92
93 {{code language="bash"}}
94 mount proc /proc -t proc
95 {{/code}}
96
97 {{code language="bash"}}
Leon Poon 13.1 98 exec switch_root /mnt /sbin/init
Leon Poon 6.1 99 {{/code}}
100
Leon Poon 9.1 101 {{code language="bash"}}
102 ip addr add dev eth0 IP/NM
Leon Poon 8.1 103 ip link set eth0 up
Leon Poon 9.1 104 ip route add default via GW
Leon Poon 7.1 105 {{/code}}
Leon Poon 16.1 106
107 = Network =
108
109 {{code language="bash"}}
Leon Poon 22.1 110 sed -re 's/^boot_run_hook/#\0/g' -i /etc/preinit
111 PREINIT=1 . /etc/preinit
Leon Poon 26.1 112 preinit_config_board # set up the switch and lan ports on eth0.2, and create ip link
Leon Poon 23.1 113 json_select switch
114 json_select switch0
115 json_add_boolean reset 0 # do not reset when setting up wan ports on eth0.1
116 json_select ..
117 json_select ..
Leon Poon 26.1 118 preinit_config_switch switch0 eth0.1 # set up wan ports
119 preinit_ip_config eth0.1 # create ip link
Leon Poon 25.1 120 ip address flush dev eth0 # del default address
Leon Poon 20.1 121 for pi_ifname in eth0.1 eth0.2; do
Leon Poon 23.1 122 ip -4 address flush dev $pi_ifname # del default address
Leon Poon 25.1 123 ip link set dev $pi_ifname down
Leon Poon 20.1 124 done
Leon Poon 16.1 125 {{/code}}
Leon Poon 27.1 126
127
128 = UBI =
129
Leon Poon 45.1 130 {{code language="text"}}
131 define Build/append-ubi
Leon Poon 27.1 132 sh $(TOPDIR)/scripts/ubinize-image.sh \
133 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
134 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
135 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
136 $(IMAGE_ROOTFS) \
137 $@.tmp \
138 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
139 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
140 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
141 $(UBINIZE_OPTS)
142 cat $@.tmp >> $@
143 rm $@.tmp
Leon Poon 45.1 144 endef
145 {{/code}}
Leon Poon 47.1 146