“Ubuntu From Scratch(UFS)”并不是一个官方标准项目(官方有 Linux From Scratch (LFS),也有社区向的 Ubuntu 定制构建思路)。如果你指的是从零构建最小可用的 Ubuntu 系统(或基于 Debian/Ubuntu 的 rootfs),可以从以下几个层面来“精简”。
不要使用 ubuntu-desktop 或 minimal?task=ubuntu-server。
推荐方式:
debootstrap --variant=minbase focal ./rootfs http://archive.ubuntu.com/ubuntu
minbase 只装最基础包。
mmdebstrap(更快、可控)mmdebstrap --variant=essential focal rootfs
在构建时直接排除:
*-docman-dblocales(如不需要多语言)apt(若系统只读或固件)systemd → 可用 runit / openrc示例:
debootstrap --exclude=apt,man-db,locales focal rootfs
rm -rf /usr/share/doc/*
rm -rf /usr/share/man/*
rm -rf /usr/share/locale/*
apt-get clean
rm -rf /var/lib/apt/lists/*
apt-rdepends 检查冗余apt-rdepends package | sort -u
只保留运行必需依赖。
systemd → 用 systemd --minimal 或 openrcinit=/bin/sh + 脚本make localmodconfig
禁用所有非必需服务:
systemctl disable bluetooth ssh cron
squashfs(只读)ext4 + discardoverlayfsstrip --strip-unneeded /usr/bin/*
| 方案 | 体积 |
|---|---|
| minbase | ~80MB |
| + kernel | ~120MB |
| 再 strip + squashfs | < 50MB |
你现在的“fromscratch”是:学习用 / 容器 / 嵌入式 / 服务器?