@@ -26,6 +26,7 @@ DEPEND="
26
26
coreos-base/coreos-init:=
27
27
sys-apps/azure-vm-utils[dracut]
28
28
sys-apps/baselayout
29
+ sys-apps/busybox
29
30
sys-apps/coreutils
30
31
sys-apps/findutils
31
32
sys-apps/grep
@@ -72,6 +73,16 @@ src_prepare() {
72
73
use amd64 && config_update " CONFIG_EXTRA_FIRMWARE_DIR=\" ${fw_dir} \" "
73
74
}
74
75
76
+ copy_in () {
77
+ # Simple setup, assume we only have /lib64 to care about
78
+ cp " ${ESYSROOT} " /usr/" $1 " ./" $1 "
79
+ for LIBFILE in $( patchelf --print-needed ./" $1 " ) ; do
80
+ if [ ! -e ./lib64/" ${LIBFILE} " ]; then
81
+ copy_in /lib64/" ${LIBFILE} "
82
+ fi
83
+ done
84
+ }
85
+
75
86
src_compile () {
76
87
local BE_ARGS=()
77
88
@@ -89,6 +100,76 @@ src_compile() {
89
100
90
101
tc-export PKG_CONFIG
91
102
" ${ESYSROOT} " /usr/bin/update-bootengine -k " ${KV_FULL} " -o " ${S} " /build/bootengine.cpio " ${BE_ARGS[@]} " || die
103
+ # Copy full initrd over to /usr as filesystem image
104
+ mkdir " ${S} " /build/bootengine || die
105
+ pushd " ${S} " /build/bootengine || die
106
+ sudo lsinitrd --unpack " ${S} " /build/bootengine.cpio || die
107
+ sudo mksquashfs . " ${S} " /build/bootengine.img -noappend -xattrs-exclude ^btrfs. || die
108
+ popd || die
109
+ # Create minimal initrd
110
+ if use amd64; then
111
+ microcode=$( cpio -t < " ${S} " /build/bootengine.cpio 2>&1 > /dev/null | cut -d " " -f 1)
112
+ # Only keep early cpio for microcode
113
+ truncate -s $(( microcode* 512 )) " ${S} " /build/bootengine.cpio || die
114
+ # Debug: List contents after truncation
115
+ cpio -t < " ${S} " /build/bootengine.cpio
116
+ else
117
+ # No early cpio, drop full initrd
118
+ > " ${S} " /build/bootengine.cpio
119
+ fi
120
+ mkdir " ${S} " /build/minimal || die
121
+ pushd " ${S} " /build/minimal || die
122
+ mkdir -p {etc,bin,sbin,dev,proc,sys,dev,lib,lib64,usr/bin,usr/sbin,usr/lib,usr/lib64,realinit,sysusr/usr}
123
+ mkdir -p lib/modules/" ${KV_FULL} " /
124
+ # Instead from ESYSROOT we can also copy kernel modules from the dracut pre-selection
125
+ cp " ${S} " /build/bootengine/usr/lib/modules/" ${KV_FULL} " /modules.* lib/modules/" ${KV_FULL} " /
126
+ mkdir -p lib/modprobe.d/
127
+ cp " ${S} " /build/bootengine/lib/modprobe.d/* lib/modprobe.d/
128
+ MODULES=(" fs/overlayfs" " fs/squashfs" " drivers/md/dm-verity.ko.xz" " drivers/md/dm-mod.ko.xz" " drivers/block/loop.ko.xz" " fs/btrfs" " drivers/nvme" " drivers/scsi" " drivers/ata" " drivers/block" " drivers/pci" " drivers/char/virtio_console.ko.xz" " drivers/hv" " drivers/input/serio" " drivers/mmc" " drivers/usb" " drivers/hid" " security/keys" )
129
+ for MODULE in " ${MODULES[@]} " ; do
130
+ if [ -f " ${S} " /build/bootengine/usr/lib/modules/" ${KV_FULL} " /kernel/" ${MODULE} " ]; then
131
+ MODULE_DIR=$( dirname " ${MODULE} " )
132
+ mkdir -p lib/modules/" ${KV_FULL} " /kernel/" ${MODULE_DIR} "
133
+ cp " ${S} " /build/bootengine/usr/lib/modules/" ${KV_FULL} " /kernel/" ${MODULE} " lib/modules/" ${KV_FULL} " /kernel/" ${MODULE} "
134
+ elif [ -d " ${S} " /build/bootengine/usr/lib/modules/" ${KV_FULL} " /kernel/" ${MODULE} " ]; then
135
+ mkdir -p lib/modules/" ${KV_FULL} " /kernel/" ${MODULE} "
136
+ cp -r " ${S} " /build/bootengine/usr/lib/modules/" ${KV_FULL} " /kernel/" ${MODULE} " /* lib/modules/" ${KV_FULL} " /kernel/" ${MODULE} " /
137
+ else
138
+ die " wrong module type/not found: ${S} " /build/bootengine/usr/lib/modules/" ${KV_FULL} " /kernel/" ${MODULE} "
139
+ fi
140
+ done
141
+ # Copy module dependencies
142
+ for MODULE in $( find ./lib/modules/" ${KV_FULL} " / -type f) ; do
143
+ MODULE=$( basename " ${MODULE} " | sed " s/\.ko\.xz$//" )
144
+ for DEP in $( modprobe -S " ${KV_FULL} " -d " ${S} " /build/bootengine -D " ${MODULE} " | grep " ^insmod " | sed " s/^insmod //" ) ; do
145
+ DEP=$( echo " ${DEP} " | sed " s,${S} /build/bootengine,/," )
146
+ DEP_DIR=$( dirname " ${DEP} " )
147
+ mkdir -p ./" ${DEP_DIR} "
148
+ cp " ${S} " /build/bootengine/" ${DEP} " ./" ${DEP} "
149
+ done
150
+ done
151
+ echo ' $MODALIAS=.* 0:0 660 @/sbin/modprobe "$MODALIAS"' > ./etc/mdev.conf
152
+ copy_in /bin/veritysetup
153
+ copy_in /bin/dmsetup
154
+ copy_in /bin/busybox
155
+ # We can't use busybox's modprobe because it doesn't support the globs in module.alias, breaking module loading
156
+ copy_in /sbin/kmod
157
+ ln -s /sbin/kmod ./sbin/modprobe
158
+ if use arm64; then
159
+ ln -s ../lib64/ld-linux-aarch64.so.1 ./lib/ld-linux-aarch64.so.1
160
+ fi
161
+ cp -a " ${ESYSROOT} " /usr/bin/minimal-init ./init
162
+ # Make it easier to debug by not relying too much on the first commands
163
+ ln -s /bin/busybox ./bin/sh
164
+ mknod ./dev/console c 5 1
165
+ mknod ./dev/null c 1 3
166
+ mknod ./dev/tty c 5 0
167
+ mknod ./dev/urandom c 1 9
168
+ mknod ./dev/random c 1 8
169
+ mknod ./dev/zero c 1 5
170
+ # No compression because CONFIG_INITRAMFS_COMPRESSION_XZ should take care of it
171
+ find . -print0 | cpio --null --create --verbose --format=newc >> " ${S} " /build/bootengine.cpio
172
+ popd || die
92
173
kmake " $( kernel_target) "
93
174
94
175
# sanity check :)
@@ -111,4 +192,7 @@ src_install() {
111
192
# For easy access to vdso debug symbols in gdb:
112
193
# set debug-file-directory /usr/lib/debug/usr/lib/modules/${KV_FULL}/vdso/
113
194
kmake INSTALL_MOD_PATH=" ${ED} /usr/lib/debug/usr" vdso_install
195
+
196
+ insinto " /usr/lib/flatcar"
197
+ doins build/bootengine.img
114
198
}
0 commit comments