CPIO root filesystem is now deterministic

This commit is contained in:
Lance Vick 2022-07-12 04:42:03 -07:00
parent baa99413c1
commit e7740995e4
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
6 changed files with 53 additions and 34 deletions

View File

@ -42,7 +42,6 @@ run: default
qemu-system-x86_64 \ qemu-system-x86_64 \
-m 512M \ -m 512M \
-nographic \ -nographic \
-initrd $(OUT_DIR)/rootfs.cpio \
-kernel $(OUT_DIR)/bzImage -kernel $(OUT_DIR)/bzImage
# Run ncurses busybox config menu and save output # Run ncurses busybox config menu and save output
@ -57,7 +56,6 @@ linux-config:
rm $(CONFIG_DIR)/linux.config rm $(CONFIG_DIR)/linux.config
make $(CONFIG_DIR)/linux.config make $(CONFIG_DIR)/linux.config
$(CONFIG_DIR)/busybox.config: $(CONFIG_DIR)/busybox.config:
$(toolchain) " \ $(toolchain) " \
cd /cache/busybox-$(BUSYBOX_VERSION) && \ cd /cache/busybox-$(BUSYBOX_VERSION) && \
@ -72,32 +70,6 @@ $(CONFIG_DIR)/linux.config:
cp .config /config/linux.config; \ cp .config /config/linux.config; \
" "
$(OUT_DIR)/rootfs.cpio: $(OUT_DIR)/busybox
mkdir -p $(CACHE_DIR)/rootfs/bin
ifdef DEBUG
cp $(OUT_DIR)/busybox $(CACHE_DIR)/rootfs/bin;
cp $(SCRIPTS_DIR)/busybox_init $(CACHE_DIR)/rootfs/init;
chmod +x $(CACHE_DIR)/rootfs/init;
endif
$(toolchain) " \
cd /cache/rootfs \
&& find . \
| cpio -o -H newc \
| gzip -f - > /out/rootfs.cpio \
"
# Currently broken determinism attempt
# $(toolchain) " \
# cd /cache/rootfs \
# && mkdir -p dev \
# && fakeroot mknod -m 0622 dev/console c 5 1 \
# && find . -mindepth 1 -execdir touch -hcd "@0" "{}" + \
# && find . -mindepth 1 -printf '%P\0' \
# | sort -z \
# | LANG=C bsdtar --uid 0 --gid 0 --null -cnf - -T - \
# | LANG=C bsdtar --null -cf - --format=newc @- \
# " > $@
$(OUT_DIR)/busybox: \ $(OUT_DIR)/busybox: \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION) \ $(CACHE_DIR)/busybox-$(BUSYBOX_VERSION) \
$(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2 \ $(CACHE_DIR)/busybox-$(BUSYBOX_VERSION).tar.bz2 \
@ -109,6 +81,27 @@ $(OUT_DIR)/busybox: \
cp busybox /out/; \ cp busybox /out/; \
" "
$(CACHE_DIR)/linux-$(LINUX_VERSION)/usr/gen_init_cpio: \
$(CACHE_DIR)/linux-$(LINUX_VERSION)
$(toolchain) " \
cd /cache/linux-$(LINUX_VERSION) && \
gcc usr/gen_init_cpio.c -o usr/gen_init_cpio \
"
$(OUT_DIR)/rootfs.cpio: \
$(OUT_DIR)/busybox \
$(CACHE_DIR)/linux-$(LINUX_VERSION)/usr/gen_init_cpio
mkdir -p $(CACHE_DIR)/rootfs/bin
cp $(SCRIPTS_DIR)/busybox_init $(CACHE_DIR)/rootfs/init
cp $(OUT_DIR)/busybox $(CACHE_DIR)/rootfs/bin/
$(toolchain) " \
cd /cache/rootfs \
&& find . -mindepth 1 -execdir touch -hcd "@0" "{}" + \
&& find . -mindepth 1 -printf '%P\0' \
&& cd /cache/linux-$(LINUX_VERSION) \
&& usr/gen_initramfs.sh -o /out/rootfs.cpio /config/rootfs.list; \
"
$(OUT_DIR)/bzImage: \ $(OUT_DIR)/bzImage: \
$(OUT_DIR)/rootfs.cpio \ $(OUT_DIR)/rootfs.cpio \
$(CACHE_DIR)/linux-$(LINUX_VERSION) \ $(CACHE_DIR)/linux-$(LINUX_VERSION) \
@ -121,4 +114,3 @@ $(OUT_DIR)/bzImage: \
make -j$(CPUS) ARCH=$(ARCH) bzImage && \ make -j$(CPUS) ARCH=$(ARCH) bzImage && \
cp arch/x86_64/boot/bzImage /out/; \ cp arch/x86_64/boot/bzImage /out/; \
" "

View File

@ -1,6 +1,12 @@
export BUSYBOX_VERSION = 1.33.2 export BUSYBOX_VERSION = 1.33.2
export LINUX_VERSION = 5.18.5 export LINUX_VERSION = 5.18.5
export SOURCE_DATE_EPOCH = 0
export KBUILD_BUILD_TIMESTAMP = "1970-01-01 00:00:00 UTC"
export KCONFIG_NOTIMESTAMP = 1
export KBUILD_BUILD_USER = root
export KBUILD_BUILD_HOST = QuorumOS
export BUSYBOX_SERVER = https://busybox.net/downloads/ export BUSYBOX_SERVER = https://busybox.net/downloads/
export LINUX_SERVER = https://cdn.kernel.org/pub/linux/kernel/v5.x/ export LINUX_SERVER = https://cdn.kernel.org/pub/linux/kernel/v5.x/
@ -9,3 +15,4 @@ export LINUX_KEY = 647F28654894E3BD457199BE38DBBDC86092693E
export LINUX_KEYS_REPO = https://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git export LINUX_KEYS_REPO = https://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git
export DEBIAN_HASH = 3f1d6c17773a45c97bd8f158d665c9709d7b29ed7917ac934086ad96f92e4510 export DEBIAN_HASH = 3f1d6c17773a45c97bd8f158d665c9709d7b29ed7917ac934086ad96f92e4510

View File

@ -1,6 +1,6 @@
.PHONY: toolchain-shell .PHONY: toolchain-shell
build-shell: toolchain build-shell: toolchain
$(toolchain) $(toolchain) bash
.PHONY: toolchain .PHONY: toolchain
toolchain: toolchain:
@ -12,13 +12,19 @@ toolchain:
toolchain := \ toolchain := \
docker run \ docker run \
--interactive \
--rm \ --rm \
--interactive \
--user=$(shell id -u):$(shell id -g) \ --user=$(shell id -u):$(shell id -g) \
-v $(PWD)/$(CONFIG_DIR):/config \ -v $(PWD)/$(CONFIG_DIR):/config \
-v $(PWD)/$(KEY_DIR):/keys \ -v $(PWD)/$(KEY_DIR):/keys \
-v $(PWD)/$(CACHE_DIR):/cache \ -v $(PWD)/$(CACHE_DIR):/cache \
-v $(PWD)/$(OUT_DIR):/out \ -v $(PWD)/$(OUT_DIR):/out \
-v $(PWD)/$(SCRIPTS_DIR):/scripts \
-e GNUPGHOME=/cache/.gnupg \ -e GNUPGHOME=/cache/.gnupg \
-e KBUILD_BUILD_USER=$(KBUILD_BUILD_USER) \
-e KBUILD_BUILD_HOST=$(KBUILD_BUILD_HOST) \
-e KBUILD_BUILD_TIMESTAMP=$(KBUILD_BUILD_TIMESTAMP) \
-e KCONFIG_NOTIMESTAMP=$(KCONFIG_NOTIMESTAMP) \
-e SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \
-t local/$(NAME)-build \ -t local/$(NAME)-build \
bash -c bash -c

View File

@ -3,9 +3,7 @@
busybox mount -t devtmpfs none /dev busybox mount -t devtmpfs none /dev
busybox mkdir -p /dev/pts busybox mkdir -p /dev/pts
busybox mount -t devpts none /dev/pts busybox mount -t devpts none /dev/pts
busybox mkdir /sys
busybox mount -t sysfs none /sys busybox mount -t sysfs none /sys
busybox mkdir -p /usr/bin /sbin /usr/sbin /sbin /proc /etc
busybox mount -t proc none /proc busybox mount -t proc none /proc
/bin/busybox --install /bin/busybox --install

View File

@ -203,7 +203,11 @@ CONFIG_NET_NS=y
# CONFIG_SYSFS_DEPRECATED is not set # CONFIG_SYSFS_DEPRECATED is not set
CONFIG_RELAY=y CONFIG_RELAY=y
CONFIG_BLK_DEV_INITRD=y CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="" CONFIG_INITRAMFS_SOURCE="/out/rootfs.cpio"
CONFIG_INITRAMFS_ROOT_UID=0
CONFIG_INITRAMFS_ROOT_GID=0
CONFIG_INITRAMFS_COMPRESSION_GZIP=y
CONFIG_RD_GZIP=y CONFIG_RD_GZIP=y
CONFIG_RD_BZIP2=y CONFIG_RD_BZIP2=y
CONFIG_RD_LZMA=y CONFIG_RD_LZMA=y

12
targets/local/rootfs.list Normal file
View File

@ -0,0 +1,12 @@
dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1
dir /sys 0755 0 0
dir /usr 0755 0 0
dir /etc 0755 0 0
dir /proc 0755 0 0
dir /bin 0755 0 0
dir /sbin 0755 0 0
dir /usr/bin 0755 0 0
dir /usr/sbin 0755 0 0
file /init /cache/rootfs/init 0755 0 0
file /bin/busybox /cache/rootfs/bin/busybox 0755 0 0