目标 :将gentoo配置为服务器,
一、下载并解压stage文件
1.官网下载stage文件
网址:https://www.gentoo.org/downloads/
将gentoo配置为服务器,所以只下载了stage3-amd64-systemd-20241117T163407Z.tar.xz这个最小的stage文件.
基于远程ssh连接debian(服务器有debian linux系统)安装,通过scp上传至服务器中.
2.解压stage文件
#cp /home/chxf/stage* /mnt/gentoo
#tar xpvf stage3-amd64-systemd-20241117T163407Z.tar.xz --xattrs-include=‘*.*’ --numeric-owner
二、安装gentoo基础系统
(一)Chrooting
1.复制DNS信息
root@debian-gentoo:/mnt/gentoo# cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
2.挂载必要的文件系统
需要提供的文件系统是:
/proc/ 是一个伪文件系统,虽然它看起来像是常规文件,但是却是由 Linux 内核生成
/sys/ 是一个伪文件系统,它类似被取代的 /proc/,但是比 /proc/ 更结构化
/dev/ 是一个包含全部设备文件的常规文件系统,一部分由Linux设备管理器(通常是udev)管理
/run/ 是一个临时文件系统,用于运行时生成的文件,例如 PID 文件和锁
/proc/位置将要挂载到/mnt/gentoo/proc/,而其它的都是绑定挂载。字面上的意思是,例如/mnt/gentoo/sys/事实上就是/sys/(它只是同一个文件系统的第二个条目点),而/mnt/gentoo/proc/是(可以说是)文件系统的一个新的挂载。
root@debian-gentoo:/mnt/gentoo# mount --types proc /proc /mnt/gentoo/proc
root@debian-gentoo:/mnt/gentoo# mount --rbind /sys /mnt/gentoo/sys
root@debian-gentoo:/mnt/gentoo# mount --make-rslave /mnt/gentoo/sys
root@debian-gentoo:/mnt/gentoo# mount --rbind /dev /mnt/gentoo/dev
root@debian-gentoo:/mnt/gentoo# mount --make-rslave /mnt/gentoo/dev
root@debian-gentoo:/mnt/gentoo# mount --bind /run /mnt/gentoo/run
root@debian-gentoo:/mnt/gentoo# mount --make-slave /mnt/gentoo/run
root@debian-gentoo:/mnt/gentoo# test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
root@debian-gentoo:/mnt/gentoo# mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
root@debian-gentoo:/mnt/gentoo# chmod 1777 /dev/shm
3.进入新环境
root@debian-gentoo:/mnt/gentoo# chroot /mnt/gentoo /bin/bash
debian-gentoo / # source /etc/profile
debian-gentoo / # export PS1=“(chroot) ${PS1}”
4.为bootloader作准备
(chroot) debian-gentoo / # mkdir /efi
(chroot) debian-gentoo / # mount /dev/sdb1 /efi
(二)配置 Portage
1.从网站安装 Gentoo ebuild 数据库快照
(chroot) debian-gentoo / # emerge-webrsync
2.选择镜像站点
(chroot) debian-gentoo / # emerge --ask --verbose --oneshot app-portage/mirrorselect
(chroot) debian-gentoo / # mirrorselect -i -o >> /etc/portage/make.conf
3.更新Portage ebuild 数据库
(chroot) debian-gentoo / # emerge --sync
4.选择正确的配置文件
(chroot) debian-gentoo / # eselect profile list
(chroot) debian-gentoo / # eselect profile set 22
5.配置/etc/portage/make.conf
(chroot) debian-gentoo / # cat /etc/portage/make.conf
#These settings were set by the catalyst build script that automatically
#built this stage.
#Please consult /usr/share/portage/config/make.conf.example for a more
#detailed example.
COMMON_FLAGS=“-march=native -O2 -pipe”
CFLAGS=“ C O M M O N F L A G S " C X X F L A G S = " {COMMON_FLAGS}" CXXFLAGS=" COMMONFLAGS"CXXFLAGS="{COMMON_FLAGS}”
FCFLAGS=“ C O M M O N F L A G S " F F L A G S = " {COMMON_FLAGS}" FFLAGS=" COMMONFLAGS"FFLAGS="{COMMON_FLAGS}”
USE=“-bindist”
#NOTE: This stage was built with the bindist USE flag enabled
#This sets the language of build output to English.
#Please keep this setting intact when reporting bugs.
LC_MESSAGES=C.utf8
GENTOO_MIRRORS=“https://mirrors.ustc.edu.cn/gentoo/”
ACCEPT_LICENSE=“*”
MAKEOPTS=“-j2”
6.更新@world集合
(chroot) debian-gentoo / #emerge -auvDN --with-bdeps=y @world
等它跑完了,先别急
运行下这几个命令:
(chroot) debian-gentoo / # emerge @preserved-rebuild
(chroot) debian-gentoo / # perl-cleaner --all
(chroot) debian-gentoo / # emerge -auvDN --with-bdeps=y @world
确定没有更新之后再继续,否则查看输出尝试重复运行
(三)配置时区和地区
(chroot) debian-gentoo / # echo “Asia/Shanghai” > /etc/timezone
(chroot) debian-gentoo / # emerge --config sys-libs/timezone-data
(chroot) debian-gentoo / # ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
(chroot) debian-gentoo / # echo “en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8” >> /etc/locale.gen
(chroot) debian-gentoo / # locale-gen
(chroot) debian-gentoo / # eselect locale list
这里建议使用英语易于排错,之后你可以自行换成中文:
(chroot) debian-gentoo / # eselect locale set 4