温馨提示×

ubuntu fromscratch出错咋办

小樊
45
2026-09-07 12:51:41
栏目: 智能运维

“Ubuntu From Scratch(UFS)”通常指两类情况:

  1. 你自己从零构建 Ubuntu(LFS 思路做 Ubuntu)
  2. 使用了某个叫 Ubuntu From Scratch 的项目/脚本(如 ufs 工具、GitHub 项目)

你可以先告诉我:具体报错信息是什么?(终端最后几行最关键)
在不知道错误前,下面是常见原因 + 通用排查办法,基本能解决 80% 的问题。


一、先做的 5 个通用排查(必看)

uname -a
lsb_release -a
df -h
free -h

重点看:

  • 磁盘是否满(/tmp 或构建目录)
  • 内存是否不足(构建容易 OOM)
  • Ubuntu 版本是否太新/太旧

二、常见错误 & 解决办法

1️⃣ 依赖缺失(最常见)

报错类似:

E: Unable to locate package xxx
configure: error: xxx not found

解决:

sudo apt update
sudo apt install -y build-essential \
  debhelper devscripts fakeroot \
  bison flex ncurses-dev

如果是 UFS 项目:

sudo apt build-dep ubuntu-minimal

2️⃣ 脚本中断 / 网络问题

报错:

Failed to fetch
Connection timed out

解决:

export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

或换源:

sudo sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
sudo apt update

3️⃣ 权限问题

报错:

Permission denied
must be root

解决:

sudo -i

不要混用 root 和普通用户构建


4️⃣ chroot / 挂载失败

报错:

failed to run command ‘/bin/bash’: No such file or directory
mount: permission denied

检查:

mount | grep chroot
ls -l /path/to/rootfs/bin/bash

修复示例:

sudo mount --bind /dev fs/dev
sudo mount --bind /proc fs/proc
sudo chroot fs

5️⃣ 构建到底层包就挂(glibc / gcc)

这是正常难度问题,不是你的问题
✅ 建议:

  • Ubuntu 官方 debootstrap 替代手工 From Scratch
sudo debootstrap noble /mnt/ubuntu http://mirrors.tuna.tsinghua.edu.cn/ubuntu

三、如果你只是“想做一个最小 Ubuntu”

强烈建议别 From Scratch,用:

debootstrap

ubuntu-base tarball + chroot

四、请把这些贴出来,我可以直接帮你改

请发:

  1. 你用的命令
  2. 完整报错最后 20 行
  3. Ubuntu 版本(22.04 / 24.04

我可以直接告诉你哪一步错了、怎么改

0