換到 Wayland!

之前有提到,我一直受一個 mesa 的 bug 所苦,經常兩三天桌面環境用一用就會自己定格,而且似乎是整個 X server 卡住,而不單只是 KDE Plasma 卡住。

前幾個月升級到 Ubuntu 23.04 之後,儘管 mesa 也跟著升到 23.0.2-1ubuntu1 ,這個卡住的問題還是偶爾會發生,只是比較不頻繁,變成大約十天一次。

於是某次又遇到卡住重開機之後,正準備登入的時候,突然想說,不然來試試看 Wayland 好了,於是登入時直接選了 Wayland 環境。

我之前從來沒有特別安裝過或是設定過 Wayland,但看來他是已經內建了。

登入之後發現:哇塞竟然會動!

  • Firefox 自己偵測並使用了 Wayland 後端
  • 很靠腰的 Spotify (Snap 版)開起來也沒問題
  • VLC 沒問題
  • Signal Desktop 似乎是用 Xwayland 開,所以觸控板捲動有點延遲,但除此之外也沒問題
  • Chromium Snap 沒問題
  • Telegram Desktop 正常,但使用 fcitx 輸入法的時候選字框的位置會很奇怪,不會在輸入游標的附近,會跑到外接螢幕的接近正中間
  • 使用 Java GUI 的 JADX 正常

當中最讓我意外的是:

  • Xpra 沒特別設定,他自己直接用 Xwayland 開起來,除了初始化視窗多了一個視窗邊框,其餘功能完全正常
  • 上述應用程式裡面,使用 fcitx 輸入法框架輸入中文,完全正常

在 Linux 上面換了一個 display server ,竟然這麼順利?還真是嚇了我一跳。

不過還是有遇到幾個小困難暫時無法解決:

  • 我平常使用 RSIBreak 螢幕計時器,每隔一段時間會阻擋輸入強迫眼睛休息。它似乎在 Wayland 上面無法正確偵測使用者輸入是否閒置(沒有鍵盤和滑鼠動作),所以會以為一直有輸入,於是休息時的計時器就無法正確倒數
  • Xsuspender 在 Wayland 底下尚且還沒有任何替代方案
  • KDE 的螢幕截圖工具截圖時想要隱藏自己,但是仍留有殘影,這個是已知的 bug
  • 在 Telegram 內使用 fcitx,選字框不會隨著輸入位置移動,無論 Telegram 視窗在哪裡選字框都會留在螢幕上固定的位置,其他應用程式沒有這個問題
  • Xpra 雖然可以透過 XWayland 正常顯示和使用,但顯示某些(在 Ghidra 內)懸浮提示框(tooltip)的時候會不正確地顯示視窗邊框和最小、最大、關閉的按鈕

Downgrading Ubuntu packages that are no longer available on package mirrors

My computer has been experiencing random freezes after upgrading to Ubuntu 22.10. I wan’t able to find the cause, but today I came across this bug report alleging that Mesa 22.2 was the culprit. So I decided to downgrade Mesa to see if it resolves the issue.

If the version is still available in the archive

https://www.linuxuprising.com/2019/02/how-to-downgrade-packages-to-specific.html

But I need to downgrade to Mesa 22.1, which is not available in the archive.

Finding the old version deb file

https://askubuntu.com/questions/1209643/where-do-i-find-old-version-of-deb-files

1. First go to the source package page: https://launchpad.net/ubuntu/+source/mesa/

2. Click on your release, my is Kinetic https://launchpad.net/ubuntu/kinetic/+source/mesa

3. Click on the version you want under Releases in Ubuntu https://launchpad.net/ubuntu/+source/mesa/22.1.7-0ubuntu1

4. Click on amd64 under Build

Now download the debs.

Checking which debs are needed

  1. Use apt list -a --installed <package_name>*to check if the package has an already installed version
  2. Delete the deb if not.

Installing the deb

Have the debs ready in a folder, run sudo apt install ./* . It should automatically resolve the dependency. apt should say DOWNGRADING some packages, while not uninstalling anything else.

Use sudo apt --dry-run install ./* to verify before actually installing.

Hold the old versions

sudo apt-mark hold libegl-mesa0 libgbm1 libgl1-mesa-dri libglapi-mesa libglx-mesa0 libxatracker2 mesa-va-drivers mesa-vdpau-drivers mesa-vulkan-drivers

To avoid the old versions from being replaces when you run apt upgrade next time.

References

https://www.reddit.com/r/linux_gaming/comments/ynue9u/how_can_i_check_what_mesa_driver_is_in_use/

Ubuntu 上的 pi-hole 和 systemd-resolved 衝突

最近要把家中的 pi-hole 從舊的 Raspbian + Rpi3b+ 移到新的 Ubuntu + Rpi4,沒想到遇到麻煩的 systemd-resolved 衝突問題,這篇做一些筆記。

現在比較新的桌面版 Linux 都有內建 systemd-resolved ,systemd-resolved 實作了一個 stub resolver,會聆聽在 127.0.0.53:53 回應 DNS 查詢。另外 systemd-resolved 預設也會去編輯 /etc/resolv.conf,當中把網域名稱伺服器設為 127.0.0.53,這樣一來不支援 glibc 或是 DBUS DNS 查詢的程式就會利用 stub resolver 解析域名。

不過這樣一來本機的 port 53 就被佔用,pi-hole 就沒辦法聆聽。

下了一堆錯誤關鍵字繞了一大圈才發現 pi-hole 文件就有特別說明 Installing on Ubuntu or Fedora

基本原理是這樣:

  1. 把 stub resolver 關閉(不能把 resolved 整個關閉,因為這樣 DBUS 和其他查詢 API 會失效)
  2. 確保 /etc/resolv.conf 指向 resolved 控制的 /run/systemd/resolve/resolv.conf
  3. 修改 netplan 設定確保該網卡界面使用 127.0.0.1 作為域名伺服器

至於為什麼要有 systemd-resolved 這麼複雜又麻煩的設計?主要原因是出於如果讓各應用程式和網卡界面直接去修改 resolv.conf 的話會讓新啟動的界面去覆蓋原有界面的 resolv.conf 設定。例如有多重 VPN 連線提供不同路由目標 (route destination) 連線的時候,新啟動的 VPN 如果覆蓋了先前啟動的 VPN 設定的域名伺服器,就會讓所有 DNS 查詢送往新 VPN 指定的域名伺服器,破壞了先前啟動的 VPN 的設定,造成 DNS query leak 。

關於為什麼要有 systemd-resolved,這篇文章解釋得非常詳盡清楚

參考資料:

Building an existing Ubuntu package on Open Build Service

I’ve complained a lot on how the Snap version of Firefox sucks. In the end I found that it’s not possible to run Firefox snap in my own custom network namespace, so I decided to switch to the mozillateam PPA (had to configure APT pinning). But, just in case someday they stop updating the PPA too, I decided to learn to package my own Firefox. Turned out it was not that difficult!

Open Build Service

Open Build Service is provided by SUSE. It’s essentially a CI server for Linux packages. For me the advantages of using OBS are:

  1. OBS has all the package building environment set up, so I don’t have to set up my own.
  2. I don’t have to learn how to *build* the package. I can just download a source package from a PPA and upload it to OBS and it builds it for me.
  3. OBS provides package hosting as well. There’s no extra effort needed from me if I want to let somebody else use my package.

Technically I can also use PPA to achieve those as well, but OBS provides a possibility to also target other distributions. (It looks like a lot of work to configure that though.)

The source of my Firefox package can come from mozillateam PPA, Linux Mint, or PopOS.

OBS Concepts

OBS provides a User Guide, but I found that the openSUSE wiki gives a much better explanation around basic concepts in OBS.

Each project contains the resources needed to build one or more packages (i.e. RPMs/DEBs/etc.). These resources include source archives, patch files, spec files, etc. The output of a project is one or more repositories. A repository is an old familiar concept: simply a bunch of RPMs organized in a directory hierarchy along with some index/meta-data files that make it easy for tools like zypper to search and resolve dependencies.

  • Project: it’s also a namespace for configurations such as build constraints and build depedency preferences. Projects can have Subprojects, which is just an entirely separated project, only with similar names.
  • Repository: repositories can also be used as sources of other projects’ build dependency. The resulting package of a project’s build is also put into the project’s repository.

Each project is also essentially a version-controlled folder (in the folder are those resources mentioned above), managed by the osc commandline tool.

Importing an existing Debian package

I learned about the osc dput command from a talk at DebConf. But when running osc dput it complained “There is no sha256 sum for file _meta.". I worked around it by just downloading the source package files and running osc add on them.

Source package files contains:

  • <package_name_and_version>.dsc : the Debian source control file, which describes a package.
  • <package_name_and_version>.orig.tar.xz : archive file containing the original tarball (source code).
  • <package_name_and_version>.debian.tar.xz : archive file containing Debian build configurations, patches, changelogs, and so on.

After running osc add, run osc ci to commit and upload the changes.

Providing build dependency source repositories

Once uploaded, OBS will immediately start building the package. However it soon returned error saying that it couldn’t find some build dependencies. After rewatching the DebConf talk I realized I have to import the Ubuntu repositories.

After I manually added the update repo

At first, I simply clicked “Add from a Distribution". But OBS still complained that it couldn’t get new enough version of some build dependency. Then I realized that when adding Ubuntu:22.04, only universe is added but not update. A list of all repositories for Ubuntu 22.04 can be found here. I don’t know what universe-update is but I added it anyways.

OBS Project Configuration for Firefox

Two more things I had to change are the build constraints and prefer depedency settings.

Repotype: debian
Constraint: hardware:disk:size unit=G 30
Constraint: hardware:memory:size unit=G 8
Prefer: libncurses-dev
  • Constraint: constraints to the build worker machine. I took the information from here.
  • Prefer: when resolving build dependencies, when multiple packages fits the criteria, OBS doesn’t just randomly choose one out of them. You’re required to explicitly tell it which one to use. If I don’t specify, the build will show a warning message.
    • I checked apt policy libtinfo-dev on my machine and it shows that it’s only a transitional package. Therefore I selected the other option libncurses-dev.

All available project config options are here: https://openbuildservice.org/help/manuals/obs-user-guide/cha.obs.prjconfig.html

The build should be successful since we did not change anything from the original package. The build artifact (resulting package) will be available in the repository like at https://build.opensuse.org/repositories/home:pellaeon

Modifying the package

I will leave this for Part 2.

Firefox snap 依舊雷翻天,我不該浪費時間研究 snap 的,我錯了

把主力機升到 Ubuntu 22.04 之後,我這兩天繼續浪費時間搞 Firefox snap,目前 Firefox snap 主要的問題是:

  1. native messaging 不會動,導致 Mailvelope 這類的插件沒辦法和 snap 環境外的 gpg 程式溝通,不過官方好像已經有解法在 beta 了
  2. 我平常使用 Firefox 會分好幾個 profile ,不同 profile 過不同的 network namespace ,然後在 network namespace 裡面設定 VPN,整體使用 vopono https://github.com/jamesmcm/vopono 設定起來非常方便愉快,但是!snap 自己也有用自己的 network namespace 的樣子,所以只要在自己的 network namespace 裡面就無法使用 snap,我已經解掉很多問題成功把 firefox snap 跑起來了,但是最後還是卡在 snap 無法自訂 /etc/resolv.conf ,導致 firefox 無法使用 VPN 的 DNS server ,功敗垂成
  3. 即使界面語言選擇正體中文,仍然顯示英文給你看,這我就懶得修了,我就看英文吧,但這種低級的 bug 居然可以過 Mozilla 和 Canonical 的品管??

我跑去問了問題但還是沒有人回。

所以是時候拋棄 snap ,改用回傳統套件包的 firefox 了。

關於我 debug 在 netns 裡面跑 snap 的過程,我也有在論壇上記錄

套件包

我先試了 Linux Mint 的來源,好不容易把 APT pinning 搞定之後,要裝的時候發現 Linux Mint 的版本依賴 Mint 的 ubuntu-system-adjustments 套件,會做一些 Mint 自己的系統變更(比如說設定拒絕安裝 snapd,還有 grub 訊息改成 Linux Mint 之類的)。

所以,還是得要回去用 mozillateam 的 PPA

套件包 GPG 簽章設定

為了增加 Mint 的 APT 來源到我的系統,也要增加 Mint 的 GPG 公鑰,為此順便也學習了 apt-key 被棄用的原因。

簡單來說,原本的 apt-key 的設計是,匯入了一個簽章之後,這個簽章就是全域受信任的,不管套件的來源是哪一個 APT source ,只要有任何一個受信任公鑰的簽名,該套件就會被視為受信任的。這有一個嚴重的問題是,通常不同 APT 來源的發行者是不同人,自然也會擁有不同的簽章,但上面那個設計會導致任何一個受信任簽章持有人都可以發行一個和系統內某個套件同名的套件來蓋掉它

因此現在才改成將 GPG 公鑰寫入 /usr/share/keyrings ,然後額外在每個 APT source 裡面標注該來源使用的簽章:

deb [arch=amd64 signed-by=/usr/share/keyrings/signal-desktop-keyring.gpg] https://updates.signal.org/desktop/apt xenial main

Snap

垃圾爛系統,毫無客製選項和自由度,唯一會正常工作的情境是開發者想像中的一般使用者的環境,其餘情境下慘不忍睹。我不敢說預設設定的環境不常見,但會用 Linux 的人就是為了可以大幅度客製化自己的環境啊,所以有客製化環境的人所佔的比例肯定比 windows 和 macos 高很多。

Snap 這設計邏輯,堪稱微軟。看看微軟要不要趕快挖角一下 Snap 這垃圾,把它領走好不好,整個子系統都給微軟維護最適合不過了。

自己編譯 Firefox ?

過陣子再來自己研究看看…在 Reddit 上面看到有日本人之前自己維護的優化版 Firefox,似乎可以來自己研究一下怎麼修改編譯選項,改成一些適合我處理器的選項。gcc znver3 選項平均可以提升程式 11% 的效能呢

參考

Problems about /dev/mapper/cryptswap1 on Karmic

Recently I always get a error mounting /dev/mapper/cryptswap1 when booting. I heard that it was because Ubuntu is trying to mount the swap even before it is created. I added these two lines to /etc/rc.local and the problem is solved.

swapoff -a

swapon -a

Although the error no longer occurs, I still don’t understand why would this happen.

在Ubuntu中強制移除套件

有時候套件安裝不完整時就會出現這個訊息:
E: Sub-process /usr/bin/dpkg returned an error code (1)

這時候就算你想移也移除不掉,這是我以前用過成功強制移除的方法,可以試試看:

1.備份status
sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.back
2.打開
sudo gedit /var/lib/dpkg/status
3.搜尋"Package: ubuntu-tweak",把那一整段刪除(刪到下個"Package: xxx"之前)
4.存檔,重新載入套件庫。

Picasa3在Ubuntu中的中文字型問題

最近要管理相片,建個網路相簿,先找了flickr,但是flickr的相片上傳還要用第三方插件,而不是官方支援,真是有夠沒誠意,而且又不能管理相片,所以我最後用了Picasa。

先去google抓了Picasa3 for linux(只有英文,但是我沒差啦),裝好了,我這時才發現它還是要用WINE,還是很沒誠意,不過至少他是官方的,比flickr好一點。

還有,Picasa的中文顯示還是有問題,在一般界面時還OK,但是要開啓檔案或新增相簿時,跳出來的小視窗的中文字就會變成框框。

這一點不便算是還可以接受,我找過解決方法了,但是目前好像還沒有找到管用的。