——「1」livecd连网 #通常可自动连接,特殊网络环境不在本文讲解范围之内
——「2」硬盘分区 #此处仅为示例,具体分区方案依实际情况规划
lsblk #查看磁盘概略信息,也可选择用fdisk -l查看
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 119.2G 0 disk
├─sda1 8:1 0 599M 0 part /boot/efi
└─sda2 8:2 0 118.7G 0 part /
sdb 8:16 0 931.5G 0 disk
└─sdb1 8:17 0 931.5G 0 part
└─vgx-home 253:0 0 2.7T 0 lvm /home
sdc 8:32 0 931.5G 0 disk
└─sdc1 8:33 0 931.5G 0 part
└─vgx-home 253:0 0 2.7T 0 lvm /home
sdd 8:48 0 931.5G 0 disk
└─sdd1 8:49 0 931.5G 0 part
└─vgx-home 253:0 0 2.7T 0 lvm /home
parted -a optimal /dev/sda #-a optimal确保4k对齐
mkpart ESP 0% 600M
mkpart rootfs 600M 100%
set 1 boot on #标记ESP分区
p
align-check optimal ? #检测4k对齐,?指分区序号1/2/3...
mkfs.vfat -F 32 /dev/sda1 #ESP分区必须为fat32格式
mkfs.ext4 /dev/sda2
parted -a optimal /dev/sdb
mkpart lvm 0% 100%
p
align-check optimal 1
lvm2磁盘操作:
pvcreate /dev/sdb1 #新建物理卷
vgcreate vg /dev/sdb1 #新建卷组并命名为vg
lvcreate --size 2g --name swap vg #新建逻辑卷并命名为swap
lvcreate --extends 100%FREE --name home vg #使用全部剩余空间,新建逻辑卷并命名为home
vgchange --activate y #激活卷组
ls /dev/vg #查看已创建的lvm分区
mkswap /dev/vg/swap
swapon /dev/vg/swap #激活swap分区
mkfs.ext4 /dev/vg/home
——「3」基本环境搭建:下载stage3并chroot
mount /dev/sda2 /mnt/gentoo
cd /mnt/gentoo/
links
http://www.gentoo.org/main/en/mirror.xml #选择网易镜像,到releases/amd64/autobuilds目录下载stage3,D下载Q结束
tar jxvfp stage3....tar.bz2
blkid | grep /dev/sda2 >> /mnt/gentoo/etc/fstab #存储rootfs的PARTUUID,以备第6步操作中写入内核
mkdir -p /mnt/gentoo/boot/efi
mount /dev/sda1 /mnt/gentoo/boot/efi
mkdir -p /mnt/gentoo/boot/efi/gentoo/boot #EFI分区存放内核的目录
mount /dev/vg/home /mnt/gentoo/home
mount -t proc proc /mnt/gentoo/proc #chroot准备
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mirrorselect -i -o >> ./etc/portage/make.conf #设置portagetree更新源
mirrorselect -i -r -o >> ./etc/portage/make.conf #设置snapshots更新源
cp -L /etc/resolv.conf ./etc #nameserver data #复制域名服务器信息
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="[chroot]$PS1" #可选操作,仅为提示功能
emerge-webrsync #更新快照
emerge --sync --quiet #更新portagetree
eselect profile list #选择mirror具体目录
eselect profile set ? #可选择纯64位安装
——「4」编译参数设置
nano -w /etc/portage/make.conf
CFLAGS="-march=native -o2 -pipe"
MAKEOPTS="-j9" #CPU线程数+1
USE="默认项 ssse3 sse4 avx avx2” #查看/proc/cpuinfo核对
USE=“-gnome -kde -minimal -qt4 dbus jpeg lock session startup-notification thunar X" #xfce4桌面环境需要
USE=”gtk xvmc” #nvidia专有驱动需要
ACCEPT_LICENSE="-* @FREE" #仅使用自由软件
ACCEPT_KEYWORDS="amd64" #仅使用稳定版,添加 ~ 指兼纳不稳定版本
PORTAGE_ELOG_CLASSES="info warn error log qa"
PORTAGE_ELOG_SYSTEM="save"
VIDEO_CARDS="nvidia" #intel显卡为”intel”
INPUT_DEVICES="evdev"
LINGUAS="zh_CN zh_TW" #中文设置
——「5」本地化设置
echo "Asia/Shanghai" > /etc/timezone
emerge --config sys-libs/timezone-data
nano /etc/locale.gen
zh_CN.UTF8 UTF8
us_US.UTF8 UTF8
locale-gen
locale -a
eselect locale list
eselect locale set ?
env-update && source /etc/profile
——「6」选择内核项&编译
lspci #查看硬件型号,需先安装pciutils
lsmod #查看livecd目前有效的硬件驱动模块,供参考
emerge gentoo-sources #下载内核源码
ls -l /usr/src/linux #确认linux内核
cd /usr/src/linux
make menuconfig #内核功能选择
##添加特殊驱动、GPT&EFI支持
##精简文件系统、无关驱动、非intel相关项等
##root目录写进内核
Processor type and features --->
[*]Built-in kernel command line
root=/dev/sda2或root=PARTUUID=...#用blkid命令查看PARTUUID(特别注意:非UUID)
##x11-base/xorg-server需要的选项:
Device Drivers --->
Graphics support --->
Support for frame buffer devices --->
## (Disable all drivers, including VGA, Intel, nVidia, and ATI)
## (Further down, enable basic console support. KMS uses this.)
Console display driver support --->
<*> Framebuffer Console Support
##intel显卡(x11-base/xorg-server):
Device Drivers --->
Graphics support --->
/dev/agpgart (AGP Support) --->
<*> Intel 440LX/BX/GX, I8xx and E7x05 chipset support
Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
<*> Intel 8xx/9xx/G3x/G4x/HD Graphics
##nvidia专有驱动(x11-base/xorg-server):
[*] Enable loadable module support --->
Processor type and features --->
[*] MTRR (Memory Type Range Register) support
Device Drivers --->
Graphics support --->
Frame buffer Devices --->
<*> Support for frame buffer devices --->
<> nVidia Framebuffer Support #disable
<> nVidia Riva support #disable
make && make modules_install
cp /usr/src/linux/arch/x86_64/boot/bzimage /boot/efi/gentoo/boot/bootx64.efi
——「7」网络设置&fstab
设置有线网络:
nano /etc/conf.d/hostname #hostname="kyss"
nano /etc/conf.d/net #config_neo1="dhcp"
cd /etc/init.d
ln -s net.lo net.eno1 #eno1为示例,用ifconfig查看网卡具体名称
rc-update add net.eno1 default
emerge dhcpcd #安装dhcp客户端
nano -w /etc/fstab
/dev/sda1 /boot/efi vfat defaults,discard 0 2
/dev/sda2 / ext4 defaults,noatime,errors=remount-ro,discard 0 1
/dev/vg/swap none swap noatime,discard 0 0
/dev/vg/home /home ext4 defaults,noatime,errors=remount-ro 0 2
passwd root#为root设置密码
——「8」设置系统启动菜单
emerge efibootmgr
exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount /mnt/gentoo{/boot,/proc,/sys,}
reboot
modprobe efivars #必须切换至UEFI环境,选择/dev/sda2为root目录
efibootmgr -c -d /dev/sda -p 1 -L Gentoo -l "\gentoo\boot\bootx64.efi"
emerge lvm2 #目标主机安装lvm2
rc-update add lvm boot #添加至boot运行级,确保逻辑卷开机挂载
——「9」安装xorg&xfce4
rm stage3....tar.bz2
useradd -m -G users,wheel,audio,video,usb /bin/bash fh
passwd fh
##xorg&xfce安装详情见gentoo-wiki:
##https://wiki.gentoo.org/wiki/Xorg/Configuration#Installing_Xorg
##http://wiki.gentoo.org/wiki/Xfce/HOWTO
emerge -pv xorg-drivers #查看相关信息
echo "x11-base/xorg-server udev" >> /etc/portage/package.use
emerge --ask xorg-server #根据提示添加额外USE
env-update && source /etc/profile
##若为nvidia显卡,需要的额外操作:
##nvidia-xconfig
##eselect opengl set nvidia
##eselect opencl set nvidia
emerge --ask xfce4-meta #根据提示添加额外USE
env-update && source /etc/profile
emerge --ask x11-terms/xfce4-terminal
echo XSESSION="Xfce4" > /etc/env.d/90xsession
chown -R fh:fh /home/fh #change ownership of all in fh directory back
startx
emerge --ask:
xfce4-battery-plugin
xfce4-sensors-plugin
xfce4-power-manager
xfce4-mixer #调节音量
xfce4-taskmanager
mplayer
firefox
app-admin/syslog-ng
sys-process/cronie
sys-apps/mlocate
rc-update add syslog-ng default
rc-update add cronie default
rc-update add sshd default