gentoo 是一个 linux 的版本,所有软件编译安装,但是这种安装过程耗时太长,已经不适合这个需要快速的时代。但是通过手动安装的过程,可以更深入的了解linux。
gentoo 的文档非常全面,大部分的问题都可以通过操作手册解决
https://wiki.gentoo.org/wiki/Handbook:Main_Page
1.分区
默认:利用parted工具,进行gpt分区
parted -a optimal /dev/sda
mklabel gpt (choice yes)
unit MB
mkpart primery 1 20
name 1 grub
set 1 bios_grub on
print
mkpart primary 21 500
name 2 boot
mkpart primary 501 8501
name 3 swap
mkpart primary 8502 -1
print
name 4 root
quit
可选:利用fdisk进行mbr分区。有写电脑并不支持gpt分区,可以采用这种格式
fdisk /dev/sda
创建 bios boot (我实验中创建的是512M,显然是浪费空间了)
Command (m for help):n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (64-10486533532, default 64): 2048
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): +2M
创建 boot
Command (m for help):n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (5198-10486533532, default 5198): (Hit enter)
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): +128M
选择 a , 选择 2 ,标记 此为 boot 分区
创建swap
Command (m for help):n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First sector (5198-10486533532, default 5198): (Hit enter)
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): +512M
Command (m for help):t
Partition number (1-4): 3
选择82 或者输入 l 查看编号,查看linux swap选项。
创建 root
Command (m for help):n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 4
First sector (5198-10486533532, default 5198): (Hit enter)
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): (Hit enter)
查看p
Command (m for help):p
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 3 5198+ ef EFI (FAT-12/16/32)
/dev/sda2 * 3 14 105808+ 83 Linux
/dev/sda3 15 81 506520 82 Linux swap
/dev/sda4 82 3876 28690200 83 Linux
保存
w
创建文件系统
mkfs.ext2 /dev/sda2
mkfs.ext4 /dev/sda4
mkswap /dev/sda3
swapon /dev/sda3
挂载磁盘
mount /dev/sda4 /mnt/gentoo
2. 安装基本系统 stage
cd /mnt/gentoo
下载,选择国内的镜像下载速度会快一点
wget http://mirrors.163.com/gentoo/releases/amd64/autobuilds/20200708T103427Z/stage3-amd64-20200708T103427Z.tar.xz
解压
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
设置 镜像源,选择163
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
拷贝仓库地址
cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
拷贝DNS
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
挂载磁盘
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
进入环境
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"
挂载boot
mount /dev/sda2 /boot
配置 Portage
emerge-webrsync
emerge --sync
选择环境
eselect profile list
eselect profile set 8 (选择 kde plams 对应的编号)
emerge --ask --verbose --update --deep --newuse @world
nano -w /etc/portage/make.conf
USE="-gtk -gnome qt4 qt5 kde dvd alsa cdr"
配置时间
ls /usr/share/zoneinfo
echo "Asia/Shanghai" > /etc/timezone
emerge --config sys-libs/timezone-data
配置语言环境
nano -w /etc/locale.gen
en_US ISO-8859-1
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
locale-gen
eselect locale list
eselect locale set 5 (选择自己认为的编码作为主要显示)
env-update && source /etc/profile && export PS1="(chroot) ${PS1}"
3.编译内核
emerge --ask sys-kernel/gentoo-sources
ls -l /usr/src/linux
emerge --ask sys-kernel/genkernel
nano -w /etc/fstab
/dev/sda2 /boot ext2 defaults,noatime 0 2
/dev/sda3 none swap sw 0 0
/dev/sda4 / ext4 noatime 0 1
time genkernel all
genkernel --install initramfs
emerge --ask sys-kernel/linux-firmware
4.设置环境
nano /etc/conf.d/hostname
hostname="gentoo"
nano /etc/hosts
127.0.0.1 localhost gentoo
5.设置root 密码
passwd
6.安装必要软件
emerge --ask app-admin/sysklogd
rc-update add sysklogd default
emerge --ask sys-process/cronie
rc-update add cronie default
crontab /etc/crontab
rc-update add sshd default
rc-update add dhcpcd default
rc-update add sshd default
7.安装 grub
emerge --ask --verbose sys-boot/grub:2
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
8.重启系统
exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
reboot
以下为桌面安装部分>>>>>>>>>>>>>>>>>>>>>>>
9.创建一个普通能够登陆的用户
useradd -m -G users,wheel,audio,lp,cdrom,portage,cron -s /bin/bash super
passwd super
10.查看CPU核数并配置
cat /proc/cupinfo |grep processor
vim /etc/portage/make.conf
MAKEOPTS=-j4 (我的cpu核数是4)
11.安装ssh 和 sudo
time emerge openssh
emerge sudo
vim /etc/sudoers
%wheel ALL=(ALL)ALL (打开注释)
12.安装xorg
time emerge --ask x11-base/xorg-drivers
time emerge --quiet x11-base/xorg-server
env-update
13.安装sddm
time emerge --quiet sddm
time emerge cupid2cpuflags
cpuid2cpuflags >> /etc/portage/make.conf (把其中的:改成 =)
cat /etc/portage/make.conf
14.安装kde plasma桌面
time emerge --quiet kde-frameworks/plasma
time emerge --quiet --ask kde-plasma/plasma-meta
vim /etc/conf.d/xdm
DISPLAYMANAGER="sddm"
rc-update add xdm default
15.安装terminal
time emerge --quiet xterm
time emerge --quiet konsole
#上面为两个不同的terminal
16.重启
reboot