Improved Hibernation (s2disk) HDD Performance and less SSD aging

I still like to use HDDs. And in most scenarios the overall performance on Linux is actually quite good, especially if the computer has lots of RAM. But when it comes to having a lot of RAM some optimizations should be made.

Last year I upgraded my desktop PC to 96 GB of memory (mainly needed when compiling large FOSS). So when the PC hibernates (s2disk or s2both) Linux sets /sys/power/image_size to 2/5 of that by default (~38 GB). So not just process memory gets written to the hibernation image, but also all cached data that fits into 38GB. There’s a slight advantage of having data in the hibernation image because it’s compressed and written to the HDD in one block, resulting in a better performance then re-reading it from arbitrary locations. But a 38 GB hibernation image is clearly too much when my system is usually at 8 GB RAM usage before I hibernate it.

And on my Notebook which has an SSD and 32 GB RAM it seems even more reasonable not to write cached data into the hibernation image. On an SSD such data can be quickly reread from it’s actual location and copying it to the hibernation image just ages the SSD.

So I came up with these two files :-)

/etc/scripts/before_s2both_s2disk.bash

#!/bin/bash

sync

# ==== IMPORTANT: USE ON SSDs ====
# # Don't write cache to swap image.
# # On SSDs it'll just age the SSDs.
# sync
# echo 1 > /proc/sys/vm/drop_caches

# ==== IMPORTANT: USE ON HDDs ====
# Write only the latest cache to the compressed hibernation image.
# Will provide optimal suspend/resume speed when often doing s2disk/s2both on HDDs.
used=$(LC_ALL=C free -b | grep '^Mem:' | tr -s ' ' | cut -d' ' -f3)
echo $((used + 4 * 1024**3)) > /sys/power/image_size
# default: 2/5 of the RAM size
# check => start before shutdown: dmesg -w | grep 'PM: hibernation: Wrote'

/etc/systemd/system/before-s2both-s2disk.service

[Unit]
Description=Runs before s2both and s2disk
# Before: in which position of the sleep transaction order the command is being run
#   sleep.target places it definitely before the system goes to sleep
Before=sleep.target
# systemctl get-default => graphical.target
# Run to enable and after changing this section:
#   systemctl enable before-s2both-s2disk.service

[Service]
Type=oneshot
ExecStart=/etc/scripts/before_s2both_s2disk.bash

[Install]
# WantedBy: which actions trigger the unit, but NOT when
WantedBy=hibernate.target hybrid-sleep.target suspend-then-hibernate.target

Connecting Terminals to Untrusted Servers

I recently thought about risks when connecting to an untrusted SSH server. For example a badly maintained server you’re supposed to do work on. This is what I came up with.

This is made with SSH in mind. But it may also apply to other methods of connecting terminals like serial connections or Telnet.

Using Wayland would be a benefit here. But it would need another terminal application instead of xterm. And for the moment I’m still an X11 person.

#!/bin/bash

# License: AGPLv3


SRV_ADDR="${1}"
# e.g.: '-p50022 root@127.0.0.1'

LC_ALL=C setsid --fork xterm \
  -xrm 'XTerm*allowTitleOps: false' \
  -xrm 'XTerm*allowFontOps: false' \
  -xrm 'XTerm*allowTcapOps: false' \
  -xrm 'XTerm*allowColorOps: false' \
  -xrm 'XTerm*fontDoublesize: false' \
  -xrm 'XTerm*allowMouseOps: false' \
  -xrm 'XTerm*VT100.translations: #override Ctrl Shift C: copy-selection(CLIPBOARD) \n'\
'Ctrl Shift V: insert-selection(CLIPBOARD)' \
  -fn 9x15 \
  -maximized \
  -e 'bwrap '\
'   --unshare-all --share-net --die-with-parent '\
'   --ro-bind /usr /usr '\
'   --symlink /usr/lib /lib '\
'   --symlink /usr/lib64 /lib64 '\
'   --ro-bind /etc/ld.so.cache /etc/ld.so.cache '\
'   --ro-bind /etc/resolv.conf /etc/resolv.conf '\
'   --ro-bind /etc/passwd /etc/passwd '\
'   --dev /dev '\
'   --dir "${HOME}/.ssh" '\
'   --ro-bind "${HOME}"/.ssh/id_ed25519_untrusted-server '\
'     "${HOME}"/.ssh/id_ed25519_untrusted-server '\
'   --clearenv --setenv HOME "${HOME}" --setenv TERM "${TERM}" -- '\
'     ssh -i ~/.ssh/id_ed25519_untrusted-server '\
'     -F /dev/null -ax -o SetEnv=LC_ALL=C '\
'     -o PasswordAuthentication=no '\
'     -o KbdInteractiveAuthentication=no '\
'     -o UpdateHostKeys=no '\
'     '"${SRV_ADDR}"' || cat'
# no extra quotes around SRV_ADDR to expand it

How to compile LibreOffice Windows builds for Unix nerds

I recently needed to compile LibreOffice for Windows. And LibreOffice is relying on the MSVC compiler for that, so the straightforward way is to boot up a Windows.
If you have a nice howto for running Visual Studio under Wine / CrossOver / Proton, feel free to send me a link 😉
I’ve heard there used to be MinGW support. But it was dumped because it was ABI incompatible and maintaining two build setups was too much work.

Since I mostly work on Debian GNU/Linux since many years, I had quite some aversion clicking trough Windows setup wizards. I’m trying to keep this howto as short as possible. So here’s the solution I ended up with. Weiterlesen →

VRAM and Memory for Integrated Graphics with Linux

I got two HP EliteBook notebooks with a Ryzen CPU, featuring an integrated GPU (AMD term „APU“). The BIOS offers a setting to configure the VRAM between 256 MB and 2048 MB on the one, 512 MB on the other notebook. So I wondered what happens when the GPU required more than the dedicated VRAM. There is some information about what happens on Windows in the WWW. But I like my Linux system, so I spend some time finding out what’s happening there. Weiterlesen →

User Mode Linux (UML)

UML (User Mode Linux) is a nice way for Linux virtualization. Somewhere between containers and full or paravirtualization. But without actually using a visualizer / hypervisor.

Unfortunately UML not so well documented. So I dumped some of my notes here.
Weiterlesen →

Ein Cubieboard 2 (A20)

Mein neuestes Spielzeug ist ein Cubieboard 2 mit A20-ARM Prozessor.
http://cubieboard.org/2013/06/19/cubieboard2-is-here/
https://de.wikipedia.org/wiki/Cubieboard
Nicht zu verwechseln mit dem Cubieboard (ohne 2) mit A10 Prozessor. Der Unterschied Cubieboard (A10) zum Raspberry Pi (Model B mit 512 MB RAM) ist eher gering (bis auf dem SATA-Anschluss des Cubieboards).
http://www.raspberrypi.org/faqs
Das Cubieboard 2 (A20) hat aber einen DualCore-Prozessor und 1 GB RAM (und ebenfalls SATA). Neben dem Cubieboard 2 wird es demnächst wohl auch den noch leistungsfähigeren Cubietruck (2 GB RAM) geben. So lange wollte ich aber nicht warten.
http://cubieboard.org/2013/09/14/cubietruck-is-put-into-trial-production/
Weiterlesen →

Hardware für Linux

Wer ein Linux-Notebook oder -Computer hat steht immer mal wieder vor der Frage: Welche Hardware soll ich mir kaufen, damit Sie gut mit meinem Linux funktioniert. Eine Hilfe bei diesem Problem soll der folgende Artikel geben. Weiterlesen →