从零开始的 CentOS 构建路线概览
“from scratch”常见有三种目标:其一,在虚拟机或物理机上做一套最小化安装的 CentOS;其二,用 Docker 的 scratch 基础镜像制作极简 CentOS 容器;其三,完全从源码构建的 Linux From Scratch(LFS)。下面分别给出可执行的步骤要点与关键命令,便于直接落地。
路线一 最小化安装 CentOS 到虚拟机或物理机
yum update -y 更新系统;使用 nmtui 或编辑 /etc/sysconfig/network-scripts/ifcfg-ensXX 配置网络;安装常用工具:yum install -y net-tools bind-utils vim wget curl;启用 SSH:systemctl enable --now sshd;按需配置 firewalld:firewall-cmd --zone=public --add-service=ssh --permanent && firewall-cmd --reload。路线二 用 Docker 的 scratch 制作极简 CentOS 容器镜像
FROM scratch
ADD centos-7.4.1708-docker.tar.xz /
CMD ["/bin/bash"]
docker build -t centos:7.4-scratch .;运行:docker run -it --rm centos:7.4-scratch。RUN yum install -y make gcc gcc-c++ && yum clean all;注意 scratch 镜像没有包管理器,所有依赖需在构建时一次性装好。路线三 完全从源码构建 Linux From Scratch(LFS)并制作可启动介质
make -j$(nproc) 提速,但部分测试失败可先忽略(视版本与平台而定)。/boot。grub-install --root-directory=/mnt/target /dev/sdb;编辑 grub.cfg,示例:set root=(hd0,1)
linux /boot/vmlinuz-<version> root=/dev/sda1 rootdelay=8
initrd /boot/initramfs-<version>.img
boot
rootdelay=8 可避免早期挂载失败;/etc/fstab 需与实际磁盘 UUID/分区对应。root (hd0,0)、kernel /boot/vmlinuz-<tab>、boot。