Skip to content

Instantly share code, notes, and snippets.

@maelvls

maelvls/README.md

Last active Jul 30, 2021
Embed
What would you like to do?
Linux: things I did while configuring my linux box

Linux tips

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 currently use Ubuntu 21.04 "vanilla".

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 + 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

https://pkgs.tailscale.com/unstable/#ubuntu-focal

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.

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

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
sudo sed -i 's/^Exec=spotify %U$/Exec=spotify --force-device-scale-factor=2.0 %U/' /usr/share/applications/spotify.desktop

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 6700XT

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 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

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

Password prompt keeps popup up

On Ubuntu 21.04, after restoring from a backup (when I had to switch from btrfs to ext4), I kept having this popup:

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment