“Ubuntu From Scratch”(UFS)通常指从零开始构建自己的 Ubuntu 风格系统(类似 LFS,但面向 Ubuntu/Debian 生态),常见做法包括:
调试这类系统,核心思路是:分层隔离问题 + 尽早获得可观察性。
下面按常见阶段给你一套实用调试方法。
debootstrap --verbose focal ./rootfs http://archive.ubuntu.com/ubuntu
如果失败,加:
--debug
常见问题:
验证:
uname -m
cat ./rootfs/etc/apt/sources.list
mount --bind /dev ./rootfs/dev
mount --bind /proc ./rootfs/proc
mount --bind /sys ./rootfs/sys
chroot ./rootfs
在 chroot 中:
apt update
apt install -y bash coreutils
qemu-system-x86_64 \
-kernel bzImage \
-initrd initrd.img \
-append "console=ttyS0 root=/dev/sda1" \
-hda rootfs.img \
-nographic
init=/bin/bash
可跳过 init 系统,直接进 shell。
查看早期错误:
loglevel=7
加内核参数:
systemd.log_level=debug
systemd.log_target=console
systemd.unit=emergency.target
systemctl status <service>
journalctl -xe
blkid
cat /etc/fstab
在 initramfs 中:
ls /dev
mount -t ext4 /dev/sda1 /root
mount -o loop ubuntu-from-scratch.iso /mnt
cat /mnt/boot/grub/grub.cfg
| 场景 | 工具 |
|---|---|
| 启动验证 | QEMU |
| 日志 | journalctl / dmesg |
| 文件系统 | busybox |
| 网络 | dhclient / ip |
| 调试 shell | bash-static |
✅ debootstrap 成功
✅ chroot 可运行 apt
✅ 内核包含根设备驱动
✅ initrd 可挂载根
✅ fstab 正确
✅ GRUB 配置正确
如果你愿意,可以告诉我:
我可以直接帮你定位问题。