温馨提示×

如何入门debian fromscratch

小樊
62
2026-10-14 00:18:20
栏目: 智能运维

“Debian From Scratch”(通常简称 DFS)在开源社区里一般有两种理解:

  1. 最狭义:使用 Debian From Scratch 这个项目(一个用于从零构建 Debian 安装光盘/系统的工具集)
  2. 广义:从零开始手动构建一个 Debian 系统(类似 LFS,但基于 Debian 软件包)

下面我按**“从零构建一个最小 Debian 系统”的入门路径**来讲,这也是最常见、最有学习价值的方式。


一、先明确你要做什么

入门前先问自己:

  • ✅ 想理解 Linux 启动与系统结构?
  • ✅ 想做一个极小/定制 Debian 系统?
  • ✅ 还是只想装一个干净的 Debian?(那直接装 netinst 即可)

如果是前两者,继续往下看。


二、基础准备

1. 你需要的环境

  • 一台 Linux 主机(Ubuntu / Debian 均可)
  • 基本命令行能力
  • 一个空分区或镜像文件(推荐用 qemu + 镜像练手)

2. 必要工具

sudo apt install debootstrap binutils gcc make grub-pc qemu-system-x86

三、核心方法:用 debootstrap 从零建 Debian

这是最标准、最推荐的入门方式。

1. 创建目标目录

mkdir -p ~/debian-root

2. 用 debootstrap 拉取基础系统

sudo debootstrap --arch=amd64 stable ~/debian-root http://deb.debian.org/debian

这会得到一个最小 Debian 用户空间。


四、进入并配置系统

1. chroot 进去

sudo chroot ~/debian-root

2. 基础配置

apt update
apt install vim bash-completion
passwd root

3. 设置主机名

echo mydebian > /etc/hostname

五、让它能“启动”(关键)

1. 安装内核与 bootloader

apt install linux-image-amd64 grub-pc

2. fstab 示例

cat > /etc/fstab <<EOF
/dev/sda1 / ext4 defaults 0 1
EOF

⚠️ 实际设备名要看你用的磁盘


六、打包成可启动镜像(进阶)

常见做法:

  • 用 debootstrap + qemu-img + grub-install
  • 或用 mmdebstrap(更现代)

示例(简化):

qemu-img create -f raw debian.img 2G
mkfs.ext4 debian.img
mount debian.img /mnt
debootstrap stable /mnt
grub-install --root-directory=/mnt /dev/loopX

七、推荐学习路线(循序)

  1. ✅ 会用 debootstrap
  2. ✅ 理解 chroot / pivot_root
  3. ✅ 理解 initramfs
  4. ✅ 会自己编译内核
  5. ✅ 能定制最小系统(容器 / 嵌入式)

八、常见误区

❌ 以为 DFS = 从源码编译所有软件
✅ 实际上 Debian 的哲学是:用 Debian 的包,从零组装系统

❌ 一上来就做 ISO
✅ 先做一个能 chroot 的系统


九、参考资料(非常推荐)

  • 官方:https://wiki.debian.org/Debootstrap
  • mmdebstrap:https://gitlab.mister-muffin.de/josch/mmdebstrap
  • LFS(对比理解):https://www.linuxfromscratch.org/

如果你愿意,我可以:

  • 给你一份 一步一步可复制命令的实验清单
  • 或帮你做一个 QEMU 可启动 Debian 最小系统教程
  • 或解释 DFS 和 LFS 的本质区别

你更想从哪一步开始?

0 踩