gentoo 安装

Published by rcdfrd on 2023-11-21
# Gentoo
[ -d /sys/firmware/efi ] && echo UEFI || echo BIOS
cfdisk
mkfs.ext4 /dev/nvme0n1p1
mkfs.ext4 /dev/nvme0n1p2

mkdir /mnt/gentoo
mount /dev/nvme0n1p2 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/nvme0n1p1 /mnt/gentoo/boot
cd /mnt/gentoo
http://mirrors.ustc.edu.cn/gentoo/releases/amd64/autobuilds/current-stage3-amd64-openrc/
tar xfp stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
vi /mnt/gentoo/etc/portage/make.conf

# GCC
COMMON_FLAGS="-march=native -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
CHOST="x86_64-pc-linux-gnu"
MAKEOPTS="-j8"

# USE
USE="-bindist -systemd -X grub"

# PORTAGE
GENTOO_MIRRORS="https://mirrors.ustc.edu.cn/gentoo/"
EMERGE_DEFAULT_OPTS="--ask --verbose=y --keep-going --with-bdeps=y --load-average"
ACCEPT_LICENSE="*"
LC_MESSAGES=C.utf8

mkdir -p /mnt/gentoo/etc/portage/repos.conf
cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf

cp --dereference /etc/resolv.conf /mnt/gentoo/etc/

dd if=/dev/zero of=/mnt/gentoo/swap.img bs=1M count=2048
mkswap /mnt/gentoo/swap.img
chmod 0600 /mnt/gentoo/swap.img
swapon /mnt/gentoo/swap.img

mount -t 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
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm
chroot /mnt/gentoo/ /bin/bash

source /etc/profile
export PS1="(chroot) ${PS1}"

emerge-webrsync
emerge --sync
eselect profile list
eselect profile set 1

emerge --ask --verbose --update --deep --newuse @world

emerge @preserved-rebuild
perl-cleaner --all
emerge -auvDN --with-bdeps=y @world

echo "Asia/Shanghai" > /etc/timezone
emerge --config sys-libs/timezone-data
echo -e "en_US.UTF-8 UTF-8 \n zh_CN.UTF-8 UTF-8\n" >> /etc/locale.gen
locale-gen

eselect locale list
eselect locale set 4

emerge --ask app-portage/cpuid2cpuflags
echo "*/* $(cpuid2cpuflags)" > /etc/portage/package.use/00cpu-flags

env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

emerge --ask --verbose --update --deep --newuse @world
# emerge --ask sys-kernel/linux-firmware
# emerge --ask sys-kernel/installkernel-gentoo
emerge --ask sys-kernel/gentoo-kernel-bin
emerge --depclean
wget -qO- https://raw.githubusercontent.com/YangMame/Gentoo-Installer/master/genfstab | bash -s -- / > /etc/fstab
nano /etc/fstab

echo gentoo > /etc/hostname
# dhcp
emerge --ask net-misc/dhcpcd
rc-update add dhcpcd default
rc-service dhcpcd start
# 手动指定ip using netifrc
emerge --ask --noreplace net-misc/netifrc
nano /etc/conf.d/net

config_eth0="192.168.0.2/24  2001:1234:5678::a/64"
routes_eth0="default via 192.168.0.1 
default via 2001:1234:5678::1 dev eth0 onlink"


cd /etc/init.d
ln -s net.lo net.eth0
rc-update add net.eth0 default

passwd

# nano /etc/rc.conf
# nano /etc/conf.d/keymaps
# nano /etc/conf.d/hwclock

emerge --ask app-admin/sysklogd
rc-update add sysklogd default
emerge --ask sys-process/cronie
rc-update add cronie default
rc-update add sshd default

emerge --ask --verbose sys-boot/grub
grub-install --target=i386-pc /dev/nvme0n1

nano /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0"

grub-mkconfig -o /boot/grub/grub.cfg

emerge --ask app-portage/gentoolkit
eclean --deep distfiles
eclean --deep packages

exit
reboot