Fucked Up by Ubuntu 20.04

Fucked Up by Ubuntu 20.04

缘由及发行版的选择

先说一下结果吧: 由于工作需要,我将一台工作PC台式机安装成了 Ubuntu 20.04。

如果想直接看fucked up部分,请直从右则的TOC接跳到 #fucked-up

作为一个长期在Linux 桌面环境下工作的人,肯定是用新不用旧。新版本出来了,当然是上新版本。没点追求的话,人活着跟咸鱼有什么区别?

当然,老灯主要在用的还是Fedora. 选择哪个发行版也不是盲目选的,是根据个人需求的。

  1. 肯定是选主流发行版,看重官方支持和更新维护。
  2. Gnome 3 环境是优秀的,并且我已长期习惯这个环境了,因此 DE 必须是 Gnome 3
  3. 由于需要原生的Docker或Podman环境,因此只能是Linux系,BSD或其它系不考虑(包括苹果)
  4. 考虑到是工作环境使用,滚动升级的发行版就不考虑了。有一定的稳定性要求。
  5. 作为工作开发环境,不能是太守旧的发行版,比如Debian或CentOS就不考虑了

打开 distrowatch 看看主流发行版吧。

  • Linux Mint: 主要版本为基于Ubuntu的,DE为Cinnamon, MATE 和 Xfce, 没有 Gnome 3, 放弃。
  • Ubuntu: 主版本为Gnome 3环境,背后有Canonical公司支撑,有稳定的版本更新和发行周期,软件包一般较新。可作为候选。
  • MX Linux: 这是怎么上到这个列表的?没听过,不好意思。
  • Arch Linux: 老灯此前用过10多年, pacman非常灵活,文档最友好(没有之一),滚动升级,软件包升级非常及时,主要的不稳定性因素,可能来自厂家显卡驱动。因为Arch是滚动升级,且内核升级是相当激进,基本上是跟随mainline内核版本的,而厂商的显卡驱动可能没有那么快发布对较新内核的支持,工作中很可能导致大早上一升级崩了,一上午都在修系统。因此不太适合在工作中使用。
  • Gentoo: 安装系统需要一定的技能,安装包以编译为主,较为耗时,不利于提升工作效率。几十年来老灯一直没有尝试这个系统的想法。
  • Slackware: 略冷门,用得人比较少,有个叫unRAID的 NAS 系统好像是基于它的,不是老灯的菜。放弃。
  • Debian: 社区主导,版本发行周期较长且无固定时间,稳定性著称,一直守着点老包,有bug了就修一下,能不稳定吗?问题是,当大家都在用win10的时候,我不想还在用win7。 所以,放弃。
  • Fedora: 主版本为Gnome 3环境,软件包升级速度跟Arch有得一拼, 可能是主流里面,除了Arch之外,升级最激进的一个发行版。半年发行一个版本。有Red Hat这种商业公司在背后支持。可作为候选。
  • openSUSE: 同时支持KDE和 GNOME 3 环境。有SUSE LLC.这种商业公司在背后支撑。但是其主打 btrfs 和 KDE 桌面 (在安装界面, GNOME 一直是排在 KDE 后面)。

截止到目前(2020-06-26) Docker 官方尚未提供 Fedora 32的 Docker repo。

https://github.com/docker/for-linux/issues/955 , 虽然这里可以看到有个PR已经在 2020-04-11 merged: https://github.com/docker/docker-ce-packaging/pull/452 但是 Ubuntu 20.04 和 Fedora 32 的发布时间相差没几天,Ubuntu 20.04 (代号Focal) 的 repo https://download.docker.com/linux/ubuntu/dists/focal/ 早已OK,而 Fedora 的 repo 则还停留在 31 (见 https://download.docker.com/linux/fedora/ ),同时 RHEL 和 CentOS 的 repo 也都还停留在 7, 最新的 8 是没有的。

老灯猜测,可能是跟 RHEL 对于 Docker 的态度有关 (见 https://www.techrepublic.com/article/a-matter-of-license-and-lock-in/ ), 又或者是跟 Fedora 32 的 cgroup v2 和 nftables 有关。

由于项目需要用到 Docker, 而我也不想自己去手动把 Docker的 构建脚本修改成 Podman 适用的。 另外,podman的在非root用户时是以rootless模式运行,而该模式跟root模式相比,还存在较多的限制及坑。 因此,相对来说,如果要以当前(普通用户的身份)来构建镜像或运行容器,通过 Docker (将当前用户加入docker用户组)的方式兼容性更好。

因此,虽然老灯非常喜欢 Fedora, 但是还是不能选它。理由:不要自己给自己找麻烦。

openSUSE 历史上是以 KDE 为默认桌面环境的,后面虽然推出了 KDE, 但在安装界面, GNOME 选项还是排在 KDE 后面。另外,它默认用的 btrfs 使我有点担心。 因此,很自然地只剩下 Ubuntu 可选了。

注意: 并不是说 Fedora 32 完全没有办法使用 Docker (事实上民间有文章介绍了直接使用f31的docker仓库的方法), 但是民间终归是民间,我需要的是一个持续的,稳定的支持, 而不是依靠民间的Hacking方法。

安装过程的小波折

从清华源下载iso: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/focal/ubuntu-20.04-desktop-amd64.iso

同时,一定要注意校验hash https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/focal/SHA256SUMS

老灯这台工作机有两个硬盘,主盘nvme用来装操作系统,还有一个机械硬盘用于存数据。

机械硬盘暂时没存什么东西,因此,直接干掉了,然后用 dd 将 ubuntu-20.04-desktop-amd64.iso 写入 /dev/sda (机械硬盘)。

sudo dd if=./ubuntu-20.04-desktop-amd64.iso of=/dev/sda bs=8M

注意: /dev/sda 是我当前环境里的空闲磁盘,不可照抄。请根据自己的实际情况选择正确的磁盘设备。

通过设置BIOS优先从机械硬盘启动,成功启动Ubuntu live, 然后 ubuntu 开始校验cd内容, 提示发现一个错误,但是 ubuntu 这一点有点坑, 没有阻止继续安装,而只是提示,此错误可能会导致安装失败。然后我抱着试一试的态度,直接继续安装。导致了悲具。 现在问题来了,原来nvme是有正常工作的系统的,现在已经在 ubuntu 安装过程中被干掉了,而这个live cd又是坏的。

我的想法是,直接在live系统里,重新下载iso并校验OK, 然后再通过 dd 写入 /dev/sda (机械硬盘), 再重启,重新开始安装。

iso下载完了,你会发现 /dev/sda1 是被挂载到了 /cdrom的,并且无法被 umount, 但是不影响 dd 直接写入 /dev/sda

最终操作如期完成了。

来自老灯的警告: 如果 ubuntu live cd 提示你校验遇到错误了,不要继续安装,重新下载并注意校验 iso

安装系统时注意勾选 安装additional drivers选项,这样会自动判断显卡并选择最合适的驱动安装。 当然,这个也可以在系统安装完成后调整 (About - Software Updates - Additional Drivers)。

nvdia-driver.jpg
ubuntu-drivers-list.jpg

按惯例,执行一下neofetch:

neofetch-with-desktop-background.jpg

连文件管理器配色都带着浓浓的Ubuntu logo味儿:

filemanager-style.jpg

关于信息:

ubuntu-about.jpg

环境配置

安装完成首先把系统升级到最新:

sudo apt-get update
sudo apt-get upgrade

常用软件

sudo apt-get install vim htop nload ncdu ripgrep gnome-tweaks zsh

嫌弃 Ubuntu 默认的 terminal 背景配色的,可以使用 base16 的配色 https://github.com/aaron-williamson/base16-gnome-terminal

cockpit和kvm虚拟机

cockpit 是一个由 Red Hat 赞助的项目,主要是方便从WEB界面管理 Linux 服务器, 这个已经成为了 RHEL8 和 CentOS8 的标配。 老灯这里安装 cockpit 主要是 方便管理 kvm 虚拟机。

sudo apt-get install -y cockpit cockpit-dashboard cockpit-machines cockpit-networkmanager cockpit-storaged cockpit-system cockpit-ws

# ubuntu 上安装完默认是自动启用 和 启动 的
sudo systemctl status cockpit.socket

这里有一个问题是,网络不是默认启动(激活)的(虽然默认的default网络已经创建好了, 这个问题在 Fedora 和 CentOS 上并不存在),解决办法 (来自 https://blog.programster.org/kvm-missing-default-network ):

sudo virsh net-autostart --network default

虚拟机创建的话,我直接使用我之前打造好的 win10 镜像,创建虚拟机很简单,直接使用 cockpit 界面的导入功能导入.qcow2 镜像即可。 导入后注意把相关的io修改成virtio模式(比如网卡, 磁盘)然后再启动。

cockpit-login-page.jpg
cockpit-vm-overview.jpg
cockpit-vm.jpg
kvm-win10-guest.jpg

windows 10 guest 怎么和 host 机共享文件呢? 最简单的方法是通过smb协议。

在 host 机,也就是 Ubuntu 上安装 samba:

sudo apt-get install samba

编辑 /etc/samba/smb.conf, 增加:

假设我们有一个用户 ttys3 :

[winshare]
  comment = Media share accessible by kvm win guest
  path = /home/ttys3/winshare
  valid users = ttys3
  public = no
  writable = yes
  create mask = 0664
  directory mask = 2775
  force create mode = 0664
  force directory mode = 2775

虽然 Linux 已经有 ttys3 这个用户了,但是samba里面有另一套用户权限控制机制(注意:samba用户一定要是已经存在的Linux用户), 但是我们还是要将这个用户添加进samba:

smbpasswd -a ttys3
# 然后设置密码(注意这里的密钥是用于设置samba用户的密码,新设置的,并不是要你输入系统用户的)

然后重启 smbd 和 nmbd:

sudo systemctl restart smbd nmbd

win10 guest 机里可以用 net use 命令映射(192.168.0.x是host机的LAN ip):

net use z: \\192.168.0.x\winshare /user:ttys3 "the-smb-password" /persistent:yes

/persistent:yes 确保配置持久保存,而/user:ttys3 是指定登录的用户名, 空格后面接的是密码。

基于安全考虑,也可以用一个单独的用户:

useradd -M -s /usr/sbin/nologin winshare
usermod --shell /usr/sbin/nologin --lock winshare
smbpasswd -a winshare
# 然后设置密码(注意这里的密钥是用于设置samba用户的密码,新设置的,并不是要你输入系统用户的)
sudo systemctl restart smbd nmbd

禁止ssh登录: 编辑 /etc/ssh/sshd_config, 修改或增加:

AllowUsers root ttys3

注意这里的ttys3是当前用户,winshare作为仅用于win guest访问共享的用户,被排除在了ssh登录之外。

如果是RHEL/CentOS/Fedora还要解决 selinux 问题:

chcon -t public_content_rw_t /media/hdd/wd10t02/winshare
setsebool -P allow_smbd_anon_write=1

还有一种最简单的方法(允许匿名读写):

[global]段添加:

map to guest = Bad User

然后再在最后添加:

[winshare]
comment=share for kvm guest
path=/media/hdd/wd10t02/winshare
browsable = yes
guest ok = yes
read only = no
hosts allow = 192.168.122.0/24
create mask = 0777
directory mask = 0777

192.168.122.0/24virbr0 的网段, 主要用来限制只允许guest机读写

开发相关

sudo apt install protobuf-compiler golang

grub配置调整

显示启动信息

How to enable boot messages to be printed on screen during boot up? Edit you bootloader kernel command-line and remove quiet argument. You may also want to remove splash argument to disable graphical animation during boot to be able to see the console with messages.

修改 /etc/default/grub, 找到 GRUB_CMDLINE_LINUX 一行,移除 quietsplash

更新grub配置:

sudo update-grub

fucked up

各方面都没啥问题了。但是还是有一个问题, GNOME3 启动东西的时候总觉得有点卡的,然后执行ps看了下,内心是崩溃的。

执行snap list可查看被snap化的应用,其中包括:chromium !

core18 是 snap 应用的运行环境,而 snap-store 则是 ubuntu snap 应用商店, snapd 自然不用多说,是snap负责管理应用的daemon, 至于 gtk-common-themes, 只是为了使 snap 化的应用样式保持一致。

gnome-3-34-1804 并不是 gnome (这里老灯之前误解了):

The gnome-3-34-1804 snap description is at snap info gnome-3-34-1804:

This snap includes a GNOME 3.28 stack (the base libraries and desktop integration components) and shares it through the content interface.

This means that your other gnome-based snaps connect to this snap in order to talk to Gnome. You can test this by removing the snap. Suddenly your other gnome-based snaps won't work. Restore their function by re-installing the snap. (via https://askubuntu.com/questions/1231094/why-do-i-have-the-gnome-3-34-1804-snap-package-installed-on-ubuntu-20-04-after/1231100#1231100 )

❯ snap list
Name               Version             Rev   Tracking         Publisher   Notes
chromium           83.0.4103.106       1193  latest/stable    canonical✓  -
core18             20200427            1754  latest/stable    canonical✓  base
gnome-3-34-1804    0+git.3009fc7       36    latest/stable/…  canonical✓  -
gtk-common-themes  0.1-36-gc75f853     1506  latest/stable/…  canonical✓  -
snap-store         3.36.0-80-g208fd61  467   latest/stable/…  canonical✓  -
snapd              2.45.1              8140  latest/stable    canonical✓  snapd

然后再看看 mount 的结果,你会发现这些应用居然是以squashfs文件系统打包的,然后解包就是一个将squashfs的文件挂载为一个loop设备:

df -t squashfs
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/loop0         56320  56320         0 100% /snap/core18/1705
/dev/loop1         63616  63616         0 100% /snap/gtk-common-themes/1506
/dev/loop2        246656 246656         0 100% /snap/gnome-3-34-1804/24
/dev/loop4         27776  27776         0 100% /snap/snapd/7264
/dev/loop3         51072  51072         0 100% /snap/snap-store/433
/dev/loop5         56320  56320         0 100% /snap/core18/1754
/dev/loop6         30592  30592         0 100% /snap/snapd/8140
/dev/loop7         51072  51072         0 100% /snap/snap-store/467
/dev/loop8        261760 261760         0 100% /snap/gnome-3-34-1804/36
/dev/loop9        160000 160000         0 100% /snap/chromium/1193
snap-list.jpg

Ubuntu的默认浏览器是 Firefox , 然而很多用户或者开发者,可能都离不开 chromium (即使它不是默认浏览器),而 Ubuntu 将 chromium-browser 强制 snap 化, 等于是强制用户使用 snap 了 (Ubuntu的阴谋)。

snap后的程序有两大问题:

  • 一是慢,虽然Ubuntu官方宣称 snap 速度已经相比之前提升了几倍,但是,老灯同时在用Fedora 32, 所有程序打开流畅无比。但是 Ubuntu 20.04 下启动或关闭程序一些程序是能感受到明显的卡顿。这个卡顿在1秒以上。
  • 二是体积大。其打包的app体积,相比于AppImage 或 Flatpak, 也是大很多。以Corebird这个应用为例,snap 112MB, deb 2MB, Flatpak 12MB (参考 Snappy Sceptic Files Bug to Ask Why It Even Exists 一文).

另外, GNOME 软件中心,被 Ubuntu 偷偷替换成了 snap store! 这意味着用户要是从默认的这个所谓的“软件中心”安装任何应用,这个应用都是 snap 的!

相比于 Fedora 带的软件中心,用户默认是安装 rpm 源的应用,如果有些应用只有 Flatpak 的才会用的 Flatpak 源。

所以 Ubuntu 的意图很明显,就是经强推 snap store !

查了下, 老灯不是唯一一个不喜欢snap的,事实上, 很多人或团队都在对snap说“NO”:

Linux Mint 团队认为 Ubuntu 偷梁换柱把默认的 GNOME Software 换成了 Ubuntu store, 把 chromium-browser deb 包换成了一个空包(然后替换成了下载snap版的chromium), 这是一个“后门”行为。没有任何说明,Ubuntu 就直接这么干了。

Mint gets fresh: 'A self-installing Snap Store which overwrites part of our APT package base is a complete NO NO'

"I don't think the points we're raising here are well understood by the community. I hope we'll talk with Ubuntu and the Snap project about this. We're very interested in your feedback as well. A self-installing Snap Store which overwrites part of our APT package base is a complete NO NO. It's something we have to stop and it could mean the end of Chromium updates and access to the snap store in Linux Mint."

更多信息可查看 Snapping at Canonical's Snap: Linux Mint team says no to Ubuntu store 'backdoor'

https://blog.linuxmint.com/?p=3906

Linux Mint Dumps Ubuntu Snap

另外一部分用户则觉得自己被 fucked up 了:

I think I fucked up?

有人甚至觉得这是一个bug: Snappy Sceptic Files Bug to Ask Why It Even Exists

还有人写了如何在Ubuntu 20.04禁用snap(完全卸载snap相关组件)的教程:

Disabling Snaps in Ubuntu 20.04 相应的讨论 https://news.ycombinator.com/item?id=22972661

Ubuntu 20.04 LTS’ snap obsession has snapped me off of it 相应的讨论 https://news.ycombinator.com/item?id=23052108

How to install Flatpak apps on Ubuntu 20.04 LTS

Von Goofy 评论道(Ubuntu Switches to a Snap’d Software Store for 20.04):

We don't buy SSD's and computers with SSD's to be reverted to HDD speeds by some devs that think packaging apps and dependencies together is a cool idea no matter how slow it is. No, I don't want for basic calculator to have a startup time of 15 seconds. That is not acceptable in 2020. Not on a desktop and not with desktop apps. The idea is valid and good, the execution is poor. I understand that devs might find this very useful, but stop pushing it by default for regular users. Until the issue of speed and themes are resolved this is still beta software that shouldn't be in main stream distributions.

其它文章:

What You Need to Know About Snaps on Ubuntu 20.04

Canonical’s Snap: The Good, the Bad and the Ugly

troubleshoot

  1. Although GNOME Shell integration extension is running, native host connector is not detected

解决办法(来自 https://askubuntu.com/questions/1107848/although-gnome-shell-integration-extension-is-running-native-host-connector-is ):

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install chrome-gnome-shell 

#  Ubuntu 20.04
sudo apt-get install libproxy1-plugin-networkmanager gnome-shell-extension-system-monitor

常用扩展安装:

fmuellner 的一些扩展(Window List是老灯必装) https://extensions.gnome.org/accounts/profile/fmuellner

KStatusNotifierItem/AppIndicator Support by 3v1n0 https://extensions.gnome.org/extension/615/appindicator-support/

  1. 左边 Dock 自动隐藏(像原版GNOME3那样)

Settings - Appearance - Dock - Auto-hide the dock

  1. 卸载Ubuntu使用的一些旧组件

一些组件,GNOME 3已经有自带了,Ubuntu并没有使用。

GNOME 3.36: The 10 Best New Features这篇文章有介绍:

GNOME’s recommended roster of default apps — which most Linux distros do not ship or heed, including Ubuntu — sees a number of notable substitutions:

  • Shotwell replaced by GNOME Photos
  • Evolution replaced by Geary & GNOME Calendar
  • Rhythmbox replaced by GNOME Music

GNOME 的代码commit信息中有写原因

Many of the apps in the favorite apps list have fallen out of favor.

Replacing Rhythmbox with Music and Shotwell with Photos are obvious moves. Rhythmbox and Shotwell are not core apps, and that means we assume they are not installed by default. It doesn't really make sense to have non-default apps in the apps list.

Evolution is also not a core app, and that is not likely to change, so it should also be removed. Adding Geary might be more controversial. It is a strong candidate to become a core app, GNOME Mail, in the near future, but it is not there yet. So this could arguably be considered premature. But I figure a GSettings default is a cheap thing; we can always change it later if desired.

邮件客户端: 卸载thunderbird, 安装geary

sudo apt-get remove thunderbird
sudo apt-get install geary

照片管理: uninstall Shotwell , install gnome-photos (Fedora 32的默认应用)

GNOME3 默认的图片查看器(viewer)是 Eye of GNOME (eog), 如果需要查看exiv信息,可以安装gThumb, 而老灯用过的打开图片速度最快的是 qimgv

但是这里说的是图片管理器,并不是查看器(viewer)。

sudo apt-get remove shorewell
sudo apt-get install gnome-photos

tips: 如果要查看已经安装了哪些package, 可以用 apt list --installed

参考文档

https://blog.programster.org/kvm-missing-default-network

https://wiki.archlinux.org/index.php/Samba#User_Management

https://wiki.archlinux.org/index.php/Users_and_groups#User_management

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_virtualization/sharing-files-between-the-host-and-its-virtual-machines_configuring-and-managing-virtualization#sharing-files-between-the-host-and-windows-virtual-machines_sharing-files-between-the-host-and-its-virtual-machines

https://blog.linuxmint.com/?p=3906