fix(build): make the packed image actually bootable

There were three independent reasons a fresh build produced an image that
OVMF would not boot. All three are fixed here; verified by booting the
resulting ISO/deshab-dev.img under QEMU/OVMF through to FirstInit.

1. ESP rejected by OVMF (CODE/linux/pack_system_image.sh)
   The vfat formatter was invoked with an explicit -s 8, forcing 4KiB clusters.
   On the 256MiB ESP that yields exactly 65535 clusters - the FAT32 0xFFF5
   boundary - and OVMF's FatPkg refuses to mount the volume. Symptom: BdsDxe
   logs "failed to load ... Not Found", the ESP shows up as BLKn with no FS in
   the UEFI Shell, and the firmware falls through to the internal shell.
   The sidecar FAT32 image (make_sata_sidecar.sh) mounts fine because it calls
   the formatter without -s. Drop -s here too and let the tool pick geometry.
   Do NOT add -f 1: OVMF mounts nfat=1 and nfat=2 alike, it was not the cause.

2. Limine dropped into a panic (CODE/linux/pack_system_image.sh)
   limine.conf declares the Linux-compat guest modules. build.sh uncomments
   them once Linux has been built, but nothing ever comments them back, so the
   file says "load boot():/boot/linux-initrd.img" while only linux-bzImage
   exists on disk - Limine panics on the missing module and never reaches the
   kernel. Filter the guest module_path lines against SYSTEM/boot/ at pack
   time and write the result to the ESP. Both the root /limine.conf and
   /limine/limine.conf are written, since Limine 10 prefers the latter. The
   tracked source file is left untouched.

3. Nine drivers were never compiled (build.ps1)
   Commit 055c521 untracked the .drv binaries on the grounds that they are
   regenerable, but build.ps1 only ever invoked Build-DkmDriver for 8 of the
   17 drivers listed in manifest.json. timer/acpi/pci/ahci/bootfs/vfs/fat32/
   devfs/ps2kbd had sources under CODE/DKM/ and no build step, so the image
   shipped without them and Limine failed on the first one. Add the missing
   compile steps, grouped by load stage. All 17 now match manifest.json.

Also in this commit (environment/tooling hygiene):
- check_env.sh: stop hardcoding /mnt/d/Code/Deshab (the original author's
  machine); derive the repo root from the script's own location. It was
  reporting a bogus "wsl_mount" failure on every other checkout and sending
  people to install packages that were already present. Also check and
  advertise the image-packing tools (dosfstools/e2fsprogs/fdisk/rsync), which
  were missing from the dependency list even though pack_system_image.sh
  hard-requires them.
- build_initrd.sh: same hardcoded-path fix.
- README.md: relative path instead of the stale absolute one.

Verified: ./build.bat -Variant dev under WSL2/Ubuntu, then QEMU/OVMF boots
through BdsDxe -> Limine -> UTSM -> DKM (17/17) -> DSK -> FirstInit, with the
PS/2 mouse initialising cleanly.
This commit is contained in:
boonxiong2
2026-10-05 14:03:39 +08:00
parent ee8b607f9a
commit 1c99c77b3f
5 changed files with 109 additions and 20 deletions
+25 -8
View File
@@ -5,7 +5,7 @@
# 用途: 在 WSL/Linux 中运行,验证构建 Linux 6.6 LTS bzImage 所需依赖
#
# 使用:
# ! wsl bash /mnt/d/Code/Deshab/CODE/linux/check_env.sh
# ! wsl bash CODE/linux/check_env.sh
#
# 退出码:
# 0 = 所有依赖已满足
@@ -16,6 +16,10 @@ set -e
echo "[check] Linux 内核构建环境检查"
echo "[check] ==========================="
# 仓库根目录:按脚本自身位置推导,不依赖当前工作目录,也不认死任何盘符路径。
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
echo "[check] 仓库根: $REPO_ROOT"
# 1. 检查操作系统
if [ -f /etc/os-release ]; then
. /etc/os-release
@@ -40,6 +44,18 @@ for pkg in build-essential bc flex bison libelf-dev libssl-dev cpio gzip git; do
fi
done
# 2b. 检查镜像打包工具(pack_system_image.sh 硬依赖,不在上面那组内核依赖里)
echo "[check]"
echo "[check] 检查镜像打包工具..."
for pkg in dosfstools e2fsprogs fdisk rsync; do
if dpkg -s "$pkg" >/dev/null 2>&1; then
echo "[check] ✓ $pkg"
else
echo "[check] ✗ $pkg (缺失)"
MISSING+=("$pkg")
fi
done
# 3. 检查 gcc 版本
echo "[check]"
echo "[check] 工具链版本:"
@@ -60,7 +76,7 @@ fi
# 4. 检查磁盘空间(需要 ~3GB)
echo "[check]"
PROJECT_ROOT="/mnt/d/Code/Deshab"
PROJECT_ROOT="$REPO_ROOT"
if [ -d "$PROJECT_ROOT" ]; then
AVAILABLE_KB=$(df "$PROJECT_ROOT" | awk 'NR==2 {print $4}')
AVAILABLE_GB=$((AVAILABLE_KB / 1024 / 1024))
@@ -73,13 +89,13 @@ if [ -d "$PROJECT_ROOT" ]; then
fi
fi
# 5. 检查访问 Windows D: 盘
# 5. 检查 WSL 能否访问当前仓库(不认死盘符路径)
echo "[check]"
if [ -d "/mnt/d/Code/Deshab" ]; then
echo "[check] ✓ WSL 可访问 /mnt/d/Code/Deshab"
if [ -d "$REPO_ROOT/CODE/linux" ] && [ -d "$REPO_ROOT/SYSTEM" ]; then
echo "[check] ✓ WSL 可访问当前仓库 ($REPO_ROOT)"
else
echo "[check] ✗ WSL 无法访问 /mnt/d/Code/Deshab"
echo "[check] 请确认在 WSL 中执行,且 D: 盘已挂载"
echo "[check] ✗ WSL 无法访问当前仓库 ($REPO_ROOT)"
echo "[check] 请从仓库内运行本脚本,且 Windows 盘已挂载到 /mnt/<盘符>"
MISSING+=("wsl_mount")
fi
@@ -107,11 +123,12 @@ if [ ${#MISSING[@]} -gt 0 ]; then
echo "[check] 请运行以下命令安装依赖:"
echo "[check] sudo apt update"
echo "[check] sudo apt install -y build-essential bc flex bison libelf-dev libssl-dev cpio gzip git"
echo "[check] sudo apt install -y dosfstools e2fsprogs fdisk rsync"
exit 1
fi
echo "[check] ✓ 所有依赖已满足,可以构建 Linux 内核"
echo "[check]"
echo "[check] 下一步执行:"
echo "[check] cd /mnt/d/Code/Deshab/CODE/linux && chmod +x build.sh && ./build.sh"
echo "[check] cd $REPO_ROOT/CODE/linux && chmod +x build.sh && ./build.sh"
exit 0