blob: ad7443a4e967f946080988c0394d33ee349ff7ea (
plain)
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
|
#!/bin/sh
# generate a cpio entry for a command
gen_cmd() {
cmdp="$(command -v "$1")" || exit 1
printf 'file %s %s 0755 0 0\n' "$cmdp" "$cmdp"
# ELF interpreter handled in cpio_list.txt
ldd "$cmdp" | awk '/=>/ { print "file /lib64/" $1 " " $3 " 0755 0 0" }'
}
# generate the main file list
gen_cpio_list() {
# static entries
sed -e '/^#/d' cpio_list.txt
# modules
tr ' ' '\n' < modules.dep | sed -e "s/://;s:.*:file /lib/modules/$KERNVER/& /lib/modules/$KERNVER/& 0644 0 0:"
# commands
gen_cmd busybox
gen_cmd cryptsetup
gen_cmd dropbear
gen_cmd e2fsck
# cryptsetup needs libgcc_s.so.1 for pthread_cancel
ldconfig -p | awk '$1 == "libgcc_s.so.1" && $2 ~ /x86-64/ { print "file /lib64/" $1 " " $4 " 0755 0 0" }'
}
# insert parent directory entries
gen_dir_ents() {
awk '{ print; while (sub("/[^/]*$", "", $2) && $2) print "dir " $2 " 0755 0 0" }'
}
# generate the make dependency file
gen_depfile() {
awk -v f=/dev/fd/3 -v deps="cpio_list.txt make" '
{ print }
$1 == "file" && $3 != "/dev/null" { deps=deps " " $3 }
END { print "DEPS = " deps "\n$(DEPS):\ninitramfs.img: $(DEPS)" > f }
'
}
gen_cpio_list | gen_dir_ents | sort -u | gen_depfile 3>initramfs.d | ./gen_init_cpio -t 0 - | $COMPRESSOR > initramfs.img
|