教程 gentoo tutorial

Chroot 环境配置

在安装 Stage3 基础系统后,下一步是进入并配置 chroot 环境。Chroot 环境提供了一个隔离的系统环境,使你能够在不影响 LiveCD 系统的情况下进行 Gentoo 系统安装和配置。

一、挂载必要的文件系统

在进入 chroot 前,需要挂载以下文件系统:

bash
mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev

`

如果使用 EFI 系统,还需挂载 EFI 分区:

bash
mkdir -p /mnt/gentoo/boot/efi
mount /dev/sda1 /mnt/gentoo/boot/efi

二、复制 DNS 配置

确保 chroot 环境可以访问网络:

bash
cp -L /etc/resolv.conf /mnt/gentoo/etc/

三、进入 chroot 环境

使用以下命令进入 chroot:

bash
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"

💡 说明:

  • source /etc/profile 加载环境变量
  • 修改 PS1 提示符,便于区分 chroot 与 LiveCD

四、配置 Portage

在 chroot 环境下,首先更新 Portage 树:

bash
emerge --sync

设置基本配置:

  1. 选择镜像源(Gentoo 镜像站) 编辑 /etc/portage/make.conf:
bash
GENTOO_MIRRORS="http://mirrors.tuna.tsinghua.edu.cn/gentoo"
  1. 设置 CPU 优化和 USE 标志 在 make.conf 中配置:
bash
CFLAGS="-O2 -march=native -pipe"
USE="bindist"

根据需要可进一步优化。

五、验证 chroot 环境

在 chroot 环境下,可以检查系统信息:

bash
uname -a
ls /proc
emerge --info

确保环境正常,并可以继续安装内核和软件包。