- initramfs.img, rootfs.img for AArch64 Linux guest - mkdisk.py for disk image creation - initramfs and rootfs directories
140 lines
4.6 KiB
Makefile
140 lines
4.6 KiB
Makefile
# UniversalisOS Linux Guest Rootfs Generation
|
|
#
|
|
# Targets:
|
|
# make minimal - Build minimal initramfs (init only, ~50KB)
|
|
# make busybox - Build busybox-based initramfs (~1MB)
|
|
# make full - Build full rootfs from yocto/buildroot (~50MB)
|
|
# make disk - Create virtio-blk disk image
|
|
# make all - Build minimal + disk image
|
|
# make clean - Remove all build artifacts
|
|
#
|
|
# Prerequisites:
|
|
# - aarch64-linux-gnu-gcc (cross-compiler)
|
|
# - cpio, gzip (for initramfs)
|
|
# - python3 (for mkdisk.py)
|
|
|
|
# Configuration
|
|
CROSS_COMPILE ?= aarch64-linux-gnu-
|
|
CC = $(CROSS_COMPILE)gcc
|
|
STRIP = $(CROSS_COMPILE)strip
|
|
|
|
# Directories
|
|
ROOTFS_DIR = $(CURDIR)
|
|
OUTPUT_DIR = $(ROOTFS_DIR)/output
|
|
BUILD_DIR = $(ROOTFS_DIR)/build
|
|
INITRAMFS_DIR = $(BUILD_DIR)/initramfs
|
|
|
|
# Output files
|
|
INITRAMFS_IMG = $(OUTPUT_DIR)/initramfs.img
|
|
DISK_IMG = $(OUTPUT_DIR)/rootfs.img
|
|
|
|
# Disk image size (256 MiB for full rootfs)
|
|
DISK_SIZE = 268435456
|
|
|
|
# Busybox configuration
|
|
BUSYBOX_VERSION = 1.36.1
|
|
BUSYBOX_URL = https://busybox.net/downloads/busybox-$(BUSYBOX_VERSION).tar.bz2
|
|
|
|
# ===== Minimal initramfs (init only) =====
|
|
|
|
.PHONY: minimal
|
|
minimal: $(INITRAMFS_IMG)
|
|
|
|
$(OUTPUT_DIR):
|
|
mkdir -p $(OUTPUT_DIR)
|
|
|
|
$(BUILD_DIR):
|
|
mkdir -p $(BUILD_DIR)
|
|
|
|
$(INITRAMFS_DIR): $(BUILD_DIR)
|
|
mkdir -p $(INITRAMFS_DIR)/{bin,dev,proc,sys,etc,sbin}
|
|
|
|
$(INITRAMFS_DIR)/init: $(INITRAMFS_DIR) $(ROOTFS_DIR)/initramfs/init.c
|
|
$(CC) -static -O2 -o $@ $(ROOTFS_DIR)/initramfs/init.c
|
|
$(STRIP) $@
|
|
|
|
$(INITRAMFS_DIR)/etc/init.d/rcS: $(INITRAMFS_DIR)
|
|
mkdir -p $(INITRAMFS_DIR)/etc/init.d
|
|
@echo '#!/bin/sh' > $@
|
|
@echo 'mount -t proc proc /proc' >> $@
|
|
@echo 'mount -t sysfs sysfs /sys' >> $@
|
|
@echo 'mount -t tmpfs tmpfs /dev' >> $@
|
|
@chmod +x $@
|
|
|
|
$(INITRAMFS_DIR)/etc/fstab: $(INITRAMFS_DIR)
|
|
@echo '# <filesystem> <mount> <type> <opts> <dump> <pass>' > $@
|
|
@echo 'proc /proc proc defaults 0 0' >> $@
|
|
@echo 'sysfs /sys sysfs defaults 0 0' >> $@
|
|
@echo 'tmpfs /dev tmpfs defaults 0 0' >> $@
|
|
|
|
$(INITRAMFS_IMG): $(INITRAMFS_DIR)/init $(INITRAMFS_DIR)/etc/init.d/rcS $(INITRAMFS_DIR)/etc/fstab
|
|
cd $(INITRAMFS_DIR) && find . -print0 | cpio --null -o --format=newc 2>/dev/null | gzip -9 > $@
|
|
@echo "Initramfs: $$(du -h $@ | cut -f1)"
|
|
|
|
# ===== Busybox initramfs =====
|
|
|
|
.PHONY: busybox
|
|
busybox: $(OUTPUT_DIR)/busybox-initramfs.img
|
|
|
|
$(BUILD_DIR)/busybox-$(BUSYBOX_VERSION): $(BUILD_DIR)
|
|
cd $(BUILD_DIR) && curl -L $(BUSYBOX_URL) | tar xj
|
|
cd $(BUILD_DIR)/busybox-$(BUSYBOX_VERSION) && make ARCH=aarch64 CROSS_COMPILE=$(CROSS_COMPILE) defconfig
|
|
cd $(BUILD_DIR)/busybox-$(BUSYBOX_VERSION) && sed -i 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/' .config
|
|
cd $(BUILD_DIR)/busybox-$(BUSYBOX_VERSION) && make ARCH=aarch64 CROSS_COMPILE=$(CROSS_COMPILE) -j$$(nproc)
|
|
|
|
$(BUILD_DIR)/busybox-rootfs: $(BUILD_DIR)/busybox-$(BUSYBOX_VERSION)
|
|
mkdir -p $@/{bin,dev,proc,sys,etc,sbin,tmp,root}
|
|
cp $(BUILD_DIR)/busybox-$(BUSYBOX_VERSION)/busybox $@/bin/busybox
|
|
cd $@/bin && for cmd in sh ls cat echo mount mkdir mknod sleep reboot; do ln -sf busybox $$cmd; done
|
|
cd $@/sbin && ln -sf ../bin/busybox init
|
|
@echo '#!/bin/sh' > $@/etc/init.d/rcS
|
|
@echo 'mount -t proc proc /proc' >> $@/etc/init.d/rcS
|
|
@echo 'mount -t sysfs sysfs /sys' >> $@/etc/init.d/rcS
|
|
@echo 'mount -t tmpfs tmpfs /dev' >> $@/etc/init.d/rcS
|
|
@echo 'mount -t devpts devpts /dev/pts' >> $@/etc/init.d/rcS
|
|
@chmod +x $@/etc/init.d/rcS
|
|
|
|
$(OUTPUT_DIR)/busybox-initramfs.img: $(BUILD_DIR)/busybox-rootfs $(OUTPUT_DIR)
|
|
cd $(BUILD_DIR)/busybox-rootfs && find . -print0 | cpio --null -o --format=newc 2>/dev/null | gzip -9 > $@
|
|
@echo "Busybox initramfs: $$(du -h $@ | cut -f1)"
|
|
|
|
# ===== Full rootfs (yocto/buildroot placeholder) =====
|
|
|
|
.PHONY: full
|
|
full: $(OUTPUT_DIR)/full-rootfs.img
|
|
|
|
$(OUTPUT_DIR)/full-rootfs.img: $(OUTPUT_DIR)
|
|
@echo "=== Full rootfs generation ==="
|
|
@echo "This target requires yocto or buildroot to be configured."
|
|
@echo "To use:"
|
|
@echo " 1. Configure yocto/buildroot for aarch64"
|
|
@echo " 2. Build the rootfs"
|
|
@echo " 3. Copy the output to $(OUTPUT_DIR)/full-rootfs/"
|
|
@echo " 4. Run: make disk INPUT=$(OUTPUT_DIR)/full-rootfs/"
|
|
@echo ""
|
|
@echo "For now, using minimal initramfs as fallback."
|
|
$(MAKE) minimal
|
|
cp $(INITRAMFS_IMG) $@
|
|
|
|
# ===== Disk image generation =====
|
|
|
|
.PHONY: disk
|
|
disk: $(DISK_IMG)
|
|
|
|
$(DISK_IMG): $(INITRAMFS_IMG)
|
|
python3 ../mkdisk.py $(INITRAMFS_IMG) $@ --size=$(DISK_SIZE)
|
|
@echo "Disk image: $$(du -h $@ | cut -f1)"
|
|
|
|
# ===== All =====
|
|
|
|
.PHONY: all
|
|
all: minimal disk
|
|
@echo "=== Build complete ==="
|
|
@echo "Initramfs: $(INITRAMFS_IMG)"
|
|
@echo "Disk image: $(DISK_IMG)"
|
|
|
|
# ===== Clean =====
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf $(BUILD_DIR) $(OUTPUT_DIR)
|