2024年4月28日

HYEOS

随事而为

Gentoo更新systemd又切换openrc 20230611更新

5 min read

本来是要切换到systemd引导方式下进行安装snap的,结果一个不小心删除掉了基础命令工具,懒得去想办法恢复,于是备份了一些文件进行系统重装,安装好之后呢,snap没有我想的那么好用,装了一些软件结果却是不能使用,另外就是systemd的服务管理让我有点头晕,习惯了openrc的配置,想要在systemd下进行配置的时候找不到入口,虽然承认systemd安装使用gentoo会方便不少,可不是我的菜,于是又切换回openrc引导来了,为了干净二次重装了系统。我的建议还是使用openrc,如果真想体验systemd snap,还是装个辅助备用的系统debian就好了,工控机安装的就是debian,当然也可以使用virtualbox安装虚拟机。

官方的安装指导结合以下的操作说明,systemd和openrc没有什么太大的区别,包括nvidia显卡安装部分,显示管理器kde使用display-manager,sddm配置部分是一样的。

我之前一直使用的是bios引导,所以使用efi引导的时候要将硬盘mbr转换为gpt,对于硬盘上已经有数据不想重新格式化以致于丢失数据的,可以使用fdisk和gdisk两个工具配合使用,gdisk进行gpt无损转化,fdisk进行efi分区创建格式化,建议按官方建议格式化为vfat文件系统。

第一步,当然是下载CD映像制作U盘启动,使用U盘引导进入系统后,进行分区操作。
mkfs.vfat -F 32 /dev/sda3 ##efi分区
mkfs.ext4 /dev/sda5 ##根目录分区

挂载分区到gentoop根目录和boot目录,以下为U盘引导的系统后将要chroot的gentoo目录,也就是之后的gentoo根目录
mount /dev/sda5 /mnt/gentoo
mount /dev/sda3 /mnt/gentoo/boot

cd /mnt/gentoo //进入根目录
links https://www.gentoo.org/downloads/mirrors/ //终端访问镜像进行stage3下载,也可提前下载好到u盘copy到根目录

tar xpvf stage3-.tar.xz --xattrs-include='.' --numeric-owner //解压缩文件,后面的参数不要忘记*

配置make
nano -w /mnt/gentoo/etc/portage/make.conf
在末尾追加以下内容

start

GENTOO_MIRRORS="https://mirrors.tuna.tsinghua.edu.cn/gentoo/" #使用清华源
ACCEPT_LICENSE="*"
MAKEOPTS="-j8 -l8" #此处请根据你的cpu线程数和你的实际内存来确定,我是i7(12线程) 16GB的memory
GRUB_PLATFORMS="efi-64" #使用amd64平台的grub进行引导
VIDEO_CARDS="intel i965 iris nvidia" ##显卡支持配置

end

配置全局ebulid软件仓库
mkdir --parents /mnt/gentoo/etc/portage/repos.conf
cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
nano /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
把原来的sync-uri这一行注释
添加sync-uri = rsync://http://rsync.mirrors.tuna.tsinghua.edu.cn/gentoo-portage/

开始chroot
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
mount --bind /run /mnt/gentoo/run
mount --make-slave /mnt/gentoo/run
chroot /mnt/gentoo /bin/bash

chroot后

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

更新数据库
emerge-webrsync
eselect profile list
systemd选这个,openrc选第9个plasma就可
[11] default/linux/amd64/17.1/desktop/plasma/systemd/merged-usr (stable)
eselect profile set 11

emerge --ask app-portage/cpuid2cpuflags
cpuid2cpuflags
出现以下内容,我的机子,仅供参考
CPU_FLAGS_X86: aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3
稍作修改,将以下内容添加到/etc/portage/make.conf里
CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3"

emerge --ask ccache aria2
mkdir -p /var/cache/ccache
chown root:portage /var/cache/ccache -R
chmod 2775 /var/cache/ccache -R
在make.conf添加以下内容,如果在安装软件过程中报错无法进行下去,将以下内容注释掉即可,在安装systemd时没有问题,换回openrc时老是执行不下去,以前更新系统也出现过,虽然下载速度确实快,可不知道什么原因总是会断掉还无法继续执行,因此注释掉即可,更新完系统再取消注释平时安装软件也有用,或者干脆就不用

start

FEATURES="ccache -test"
CCACHE_DIR="/var/cache/ccache"
FETCHCOMMAND="/usr/bin/aria2c -d \${DISTDIR} -o \${FILE} --allow-overwrite=true --max-tries=5 --max-file-not-found=2 --max-concurrent-downloads=5 --connect-timeout=5 --timeout=5 --split=5 --min-split-size=2M --lowest-speed-limit=20K --max-connection-per-server=9 --uri-selector=feedback \${URI}"
RESUMECOMMAND="${FETCHCOMMAND}"

end

更新@word
emerge --ask --verbose --update --deep --newuse @world
etc-update --automode -3

设置时区(systemd设置方法,openrc参考官方)
ls /usr/share/zoneinfo
ln -sf ../usr/share/zoneinfo/Asia/Shanghai /etc/localtime

echo "en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8" >> /etc/locale.gen

locale-gen

或者

设置系统语言

nano /etc/locale.gen

将以下两行取消注释(删除前面的井号)

en_US.UTF-8 UTF-8

zh_CN.UTF-8 UTF-8

生成本地语言信息

locale-gen

设置本地语言环境变量

nano /etc/locale.conf


LANG=en_US.UTF-8

安装内核源码和固件微代码
emerge --ask sys-kernel/linux-firmware sys-kernel/gentoo-sources sys-kernel/genkernel
eselect kernel list
eselect kernel set 1 ##默认内核啥也没有,直接设置1 刚刚下载的内核源码
cd /usr/src/linux
genkernel all ##使用genkernel锁定内核配置时间,后续可自行优化内核

禁用nouveau
mkdir /etc/modprobe.d/
touch /etc/modprobe.d/blacklist.conf
nano /etc/modprobe.d/blacklist.conf

加入这些begin

blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0

加入这些end

安装显卡驱动
emerge -av x11-base/xorg-server x11-apps/xrandr x11-base/xorg-drivers media-libs/mesa x11-drivers/nvidia-drivers

emerge --ask sys-boot/grub sys-boot/os-prober sys-fs/ntfs3g sys-fs/btrfs-progs
nano /etc/default/grub
添加如下行,开启os探测

srart

GRUB_DISABLE_OS_PROBER=false

end

grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Gentoo
grub-mkconfig -o /boot/grub/grub.cfg

安装kde桌面
emerge sudo layman sys-apps/dbus kde-plasma/plasma-meta kde-apps/konsole kde-apps/dolphin
systemctl enable sddm
安装networkmanager(systemd网络管理器,openrc的参考官方)
emerge networkmanager
systemctl enable NetworkManager

emerge sys-apps/mlocate //日志管理
安装键盘鼠标驱动
emerge x11-drivers/xf86-input-void x11-drivers/xf86-input-evdev

安装蓝牙驱动
emerge net-wireless/bluez
systemctl enable bluetooth

声卡
emerge media-sound/pulseaudio media-libs/pulseaudio-qt kde-apps/kmix

中文字体
emerge wqy-zenhei ##可以自行添加字体,我选择的是通用型

系统监测辅助
emerge --ask acpid
emerge --ask thermald
emerge --ask cpupower

rc-update add acpid default //openrc
rc-update add thermald default //openrc
rc-update add cpupower default //openrc

passwd ##设定root密码
useradd --create-home hye #semes是我的用户名
passwd hye ##设定用户密码
usermod -aG wheel,users,audio,video,portage,plugdev hye #添加用户到组

visudo
找到root ALL=(ALL:ALL) ALL
在下面添加
semes ALL=(ALL:ALL) ALL
取消 # %wheel ALL=(ALL:ALL) ALL #让wheel的用户可使用sudo,双倍保险

系统安装完成,可以重启了

配置nvidia
nano /etc/modules-load.d/nvidia.conf

加入这些begin

nvidia

加入这些end

systemctl start systemd-modules-load.service

nano /etc/modprobe.d/nvidia-drm.conf

加入这些begin

options nvidia-drm modeset=1

加入这些end

nano /etc/X11/xorg.conf
##############加入这些begin##############################

nvidia-xconfig: X configuration file generated by nvidia-xconfig

Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0"
Inactive "InactiveDevice1"
Option "AllowNVIDIAGPUScreens" "true"
Option "AllowPRIMEDisplayOffloadSink" "true"
EndSection

Section "Files"
EndSection

Section "InputClass"
Identifier "libinput pointer catchall"
Driver "libinput"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Option "AccelProfile" "flat" #禁用鼠标加速,玩游戏必备
Option "AccelSpeed" "0"
EndSection

Section "InputClass"
Identifier "libinput keyboard catchall"
Driver "libinput"
MatchIsKeyboard "on"
MatchDevicePath "/dev/input/event*"
EndSection

Section "InputClass"
Identifier "libinput touchpad catchall"
Driver "libinput"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
option "Tapping" "True"
option "TappingDrag" "True"
option "NaturalScrolling" "True"
EndSection

Section "Module"
Load "fb"
Load "shadow"
Load "exa"
Load "glamoregl"
Load "glx"
Load "dri3"
EndSection

Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
Option "DPMS"
EndSection

Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BusID "PCI:1:0:0"
Option "Accel" "true"
Option "RenderAccel" "true"
Option "NoFlip" "false"
Option "SWCursor" "false"
Option "HWCursor" "true"
Option "DamageEvents" "true"
Option "ModeDebug" "false"
Option "AllowSHMPixmaps" "false"
Option "SidebandSocketPath" "/tmp"
Option "UseSysmemPixmapAccel" "true"
Option "MultisampleCompatibility" "true"
Option "AllowEmptyInitialConfiguration" "true"
Option "ForceCompositionPipeline" "true"
Option "ForceFullCompositionPipeline" "true"
Option "AllowIndirectGLXProtocol" "false"
Option "TripleBuffer" "true" #
Option "Stereo" "0"
Option "BaseMosaic" "false"
Option "MultiGPU" "false"
Option "SLI" "false"
Option "PrimaryGPU" "yes"
EndSection

Section "Device"
Identifier "InactiveDevice1"
Driver "modesetting"
VendorName "Unknown"
Option "AccelMethod" "glamor"
Option "DRI" "3"
Option "TearFree" "true"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
EndSubSection
EndSection

Section "Screen"
Identifier "Screen1"
Device "InactiveDevice1"
EndSection

Section "ServerFlags"
Option "DontVTSwitch" "True"
Option "DontZap" "True"
EndSection
#############加入这些end###############

nano /usr/share/sddm/scripts/Xsetup

加入这些begin

xrandr --setprovideroutputsource modesetting NVIDIA-0 #加入这一行
xrandr --auto #加入这一行

加入这些end

chmod u+s /usr/bin/xinit
修改grub启动参数
nano /etc/default/grub
找到

GRUB_CMDLINE_LINUX=""

改为
GRUB_CMDLINE_LINUX="nvidia-drm.modeset=1"
然后更新grub引导
grub-mkconfig -o /boot/grub/grub.cfg

重新启动
登陆用户

安装中文输入法 //openrc参考官方进行设置
sudo nano /etc/environment

start

GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
SDL_IM_MODULE=fcitx

end

sudo emerge --ask app-i18n/fcitx emerge --ask app-i18n/fcitx-rime app-i18n/kcm-fcitx app-i18n/fcitx-configtool

给日常用户写启动文件
nano ~/.xprofile

start

eval "$(dbus-launch --sh-syntax --exit-with-session)"
export XMODIFIERS="@im=fcitx"
export QT_IM_MODULE=fcitx
export GTK_IM_MODULE=fcitx

end

省电需要
换intel_GPU就改xorg.conf

把/etc/X11/xorg.conf的内容修改为:
##############################################################
Section "ServerLayout"
Identifier "layout"
Screen 0 "iGPU"
Option "AllowNVIDIAGPUScreens"
EndSection

Section "Device"
Identifier "iGPU"
Driver "modesetting"
BusID "PCI:0:2:0"
EndSection

Section "Screen"
Identifier "iGPU"
Device "iGPU"
EndSection

Section "Device"
Identifier "nvidia"
Driver "nvidia"
BusID "PCI:1:0:0"
EndSection
###################################################################

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注