Skip to content

Instantly share code, notes, and snippets.

@maelvls
Last active September 10, 2024 15:14
Show Gist options
  • Save maelvls/3028862dd516005403cf728f4705f4bb to your computer and use it in GitHub Desktop.
Save maelvls/3028862dd516005403cf728f4705f4bb to your computer and use it in GitHub Desktop.
My hundred struggles while using Linux as my desktop driver (Ubuntu 22.04)

My hundred struggles while using Linux as my desktop driver (Ubuntu 24.04)

Hi! On Thursday 25 April 2021, I entirely switched from macOS to Linux: https://maelvls.dev/evolution-of-my-home-office/. I took note of every adjustment I had to make along the way. I use Ubuntu "vanilla" (with Gnome as my desktop manager).

🔥 Update 26 June 2023: I am abandoning "desktop" Linux! I can't bear having to work around everything all the time, not even counting the tons of problems that occur whenever I do a major version upgrade (e.g., when I upgraded from 21.10 to 22.04, my PPAs broken obviously, and also I lost all the hack I had made to the /etc to work around problems). I am officially back to macOS starting 26 June 2023. I'll still use my Linux workstation remotely over Mosh, but not as a desktop environment.

To smoothen the transition, I use the following hacks on macOS:

  1. Linear Mouse since I can't stand macOS' mouse acceleration and also to fix my mouse wheel's direction. My config:

    Setting Value
    Pointer -> Pointer acceleration 0.5
    Pointer -> Pointer speed 0.1717
    Scrolling -> Scrolling mode By Lines
    Scrolling -> Distance 2
  2. Magnet to be able to move windows around and move them to 1/2 of the display.

  3. AltTab to switch between windows instead cmd+tab's application switching.

  4. Audio Switch to make sure my bluetooth headset's microphone never get used (any wired mic close enough to the mouth is better than a bluetooth mic; the macbook pro's mics are good for that matter).

  5. MenuMeters to see the network activity in the top menu bar.

To fix the Play/Pause/Forward/Backward buttons in YouTube Music's Electron app, make sure that the Media flag is enabled in chrome://flags. Also, don't try to disable Apple Music app from launching on "Play", otherwise you will also disable the media keys entirely!

iTerm2 writes weird characters on click after an ssh session with tmux unexpectedly ended:

$ 0;37;9M0;37;9m0;24;6M0;24;6m

That's because "mouse reporting" is still enabled for the current shell session. To disable mouse reporting, run:

printf '\e[?1000l'  # disables mouse reporting

To know more: https://superuser.com/questions/802698/disable-mouse-reporting-in-a-terminal-session-after-tmux-exits-unexpectedly


My other articles:

My hundred struggles:

Replace Ubuntu's Dock

Tested on Ubuntu 21.04.

sudo apt remove gnome-shell-extension-ubuntu-dock

Then, install dash-to-dock which is much better. I also tried Plank but it does not seem to work very well.

To access the dock's settings, right click on the "Applications" icon in the dock.

Correct key repetition speed and mouse speed

gsettings set org.gnome.desktop.peripherals.keyboard repeat-interval 30
gsettings set org.gnome.desktop.peripherals.keyboard delay 500
gsettings set org.gnome.desktop.peripherals.mouse natural-scroll false
gsettings set org.gnome.desktop.peripherals.mouse speed 0.0
gsettings set org.gnome.desktop.peripherals.mouse accel-profile 'default'

Shortcuts I often forget about

  • Ubuntu restart GNOME session: Alt + F2 + R
  • Restart X: Ctrl + Alt + Del (has to be enabled: gnome tweaks -> Keyboard and Mouse -> Additional Layout Options' and enable 'Key sequence to kill the x server')
  • Switch from X to terminal: Ctrl + Alt + F3
  • Switch from terminal to X: Ctrl + Alt + F2

(source) Linux systems come with a bunch of virtual terminals, or VTs. Your graphical user interface on Ubuntu runs on VT7, and VT1 to VT6 allow you to login via command line.

You switched to VT3. Press Ctrl+Alt+F7 to get back.

Also, like on macOS, you can select a file by Shift + drag-and-dropping it from another file manager window:

shift+drag-and-drop

Compose key

And to type special characters, I use the compose key. I use the CapsLock key as the compose key:

gsettings set org.gnome.desktop.input-sources xkb-options \
  "['eurosign:e', 'terminate:ctrl_alt_bksp', 'compose:caps']"

Note that 'eurosign:e' is useless since I use the compose key for typing the euro sign. The terminate:ctrl_alt_bksp allows me to do Ctrl + Alt + Del to restart the X session.

Most useful compose combinations (remember that CapsLock means "compose key" in my case):

cat /usr/share/X11/locale/en_US.UTF-8/Compose
Combination Sign UTF8 key Meaning
CapsLock + - + - + . U2013 EN DASH
CapsLock + - + - + - U2014 EM DASH
CapsLock + < + - U2190 LEFTWARDS ARROW
CapsLock + - + > U2192 RIGHTWARDS ARROW
CapsLock + - + > U2192 RIGHTWARDS ARROW
CapsLock + = + > U21D2 RIGHTWARDS DOUBLE ARROW
CapsLock + / + = U2260 NOT EQUAL TO
CapsLock + < + = U2264 LESS-THAN OR EQUAL TO
CapsLock + > + = U2265 GREATER-THAN OR EQUAL TO
CapsLock + C + = EuroSign EURO SIGN
CapsLock + L + - £ Sterling POUND SIGN
CapsLock + A + ` À Agrave LATIN CAPITAL LETTER A WITH GRAVE
CapsLock + ` + a à agrave LATIN SMALL LETTER A WITH GRAVE
CapsLock + U + ` Ù Ugrave LATIN CAPITAL LETTER U WITH GRAVE
CapsLock + ` + e è egrave LATIN SMALL LETTER E WITH GRAVE
CapsLock + ' + e é eacute LATIN SMALL LETTER E WITH ACUTE
CapsLock + e + > ê ecircumflex LATIN SMALL LETTER E WITH CIRCUMFLEX
CapsLock + " + e ë ediaeresis LATIN SMALL LETTER E WITH DIAERESIS
CapsLock + c + , ç ccedilla LATIN SMALL LETTER C WITH CEDILLA
CapsLock + . + - · periodcentered MIDDLE DOT
CapsLock + ( + 1 + ) U2460 CIRCLED DIGIT ONE
CapsLock + ( + 2 + ) U2461 CIRCLED DIGIT TWO
CapsLock + ( + 3 + ) U2462 CIRCLED DIGIT THREE
CapsLock + ( + 4 + ) U2463 CIRCLED DIGIT FOUR
CapsLock + ( + 5 + ) U2464 CIRCLED DIGIT FIVE
CapsLock + ( + 6 + ) U2465 CIRCLED DIGIT SIX
CapsLock + ( + 7 + ) U2466 CIRCLED DIGIT SEVEN
CapsLock + ( + 8 + ) U2467 CIRCLED DIGIT EIGHT
CapsLock + ( + 9 + ) U2468 CIRCLED DIGIT NINE
CapsLock + x + x × multiply MULTIPLICATION SIGN

lm_sensors with the right fan labels

From here:

sudo tee /etc/sensors.d/gigabyte-x570.conf <<'EOF'
chip "it8688-*"
    label fan1 "CPU_FAN"
    label fan2 "SYS_FAN1"
    label fan3 "SYS_FAN2"
    label fan4 "Chipset fan"
    label fan5 "CPU_OPT"

    label temp1 "SYS1 (rear)"
    label temp2 "SYS2 (front)"
    label temp3 "CPU"
    label temp4 "PCIe"
    label temp5 "VRM"
    label temp6 "Chipset"
EOF

sudo tee /etc/modprobe.d/it87.conf <<'EOF'
options it87 ignore_resource_conflict=1
EOF

sudo tee /etc/modules-load.d/it87.conf <<'EOF'
it87
EOF

sudo git clone https://github.com/frankcrawford/it87 /usr/src/it87
cd /usr/src/it87
sudo ./dkms-install.sh

sudo modprobe it87
lsmod | grep it87

Hardware

See on pcpartpicker.

Part Name Price (01 May 2021)
CPU AMD Ryzen 9 5900X 3.4 GHz 12-Core Processor (I sent it back) € 708 (street price)
CPU AMD Ryzen 9 5950X 3.4 GHz 16-Core Processor (bought on AMD.com at MSRP) € 795 (MSRP)
CPU Cooler Noctua NH-D15 CHROMAX.BLACK 82.52 CFM CPU Cooler € 99
Motherboard Gigabyte X570 AORUS MASTER ATX AM4 Motherboard € 359
Memory G.Skill Trident Z RGB 32 GB (2 x 16 GB) DDR4-3600 CL16 Memory € 304
Storage Samsung 980 Pro 1 TB M.2-2280 NVME Solid State Drive € 219
Video Card Gigabyte Radeon RX 6700 XT 12 GB EAGLE (I sent it back) € 858 (street price)
Video Card AMD Radeon RX 6800 16 GB (bought on AMD.com at MSRP) € 579 (MSRP)
Case Fractal Design Define 7 Compact ATX Mid Tower Case € 133
Power Supply be quiet! Dark Power Pro 11 750 W 80+ Platinum Semi-modular ATX Power Supply € 243
Case Fan × 4 be quiet! Silent Wings 3 59.5 CFM 140 mm Fan PWM € 29 × 4
Total € 2847

mitmproxy, x509: certificate signed by unknown authority

sudo mkdir -p /usr/share/ca-certificates/mitmproxy
sudo cp ~/.mitmproxy/mitmproxy-ca-cert.pem /usr/share/ca-certificates/mitmproxy/mitmproxy-ca-cert.crt
grep mitmproxy/mitmproxy-ca-cert.crt /etc/ca-certificates.conf \
  || sudo tee --append /etc/ca-certificates.conf <<<mitmproxy/mitmproxy-ca-cert.crt
sudo update-ca-certificates

To copy the HTTP response (headers and body):

:export.clip raw_response @focus

HTTP request:

:export.clip raw_request @focus

How to copy the response body of an HTTP request within mitmproxy

Bug left-click

Sometimes, tmux will get into a weird state where clicking will print characters instead. You can use the command reset (directly typed to the shell) to work around that.

bug-terminal-left-click

Gnome terminal: disable "Close this terminal?" modal

gsettings set org.gnome.Terminal.Legacy.Settings confirm-close false

Dark themed apps

% cat ~/.config/gtk-3.0/settings.ini
gtk-application-prefer-dark-theme=1

% cat ~/.config/gtk-3.0/settings.ini
gtk-application-prefer-dark-theme=1

GNOME shortcuts suck

Shift + Super + 1-9 are taken by an extension:

 gsettings list-recursively | grep -i org.gnome.shell.extensions.dash-to-dock | grep '<Super>' | cut -d" " -f2 | xargs -L1 -I'%' gsettings set org.gnome.shell.extensions.dash-to-dock '%' '@as []'

1Password for Linux uses Shift + Ctrl + \ to open itself. I need this shortcut in VSCode. Open ~/.config/1Password/settings/settings.json and add:

  "keybinds.open": ""

Here is why Super behaves the same as Ctrl + Alt sometimes.

I use the shortcut Shift + Ctrl + E to select the Tree view in VSCode. Unfortunately, Ubuntu already uses this shortcut for their emoji picker:

gsettings set org.freedesktop.ibus.panel.emoji unicode-hotkey "@as []"

But it won't work in VSCode for some weird reason. The workaround is to follow this:

# In ~/.profile:

# Workwround for the Shift+Ctrl+E that was stolen by ibus. See:
# https://askubuntu.com/questions/1125726
export GTK_IM_MODULE="xim"

The shortcuts I like:

To change the "Activity overview" shortcut, use:

# Free the key <Super> (Ctrl + Alt)
gsettings set org.gnome.mutter overlay-key ''

# Free the shortcut <Alt>space
gsettings set org.gnome.desktop.wm.keybindings activate-window-menu "['']"

# Free the key <Super> + S (which is the same as the above <Super>)
gsettings set org.gnome.shell.keybindings toggle-overview "['']"

gsettings set org.gnome.shell.keybindings toggle-overview "['<Super>space']"

# Free <Shift> + <Alt> + S
gsettings set org.gnome.settings-daemon.plugins.media-keys screenreader "['']"

Note: you can reset it by going into gnome-tweaks:

# Enable Ctrl + Tab to switch languages (English -> French):
gsettings set org.gnome.desktop.input-sources xkb-options "['grp:ctrl_shift_toggle']"

# Disable Super + Space and Shift+Super+Space
gsettings set org.gnome.desktop.wm.keybindings switch-input-source "['']"
gsettings set org.gnome.desktop.wm.keybindings switch-input-source-backward  "['']"
gsettings set org.freedesktop.ibus.general.hotkey triggers "['']"

List all the keybindings:

gsettings list-recursively org.gnome.desktop.wm.keybindings | sort | less

The super key corresponds to both Win or ctrl + alt.

The Alt key steals focus in VSCode

The Alt key steals the focus and I hate it. It does that in all Electron apps like VSCode, Slack. Weirdly enough, Discord does not have this issue. Here is what it looks like on Slack:

alt-steals-focus

Workaround for VSCode: in my settings.json (Ctrl + , to open it):

  // Fixes the focus steal by the 'Alt' key behavior on Ubuntu 20.04.
  "window.enableMenuBarMnemonics": false,
  "window.customMenuBarAltFocus": false,
  "window.menuBarVisibility": "hidden",

Save screenshots to the right place

Shortcut Action
ctrl + alt + PrtSc Screenshot of the current window
alt + PrtSc Screenshot zone
shift + ctrl + alt + R Screencast full screen

To change the folder where the screenshots are saved, the (mostly) only way is to use the screenshot-locations.

⚠ NOTE ⚠ Many places on the internet says the good way is to set the gsetting auto-save-directory. But this method does not work for Ubuntu 20.04 and later.

# Won't work for Ubuntu 20.04 and later!
gsettings set org.gnome.gnome-screenshot auto-save-directory "file:///home/$USER/Pictures/"

gnome-terminal proper colors

IPv6 sucks

Disable IPv6 until restart:

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

Disable IPv6 entirely:

sudo vim /etc/sysctl.conf

Compress PNG with a right-click

sudo apt install nautilus-actions

# Apparently, caja-actions is another frontend, so you can
# use that too:

sudo apt install caja-actions

Open "Nautilus Actions" (which is the same as "Caja Actions" apparently). Make sure to go into the settings and disable the "root menu" option.

Screenshot from 2021-05-07 08-45-34

Create an action "tinypng":

Screenshot from 2021-05-07 08-43-58

Grab your API key at https://tinypng.com/ and set the right API key:

Screenshot from 2021-05-07 08-44-28

Make sure that the menu item "tinypng" only shows for image MIME types:

Screenshot from 2021-05-07 08-44-45

Finally, right-click on some .png image and click "tinypng"!

Linuxbrew while sudoing

Solution 1: use -i to load the current user's ~/.zshrc instead of root's ones.

sudo -i bandwhich

Solution 2 (not recommended):

test -f /etc/profile.d/linuxbrew.sh \
  || sudo tee /etc/profile.d/linuxbrew.sh <<<'export PATH=/home/linuxbrew/.linuxbrew/bin:"$PATH"'

Recompile my kernel

sudo apt install libncurses-dev gawk flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf debconf-utils dpkg-dev debhelper build-essential kernel-package libncurses5-dev
git clone https://github.com/torvalds/linux
cd linux
cp /boot/config-$(uname --kernel-release) .config
yes "" | make oldconfig

Tailscale

The installation instruction for Debian and Ubuntu are bluntly listed in https://pkgs.tailscale.com/stable.

Avoiding relays

Tailscale checks whether UDP 41641 can be used in order to establish a wireguard connection over UDP (see What firewall ports should I open to use Tailscale? ). If it can, it uses this port to establish a un-relayed connection.

I had to add a firewall rule to my router (Livebox v4):

livebox-v4-firewall-tailscale-port-41641

I use a CLI, livebox, to add the firewall rules.

Let's add the IPv4 port forwarding:

livebox --password $(lpass show livebox -p) api <<EOF | jq
{
  "service": "Firewall",
  "method": "setPortForwarding",
  "parameters": {
    "id": "webui_tailscale",
    "description": "tailscale",
    "internalPort": "41641",
    "externalPort": "41641",
    "destinationIPAddress": "$(ip -4 -brief addr show enp6s0 dynamic primary | awk '{print $3}' | cut -f1 -d/)",
    "enable": true,
    "persistent": true,
    "protocol": "17",
    "sourceInterface": "data",
    "origin": "webui",
    "destinationMACAddress": "",
    "sourcePrefix": ""
  }
}
EOF

And let's pin a hole into the IPv6 firewall:

livebox --password $(lpass show livebox -p) api <<EOF | jq
{
  "service": "Firewall",
  "method": "setPinhole",
  "parameters": {
    "id": "tailscale",
    "origin": "webui",
    "sourceInterface": "data",
    "sourcePort": "",
    "destinationPort": "41641",
    "destinationIPAddress": "$(ip -6 -brief addr show enp6s0 dynamic primary | awk '{print $3}' | cut -f1 -d/)",
    "sourcePrefix": "",
    "protocol": "17",
    "ipversion": 6,
    "enable": true,
    "persistent": true
  }
}
EOF

It should now show:

$ livebox --password $(lpass show livebox -p) firewall
IPv4 17  :58999     -> 192.168.1.154:9                                webui_wol-aorus
IPv4 17  :41641     -> 192.168.1.154:41641                            webui_tailscale
IPv6 17  :          -> 2a01:cb19:86a2:8c00:74d2:9ea9:2592:435c:41641  webui_tailscale

If everything works, you should see this on mbp-mael-1:

$ tailscale status
100.127.221.57  aorus        maelvls@     macOS   active; direct 90.76.42.200:41641, tx 3512 rx 3848

On aorus, we can see that the connection is established thanks to UDP 41641 being open on aorus side:

$ tailscale status
100.114.149.88  mbp-mael-1   maelvls@     macOS   active; direct 176.180.86.187:6152, tx 3512 rx 3848

If IPv6 is enabled on mbp-mael-1, you should see this instead:

$ tailscale status
100.127.221.57  aorus        maelvls@     linux   active; direct [2a01:cb19:86a2:8c00:6a04:65cd:b601:a24f]:41641, tx 23332 rx 21932

And on aorus side:

$ tailscale status
100.114.149.88  mbp-mael-1   maelvls@     macOS   active; direct [2a04:cec0:113c:c4eb:d5f2:195d:d6fd:49a2]:62156, tx 75056 rx 79600

Wake-on-LAN (WoL) and wake-on-WAN (WoW)

In the above screenshot, you can notice a "Wake on LAN" port forwarding.

As you may be notice, I am not using the broadcast address 255.255.255.255, which means it can't wake up the machine when it is totally off. That's due to the fact that when my machine turns off, my router clears the entry that corresponds to the MAC adress of my machine in its ARP table; it can't know where to send the packet to anymore.

I tried having my router forward the UDP magic packet to the broadcast address instead of a single IP, but it does not seem to work.

My configuration using the livebox CLI:

livebox --password $(lpass show livebox -p) api <<EOF | jq
{
  "service": "Firewall",
  "method": "setPortForwarding",
  "parameters": {
    "id": "webui_wol-aorus",
    "description": "wol-aorus",
    "internalPort": "9",
    "externalPort": "58999",
    "destinationIPAddress": "$(ip -4 -brief addr show enp6s0 dynamic primary | awk '{print $3}' | cut -f1 -d/)",
    "enable": true,
    "persistent": true,
    "protocol": "17",
    "sourceInterface": "data",
    "origin": "webui",
    "destinationMACAddress": "",
    "sourcePrefix": ""
  }
}
EOF

Important: the machine should never be totally powered off. It should always be either awake or sleeping.

pbcopy, pbpaste (that I used to use on macOS)

sudo apt install xclip xsel
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'

Pin apps to workspaces

Install Auto move windows, and open Tweaks and open the settings of Auto move windows.

pin apps

pin apps

Clockify

curl -LO https://clockify-resources.s3.eu-central-1.amazonaws.com/downloads/Clockify_Setup.deb
sudo dpkg -i Clockify_Setup.deb

Docker

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

OBS

sudo apt install ffmpeg
cd ~/.config/obs-studio
curl -LO https://github.com/obsproject/obs-amd-encoder/releases/download/2.6.0/obs-amd-encoder-2.6.0.0.zip
unzip obs-amd-encoder-2.6.0.0.zip

Also to have the "Start Virtual Camera" without sudo privileges:

sudo apt install v4l2loopback-utils v4l2loopback-dkms
sudo modprobe v4l2loopback video_nr=2 card_label="OBS Virtual Camera"

Install OBS itself: don't install from apt since the version will be outdated. Instead:

sudo snap install obs-studio --edge
sudo snap connect obs-studio:alsa
sudo snap connect obs-studio:audio-record
sudo snap connect obs-studio:avahi-control
sudo snap connect obs-studio:camera
sudo snap connect obs-studio:jack1
sudo snap connect obs-studio:kernel-module-observe

GNOME shell extensions I use

  • system-monitor. It requires those:

    sudo apt install gir1.2-gtop-2.0 gir1.2-nm-1.0 gir1.2-clutter-1.0 gnome-system-monitor
    
  • emoji picker and I set the shortcut ctrl + alt + space. Not available anymore in GNOME 40. I switched to emote which works much more like macOS' emoji picker.

1Password

curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo apt-key add -
Add the 1Password beta apt repository:
echo 'deb [arch=amd64] https://downloads.1password.com/linux/debian/amd64 beta main' | sudo tee /etc/apt/sources.list.d/1password-beta.list
sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/
 curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | sudo tee /etc/debsig/policies/AC2D62742012EA22/1password.pol
sudo mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22
curl -sS https://downloads.1password.com/linux/keys/1password.asc | sudo gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg

Don't forget to enable the Browser integration so that you don't have to unlock in the browser:

1password for linux desktop

Spotify on a HiDPI screen

Still an issue on Ubuntu Jessie 22.04.

curl -sS https://download.spotify.com/debian/pubkey_0D811D58.gpg | sudo apt-key add -
echo "deb http://repository.spotify.com stable non-free" | sudo tee /etc/apt/sources.list.d/spotify.list
sudo apt update
sudo apt install spotify-client
locate spotify.desktop | xargs sudo sed -i 's/spotify %U$/spotify --force-device-scale-factor=2.0 %U/'

Or with snap:

sudo snap install spotify
sudo sed -i 's/spotify %U$/spotify --force-device-scale-factor=2.0 %U/'  /var/lib/snapd/desktop/applications/spotify_spotify.desktop

I use a 4k screen scaled at 150%, and Spotify looks nice:

spotify

Drivers for the Radeon RX 6800

First, download amdgpu.tar.gz here.

Then

amdgpu-uninstall
./amdgpu-install

Make my camera work

sudo apt install v4l-utils
% v4l2-ctl --device=/dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Type: Video Capture

	[0]: 'MJPG' (Motion-JPEG, compressed)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 640x360
			Interval: Discrete 0.033s (30.000 fps)
	[1]: 'YUYV' (YUYV 4:2:2)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 640x360
			Interval: Discrete 0.033s (30.000 fps)
	[2]: 'H264' (H.264, compressed)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
			Interval: Discrete 0.042s (24.000 fps)
			Interval: Discrete 0.050s (20.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
			Interval: Discrete 0.042s (24.000 fps)
			Interval: Discrete 0.050s (20.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)
			Interval: Discrete 0.042s (24.000 fps)
			Interval: Discrete 0.050s (20.000 fps)
		Size: Discrete 640x360
			Interval: Discrete 0.033s (30.000 fps)
			Interval: Discrete 0.042s (24.000 fps)
			Interval: Discrete 0.050s (20.000 fps)
sudo add-apt-repository ppa:openrazer/stable
sudo apt update
sudo apt install openrazer-meta

and restart.

Start code over ssh

On my local machine's ~/.ssh/config:

Host aorus
  User mvalais
  Port 22
  HostName aorus.home

From my local machine:

code --folder-uri vscode-remote://ssh-remote+aorus/home/mvalais/code/cert-manager

ssh-remote

I did not figure out how to use code . from inside the remote-ssh vscode window though. This stackoverflow thread has no good answer for that.

Here is my solution to open a new VSCode window from inside the remote-ssh session. In the below example, mpb-mael is where I run VSCode, and aorus is the remote. With the following, I can run code . from inside the remote-ssh session (or any other shell session):

#! /bin/bash
# File: ~/bin/coder

args="code"
while [ $# -gt 0 ]; do
    if [ -f "$1" ]; then
        args+=" --file-uri \"vscode-remote://ssh-remote+aorus$(readlink -f "$1")\""
    elif [ -d "$1" ]; then
        args+=" --folder-uri \"vscode-remote://ssh-remote+aorus$(readlink -f "$1")\""
    else
        args+=" $1"
    fi
    shift
done

cat <<EOF >&2
exec ssh mbp-mael -q -t -x "exec zsh -l -c '${args[@]}'"
EOF
exec ssh mbp-mael -q -t -x "exec zsh -l -c '${args[@]}'"

Bluetooth Beats Solo 3

First, check that pulseaudio is running OK. For example, if it shows "pa_pid_file_create() failed":

% pulseaudio -v
E: [pulseaudio] pid.c: Daemon already running.
E: [pulseaudio] main.c: pa_pid_file_create() failed.

# Or:
% start-pulseaudio-x11
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

That might be due to this issue:

The bluetooth service tries to load the pulseaudio bluetooth module at startup, which fails because they require X11 to be running. You need to change the configuration so that the pulseaudio bluetooth module is loaded after X11.

In my case, I realized that I had imported an old pulse config from an old backup. So I just had to remove those config files (will remove default sinks!)

rm -rf  ~/.config/pulse/*

Other check:

% pulseaudio -v 2>&1 | grep '^E: '
E: [pulseaudio] main.c: D-Bus name org.PulseAudio1 already taken.

In the end, my issue was that I had broken the Linux permissions (I copied a /home over from a backup). What I did:

sudo chown -R mvalais:mvalais /home/mvalais
rm -rf /run/user/$UID/pulse
rm -rf ~/.config/pulse
killall pulseaudio
pulseaudio --start

Then, make sure pulseaudio is running with:

pacmd list-cards

If it shows an error, then restart pulseaudio with:

# kill pulseaudio in case
pulseaudio -k
# start pulseaudio
pulseaudio -D

Then, connect (the connection will fail if pulseaudio is not running):

% bluetoothctl
$ scan on
$ devices
Device E0:51:63:DE:A0:91 Bbox Miami
Device D4:90:9C:3B:0D:86 Beats Solo³ de Maël
$ connect D4:90:9C:3B:0D:86                      # use tab to commplete the MAC address

bluetoothctl

Finally, make sure to select this "sink":

% pacmd list-sinks
1 sink(s) available.
  * index: 1
	name: <bluez_sink.D4_90_9C_3B_0D_86.a2dp_sink>

to use this sink:

pacmd set-default-sink 1

Change volume from the terminal

Component Description
PulseAudio The audio proxy
ALSA The card drivers

To be able to run without sudo, open:

sudo vim /etc/group

and do the change:

-audio:x:29:pulse
+audio:x:29:pulse,mvalais

Equivalent:

sudo usermod -aG audio $USER

Then, you can set volumes with the alsamixer TUI:

alsamixer

alsamixer-without-sudo

Also, the mypa CLI is helpful to change the sink:

curl -L https://raw.githubusercontent.com/mpapis/home_dotfiles/master/bin/mypa > ~/bin/mypa && chmod +x ~/bin/mypa

Docker without sudo

As detailed here, you want to add yourself to the docker UNIX group:

sudo groupadd docker
sudo usermod -aG docker $USER

and then restart your X session:

sudo systemctl restart display-manager

Pair Beats Solo 3

sudo apt install pulseaudio-module-bluetooth
pulseaudio -k
pulseaudio --start

and then

bluetoothctl
connect <tab> # (select the correct MAC address)

Locale

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LC_TERMINAL = "iTerm2",
	LC_NUMERIC = "fr_FR.UTF-8",
	LC_TIME = "fr_FR.UTF-8",
	LC_MONETARY = "fr_FR.UTF-8",
	LC_PAPER = "fr_FR.UTF-8",
	LC_NAME = "fr_FR.UTF-8",
	LC_ADDRESS = "fr_FR.UTF-8",
	LC_TELEPHONE = "fr_FR.UTF-8",
	LC_MEASUREMENT = "fr_FR.UTF-8",
	LC_IDENTIFICATION = "fr_FR.UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

Solution: add this to ~/.zshrc:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

This issue may also appear due to ssh which forwards the LC_* variables, see the local /etc/ssh/ssh_config:

Host *
    SendEnv LANG LC_*

Remote X

Remember: the "server" is the local machine, the client is the remote.

% ssh aorus -Y
% startx
/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error
Couldn't get a file descriptor referring to the console

To fix this:

sudo vim /etc/X11/Xwrapper.config

and change:

-allowed_users=console
+allowed_users=anybody

Flatcar and .profile

# In ~/.profile:

# Flatcar.
export XDG_DATA_DIRS="$HOME/.local/xdg:$XDG_DATA_DIRS"
export XDG_DATA_DIRS="/var/lib/flatpak/exports/share:$XDG_DATA_DIRS"
export XDG_DATA_DIRS="$HOME/.local/share/flatpak/exports/share:$XDG_DATA_DIRS"

Reinstall GRUB after installing Windows 10

(source)

First, let's look for the partitions we want to have in GRUB:

ubuntu@ubuntu:~$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 232.9G  0 disk
├─sda1        8:1    0    16M  0 part
└─sda2        8:2    0 232.9G  0 part
sdb           8:16   1  14.9G  0 disk
└─sdb1        8:17   1  14.9G  0 part /cdrom
nvme1n1     259:0    0 465.8G  0 disk
└─nvme1n1p1 259:1    0 465.8G  0 part            # My Windows
nvme0n1     259:2    0 931.5G  0 disk
├─nvme0n1p1 259:3    0   487M  0 part            # EFI
└─nvme0n1p2 259:4    0   931G  0 part /mnt       # My Ubuntu
sudo mount /dev/nvme0n1p2 /mnt
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt/@/$i; done
sudo chroot /mnt/@
sudo update-grub

Of course, it wouldn't work right away since I'm using btrfs (the above askubuntu thread assumes the use of ext4):

$ sudo update-grub
sudo: unable to resolve host ubuntu: Name or service not known
/usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).

This other askubuntu thread gives a clue on how to properly mount without having to use /mnt/@$i:

sudo mount -t btrfs -o subvol=@ /dev/nvme0n1p2 /mnt
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt
sudo update-grub
exit

Of course (second time!) it didn't work as planned:

# This is inside the chroot shell session.
% grub-install /dev/nvme0n1
Installing for x86_64-efi platform.
grub-install: error: cannot find EFI directory.

Going through this, I realized how toxic some parts of the community are:

It's very hard to help you because you don't know basic commands... but I'll try okay? Now, mount your system at /mnt. Remember? Linux filesystem? Yes. It's /dev/sda10.

The answer to that is hidden in one of the comments on this askubuntu issue:

You also need to mount the EFI partition for modern installations:

# This is outside the chroot shell session.
sudo mount /dev/nvme0n1p1 /mnt/boot/efi

– CyberEd May 30 '17 at 22:14

So I did:

# This is outside the chroot shell session.
sudo mount /dev/nvme0n1p1 /mnt/boot/efi

# This is inside the chroot shell session.
% grub-install /dev/nvme0n1
sudo mount /dev/nvme0n1p1 /mnt/boot/efi

This time it works!

Finally, I need to add Windows 10 as an entry in GRUB update GRUB's /boot/grub/grub.cfg which should automatically find the "Windows Boot Manager":

% sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.8.0-53-generic
Found initrd image: /boot/initrd.img-5.8.0-53-generic
Found linux image: /boot/vmlinuz-5.8.0-50-generic
Found initrd image: /boot/initrd.img-5.8.0-50-generic
Found Windows Boot Manager on /dev/nvme0n1p1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings
done

LUKS-encrypted btrfs backup

% lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda           8:0    0   1.8T  0 disk
└─sda1        8:1    0   1.8T  0 part
  └─backup3 253:0    0   1.8T  0 crypt

First, let's map the LUKS device and mount it:

sudo apt install cryptsetup
sudo cryptsetup luksOpen --type=luks /dev/sda1 backup3
sudo mount -t btrfs /dev/mapper/backup3 /mnt

Then, create the btrfs children @ and @home:

sudo btrfs subvolume create /mnt/@
sudo btrfs subvolume create /mnt/@home
sudo umount /mnt
sudo cryptsetup close backup3

Have screenshots created in $HOME/Pictures instead of $HOME

First, make appear the "Picture" tab in the Folders app. Open this file:

vim ~/.config/user-dirs.dirs

and edit it:

-XDG_PICTURES_DIR="$HOME/"
+XDG_PICTURES_DIR="$HOME/Pictures"

pictures-tab-in-ubuntu

Upgrade from 20.40 to 20.10

# AMD drivers are useless with 20.10.
cd amdgpu-pro-21.10-1247438-ubuntu-20.04
./amdgpu-install uninstall

# Let's uninstall all my kernel modules in case.
sudo apt install ppa-purge

# The kernel modules are still referenced by the initramfs, let's fix that.
sudo update-initramfs -k all -u -v

The PPAs:

% egrep -v '^#|^ *$' /etc/apt/sources.list /etc/apt/sources.list.d/* | grep ppa
/etc/apt/sources.list.d/aslatter-ubuntu-ppa-focal.list:deb http://ppa.launchpad.net/aslatter/ppa/ubuntu focal main
/etc/apt/sources.list.d/aslatter-ubuntu-ppa-focal.list.save:deb http://ppa.launchpad.net/aslatter/ppa/ubuntu focal main
/etc/apt/sources.list.d/atareao-ubuntu-atareao-focal.list:deb http://ppa.launchpad.net/atareao/atareao/ubuntu focal main
/etc/apt/sources.list.d/lutris-team-ubuntu-lutris-focal.list:deb http://ppa.launchpad.net/lutris-team/lutris/ubuntu focal main
/etc/apt/sources.list.d/lutris-team-ubuntu-lutris-focal.list.save:deb http://ppa.launchpad.net/lutris-team/lutris/ubuntu focal main
/etc/apt/sources.list.d/obsproject-ubuntu-obs-studio-focal.list:deb http://ppa.launchpad.net/obsproject/obs-studio/ubuntu focal main
/etc/apt/sources.list.d/obsproject-ubuntu-obs-studio-focal.list.save:deb http://ppa.launchpad.net/obsproject/obs-studio/ubuntu focal main
/etc/apt/sources.list.d/openrazer-ubuntu-stable-focal.list:deb http://ppa.launchpad.net/openrazer/stable/ubuntu focal main
/etc/apt/sources.list.d/openrazer-ubuntu-stable-focal.list.save:deb http://ppa.launchpad.net/openrazer/stable/ubuntu focal main

Now, I uninstall them:

sudo ppa-purge lutris-team/lutris
sudo ppa-purge openrazer/stable
sudo ppa-purge atareao/atareao
sudo ppa-purge aslatter/ppa

Yubikey

I use the Yubikey 5C NFC.

sudo apt install libu2f-udev libpam-u2f
curl https://github.com/Yubico/libu2f-host/blob/master/70-u2f.rules -O
sudo mv 70-u2f.rules /etc/udev/rules.d/

In /etc/pam.d/sudo:

#%PAM-1.0

session    required   pam_env.so readenv=1 user_readenv=0
session    required   pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0
@include common-auth
auth       required   pam_u2f.so
@include common-account
@include common-session-noninteractive

Open VSCode when opening a .txt or .go file

The mapping between MIME types and the .desktop apps is done in ~/.config/mimeapps.list.

For example, let's imagine I installed code-insiders using apt. The .desktop is:

/usr/share/applications/code-insiders.desktop

Now, I can assign text/plain to it:

gio mime text/plain code-insiders-url-handler.desktop
gio mime text/html code-insiders-url-handler.desktop

Fix Bluetooth disconnects on Ubuntu 21.04 (AX200)

Every 20 minutes or so, my Bluetooth headphones (Beats Solo³) would get disconnected and would immediately reconnect. At this exact moment, I would see this syslog message:

Jul 12 14:48:54 aorus acpid: input device has been disconnected, fd 27

It seems like it is related to some versions of the linux-firmware package for anyone using the Intel AX200 or AX201 network chipset. It has been reported on Arch forums, on a Pulseaudio issue and on a Pipewire issue.

% lspci | grep Intel
05:00.0 Network controller: Intel Corporation Wi-Fi 6 AX200 (rev 1a)

% sudo apt show linux-firmware | grep Version
Version: 1.197.2

% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 21.04
Release:        21.04
Codename:       hirsute

% uname -a
Linux aorus 5.11.0-22-generic #23-Ubuntu SMP Thu Jun 17 00:34:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

The workaround is to install a newer version of the Intel firmwares:

wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/snapshot/linux-firmware-20210716.tar.gz
tar xfvz linux-firmware-20210716.tar.gz
cd linux-firmware-20210716
sudo cp intel/ibt-* /lib/firmware/intel/

And then reboot.

Massive freezes under Ubuntu 21.04

From time to time I would get a 1-5 minutes freeze.

sudo dmesg --follow

Output:

[46278.914033] INFO: task btrfs-transacti:965 blocked for more than 120 seconds.
[46278.914039]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914041] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914042] task:btrfs-transacti state:D stack:    0 pid:  965 ppid:     2 flags:0x00004000
[46278.914045] Call Trace:
[46278.914048]  __schedule+0x23d/0x670
[46278.914052]  schedule+0x4f/0xc0
[46278.914055]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914075]  ? wait_woken+0x80/0x80
[46278.914080]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914094]  ? start_transaction+0xd5/0x590 [btrfs]
[46278.914108]  ? __next_timer_interrupt+0x110/0x110
[46278.914110]  transaction_kthread+0x138/0x1b0 [btrfs]
[46278.914123]  kthread+0x12f/0x150
[46278.914125]  ? btrfs_cleanup_transaction.isra.0+0x290/0x290 [btrfs]
[46278.914138]  ? __kthread_bind_mask+0x70/0x70
[46278.914140]  ret_from_fork+0x22/0x30
[46278.914145] INFO: task systemd-journal:1023 blocked for more than 120 seconds.
[46278.914146]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914147] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914147] task:systemd-journal state:D stack:    0 pid: 1023 ppid:     1 flags:0x00004220
[46278.914149] Call Trace:
[46278.914150]  __schedule+0x23d/0x670
[46278.914151]  schedule+0x4f/0xc0
[46278.914152]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914165]  ? wait_woken+0x80/0x80
[46278.914166]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914180]  ? btrfs_wait_ordered_range+0x13f/0x210 [btrfs]
[46278.914197]  btrfs_sync_file+0x445/0x480 [btrfs]
[46278.914212]  vfs_fsync_range+0x49/0x80
[46278.914214]  ? syscall_trace_enter.constprop.0+0xa0/0x1c0
[46278.914216]  __x64_sys_fsync+0x39/0x60
[46278.914217]  do_syscall_64+0x38/0x90
[46278.914219]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914220] RIP: 0033:0x7f3fe6069d4b
[46278.914222] RSP: 002b:00007ffeea51d690 EFLAGS: 00000293 ORIG_RAX: 000000000000004a
[46278.914223] RAX: ffffffffffffffda RBX: 000055db62a02630 RCX: 00007f3fe6069d4b
[46278.914224] RDX: 0000000000000002 RSI: 000055db62a02820 RDI: 0000000000000017
[46278.914225] RBP: 0000000000000001 R08: 0000000000000000 R09: 00007ffeea51d7d8
[46278.914226] R10: 00007f3fe63b5ab4 R11: 0000000000000293 R12: 000055db62a02630
[46278.914226] R13: 00007ffeea51d7d0 R14: 0000000000000000 R15: 00007ffeea51d7d0
[46278.914308] INFO: task gnome-shell:6494 blocked for more than 120 seconds.
[46278.914309]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914310] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914311] task:gnome-shell     state:D stack:    0 pid: 6494 ppid:  5149 flags:0x00004000
[46278.914312] Call Trace:
[46278.914313]  __schedule+0x23d/0x670
[46278.914314]  schedule+0x4f/0xc0
[46278.914315]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914329]  ? wait_woken+0x80/0x80
[46278.914330]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914343]  ? dput+0x5c/0x180
[46278.914346]  btrfs_sync_file+0x445/0x480 [btrfs]
[46278.914360]  vfs_fsync_range+0x49/0x80
[46278.914361]  ? __fget_light+0x32/0x80
[46278.914363]  __x64_sys_fsync+0x39/0x60
[46278.914364]  do_syscall_64+0x38/0x90
[46278.914364]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914366] RIP: 0033:0x7f2042176d4b
[46278.914366] RSP: 002b:00007ffdd78caab0 EFLAGS: 00000293 ORIG_RAX: 000000000000004a
[46278.914367] RAX: ffffffffffffffda RBX: 00007f202809daf0 RCX: 00007f2042176d4b
[46278.914368] RDX: 0000000000000002 RSI: 0000000000000000 RDI: 0000000000000028
[46278.914369] RBP: 00007ffdd78caf10 R08: 0000000000000000 R09: 000055a6927ac270
[46278.914369] R10: 0000000000000000 R11: 0000000000000293 R12: 0000000000000000
[46278.914370] R13: 00007ffdd78caf10 R14: 000055a6952ddfa0 R15: 00007ffdd78cad1c
[46278.914424] INFO: task ThreadPoolForeg:1587785 blocked for more than 120 seconds.
[46278.914425]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914426] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914426] task:ThreadPoolForeg state:D stack:    0 pid:1587785 ppid:  6383 flags:0x00004220
[46278.914428] Call Trace:
[46278.914428]  __schedule+0x23d/0x670
[46278.914430]  schedule+0x4f/0xc0
[46278.914430]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914444]  ? wait_woken+0x80/0x80
[46278.914445]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914458]  ? dput+0x5c/0x180
[46278.914459]  btrfs_sync_file+0x445/0x480 [btrfs]
[46278.914473]  __x64_sys_fdatasync+0x4c/0x90
[46278.914474]  do_syscall_64+0x38/0x90
[46278.914475]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914476] RIP: 0033:0x7fe8759230c7
[46278.914476] RSP: 002b:00007fe789ff6820 EFLAGS: 00000293 ORIG_RAX: 000000000000004b
[46278.914477] RAX: ffffffffffffffda RBX: 00000000000000b2 RCX: 00007fe8759230c7
[46278.914478] RDX: 0000000000000000 RSI: 00007fe789ff6610 RDI: 00000000000000b2
[46278.914478] RBP: 00007fe789ff68d0 R08: 0000000000000000 R09: 0000000000000001
[46278.914479] R10: 00007ffebc0bb080 R11: 0000000000000293 R12: 00007fe7940012d0
[46278.914480] R13: 00007fe882b0f4f0 R14: 00007fe7940012f0 R15: aaaaaaaaaaaaaaaa
[46278.914481] INFO: task ThreadPoolForeg:1598793 blocked for more than 120 seconds.
[46278.914482]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914482] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914483] task:ThreadPoolForeg state:D stack:    0 pid:1598793 ppid:  6383 flags:0x00004220
[46278.914485] Call Trace:
[46278.914486]  __schedule+0x23d/0x670
[46278.914487]  schedule+0x4f/0xc0
[46278.914488]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914501]  ? wait_woken+0x80/0x80
[46278.914502]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914515]  ? btrfs_wait_ordered_range+0x19a/0x210 [btrfs]
[46278.914529]  btrfs_sync_file+0x445/0x480 [btrfs]
[46278.914543]  __x64_sys_fdatasync+0x4c/0x90
[46278.914544]  do_syscall_64+0x38/0x90
[46278.914544]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914546] RIP: 0033:0x7fe8759230c7
[46278.914546] RSP: 002b:00007fe7a19e6940 EFLAGS: 00000293 ORIG_RAX: 000000000000004b
[46278.914547] RAX: ffffffffffffffda RBX: 000000000000008f RCX: 00007fe8759230c7
[46278.914548] RDX: 0000000000000000 RSI: 0000000000000002 RDI: 000000000000008f
[46278.914548] RBP: 00007fe7a19e6990 R08: 0000000000000000 R09: 0000000000000001
[46278.914549] R10: 0000000000004400 R11: 0000000000000293 R12: 0000000000000000
[46278.914549] R13: d763a120f905d5d9 R14: 0000000000000000 R15: 0000000000001000
[46278.914580] INFO: task ThreadPoolForeg:1592907 blocked for more than 120 seconds.
[46278.914582]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914582] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914583] task:ThreadPoolForeg state:D stack:    0 pid:1592907 ppid:  9315 flags:0x00004220
[46278.914584] Call Trace:
[46278.914584]  __schedule+0x23d/0x670
[46278.914586]  schedule+0x4f/0xc0
[46278.914586]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914599]  ? wait_woken+0x80/0x80
[46278.914600]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914614]  ? btrfs_wait_ordered_range+0x13f/0x210 [btrfs]
[46278.914627]  btrfs_sync_file+0x445/0x480 [btrfs]
[46278.914641]  __x64_sys_fdatasync+0x4c/0x90
[46278.914642]  do_syscall_64+0x38/0x90
[46278.914642]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914644] RIP: 0033:0x7f40d776e0c7
[46278.914644] RSP: 002b:00007f40cd071d40 EFLAGS: 00000293 ORIG_RAX: 000000000000004b
[46278.914645] RAX: ffffffffffffffda RBX: 000000000000001f RCX: 00007f40d776e0c7
[46278.914645] RDX: 0000000000000000 RSI: 0000000000000002 RDI: 000000000000001f
[46278.914646] RBP: 00007f40cd071d90 R08: 0000000000000000 R09: 0000000000003fdf
[46278.914646] R10: 0000000000002400 R11: 0000000000000293 R12: 0000000000000000
[46278.914647] R13: d763a120f905d5d9 R14: 0000000000000000 R15: 0000000000001000
[46278.914659] INFO: task ThreadPoolForeg:1541344 blocked for more than 120 seconds.
[46278.914660]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914661] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914661] task:ThreadPoolForeg state:D stack:    0 pid:1541344 ppid:  9301 flags:0x00004220
[46278.914663] Call Trace:
[46278.914663]  __schedule+0x23d/0x670
[46278.914664]  schedule+0x4f/0xc0
[46278.914665]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914678]  ? wait_woken+0x80/0x80
[46278.914679]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914692]  ? dput+0x5c/0x180
[46278.914694]  btrfs_sync_file+0x445/0x480 [btrfs]
[46278.914707]  __x64_sys_fdatasync+0x4c/0x90
[46278.914708]  do_syscall_64+0x38/0x90
[46278.914709]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914710] RIP: 0033:0x7f814578d0c7
[46278.914710] RSP: 002b:00007f8131bd3e00 EFLAGS: 00000293 ORIG_RAX: 000000000000004b
[46278.914711] RAX: ffffffffffffffda RBX: 000000000000001e RCX: 00007f814578d0c7
[46278.914712] RDX: 0000000000000000 RSI: 00007f8131bd3bf0 RDI: 000000000000001e
[46278.914712] RBP: 00007f8131bd3eb0 R08: 0000000000000000 R09: 0000000000000001
[46278.914713] R10: 00007fff05dd7080 R11: 0000000000000293 R12: 00007f81240ab3ab
[46278.914713] R13: 000000000000021b R14: 00007f8131bd3ff0 R15: 00007f8131bd3f30
[46278.914715] INFO: task ThreadPoolForeg:1598386 blocked for more than 120 seconds.
[46278.914716]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914716] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914717] task:ThreadPoolForeg state:D stack:    0 pid:1598386 ppid:  9301 flags:0x00004220
[46278.914717] Call Trace:
[46278.914718]  __schedule+0x23d/0x670
[46278.914719]  schedule+0x4f/0xc0
[46278.914720]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914733]  ? wait_woken+0x80/0x80
[46278.914734]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914747]  ? dput+0x5c/0x180
[46278.914748]  btrfs_sync_file+0x445/0x480 [btrfs]
[46278.914762]  __x64_sys_fdatasync+0x4c/0x90
[46278.914763]  do_syscall_64+0x38/0x90
[46278.914763]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914765] RIP: 0033:0x7f814578d0c7
[46278.914765] RSP: 002b:00007f811bffce00 EFLAGS: 00000293 ORIG_RAX: 000000000000004b
[46278.914766] RAX: ffffffffffffffda RBX: 0000000000000020 RCX: 00007f814578d0c7
[46278.914766] RDX: 0000000000000000 RSI: 00007f811bffcbf0 RDI: 0000000000000020
[46278.914767] RBP: 00007f811bffceb0 R08: 0000000000000000 R09: 0000000000000001
[46278.914768] R10: 00007fff05dd7080 R11: 0000000000000293 R12: 00007f81240e96d0
[46278.914768] R13: 00000000000009f0 R14: 00007f811bffcff0 R15: 00007f811bffcf30
[46278.914769] INFO: task ThreadPoolForeg:1598937 blocked for more than 120 seconds.
[46278.914770]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914771] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914771] task:ThreadPoolForeg state:D stack:    0 pid:1598937 ppid:  9301 flags:0x00004220
[46278.914772] Call Trace:
[46278.914773]  __schedule+0x23d/0x670
[46278.914774]  schedule+0x4f/0xc0
[46278.914775]  wait_for_commit+0x5e/0x90 [btrfs]
[46278.914788]  ? wait_woken+0x80/0x80
[46278.914789]  btrfs_commit_transaction+0x6a3/0x9c0 [btrfs]
[46278.914802]  ? btrfs_wait_ordered_range+0x13f/0x210 [btrfs]
[46278.914815]  btrfs_sync_file+0x445/0x480 [btrfs]
[46278.914828]  __x64_sys_fdatasync+0x4c/0x90
[46278.914829]  do_syscall_64+0x38/0x90
[46278.914830]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914831] RIP: 0033:0x7f814578d0c7
[46278.914832] RSP: 002b:00007f81323d48b0 EFLAGS: 00000293 ORIG_RAX: 000000000000004b
[46278.914833] RAX: ffffffffffffffda RBX: 0000000000000025 RCX: 00007f814578d0c7
[46278.914833] RDX: 0000000000000000 RSI: 0000000000000002 RDI: 0000000000000025
[46278.914834] RBP: 00007f81323d4900 R08: 0000000000000000 R09: 0000000000000001
[46278.914834] R10: 0000000000002400 R11: 0000000000000293 R12: 0000000000000000
[46278.914835] R13: d763a120f905d5d9 R14: 0000000000000000 R15: 0000000000001000
[46278.914841] INFO: task ThreadPoolForeg:1599116 blocked for more than 120 seconds.
[46278.914842]       Tainted: G           OE     5.11.0-22-generic #23-Ubuntu
[46278.914842] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[46278.914843] task:ThreadPoolForeg state:D stack:    0 pid:1599116 ppid:  9301 flags:0x00000220
[46278.914844] Call Trace:
[46278.914845]  __schedule+0x23d/0x670
[46278.914846]  schedule+0x4f/0xc0
[46278.914847]  wait_current_trans+0xd6/0x140 [btrfs]
[46278.914860]  ? wait_woken+0x80/0x80
[46278.914861]  start_transaction+0x4af/0x590 [btrfs]
[46278.914874]  btrfs_start_transaction+0x1e/0x20 [btrfs]
[46278.914887]  btrfs_create+0x57/0x210 [btrfs]
[46278.914901]  lookup_open.isra.0+0x2e8/0x3d0
[46278.914903]  open_last_lookups+0x194/0x420
[46278.914904]  ? path_init+0x2bd/0x3e0
[46278.914905]  path_openat+0x8d/0x1d0
[46278.914906]  do_filp_open+0x8c/0x130
[46278.914908]  ? __check_object_size+0x1c/0x20
[46278.914910]  do_sys_openat2+0x9b/0x150
[46278.914912]  __x64_sys_openat+0x56/0x90
[46278.914914]  do_syscall_64+0x38/0x90
[46278.914914]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[46278.914916] RIP: 0033:0x7f8148ad7e9e
[46278.914916] RSP: 002b:00007f8119e7dde0 EFLAGS: 00000293 ORIG_RAX: 0000000000000101
[46278.914917] RAX: ffffffffffffffda RBX: 00007f8119e7de50 RCX: 00007f8148ad7e9e
[46278.914918] RDX: 0000000000000241 RSI: 00007f812410af60 RDI: 00000000ffffff9c
[46278.914918] RBP: 00007f8119e7def0 R08: 0000000000000000 R09: 0000000000000001
[46278.914919] R10: 0000000000000180 R11: 0000000000000293 R12: 0000000000000241
[46278.914919] R13: 00007f81241a9d00 R14: 00007f8119e7df70 R15: 0000000000008048

This might be due to Docker: https://gist.github.com/hopeseekr/cd2058e71d01deca5bae9f4e5a555440

I fixed this issue by moving from btrfs to ext4.

Switch from btrfs to ext4

I had so many performance issues (freezes when multiple containers would be running) that I decided to ditch btrfs. I was not using any of the btrfs features anyway, I just wanted to try the "cool kids" file system. My backup uses a good old rsync over ext4 disk, and I never felt (or thought about) using the instant snapshotting mechanism that btrfs offers.

I have been told that I should try ZFS instead if I wanted to go with an exotic file system. But I realize that what I need on my main workstation is stability, and ext4 is perfect for that.

The steps I took to migrate:

  1. Make sure my Timeshift-over-rsync backup "works" and has both / and /home backed up,
  2. Reinstall Ubuntu 21.04 with ext4,
  3. Run Ubuntu in live CD mode to run update-grub and to fix my /etc/fstab

When upgrading from Ubuntu 21.04 to 21.10, I had this kernel panic: image

I had upgraded Ubuntu from the command line:

sudo do-release-upgrade

Steps I took:

Boot Ubuntu live using my USB drive with 21.04 that I always keep around.

Let us mount the root partition to see what /etc/fstab looks like. First, we need to find which /dev my root partition is:

$ blkid
/dev/nvme0n1p2: UUID="B5B8-AEF1" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="f4b7b5eb-8ea6-4626-a520-99f6bf067bb9"
/dev/nvme0n1p3: UUID="5fa84dcd-07de-43a6-bde1-267b9ea9ed57" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="ab2125b9-ca98-44d5-9b28-3e75f1f63674"
/dev/nvme1n1p1: BLOCK_SIZE="512" UUID="6AA09C4AA09C1F1F" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="ecfb1344-ee00-4dbe-b488-93d484422333"
/dev/sdb1: BLOCK_SIZE="2048" UUID="2021-04-20-11-16-16-00" LABEL="Ubuntu 21.04 amd64" TYPE="iso9660" PARTLABEL="ISO9660" PARTUUID="af8737a9-1e23-4373-b87b-c8b16199d461"

Then, mount it:

sudo mkdir /mnt/boot
sudo mount /dev/nvme0n1p3 /mnt/boot/
cat /mnt/boot/etc/fstab

The fstab file looks fine:

UUID=5fa84dcd-07de-43a6-bde1-267b9ea9ed57 /               ext4   errors=remount-ro 0       1
UUID=B5B8-AEF1  /boot/efi                                 vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0

As per https://askubuntu.com/questions/41930/kernel-panic-not-syncing-vfs-unable-to-mount-root-fs-on-unknown-block0-0, it seems to be due to the fact that there is no initramfs for this kernel.

First, remove the mounting point I created earlier:

sudo umount /mnt/boot
sudo rm -rf /mnt/boot

Let us chroot; first, let us use another method for finding on which /dev the root partition is:

sudo fdisk -l

The correct /dev is /dev/nvme0n1p3 by reading the following output:

Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 980 PRO 1TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F44B5464-48D8-4EC1-8671-3836C950A055

Device           Start        End    Sectors  Size Type
/dev/nvme0n1p2    4096    1054719    1050624  513M EFI System
/dev/nvme0n1p3 1054720 1953523711 1952468992  931G Linux filesystem

Then, we can chroot:

sudo mount /dev/nvme0n1p3 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt

Finally:

update-initramfs -u -k 5.13.0-21-generic
update-grub2

Note that I had a couple of warnings:

update-initramfs: Generating /boot/initrd.img-5.13.0-21-generic
cp: cannot stat '/lib/firmware/updates/amdgpu': No such file or directory
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_gpu_info.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/aldebaran_ta.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/aldebaran_sos.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/aldebaran_rlc.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/aldebaran_mec2.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/aldebaran_mec.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/aldebaran_sdma.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/sienna_cichlid_mes.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/navi10_mes.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/aldebaran_vcn.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/aldebaran_smc.bin for module amdgpu

To fix it, run (still in the chroot jail):

sudo update-initramfs -k all -u -v

Password prompt keeps popping up

On Ubuntu 21.04, after restoring from a backup (when I had to switch from btrfs to ext4), I kept having the system policy pop up when running apt:

Authentication required to refresh system repositories

Screenshot from 2021-07-29 09-48-02

sudo tee /etc/polkit-1/localauthority/50-local.d/46-allow-update-repo.pkla <<EOF
[Allow Package Management all Users]
Identity=unix-user:*
Action=org.freedesktop.packagekit.system-sources-refresh
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF

Authentication required to create managed color device

sudo tee /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla <<EOF
[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes
EOF

Authentication required. System policy prevents Wi-fi scans

Screenshot from 2021-10-25 10-36-21-1

I haven't found a work around yet.

Authentication Required. System policy prevents control of network connections.

Screenshot from 2021-10-27 16-06-03

From https://code.luasoftware.com/tutorials/linux/ubuntu-prompt-system-policy-prevents-modification-of-network-settings-for-all-users/.

Wifi cannot be enabled

foo

I investigated:

$ lshw -C network
  *-network DISABLED # 🔥
       description: Wireless interface
       product: Wi-Fi 6 AX200
       vendor: Intel Corporation
       physical id: 0
       bus info: pci@0000:05:00.0
       logical name: wlp5s0
       version: 1a
       serial: 34:c9:3d:0f:85:39
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=iwlwifi driverversion=5.11.0-25-generic firmware=59.601f3a66.0 cc-a0-59.ucode latency=0 link=no multicast=yes wireless=IEEE 802.11
       resources: irq:165 memory:fc600000-fc603fff
  *-network
       description: Ethernet interface
       product: I211 Gigabit Network Connection
       vendor: Intel Corporation
       physical id: 0
       bus info: pci@0000:06:00.0
       logical name: enp6s0
       version: 03
       serial: 18:c0:4d:89:0c:84
       capacity: 1Gbit/s
       width: 32 bits
       clock: 33MHz
       capabilities: pm msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=igb driverversion=5.11.0-25-generic firmware=0. 6-1 latency=0 link=no multicast=yes port=twisted pair
       resources: irq:24 memory:fc500000-fc51ffff ioport:e000(size=32) memory:fc520000-fc523fff
  *-network
       description: Ethernet interface
       product: RTL8125 2.5GbE Controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:07:00.0
       logical name: enp7s0
       version: 05
       serial: 18:c0:4d:89:0c:86
       size: 1Gbit/s
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix vpd bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=5.11.0-25-generic duplex=full firmware=rtl8125b-2_0.0.2 07/13/20 ip=192.168.1.43 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s
       resources: irq:39 ioport:d000(size=256) memory:fc400000-fc40ffff memory:fc410000-fc413fff
  *-network:0
       description: Ethernet interface
       physical id: 1
       logical name: veth930ecaf
       serial: 32:87:37:86:6d:28
       size: 10Gbit/s
       capabilities: ethernet physical
       configuration: autonegotiation=off broadcast=yes driver=veth driverversion=1.0 duplex=full link=yes multicast=yes port=twisted pair speed=10Gbit/s
  *-network:1
       description: Ethernet interface
       physical id: 2
       logical name: veth1ffe26e
       serial: 56:4c:5e:f9:89:e0
       size: 10Gbit/s
       capabilities: ethernet physical
       configuration: autonegotiation=off broadcast=yes driver=veth driverversion=1.0 duplex=full link=yes multicast=yes port=twisted pair speed=10Gbit/s
  *-network:2
       description: Ethernet interface
       physical id: 3
       logical name: vethafa4ad4
       serial: ae:40:e7:6e:8c:f2
       size: 10Gbit/s
       capabilities: ethernet physical
       configuration: autonegotiation=off broadcast=yes driver=veth driverversion=1.0 duplex=full link=yes multicast=yes port=twisted pair speed=10Gbit/s
  *-network:3
       description: Ethernet interface
       physical id: 4
       logical name: veth130e819
       serial: e2:b6:aa:3a:d7:7a
       size: 10Gbit/s
       capabilities: ethernet physical
       configuration: autonegotiation=off broadcast=yes driver=veth driverversion=1.0 duplex=full link=yes multicast=yes port=twisted pair speed=10Gbit/s
$ lspci -knn | grep Net -A3
05:00.0 Network controller [0280]: Intel Corporation Wi-Fi 6 AX200 [8086:2723] (rev 1a)
	Subsystem: Intel Corporation Wi-Fi 6 AX200 [8086:0084]
	Kernel driver in use: iwlwifi
	Kernel modules: iwlwifi
06:00.0 Ethernet controller [0200]: Intel Corporation I211 Gigabit Network Connection [8086:1539] (rev 03)
	Subsystem: Gigabyte Technology Co., Ltd I211 Gigabit Network Connection [1458:e000]
	Kernel driver in use: igb
	Kernel modules: igb
07:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125] (rev 05)
$ lspci -knn | grep Net; rfkill list
05:00.0 Network controller [0280]: Intel Corporation Wi-Fi 6 AX200 [8086:2723] (rev 1a)
06:00.0 Ethernet controller [0200]: Intel Corporation I211 Gigabit Network Connection [8086:1539] (rev 03)
	Subsystem: Gigabyte Technology Co., Ltd I211 Gigabit Network Connection [1458:e000]
0: hci0: Bluetooth
	Soft blocked: no
	Hard blocked: no
1: phy0: Wireless LAN
	Soft blocked: yes # 🔥
	Hard blocked: no

I unblocked phy0 with

$ sudo rfkill unblock all

As pointed out on the thread Network Disabled on Ubuntu 18.04, it could be due to the NetworkManager state being "off":

$ sudo cat /var/lib/NetworkManager/NetworkManager.state
[main]
NetworkingEnabled=true
WirelessEnabled=false
WWANEnabled=true

It also showed this with nmcli:

wlp5s0: unavailable
        "Intel 6 AX200"
        wifi (iwlwifi), 34:C9:3D:0F:85:39, sw disabled, hw, mtu 1500
#                                          <----🔥---->

What was weird also was that nmcli required to be sudo, which I had never had needed before.

$ nmcli radio wifi on
Error: failed to set Wi-Fi radio: Not authorized to perform this operation

Reading Why does my network feature is disabled?:

$ sudo ls -al /var/lib/NetworkManager/
total 80
drwx------  2 root root 4096 Jul 30 11:16 .
drwxr-xr-x 80 root root 4096 Jul 27 16:32 ..
-rw-r--r--  1 root root   59 Jul 26 11:21 internal-3b0bb553-c3cc-3564-9ace-1d0ae797a5e8-enp6s0.lease
-rw-r--r--  1 root root   58 May 31 15:42 internal-67a825de-b9e3-4dd3-9b4c-c8e696a3e5ea-wlp5s0.lease
-rw-r--r--  1 root root   59 Apr 30 12:24 internal-6a0fa3cb-d274-4825-b4e5-98f306e010e1-enp5s0.lease
-rw-r--r--  1 root root   59 Jul 30 10:36 internal-73d895f5-7d31-3024-b566-e663d1658aeb-enp7s0.lease
-rw-r--r--  1 root root   59 Jul 30 10:57 internal-853565d9-9dde-487b-9db0-390cdadc71ea-wlp5s0.lease
-rw-r--r--  1 root root   58 Jun 11 07:59 internal-86141056-384a-3936-86cb-2b7f57ce664f-enx928c43baf3ac.lease
-rw-r--r--  1 root root   59 Apr 29 07:41 internal-9ce3a531-4c0a-4514-b6f7-f9004636f124-wlp4s0.lease
-rw-r--r--  1 root root   58 May 11 07:44 internal-a94a1832-44d8-437e-9b61-cb4d266cbd42-wlp4s0.lease
-rw-r--r--  1 root root   59 Jun 19 16:49 internal-c5d0884d-841a-4b6f-bafb-2c7dec7668ae-wlp5s0.lease
-rw-r--r--  1 root root   59 May 15 18:32 internal-d023fb7f-3851-378d-bb9a-0fc2c39e0ac0-enp5s0.lease
-rw-r--r--  1 root root   59 May 11 07:51 internal-d04d48c0-1065-4d6a-9390-ac8ffc5445fc-wlp4s0.lease
-rw-r--r--  1 root root   58 May 12 09:01 internal-e228a7f5-e492-355a-bfd4-2ba65af6a4ab-enx928c43baf3ac.lease
-rw-r--r--  1 root root   59 Jul  8 11:04 internal-e237cc32-05b6-4073-ac71-12c74458a537-wlp5s0.lease
-rw-r--r--  1 root root   60 Apr 30 12:17 internal-f2585864-cfe9-4532-b960-c9ff569fd5e3-wlp4s0.lease
-rw-r--r--  1 root root  939 Apr 28 19:28 NetworkManager-intern.conf
-rw-r--r--  1 root root   69 Jul 30 10:58 NetworkManager.state # 🔥
-rw-------  1 root root   50 Apr 28 19:28 secret_key
-rw-r--r--  1 root root  552 Jul 30 10:57 seen-bssids
-rw-r--r--  1 root root 2125 Jul 30 11:16 timestamps

Apparently, the trick is to remove this state, which is (seemingly) the source of this issue:

sudo systemctl stop NetworkManager.service
sudo rm /var/lib/NetworkManager/NetworkManager.state
sudo systemctl start NetworkManager.service

The "Power" button powers off instead of suspending

Solution (18 Jan 2022):

sudo sed -i~ 's/^.*HandlePowerKey=.*/HandlePowerKey=suspend/' /etc/systemd/logind.conf
sudo systemctl restart systemd-logind

When clicking the button "Power" at the top of my desktop machine, the ACPI event would be PBTN followed by LNXPWRBN:00.

$ acpi_listen
button/power PBTN 00000080 00000000
button/power LNXPWRBN:00 00000080 00000001

But apparently, acpid is not in charge of PBTN under Ubuntu 21.04:

$ grep -R PBTN /etc/acpi/events
$ ls /etc/acpi/events
asus-keyboard-backlight-down  asus-wireless-off  ibm-wireless   thinkpad-cmos
asus-keyboard-backlight-up    asus-wireless-on   lenovo-undock  tosh-wireless

After going throught man acpid.8, I realized that acpid might not be the one handling PBTN:

When troubleshooting acpid, it is important to be aware that other parts of a system might be handling ACPI events. systemd(1) is capable of handling the power switch and various other events that are commonly handled by acpid. See the description of HandlePowerKey in logind.conf(5) for more. Some window managers also take over acpid's normal handling of the power button and other events.

But it seems like /etc/systemd/logind.conf isn't the place where this configuration happens either:

# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.

[Login]
...
#HandlePowerKey=poweroff

Then I realized that it might be something off with settings-deamon. When launching the gnome-control-center, the "Suspend & Power Button" section would be blank; screenshot on Ubuntu 21.04:

127770176-beb05699-c95d-4a79-b950-cf00e01e711a

On Ubuntu 21.10, the whole section has disappeared:

Screenshot from 2021-11-14 11-36-31

And I noticed that some DBus event was getting an error when running gnome-control-center --verbose:

$ dbus-monitor | rg -C5 -i ^error
method call time=1636886995.039493 sender=:1.742 -> destination=org.freedesktop.DBus serial=19 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=StartServiceByName
   string "org.gnome.SettingsDaemon.Power"
   uint32 0
error time=1636886995.039496 sender=org.freedesktop.DBus -> destination=:1.742 error_name=org.freedesktop.DBus.Error.ServiceUnknown reply_serial=19
   string "The name org.gnome.SettingsDaemon.Power was not provided by any .service files

To reproduce the issue:

dbus-send --print-reply --type=method_call --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.StartServiceByName string:"org.gnome.SettingsDaemon.Power" uint32:0

It seems like I do have a .service under that name though (using fd):

$ fd org.gnome.SettingsDaemon.Power /usr/
/usr/lib/systemd/user/org.gnome.SettingsDaemon.Power.service
/usr/lib/systemd/user/org.gnome.SettingsDaemon.Power.target

$ cat /usr/lib/systemd/user/org.gnome.SettingsDaemon.Power.service
[Unit]
Description=GNOME power management service
CollectMode=inactive-or-failed
RefuseManualStart=true
RefuseManualStop=true
After=gnome-session-initialized.target
# Requisite/PartOf means the dependency is not loaded automatically.
# The ordering here also implies Before=gnome-session.target
Requisite=org.gnome.SettingsDaemon.Power.target
PartOf=org.gnome.SettingsDaemon.Power.target
Before=org.gnome.SettingsDaemon.Power.target

[Service]
Slice=session.slice
Type=dbus
ExecStart=/usr/libexec/gsd-power
Restart=on-failure
BusName=org.gnome.SettingsDaemon.Power
TimeoutStopSec=5
# We cannot use OnFailure as e.g. dependency failures are normal
# https://github.com/systemd/systemd/issues/12352
ExecStopPost=/usr/libexec/gnome-session-ctl --exec-stop-check

I then noticed the org.gnome.SettingsDaemon.Power.service is actually a "user" unit, not a system-wide one:

$ systemctl list-unit-files | grep Power
# Nothing.
$ systemctl --user list-unit-files | grep Power
org.gnome.SettingsDaemon.Power.service     static    -
org.gnome.SettingsDaemon.Power.target      static    -
$ systemctl --user status org.gnome.SettingsDaemon.Power.service
● org.gnome.SettingsDaemon.Power.service - GNOME power management service
     Loaded: loaded (/usr/lib/systemd/user/org.gnome.SettingsDaemon.Power.service; static)
     Active: active (running) since Sun 2021-08-01 12:45:57 CEST; 6h ago
   Main PID: 7843 (gsd-power)
     CGroup: /user.slice/user-1000.slice/[email protected]/session.slice/org.gnome.SettingsDaemon.Power.service
             └─7843 /usr/libexec/gsd-power

Aug 01 12:45:57 aorus systemd[2523]: Starting GNOME power management service...
Aug 01 12:45:57 aorus systemd[2523]: Started GNOME power management service.
Aug 01 13:14:16 aorus gsd-power[7843]: gsd_power_backlight_abs_to_percentage: assertion 'max > min' failed

I tried to "purge" gnome-settings-daemon:

apt purge --dry-run gnome-control-center gnome-settings-daemon | grep -Po '^Purg \K[^ ]+' | tee /tmp/to-be-reinstalled-after
sudo apt purge gnome-control-center gnome-settings-daemon
sudo apt install $(cat /tmp/to-be-reinstalled-after)

The "Suspend & Power Button" section reappears... Unfortunately, it consistently disappears after a system reboot, both with 21.04 and 21.10.

Note that The equivalent gsettings of the above "Power Button Behavior" dropdown menu is:

gsettings set org.gnome.settings-daemon.plugins.power power-button-action suspend

I also tried going into the X570 Gygabyte Aorus BIOS, and set the option "Soft-off by PWR-BTTN" to "Delay 4 Sec." but it did not do anything:

bios-x570-aorus

Another symptom is that when I click "Suspend" in the top-right corner menu, I get the message Authentication is required to suspend the system. It looks like this:

Screenshot from 2021-08-01 14-03-19Screenshot from 2021-08-01 14-01-56

I followed the instructions in the thread Authentication required before suspend:

sudo vim /usr/share/polkit-1/actions/org.freedesktop.login1.policy
         <action id="org.freedesktop.login1.suspend">
                 <description gettext-domain="systemd">Suspend the system</description>
                 <message gettext-domain="systemd">Authentication is required to suspend the system.</message>
                 <defaults>
-                        <allow_any>auth_admin_keep</allow_any>
+                        <allow_any>yes</allow_any>
                         <allow_inactive>auth_admin_keep</allow_inactive>
                         <allow_active>yes</allow_active>
                 </defaults>
         </action>
         <action id="org.freedesktop.login1.suspend-multiple-sessions">
                 <description gettext-domain="systemd">Suspend the system while other users are logged in</description>
                 <message gettext-domain="systemd">Authentication is required to suspend the system while other users are logged in.</message>
                 <defaults>
-                        <allow_any>auth_admin_keep</allow_any>
+                        <allow_any>yes</allow_any>
                         <allow_inactive>auth_admin_keep</allow_inactive>
                         <allow_active>yes</allow_active>
                 </defaults>
                 <annotate key="org.freedesktop.policykit.imply">org.freedesktop.login1.suspend</annotate>
         </action>

And it works!! Clicking on "Suspend" started working, as well as the "Power" settings! Screenshot on Ubuntu 21.04:

127780728-12f951a8-a351-4ff7-81c8-37c35cb53df5

Screenshot on Ubuntu 21.10: Screenshot from 2021-11-14 12-03-02

Issue after using my own patched firmware version:

cp: cannot stat '/lib/firmware/updates/amdgpu': No such file or directory
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_gpu_info.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_gpu_info.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_toc.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_asd.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_ta.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_asd.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_sos.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_rlc.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_mec2.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_mec.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_rlc.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_mec2.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_mec.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_me.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_pfp.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_ce.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_sdma.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_sdma.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/sienna_cichlid_mes.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/navi10_mes.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_vcn.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_vcn.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/arcturus_smc.bin for module amdgpu

After installing my own patched firmware, I had forgotten to run

sudo update-initramfs -k all -u -v

Source: https://askubuntu.com/questions/1124253/missing-firmware-for-amdgpu

Disable unwanted mics (like my webcam's mic) to avoid them to be picked

pactl list short modules | grep -i kiyo | awk '{print $1}' | xargs --no-run-if-empty pactl unload-module

Use X11 from containers

Run a container with the X11 unix socket mounted:

docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY -h $HOST -v $HOME/.Xauthority:$HOME/.Xauthority -it --rm ubuntu:xenial

Then:

apt update
apt install -y software-properties-common
add-apt-repository -y ppa:beineri/opt-qt562-xenial
apt update
apt install -y qt56base qt56tools qt56svg git cmake g++ mesa-common-dev libglu1-mesa-dev qt56x11extras extra-cmake-modules
cd
git clone https://github.com/ksnip/kImageAnnotator
git -C kImageAnnotator checkout v0.2.1
git clone https://github.com/ksnip/kColorPicker
git -C kColorPicker checkout v0.1.1
git clone https://github.com/ksnip/ksnip
git -C ksnip checkout f8800719
export CMAKE_PREFIX_PATH=/opt/qt56
(cd ~/kColorPicker && mkdir -p build && cd build && cmake .. && make -j32 && make install && cd ~/kImageAnnotator && mkdir -p build && cd build && cmake .. && make -j32 && make install && cd ~/ksnip && mkdir -p build && cd build && cmake .. && make -j32 && make install)

Debug pulseaudio

sudo vim /usr/lib/systemd/user/pulseaudio.service
-ExecStart=/usr/bin/pulseaudio --daemonize=no
+ExecStart=/usr/bin/pulseaudio --daemonize=no --log-target=journal
systemctl restart --user pulseaudio

Plex + Tailscale

From https://gist.github.com/churro-s/fa3fdeb5cf10ebb251aa88338b8b37db:

sudo tailscale cert --cert-file aorus.crt --key-file aorus.key aorus.beluga-pangolin.ts.net
sudo openssl pkcs12 -export -out certificate.pfx -inkey aorus.key -in aorus.crt -passout pass:
sudo mv certificate.pfx /var/lib/plexmediaserver/certificate.pfx
sudo chown plex:plex /var/lib/plexmediaserver/certificate.pfx

Timeshift does not launch

$ timeshift-launcher
==== AUTHENTICATING FOR in.teejeetech.pkexec.timeshift-gtk ===
Authentication is required to run Timeshift as Administrator
Authenticating as: Mael Valais,,, (mvalais)
Password:
polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized

This incident has been reported.

Solution: skip pkexec by using sudo:

sudo timeshift-launcher

Copy-paste broken in Tmux

Select + Y does not copy in tmux. No error is printed anywhere; in order to debug the issue, I had to use xclip directly:

$ xclip -selection clipboard <<<"foo"
Error: can't open display: (null)

But the following works:

DISPLAY=:0 xclip -selection clipboard <<<"foo"

Workaround: exit tmux and re-launch.

Another problem with y when copying in vi mode (after Ctrl + ]): the selection would get cancelled and I would loose the selection as well as return to the prompt.

The solution was to add to ~/.tmux.conf:

run -b 'tmux bind -t vi-copy y copy-selection -x 2> /dev/null || true'
#                                             ^^
#                                            THIS

The -x option in copy-selection -x prevents exiting copying mode (see changes).

Zsh Shell history

Merge my remote history to my local machine:

# aorus -> mbp-mael:
rsync --compress aorus:.zsh_hist /tmp/hist && builtin fc -R -I /tmp/hist && builtin fc -W ~/.zsh_hist

# mbp-mael -> aorus:
rsync --compress mbp-mael:.zsh_hist /tmp/hist && builtin fc -R -I /tmp/hist && builtin fc -W ~/.zsh_hist

Avoid having your ~/.zsh_history being trimmed by another zsh that has a lower HISTSIZE: just use a different HISTSAVE name! In my case, I have in my zshrc:

# Remeber that oh-my-zsh is also setting HISTSIZE. So I have
# to keep these at the end of zshrc to avoid being overwritten.
# I had to set another HISTFILE due to the fact that (somehow) the
# ~/.zsh_history would get emptied for no reason, probably due to $HOME not
# being set? It seems to always happen after a Time Machine backup?
# See: https://unix.stackexchange.com/questions/568907/why-do-i-lose-my-zsh-history
HISTFILE=~/.zsh_hist
HISTSIZE=500000
SAVEHIST=500000
setopt EXTENDED_HISTORY

Watch out though. I found out that above 250000 entries, zsh-navigation-tools's n-history (ctrl + R) started crashing with a segfault.

To avoid this problem, I thought about decreasing HISTSIZE (i.e., the number of lines loaded into memory). But after some attempts, I managed to work around the segfaults by using:

HISTCONTROL=ignoredups:erasedups

A lot less lines are loaded to memory:

$ history | wc -l
183667

$ cat ~/.zsh_hist | wc -l                      
243789

$ du -h ~/.zsh_hist              
12M     /home/mvalais/.zsh_hist

Ubuntu does not wake up

Symptoms: when in sleep mode, clicking or pressing a key on the keyboard or pressing the power button on the tower does nothing. The power light is turned on, the fans are spinning, the screen does not turn on.

Looking at the logs:

$ journalctl --boot=-1
Nov 26 14:06:06 aorus systemd-logind[2353]: Power key pressed.
...
Nov 26 14:09:37 aorus kernel: fbcon: Taking over console
Nov 26 14:09:37 aorus kernel: [drm:dc_dmub_srv_wait_idle [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
...
Nov 26 14:11:07 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
Nov 26 14:11:07 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error queuing DMUB command: status=2
Nov 26 14:11:07 aorus kernel: [drm:dc_dmub_srv_wait_idle [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
Nov 26 14:11:07 aorus kernel: [drm] enabling link 0 failed: 15
Nov 26 14:11:07 aorus dbus-daemon[2332]: [system] Failed to activate service 'org.freedesktop.nm_dispatcher': timed out (service_start_timeout=25000ms)
Nov 26 14:11:12 aorus kernel: [drm] Failed to add display topology, DTM TA is not initialized.
Nov 26 14:11:12 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
Nov 26 14:11:12 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error queuing DMUB command: status=2
Nov 26 14:11:12 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
Nov 26 14:11:12 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error queuing DMUB command: status=2
Nov 26 14:11:13 aorus kernel: [drm:dc_dmub_srv_wait_idle [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
Nov 26 14:11:18 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
Nov 26 14:11:18 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error queuing DMUB command: status=2
Nov 26 14:11:18 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
Nov 26 14:11:18 aorus kernel: [drm:dc_dmub_srv_cmd_queue [amdgpu]] *ERROR* Error queuing DMUB command: status=2
Nov 26 14:11:18 aorus kernel: [drm:dc_dmub_srv_wait_idle [amdgpu]] *ERROR* Error waiting for DMUB idle: status=3
Nov 26 14:11:33 aorus kernel: [drm:drm_atomic_helper_wait_for_flip_done [drm_kms_helper]] *ERROR* [CRTC:77:crtc-0] flip_done timed out
...
Nov 26 14:30:00 aorus gnome-shell[9196]: amdgpu: The CS has been rejected, see dmesg for more information (-19).
Nov 26 14:30:00 aorus kernel: amdgpu: Move buffer fallback to memcpy unavailable
Nov 26 14:30:00 aorus kernel: [drm:amdgpu_cs_ioctl [amdgpu]] *ERROR* Failed to process the buffer list -19!
Nov 26 14:33:07 aorus systemd-logind[2353]: Power key pressed.

Keep my main PC from sleeping when I ssh into it

When working from outside, I use something like:

sudo tee /usr/local/bin/inhibit-sleep-for-ssh <<'EOF' && sudo chmod +x /usr/local/bin/inhibit-sleep-for-ssh
#!/bin/bash
# https://bbs.archlinux.org/viewtopic.php?pid=1891257#p1891257
sudo systemd-inhibit --what sleep --why "Do not sleep while $SSH_TTY session is active" sleep infinity &
INHIBIT_PID=$!
if [ -z "$SSH_ORIGINAL_COMMAND" ]; then
  $SHELL
else
  $SSH_ORIGINAL_COMMAND
fi
sudo kill $INHIBIT_PID
EOF

sudo tee /etc/sudoers.d/inhibit-sleep-for-ssh <<EOF
%admin ALL = NOPASSWD: /usr/local/bin/inhibit-sleep-for-ssh
EOF

sudo tee /usr/local/bin/inhibit-sleep-for-ssh-shim <<'EOF' && sudo chmod ago+x /usr/local/bin/inhibit-sleep-for-ssh-shim
#!/bin/bash
sudo /usr/local/bin/inhibit-sleep-for-ssh
EOF

Then, add the line in /etc/ssh/sshd_config:

ForceCommand /usr/local/bin/inhibit-sleep-for-ssh

Take a screenshot of a Youtube video for embedding in Markdown

  1. Take the video slug. In the following, -a46Z_CI0_Q is the video slug.

  2. Copy the "embed" link: https://www.youtube.com/embed/-a46Z_CI0_Q?hl=en

  3. Go to https://www.site-shot.com/

  4. Select 1280x720 + JPEG quality instead of PNG:

    Screenshot from 2021-12-22 21-48-58

  5. Right click on image, download image.

  6. Use the command:

    tinypng -k $(lpass show -p tinypng) download.jpeg

gsettings does not seem to work

At some point, I did not understand why gsettings wasn't doing anything. I realized later that I had glib installed through Homebrew and that it came with its own gsettings, and it was shadowing the system gsettings.

I just did

brew unlink glib

and gsettings started working again.

Login loops inifinitely, "unable to locate daemon control file"

After waking up from being suspended:

foo.mp4

I was getting:

$ sudo journalctl -u gdm --follow
Jan 04 11:04:29 aorus gdm-password][215110]: gkr-pam: unable to locate daemon control file
Jan 04 11:04:29 aorus gdm-password][215110]: gkr-pam: stashed password to try later in open session
Jan 04 11:04:29 aorus gdm-password][215110]: pam_unix(gdm-password:session): session opened for user mvalais by (uid=0)
Jan 04 11:04:29 aorus gdm-password][215110]: gkr-pam: gnome-keyring-daemon started properly and unlocked keyring

IMG_0312_2

To fix that, I ran:

sudo apt reinstall libpam-gnome-keyring
sudo systemctl restart gdm.service
pkill gnome-keyring-daemon

And it started working again.

Cannot log in to the Ubuntu purple screen

cannot-login-ubuntu-21-10-purple-screen.mp4

Logs:

Screenshot from 2022-01-10 11-21-02

Solution:

ulimit -n 1000000
sudo apt reinstall libpam-gnome-keyring
sudo systemctl restart gdm.service

Ssh agent forward does not work in tmux

This also affects pbcopy, pbpaste, xclip.

Solution as explained in this gist:

  1. In ~/.tmux.conf.local (since I use gpakosz/.tmux.git)

    setenv -g SSH_AUTH_SOCK $HOME/.ssh/ssh_auth_sock
    setenv -g DISPLAY $DISPLAY
    set -g update-environment -r
  2. In ~/.ssh/rc:

    if test "$SSH_AUTH_SOCK" ; then
        ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
    fi

Kiyo exposition and gain

Before:

before

After:

after

v4l2-ctl --set-ctrl exposure_auto=1 \
    --set-ctrl exposure_absolute=2047 \
    --set-ctrl gain=45 \
    --set-ctrl exposure_auto_priority=0 \
    --set-ctrl power_line_frequency=1 \
    --set-ctrl zoom_absolute=120
  • exposure_auto=1: the power line is set to 50Hz since I live in France.
  • zoom_absolute=120: I use a 20% zoom

The whole list of parameters:

$ v4l2-ctl --list-ctrls-menus
                     brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
                       contrast 0x00980901 (int)    : min=0 max=255 step=1 default=128 value=128
                     saturation 0x00980902 (int)    : min=0 max=255 step=1 default=128 value=128
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                           gain 0x00980913 (int)    : min=0 max=255 step=1 default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=2 value=2
                                0: Disabled
                                1: 50 Hz
                                2: 60 Hz
      white_balance_temperature 0x0098091a (int)    : min=2000 max=7500 step=10 default=4000 value=4000 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=255 step=1 default=128 value=128
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=0 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
                                1: Manual Mode
                                3: Aperture Priority Mode
              exposure_absolute 0x009a0902 (int)    : min=3 max=2047 step=1 default=127 value=2047 flags=inactive
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=0
                   pan_absolute 0x009a0908 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                  tilt_absolute 0x009a0909 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                 focus_absolute 0x009a090a (int)    : min=0 max=255 step=1 default=0 value=0 flags=inactive
                     focus_auto 0x009a090c (bool)   : default=1 value=1
                  zoom_absolute 0x009a090d (int)    : min=100 max=140 step=10 default=100 value=100

Set the correct mic and bluetooth headphones

# Disable the annoying Kiyo microphone.
pactl list short modules | grep -i kiyo | awk '{print $1}' | xargs --no-run-if-empty pactl unload-module

pactl list cards short | grep -i 'bluez' | awk '{print $2}' | tee /dev/stderr | xargs -I@ --no-run-if-empty pactl set-card-profile @ a2dp_sink
pactl list sources short | grep -i 'alsa_input.*Yeti' | awk '{print $2}' | tee /dev/stderr | xargs --no-run-if-empty pactl set-default-source
pactl list sources short | grep -i 'alsa_input.*Yeti' | awk '{print $2}' | tee /dev/stderr | xargs -I@ --no-run-if-empty pactl set-source-volume @ 70%
pactl list sinks short | grep -i 'bluez' | awk '{print $2}' | tee /dev/stderr | xargs --no-run-if-empty pactl set-default-sink

Raise the ulimit -n (file descriptors)

sudo vim /etc/security/limits.conf

and add the line:

*               -       nofile           1000000

Then, make sure these limits are loaded by adding the following line to /etc/pam.d/common-session:

session required pam_limits.so

You can see the number of files open:

# WARNING: this command gives the wrong numbers. See below command.
sudo lsof 2>/dev/null | awk '{print $1,$2}' | sort | uniq -c --skip-fields=1 | sort -n | tail -20
# This command should give accurate results.
for pid in /proc/[0-9]*; do echo $(sudo ls $pid/fd 2>/dev/null | wc -l) $(ps -p $(basename $pid) -o comm=); done | awk '{of[$2]+=$1} END {for (name in of) printf("%4d %s\n", of[name], name)}' | sort -n | awk '{sum+=$1; print $0} END {printf("files open: %d\n", sum)}' | tail -10

In my case, I had 3 k3s clusters running:

   1852 kubelet 12072
   2090 container 2600
   2136 chrome-re 4327
   2223 libvirtd 2574
   3325 Plex\x20M 6474
   3420 Xwayland 4148
   3783 container 10004
   3838 kube-apis 13813
   3939 etcd 13716
   4512 vsls-agen 26195
   4992 ibus-x11 5276
   5031 container 10236
   5712 container 10335
   6600 container 10361
   9125 dockerd 6430
  21471 gnome-she 2798
  22518 k3s 156648
  36309 k3s 9259
  37201 k3s 9694
  39672 k3s 9867

With the second command:

  24 tailscaled
  25 gnome-software
  26 goa-daemon
  27 gsd-keyboard
  27 tmux:
  28 acpid
  28 evolution-calen
  28 gjs
  28 libvirtd
  29 gsd-power
  29 ibus-x11
  29 NetworkManager
  30 ibus-daemon
  33 bluetoothd
  34 dnsmasq
  37 gsd-color
  42 gnome-session-b
  42 pipewire-media-
  45 obs
  46 gsd-media-keys
  47 xdg-desktop-por
  49 dockerd
  54 systemd-logind
  60 postgres
  62 containerd
  66 gopls
  68 pipewire
  68 sh
  73 chrome-remote-d
  79 gnome-calendar
  92 containerd-shim
  92 dropbox
 104 gnome-shell
 111 zsh
 115 tracker-miner-f
 129 Xorg
 143 pulseaudio
 163 deno
 193 systemd-journal
 262 vsls-agent
 332 dbus-daemon
 336 Discord
 338 systemd
 370 k3s
 418 spotify
 481 slack
1241 code
1316 nginx
1907 chrome
files open: 10765

which makes much more sense and is in the same ball park as what /proc/sys/fs/file-nr shows.

$ cat /proc/sys/fs/file-nr
24832   0   9223372036854775807
<--->       <---------------->
open          max open files
files         
$ ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-m: resident set size (kbytes)      unlimited
-u: processes                       127786
-n: file descriptors                1024           <---
-l: locked-in-memory size (kbytes)  4098764
-v: address space (kbytes)          unlimited
-x: file locks                      unlimited
-i: pending signals                 127786
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 0
-N 15:                              unlimited

On every Ubuntu upgrade, the contents of some of the files in /etc are overridden, for example /etc/pam.d/common-session gets reset, which means the limits set in /etc/security/limits.conf are not properly loading anymore. You shall do:

sudo vim /etc/pam.d/common-session

and then add the following line at the end:

session required pam_limits.so

What bewieldered me is that /proc/sys/fs/file-max said 100,000 but the actual number was much lower, around 12,000. I think it comes from the fact that the "systemd --user" process is launched after the limit is raised to 100,000 or something like that.

htop-sbin-init-splash lib-systemd-systemd-user

The process /lib/systemd/systemd --user is the "login" process which probably has picked up the limit of 10,000 instead of the limit of 100,000:

$ cat /proc/$(ps -aux | grep -v grep | grep "^$USER.*/lib/systemd/systemd --user" | awk '{print $2}')/limits | grep 'Max open files'
Max open files            500000               500000               files

Another weirdness is that sometimes I would get a very large number when reading /proc/sys/fs/file-max:

$ cat /proc/sys/fs/file-max
9223372036854775807

I finally managed to find why kube-proxy kept crashing with "too many open files":

sudo sysctl -w fs.inotify.max_user_watches=524288
sudo sysctl -w fs.inotify.max_user_instances=512

k3s boot loop

Another symptom of having the number of file descriptors used is this:

k3d cluster create
docker logs k3d-test-cluster-server-0
time="2022-01-21T11:45:53Z" level=info msg="Waiting for control-plane node k3d-test-cluster-server-0 startup: nodes \"k3d-test-cluster-server-0\" not found"
time="2022-01-21T11:45:53Z" level=info msg="Waiting for containerd startup: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService"
time="2022-01-21T11:45:54Z" level=info msg="Waiting for control-plane node k3d-test-cluster-server-0 startup: nodes \"k3d-test-cluster-server-0\" not found"
time="2022-01-21T11:45:54Z" level=info msg="Waiting for containerd startup: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService"
time="2022-01-21T11:45:55Z" level=info msg="Waiting for control-plane node k3d-test-cluster-server-0 startup: nodes \"k3d-test-cluster-server-0\" not found"
time="2022-01-21T11:45:55Z" level=info msg="Waiting for containerd startup: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService"
time="2022-01-21T11:45:56Z" level=info msg="Waiting for control-plane node k3d-test-cluster-server-0 startup: nodes \"k3d-test-cluster-server-0\" not found"

This error does not depend on the image tag. The error suggests that containerd is partially failing.

$ docker exec -it k3d-k3s-default-server-0 containerd
WARN[2022-01-21T12:29:24.283897088Z] failed to load plugin io.containerd.grpc.v1.cri 
  error="failed to create CRI service: failed to create cni conf monitor:
    failed to create fsnotify watcher: too many open files"

sendmail + Gmail

Actually, don't use sendmail. Use msmtp instead: https://maelvls.dev/notes/msmtp_mutt/, but follow this instead: https://wiki.archlinux.org/title/msmtp

  1. Add "App password" in https://myaccount.google.com/apppasswords,
  2. Save it in lpass.

I had the following:

sh: 1: /usr/bin/lpass: Permission denied

This was fixed thanks to this stackoverflow thread:

sudo ln -s /etc/apparmor.d/usr.bin.msmtp /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.bin.msmtp 

Google Remote Desktop, Ubuntu 22.04

  • Click "(default) Open a default XSession"
  • Then follow the GIF:

2022-05-12 14 23 09

To exit the XSession, get a terminal (e.g. "open with" a file with VSCode and open the integrated terminal), and run pkill Xorg.

Other method:

  • Click "Open an Ubuntu on Xorg",
  • You should see this:

Screenshot 2022-05-12 at 14 49 29 Large

One by Wacom, cursor is off on Qt/KDE apps

I use ksnip to annotate images. When using One by Wacom, the cursor is totally off from where the click is registered, making it impossible to draw.

Workaround:

When running from the terminal, use:

QT_XCB_TABLET_LEGACY_COORDINATES="" ksnip

When running from the .desktop entry, find all ksnip.desktop entries with the command:

locate ksnip.desktop

and for each of them, edit:

-Exec=ksnip
+Exec=env QT_XCB_TABLET_LEGACY_COORDINATES="" ksnip

OVMD

QEMU for arm64:

sudo vim /etc/libvirt/qemu.conf 
nvram = [
 "/usr/share/OVMF/OVMF_CODE.fd:/var/lib/libvirt/images/OVMF_VARS_writable.fd"
]

1password 8 and Biometric signin

Using op 2.7.1:

$ op signin
[ERROR] 2022/09/26 10:13:25 connecting to desktop app: read: connection reset, make sure the CLI is correctly installed and CLI Biometric Unlock is enabled in the 1Password app

What I used to install op:

curl -L https://cache.agilebits.com/dist/1P/op2/pkg/v2.7.1/op_linux_amd64_v2.7.1.zip -o /tmp/op.zip && (cd /tmp; rm -rf op; unzip -o op.zip) && sudo mv /tmp/op /usr/local/bin && sudo chown root:onepassword-cli /usr/local/bin/op && sudo chmod g+s /usr/local/bin/op

Not sure why this error shows up.

VNC, remote access

 x0vncserver -localhost no -passwordfile ~/.vnc/passwd -display :0

Clash between Docker networks and VPN

Both use 172.17.0.0/16.

sudo vim /etc/docker/daemon.json

and set:

{
  "default-address-pools": [
    { "base": "172.42.0.1/16", "size": 16 },
    { "base": "172.43.0.1/16", "size": 16 },
    { "base": "172.44.0.1/16", "size": 16 }
  ]
}

Now, restart Docker:

sudo systemctl restart docker

Sync my ~/bin across machines

macOS version:

(cd ~/bin; find . -d 1 -type f | xargs file | grep 'text' | cut -d: -f1 \
  | rsync --files-from=- --update --times -v --archive --compress . aorus:bin)

Linux version:

(cd ~/bin; find . -maxdepth 1 -type f | xargs file | grep 'text' | cut -d: -f1 \
  | rsync --files-from=- --update --times -v --archive --compress . wksmac151474:bin)

Mouse pointer stutters (Logitech MX Master 1)

out.mp4

No idea how to fix this. Since I am using the built-in USB stick that comes with the mouse, it might mean that something (USB-C?) is interfering.

Chrome can't use the camera

Often, after using OBS, Chrome can't use the Kyio camera.

I found that it kind of work again with:

pkill obs
sudo modprobe -r uvcvideo && sudo modprobe uvcvideo

Allow shutdown from an SSH session

I need to be able to shutdown the machine remotely. I followed the Polkit guide at:

How can I make shutdown not require admin password? - Ask Ubuntu

sudo tee /etc/polkit-1/localauthority/50-local.d/allow_all_users_to_shutdown.pkla <<'EOF'
[Allow all users to shutdown]
Identity=unix-user:*
Action=org.freedesktop.consolekit.system.stop-multiple-users
ResultInactive=no
ResultActive=yes
EOF
sudo tee /etc/polkit-1/localauthority/50-local.d/allow_all_users_to_restart.pkla <<'EOF'
[Allow all users to restart]
Identity=unix-user:*
Action=org.freedesktop.consolekit.system.restart-multiple-users
ResultInactive=no
ResultActive=yes
EOF

UPDATE: In the end, I went with password-less sudo; I've added to /etc/sudoers:

mvalais ALL = (ALL)NOPASSWD:ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment