Ubuntu 21.10/22.04 配置

新电脑 R9000K 是去年买的,因此最初记录的只是 20.04 相关的一些东西,后面系统升级至 21.10 以及 22.04 就把 20.04 特有的东西做了清理,感慨每次升级总是有一些东西要折腾。

现在的 Linux 系统相比 06/07 年在学校那会已经非常的易用了,至今仍能想起在学校第一次用 hustauth 在 Fedora Core 上实现锐捷认证时的喜悦(后面有了 Mentohust,锐捷认证就变得很简单了)。

安装必要的设置软件

$ sudo apt install gnome-tweaks
$ sudo apt install gnome-shell-extensions
$ sudo apt install gnome-control-center

Nvidia driver

Ubuntu 22.04 从 Nvidia 470 驱动升级 515 驱动时(即使是官网下载的驱动),可能出现如下的错误:

[ 3141.130219] NVRM: API mismatch: the client has the version 515.65.01, but
               NVRM: this kernel module has the version 470.141.03.  Please
               NVRM: make sure that this kernel module and all NVIDIA driver
               NVRM: components have the same version.
[ 3248.189877] nvidia_uvm: module uses symbols from proprietary module nvidia, inheriting taint.
[ 3248.189970] nvidia_uvm: Unknown symbol nvUvmInterfacePagingChannelAllocate (err -2)
[ 3248.189995] nvidia_uvm: Unknown symbol nvUvmInterfacePagingChannelsMap (err -2)
[ 3248.190007] nvidia_uvm: disagrees about version of symbol nvUvmInterfaceSetPageDirectory
[ 3248.190007] nvidia_uvm: Unknown symbol nvUvmInterfaceSetPageDirectory (err -22)
[ 3248.190028] nvidia_uvm: Unknown symbol nvUvmInterfacePagingChannelPushStream (err -2)
[ 3248.190066] nvidia_uvm: disagrees about version of symbol nvUvmInterfaceRegisterGpu
[ 3248.190066] nvidia_uvm: Unknown symbol nvUvmInterfaceRegisterGpu (err -22)
$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module  470.141.03  Thu Jun 30 18:45:31 UTC 2022
GCC version:  gcc version 11.2.0 (Ubuntu 11.2.0-19ubuntu1) 
$ cat /sys/module/nvidia/version
470.141.03

$ dkms status
nvidia/515.65.01, 5.15.0-47-generic, x86_64: installed

$ ls /var/lib/dkms/nvidia/
515.65.01  kernel-5.15.0-47-generic-x86_64

更新 initramfs 即可:

$ sudo update-initramfs -u -k all

How to fix “NVRM: API mismatch” between client version and kernel module version when installing Nvidia drivers for a GTX 560 Ti in Ubuntu 20.04?
https://stackoverflow.com/questions/70276412/how-to-fix-nvrm-api-mismatch-between-client-version-and-kernel-module-version

Ubuntu Linux Install Nvidia Driver
https://www.cyberciti.biz/faq/ubuntu-linux-install-nvidia-driver-latest-proprietary-driver/

input method

$ sudo apt install fcitx5 fcitx5-pinyin fcitx5-module-cloudpinyin

Fcitx Chinese Input Setup on Ubuntu for Gaming
https://leimao.github.io/blog/Ubuntu-Gaming-Chinese-Input/

editor

$ sudo apt install vim
$ sudo update-alternatives --config editor

theme

MacOS Big Sur like theme for Gnome desktops
https://github.com/vinceliuice/WhiteSur-gtk-theme.git

MacOS Big Sur style icon theme for linux desktops
https://github.com/vinceliuice/WhiteSur-icon-theme.git

BigSur GRUB Theme
https://github.com/Teraskull/bigsur-grub2-theme.git

默认的窗口圆角太浮夸了,可以改小一些:

Change the $wm_radius: 14px; in src/sass/_variables.scss

$ git diff
diff --git a/src/sass/_variables.scss b/src/sass/_variables.scss
index 6e6a810..baaf4b1 100644
--- a/src/sass/_variables.scss
+++ b/src/sass/_variables.scss
@@ -42,7 +42,7 @@ $base_spacing: if($laptop == 'false', 6px, 4px);
 $circular_radius: 9999px;
 $bt_radius: if($laptop == 'false', 6px, 6px);
 $bd_radius: if($laptop == 'false', 8px, 8px);
-$wm_radius: if($laptop == 'false', 12px, 12px);
+$wm_radius: if($laptop == 'false', 3px, 3px);
 $mn_radius: if($laptop == 'false', 10px, 10px);
 $dash_radius: if($laptop == 'false', 24px, 18px);
 $base_border_radius: if($laptop == 'false', 8px, 8px);

Decrease the corner radius
https://github.com/vinceliuice/WhiteSur-gtk-theme/issues/33

extension

Dash to Panel
https://extensions.gnome.org/extension/1160/dash-to-panel/

ArcMenu
https://extensions.gnome.org/extension/3628/arcmenu/

AppIndicator
https://extensions.gnome.org/extension/615/appindicator-support/

User Themes
https://extensions.gnome.org/extension/19/user-themes/

Lunar Calendar 农历
https://extensions.gnome.org/extension/675/lunar-calendar/

$ sudo apt install gir1.2-lunardate-3.0
$ sudo mkdir -p /usr/share/locale/en_US/LC_MESSAGES/
$ sudo cp /usr/share/locale/zh_CN/LC_MESSAGES/lunar-date.mo /usr/share/locale/en_US/LC_MESSAGES/lunar-date.mo

在 21.10 上,如果任务栏不显示 Nautilus Filer,则需要禁用 Ubuntu Dock 插件(右键任务栏,选择 Extensions 进行配置):

如果还不行的话:

$ gsettings set org.gnome.shell.extensions.dash-to-dock isolate-locations false

dash-to-panel: Folders don’t appear on taskbar
https://github.com/home-sweet-gnome/dash-to-panel/issues/1500#issuecomment-962511964

安装 Desktop Icons NG 插件,解决桌面不能当作文件夹使用的问题:

$ sudo apt install gnome-shell-extension-desktop-icons-ng

注意,该插件无法手工安装:

Desktop Icons NG (DING)
https://extensions.gnome.org/extension/2087/desktop-icons-ng-ding/

wine

HiDPI

$ winecfg

How do I set scaling in Wine?
https://askubuntu.com/questions/1337156/how-do-i-set-scaling-in-wine

微信

[Desktop Entry]
Name=WeChat
Exec=env LANG=zh_CN.UTF-8 wine "/home/runsisi/.wine/dosdevices/c:/Program Files (x86)/Tencent/WeChat/WeChat.exe"
Type=Application
StartupNotify=true
Path="/home/runsisi/.wine/dosdevices/c:/Program Files (x86)/Tencent/WeChat"
Icon=E03C_WeChat.0
StartupWMClass=wechat.exe

Desktop entry, or other convinent but safe way to exec multiple statements
https://askubuntu.com/questions/725753/desktop-entry-or-other-convinent-but-safe-way-to-exec-multiple-statements

微信字体

$ sudo apt install fonts-wqy-microhei
$ cat font.reg
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"MS Shell Dlg"="wqy-microhei"
"MS Shell Dlg 2"="wqy-microhei"

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
"Lucida Sans Unicode"="wqy-microhei.ttc"
"Microsoft Sans Serif"="wqy-microhei.ttc"
"MS Sans Serif"="wqy-microhei.ttc"
"Tahoma"="wqy-microhei.ttc"
"Tahoma Bold"="wqy-microhei.ttc"
"wqy-microhei"="wqy-microhei.ttc"
"Arial"="wqy-microhei.ttc"
"Arial Black"="wqy-microhei.ttc"
$ wine regedit font.reg

微信输入框

$ sudo apt install winetricks
$ winetricks riched20

notepad++

[Desktop Entry]
Name=Notepad++
Exec=env WINEPREFIX="/home/runsisi/.wine" LANG=zh_CN.UTF-8 wine "/home/runsisi/.wine/dosdevices/c:/Program Files/Notepad++/notepad++.exe"
Type=Application
StartupNotify=true
Path=/home/runsisi/.wine/dosdevices/c:/Program Files/Notepad++
Icon=7ABC_notepad++.0
StartupWMClass=notepad++.exe

notepad++ 中文字符方块

选择合适的字体即可:

UI 字体如果乱码,导入上面字体替换的注册表项即可。

网易云音乐

库依赖问题

$ cd /opt/netease/netease-cloud-music/
$ ./netease-cloud-music.bash
/opt/netease/netease-cloud-music/netease-cloud-music: /opt/netease/netease-cloud-music/libs/libselinux.so.1: no version information available (required by /lib/x86_64-linux-gnu/libgio-2.0.so.0)
/opt/netease/netease-cloud-music/netease-cloud-music: symbol lookup error: /lib/x86_64-linux-gnu/libgio-2.0.so.0: undefined symbol: g_module_open_full

$ LD_DEBUG=libs ./netease-cloud-music.bash
     37349:	/opt/netease/netease-cloud-music/libs/libselinux.so.1: error: version lookup error: no version information available (required by /lib/x86_64-linux-gnu/libgio-2.0.so.0) (continued)
/opt/netease/netease-cloud-music/netease-cloud-music: /opt/netease/netease-cloud-music/libs/libselinux.so.1: no version information available (required by /lib/x86_64-linux-gnu/libgio-2.0.so.0)
     37349:	/lib/x86_64-linux-gnu/libgio-2.0.so.0: error: symbol lookup error: undefined symbol: g_module_open_full (fatal)
/opt/netease/netease-cloud-music/netease-cloud-music: symbol lookup error: /lib/x86_64-linux-gnu/libgio-2.0.so.0: undefined symbol: g_module_open_full

但是系统自带的动态库定义了相应的符号:

$ ll /lib/x86_64-linux-gnu/libgio-2.0.so.0
lrwxrwxrwx 1 root root 22  4月 14 21:35 /lib/x86_64-linux-gnu/libgio-2.0.so.0 -> libgio-2.0.so.0.7200.1
$ readelf -sW /lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.1 | grep g_module_open_full
   419: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND g_module_open_full
$ ldd /lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.1
	linux-vdso.so.1 (0x00007ffe641eb000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f92c9af4000)
	libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f92c9a94000)
	libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f92c9a8d000)
$ readelf -sW /lib/x86_64-linux-gnu/libgmodule-2.0.so.0.7200.1 | grep g_module_open_full
    40: 0000000000002970  2469 FUNC    GLOBAL DEFAULT   14 g_module_open_full

因为程序修改了 LD_LIBRARY_PATH 环境变量,导致加载的是自带的动态库:

$ cat /opt/netease/netease-cloud-music/netease-cloud-music.bash
#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")"
export LD_LIBRARY_PATH="${HERE}"/libs
export QT_PLUGIN_PATH="${HERE}"/plugins 
export QT_QPA_PLATFORM_PLUGIN_PATH="${HERE}"/plugins/platforms
exec "${HERE}"/netease-cloud-music $@
$ locate libgmodule-2.0.so.0
/opt/netease/netease-cloud-music/libs/libgmodule-2.0.so.0
$ file /opt/netease/netease-cloud-music/libs/libgmodule-2.0.so.0 
/opt/netease/netease-cloud-music/libs/libgmodule-2.0.so.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=89682f18a3e4126c5c57336057a23707c3d60cf5, stripped

拷贝系统相应的动态库覆盖程序自带的即可:

$ sudo cp /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0.7200.1 /opt/netease/netease-cloud-music/libs/libgmodule-2.0.so.0
$ sudo cp /lib/x86_64-linux-gnu/libpango-1.0.so.0.5000.6 /opt/netease/netease-cloud-music/libs/libpango-1.0.so.0
$ sudo cp /usr/lib/x86_64-linux-gnu/libfribidi.so.0.4.0 /opt/netease/netease-cloud-music/libs/libfribidi.so.0

最近发现有严重的内存泄漏的问题,网易官方好像也不再升级维护了,不用也罢。

hidpi

$ sudo vi /usr/share/applications/netease-cloud-music.desktop
Exec=env QT_SCREEN_SCALE_FACTORS=2 netease-cloud-music %U

stardict

autoreconf: running: /usr/bin/autoconf --force --warnings=no-portability
configure.ac:445: error: possibly undefined macro: AM_GCONF_SOURCE_2
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
$ sudo apt install libgconf2-dev
$ sudo apt install devscripts equivs
$ git clone https://salsa.debian.org/debian/stardict.git
$ cd stardict/
$ sudo mk-build-deps -i debian/control
$ dpkg-buildpackage -b -us -uc

stardict: build-depends on deprecated gnome-doc-utils
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=947540

(gdb) bt
#0  0x00007ffff71a5834 in XkbUseExtension () at /lib/x86_64-linux-gnu/libX11.so.6
#1  0x00007ffff719e11c in XKeysymToKeycode () at /lib/x86_64-linux-gnu/libX11.so.6
#2  0x00005555555f5f05 in x11_hotkeys::get_offending_modifiers(_XDisplay*) (dpy=0x5555556f21a0) at x11_iskeyspressed.cpp:50
#3  0x00005555555f6eec in x11_hotkeys::x11_hotkeys(_GtkWindow*) (this=this@entry=0x555556067e50, win_=win_@entry=0x55555578e2a0) at x11_iskeyspressed.cpp:252
#4  0x00005555555f299e in PlatformFactory::create_class_by_name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void*) (name="hotkeys", param=0x55555578e2a0) at class_factory.cpp:71
#5  0x00005555555a6f1f in AppCore::Create(char const*) (this=0x7fffffffbae0, queryword=0x0) at stardict.cpp:408
#6  0x00005555555a7e07 in AppCore::Init(char const*) (this=0x7fffffffbae0, queryword=0x0) at stardict.cpp:2117
#7  0x00007ffff73b4c0f in g_closure_invoke () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#8  0x00007ffff73d0ea6 in  () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#9  0x00007ffff73d2884 in g_signal_emit_valist () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#10 0x00007ffff73d2ad3 in g_signal_emit () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#11 0x00007ffff74d79d8 in  () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#12 0x00007ffff74d7bb6 in g_application_run () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#13 0x000055555559d7fc in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at stardict.cpp:2498

https://github.com/clementine-player/Clementine/issues/6587
Clementine segfaults when QT_QPA_PLATFORM=wayland

Sakura terminal crashes with “Segmentation fault”
https://bugs.chromium.org/p/chromium/issues/detail?id=905203

$ echo $XDG_SESSION_TYPE
wayland
$ GDK_BACKEND=x11 stardict
$ sudo vi /usr/share/applications/stardict.desktop
Exec=env GDK_BACKEND=x11 stardict

词典:

$ ls
stardict-21cen-2.4.2.tar.bz2                stardict-langdao-ce-gb-2.4.2.tar.bz2
stardict-babylon-oald4-cn-2.4.2.tar.bz2     stardict-langdao-ec-gb-2.4.2.tar.bz2
stardict-babylon-oxford-encn-2.4.2.tar.bz2  stardict-oald-cn-2.4.2.tar.bz2
$ mkdir -p ~/.stardict/dic
$ for i in $(ls); do tar -C ~/.stardict/dic/ -xjf $i; done

去掉广告:

$ git diff -- dict/src/mainwin.cpp
diff --git a/dict/src/mainwin.cpp b/dict/src/mainwin.cpp
index a635c15..5c62bdf 100644
--- a/dict/src/mainwin.cpp
+++ b/dict/src/mainwin.cpp
@@ -3052,7 +3052,7 @@ void BottomWin::Create(GtkWidget *vbox)
        news_label = gtk_label_new(NULL);
        gtk_container_add(GTK_CONTAINER(movenews_event_box), news_label);
        gtk_misc_set_alignment (GTK_MISC (news_label), 0.0, 0.5);
-       gtk_widget_show(news_label);
+//     gtk_widget_show(news_label);
 
 #if GTK_MAJOR_VERSION >= 3
        link_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
@@ -3077,7 +3077,7 @@ void BottomWin::Create(GtkWidget *vbox)
 #endif
        link_label = gtk_label_new(NULL);
        gtk_container_add(GTK_CONTAINER(event_box), link_label);
-       gtk_widget_show(link_label);
+//     gtk_widget_show(link_label);
        label = gtk_label_new(NULL);
        gtk_widget_show(label);
        gtk_box_pack_end(GTK_BOX(link_hbox), label, true, true, 0);

TurboVNC hidpi

$ GDK_SCALE=2.0 /opt/TurboVNC/bin/vncviewer

HiDPI
https://wiki.archlinux.org/title/HiDPI

Failed to load module “xapp-gtk3-module”

XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000

$ env | grep GTK
GTK_IM_MODULE=fcitx
GTK_MODULES=gail:atk-bridge
GTK3_MODULES=xapp-gtk3-module
``

```bash
$ sudo apt install xapp

无法打开扩展管理程序

$ gnome-extensions-app
Gdk-Message: 21:28:07.827: Error flushing display: Protocol error
$ ls /usr/share/glvnd/egl_vendor.d/
10_nvidia.json  50_mesa.json

如果禁用了 Nvidia 的显卡,直接删掉 10_nvidia.json 即可,或者:

$ __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json gnome-extensions-app

Ver 1.1.8-1 breaks some GTK3/4 apps (Gnome ToDo, Gnome Maps, Cheese) - On Hybrid Graphics configurations
https://github.com/NVIDIA/egl-wayland/issues/41


最后修改于 2022-10-23