“Ubuntu From Scratch”(或者更广义的“Linux From Scratch / 从零构建 Ubuntu”)通常不是官方标准术语,一般指:
下面按常见坑点系统总结,避免你踩雷。
qemu-user-staticbinfmt-support--archdebootstrap --arch=arm64 --foreign jammy jammy-root http://ports.ubuntu.com
坑:忘了 --foreign 或没进 chroot 前执行 second stage
mmdebootstrap构建或配置时容易失败:
mount -t proc proc /mnt/proc
mount -t sysfs sys /mnt/sys
mount -o bind /dev /mnt/dev
坑:
/proc → apt / systemd 异常/dev/pts → 终端异常chroot 里:
/etc/resolv.conf现象:
Failed to fetch http://archive.ubuntu.com ...
解决:
cp /etc/resolv.conf /mnt/etc/resolv.conf
很多人以为:
debootstrap 完就能用
实际常缺:
sudonetwork-manager / netplansystemdlocalesbash-completion建议最小集:
apt install systemd sudo netplan.io locales bash
现象:
locale: Cannot set LC_ALL to default locale
解决:
dpkg-reconfigure locales
# 或
locale-gen en_US.UTF-8
Ubuntu From Scratch 不等于 LFS:
常见选择:
apt install linux-generic
# 或
apt install linux-virtual
坑:
linux-kvm 反而更合适构建后启动:
init: no init found检查:
ls -l /sbin/init
应是:
/sbin/init -> /lib/systemd/systemd
常见于:
/etc/fstabUbuntu 强烈依赖:
/ 正确挂载swap 可选但建议配置坑:
/dev/sda1 不稳定)blkid
常见错误:
grub-efi-amd64Ubuntu 默认:
建议:
useradd -m -s /bin/bash ubuntu
passwd ubuntu
usermod -aG sudo ubuntu
原因:
openssh-serverapt install openssh-server
ssh-keygen -A
常见错误:
debootstrap 在 Docker 里但没 --variant=minbase建议:
minbase云镜像常见:
cloud-init解决:
apt remove cloud-init
# 或
rm -rf /etc/cloud
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
否则日志时间全错。
| 你以为 | 实际 |
|---|---|
| debootstrap 完就 OK | 还差 30% |
| 不用装 kernel | 必 panic |
| Ubuntu = Linux | Ubuntu ≠ LFS |
| 能 chroot 就能启动 | 不一定 |
| 能 apt 就行 | systemd 才是灵魂 |
mmdebootstrap jammy ./root --variant=minbase
然后:
ubuntu-minimalcloud-image 改如果你愿意,可以告诉我:
我可以直接给你一套可启动的最小 Ubuntu 构建流程。