Alla inlägg av Ichimusai

Set netplan to use network-manager

Network manager has been working reasonably well in Ubuntu and other Debian derivatives for quite some time and then Canonical changes to netplan. This is causing some confusion and is clearly seen by many (myself included) as a step backwards.

The original configuration file residing in /etc/netplan/01-netcfg.yaml contains the following:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s31f6:
      dhcp4: yes

This leads to the conclusion that reversion to network-manager with its text based interface (nmtui) etc might not be so easy but actually it is. Change the configuration file in netplan to the following:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
# Set and change netplan renderer to NetworkManager GUI tool 
network:
  version: 2
  renderer: NetworkManager

When done don’t forget to apply the changes to netplan:

$ sudo netplan apply

This takes care of the problem and now you can re-install network-manager with whatever interface you want to use and handle all your network interfaces through that instead.

Standard Linux installation script V1.0

This script installs some stuff I pretty much always need. It can be invoked with -d for desktop configuration in Ubuntu as well as -t for adding documentation and text utilities I use often.

Oh and it will also install zsh as your default shell including oh-my-zsh and the ’afowler’ theme.

Can easily be adapted to anything really.

# First update the system
sudo apt -y update
sudo apt -y upgrade

# General tools that is good to have for all systems
sudo apt -y install build-essential emacs git htop atop tmux byobu \
     zsh borgbackup wget curl nmap net-tools traceroute mtr mosh \
     irssi mc mg vim rsync rclone

# Oh my zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Set the good theme
sed -i 's/robbyrussell/afowler/' ~/.zshrc

while getopts hdm arg; do
    case "${arg}" in
    h)
        echo "Usage: install [options]"
        echo
        echo "-d      Install standard desktop tools needed."
        echo "-t      Text, documentation and LaTeX tools"
        ;;
    d)
        # Only if we have a desktop, othrwise skip
        sudo apt -y install dconf-editor gnome-tweaks gparted flameshot
        gsettings set org.gnome.shell.extensions.dash-to-dock extend-height false 
        gsettings set org.gnome.shell.extensions.dash-to-dock dock-position BOTTOM
        ;;
    t)
        # Multimedia stuff (with desktop)
        sudo apt -y install gimp vlc inkscape texlive-all texstudio calibre sigil
        ;;
    *)
        echo "Unknown uptions, use -h for more information."
        ;;
    esac
done

Räkna på energiåtgång varmvatten

I grunden är det ganska enkelt att räkna på hur mycket energi som går åt när vi gör av med varmvatten. Det finns några grundbitar man behöver ha koll på.

Vattnets specifika värmekapacitivitet i flytande form är 4.2 kJ per grad och liter vatten. Nästa steg är att förstå hur mycket vatten som går åt för aktiviteten. I fallet duschning i gammal hederlig dusch som inte snålspolar kanske det går åt ca 12 liter på en minut.

Om vi duschar i 20 minuter blir det totalt en vattenmängd på
12 liter / minut gånger 20 minuter = 240 liter vatten.

Energin vi söker är alltså den energi som åtgår för att värma 240 liter vatten. Nu behöver vi räkna ut hur många grader som vi skall värma vattnet. Om vi antar att vattnet till duschen håller 40°C och vattnet som kommer in i huset håller 6°C vilket inte är helt orimliga värden behöver vattnet värmas 40 – 6 = 34 grader.

Energin för att värma vattnet blir då följande:
240 liter vatten · 36 grader · 4.2 kJ = 36 288 kJ

Joule är samma sak som wattsekunder så för att få det till kilowatttimmar delar vi helt enkelt med 3600 som är antal sekunder i en timme:

36 288 / 3600 = 10.08 kWh

Så nu vet vi att förbrukningen ligger på avrundat 10 kWh för denna duschning. Nästa steg är att beräkna vad det kostar utifrån dagens elpris. Elpriset på nordpool är elhandelspriset, dvs vad elbolaget köper elen för och varierar timme för timme. Under en viss timme kan detta vara t.ex. 460 öre/kWh.

För konsumenten tillkommer sedan alltid elöverföringsavgiften som är oftast 24 eller 30 öre beroende på var man bor, vi kan anta att det är 30 öre i det här fallet. Sedan tillkommer en energiskatt om 36 öre per kWh som staten ska ha in. På det finns också det eventuella påslag som energibolaget gör men det är oftast inte jättestort. Vi kan för formens skull tänka oss 20 öre/kWh. Till sist tillkommer moms med 25 % på hela beloppet. Vi får då:

460 + 30 + 36 = 526 öre/kWh före moms
526 · 1.25 = 657,5 öre/kWh med moms

Vi kan avrunda det till 6 kr och 58 öre för 1 kWh med detta höga priset. Kostnaden för duschningen får vi så genom att multiplicera pricet med antal förbrukade kWh som var 10 stycken:

6:58 kr/kWh · 10 kWh = 65:80 kr

Man kan ganska enkelt göra ett Excelblad över detta om man vill och leka med lite olika siffror för att se vad det blir. Kolla också din senaste elräkning kan du se vad du har för faktiskt överföringsavgift.

After cloning a Ubuntu 22.04 server

Many things have changed from the oh so abundant 18.04 server and there are a few surprises that one needs to be aware of. One thing that has changed is that changing the MAC address no longer changes the ID when the server requests a new IP from a DHCP server.

This means that cloning a server into a new server they will start competing for the same IP address if they are on the same network so there are a few things you need to do before you deploy the new close.

Fix the IP address of the clone

  1. First release the DHCP address the machine has by issuing the command ”dhcpd -r” which should take care of this.
  2. Change the mac address, if you are using bridged network in particular there should not be two network interfaces on the same segment with the same MAC address. This is done in the virtual machine software.
  3. Change the machine-id of the clone. This is done by deleting the file /etc/machine-id and then running the script systemd-machine-id-setup which will create a new one.
  4. Optional: If you would like the system to change the network ID when you change mac address on the NIC then you need to change the following file(s) /etc/netplan/*.yaml and edit this to insert under each of the network interfaces you want to use MAC address as their ID ”dhcp-identifier: mac” then run sudo netplan apply.

Now shutdown the host, change the networking to whatever is needed (bridged most usually) and then restart the system and it should now be assigned a new IP address.

Fix the SSH keys of the clone

Next step is of course to change the cloes SSH keys which is done by deleting the keys in /etc/ssh by issuing the command ”rm /etc/ssh/ssh_host_*” which would delete all of them.

Then regenerate new keys from using the command ”dpkg-reconfigure openssh-server” which will generate all needed keys as if it was fresly installed.

Bevingade ord

Sleep resume in Ubuntu screws up mouse pad

I found that my Lenovo laptops did not always get the mousepad right when coming out of sleep or hibernate. After a bit of research I found that a modprobe remove and insert of the psmouse kernel module did the trick.

To automatize this you can insert a file in the systemd control structure to fix the problem yourself (if you are experiencing it). Below is a block of code. Save this to a file in /lib/systemd/system-sleep/touchpad


#!/bin/bash
# 2019 Täpp-Anders Sikvall
# Reinsert kernel module for mouse pad on lenovo after waking up
# from a sleep or a suspend so that things like gestures work 
# properly
# bugs to anders@sikvall.se
 
case "$1" in
   pre)
     exit 0                  # Do nothing just return
     ;;
   post)
     sleep 3                 # Wait for system to stabilize
     modprobe -r psmouse     # Remove psmouse from kernel
     modprobe psmouse        # Reinsert psmouse to kernel
     exit 0                  # Return no error
     ;;
   *)
     exit 1                  # Normally we should not be here
     ;;                      # but if we are, return error
 esac