-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_arcore
executable file
·185 lines (168 loc) · 6.62 KB
/
build_arcore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# Heavily inspired of archlinux mkinitcpio, using mkinitcpio functions
if [ "$#" -ne 2 ]; then
error "First parameter should be a linux kernel path"
error "Second parameter should be 'allmodules' or module list, ie. 'mod1 mod2 mod3'"
exit 128
fi
### IMAGE_INIT: include utility functions
### init BUILDROOT dir in a tmp dir with a basic unix file hierarchy
### - init _addedmodules a map of all already added module [modulename]=1 to avoid doing expensive stuff multiple time
### ( add_module toto will not do anything if already called )
### - init `_modpaths`: a list of every "path" of each module added with "add_module"
### initial _addedmodules contains module "builtin" in order to not add them to the image
. ./mkinitrd_lib/image_init "$1"
### IMAGE_BUILD: - use "add_binary" to add a binary and its lib dependency into BUILDROOT
### - use "add_symlink" to add a symlink into BUILDROOT
### - use "add_module" to search path and dependencies of a module and add them to _modpaths and _addedmodules
### - use "add_all_module" to search all modules of host and `add_module` them
### - use "add_dir" to create a simple directory in BUILDROOT
### - use "add_full_dir" to copy recursively a directory of host in BUILDROOT
### - use "add_udev_rule" to copy a udev rule file from udev searchpath into BUILDROOT, each udev program deps trigger an `add_binary`
### - use "add_systemd_unit" to copy a systemd unit file from systemd searchpath into BUILDROOT, each systemd deps trigger an other `add_systemd_unit`, each program deps a `add_binary`
# Now... have fun and build your OS
add_binary /usr/lib/systemd/systemd /init
add_binary busybox
for applet in $(busybox --list | grep -v busybox); do
add_symlink "/usr/bin/$applet" busybox
done
add_file files/system.conf /etc/systemd/system.conf
# for less color to work properly with default TERM=linux
add_file /usr/lib/terminfo/l/linux
# for lspci to find User readable hardware desc from kernel pci modalias
#add_file /usr/share/hwdata/pci.ids
case "$2" in
"allmodules")
echo "NO specific modules defined, add all"
add_all_modules '/'
;;
*)
for m in $2; do
echo "add module : "$m
add_module $m
done
esac
map add_binary \
bash \
curl \
less \
sulogin \
nologin \
mdadm \
mkfs.btrfs \
btrfs \
wipefs \
jq \
runc \
/usr/lib/systemd/systemd-hibernate-resume \
/usr/lib/systemd/systemd-sulogin-shell \
/usr/lib/systemd/systemd-shutdown \
/usr/lib/systemd/system-generators/systemd-fstab-generator \
/usr/lib/systemd/system-generators/systemd-gpt-auto-generator \
/usr/lib/systemd/system-generators/systemd-hibernate-resume-generator \
/usr/lib/systemd/system-generators/systemd-getty-generator \
systemd-tmpfiles \
networkctl \
systemd-analyze \
journalctl
# for setup only !
map add_binary \
loadkeys \
/usr/lib/systemd/systemd-vconsole-setup
add_full_dir /usr/share/kbd/keymaps
# udev rules and systemd units
map add_udev_rule "$rules" \
50-udev-default.rules \
60-persistent-storage.rules \
63-md-raid-arrays.rules \
64-md-raid-assembly.rules \
64-btrfs.rules \
80-drivers.rules \
99-systemd.rules
map add_systemd_unit \
initrd-cleanup.service \
initrd-fs.target \
initrd-parse-etc.service \
initrd-root-fs.target \
initrd-root-device.target \
initrd-switch-root.service \
initrd-switch-root.target \
initrd-udevadm-cleanup-db.service \
initrd.target \
kmod-static-nodes.service \
local-fs.target \
local-fs-pre.target \
paths.target \
reboot.target \
halt.target \
poweroff.target \
kexec.target \
rescue.service \
emergency.service \
slices.target \
sockets.target \
swap.target \
systemd-fsck@.service \
systemd-hibernate-resume@.service \
systemd-sysusers.service \
systemd-journald.service \
systemd-journal-flush.service \
systemd-journald-audit.socket \
systemd-journald-dev-log.socket \
systemd-modules-load.service \
systemd-tmpfiles-setup-dev.service \
systemd-udev-trigger.service \
systemd-udevd-control.socket \
systemd-udevd-kernel.socket \
systemd-udevd.service \
systemd-vconsole-setup.service \
timers.target \
rescue.target \
debug.service \
multi-user.target \
arcore.target \
arcorenet.service \
arcorefs.service \
arcore-wait-network.service \
systemd-networkd.service \
systemd-networkd-wait-online.service \
systemd-resolved.service \
emergency.target
add_dir "/run/systemd/resolve"
add_dir "/var/tmp"
add_dir "/tmp"
# for debugging, put rescue.target where you want
#add_symlink "/usr/lib/systemd/system/default.target" "rescue.target"
add_symlink "/usr/lib/systemd/system/default.target" "initrd.target"
add_symlink "/usr/lib/systemd/system/ctrl-alt-del.target" "reboot.target"
add_symlink "/etc/systemd/system/network-online.target.wants/arcore-wait-network.service" "/etc/systemd/system/arcore-wait-network.service"
add_symlink "/etc/systemd/system/initrd-root-fs.target.wants/arcorefs.service" "/etc/systemd/system/arcorefs.service"
add_symlink "/etc/resolv.conf" "/run/systemd/resolve/resolv.conf"
# udev wants /etc/group since it doesn't launch with --resolve-names=never
add_file "/etc/nsswitch.conf"
add_file "files/os-release" "/etc/os-release"
add_binary "$(readlink -f /usr/lib/libnss_files.so)"
add_binary "$(readlink -f /usr/lib/libnss_compat.so)"
add_binary "$(readlink -f /usr/lib/libnss_dns.so)"
#add_binary "/usr/lib/libnss_systemd.so.2"
add_binary "/usr/lib/libnss_mymachines.so.2"
add_binary "/usr/lib/libnss_resolve.so.2"
map add_binary \
runcget \
arcore_lib.sh \
arcore_net.sh \
arcore_fs.sh \
arcore_alert.sh
# add system users through sysuser.services
add_file /usr/lib/sysusers.d/basic.conf
add_file /usr/lib/sysusers.d/systemd.conf
add_systemd_drop_in systemd-udevd.service resolve-names <<EOF
[Service]
ExecStart=
ExecStart=/usr/lib/systemd/systemd-udevd --resolve-names=never
EOF
add_dir "/etc/modules-load.d"
# add static module to load in modules-load.d/xx.conf if needed
### IMAGE_BUILD: Copy modules of _modpaths in BUILDROOT/lib/module/KERNELVERSION
### then build archive BUILDROOT in a CPIO with bsdcpio and compress it
. ./mkinitrd_lib/image_build build/arcore.img