Some Bits: Nelson's log

62 posts about ubuntu

Another failed Ubuntu 23.04 upgrade

Failed again to upgrade my recalcitrant Ubuntu 23.04 system. I give up and I’m mad at Ubuntu’s EOL policies.

The fun thing is how much some new tools make this kind of thing easier and safer. I had a lot of confidence experimenting thanks to Proxmox and the ability to easy rollback the whole system or restore a backup. I also got a lot further than I thought I would using Claude. These AIs still have a problem that sometimes it confidentally recommends bullshit. But as long as you understand that and evaluate suggestions yourself it’s a lot faster using an AI to find things than searching ordinary docs and forum posts. I tried more things more quickly than I would have without the AI help.

Hacking around GRUB

The problem last time is my system was installed with GRUB referencing a disk in /dev/disk/by-id that no longer exists. When I virtualized the server those IDs got lost. Claude did a great job suggesting various fixes. Some were wrong (like a hallucinated GRUB_DEVICE config) and some were plausible but don’t work (purge and reinstall GRUB). The good suggestion was to use debconf-set-selections to force a reconfig.

echo "grub-efi grub-efi/install_devices select" | sudo debconf-set-selections
dpkg-reconfigure grub-efi-amd64

This forced GRUB to reconfigure the path. It picked /dev/vba1. Not ideal (a UUID path would be better) but should work. And it did! I could reinstall GRUB on my 23.04 system, reboot, the BIOS all seemed happy. Success!

Maybe. After far too much drama upgrading to 23.10 the system then didn’t reboot. It all looked like it worked but the BIOS was no longer happy with what it found for a boot partition. I chickened out at that point and rolled back, gave up.

Ubuntu’s hostile EOL policy

Even though I think I fixed GRUB, I once failed in my attempt to upgrade Ubuntu.

Ubuntu has a clear but obnoxious policy that outside LTS releases, their interim go end of life quickly. 23.04 went EOL on January 25, 2024. The entire lifespan of this release was 8 months and if you don’t upgrade quickly enough, too bad. I’m a little confused why it won’t still let me update to 23.10: it goes EOL in three days. But when I tried I was told “Your Ubuntu release is not supported anymore”. There’s no option to upgrade directly to 24.04 LTS either.

I don’t mind that they EOL releases and don’t offer regular patches. But they really should offer some sort of upgrade path. They kind of do, I’ve upgraded an EOL system once before by hacking the sources.list to point at http://old-releases.ubuntu.com/. But there’s absolutely no tool help for doing that and you are on your own.

This time around I tried just swapping URLs and doing apt full-upgrade. It sure looked like it worked but then the reboot failed, maybe because of a bad update process or maybe because of my weird GRUB situation. Either way, I gave up.

At this point I’m going to give up and use Ubuntu LTS releases only. Which means one release every two years. I guess I’ll use something with rolling releases (Arch or Debian testing) if I need a more updated OS.

And now I’m doubly committed to rebuilding my main home Linux server. I kind of punted on that six months ago when I virtualized it into Proxmox as a whole system. I don’t relish rebuilding it all as lots of little containers but it’s probably a good idea. (Oh joy, now I can update 20 little Ubuntu systems instead of one big one!)

ssh firedrill: patches, fail2ban

Major new ssh vulnerability including a remote root exploit of SSH servers. So far the exploit has only been demonstrated on 32 bit systems and that takes several hours of hammering a race condition. But it’s likely to get worse over time.

The easy fix is to install an update; here’s how to do that in Ubuntu. The openssh release notes are also helpful. They released version 9.8 to fix it. Ubuntu backported that fix to older versions. Unfortunately I have a system stuck at Ubuntu 23.04 which is not getting updates anymore. So I need a temporary workaround.

I went with installing fail2ban. I do not like that system, it’s a gross hack with way too many config options that can completely break your system. But I got it done. The ubuntu fail2ban by default doesn’t ban anything (I think). You copy jail.conf to jail.local and then edit the sshd section to enable it. There’s a bunch of outdated guides, I ended up using the Claude AI to figure it out.

Anyway, end of the day fail2ban scans your ssh log files and creates IP table rules to block aggressive clients. Not a full fix but should make a race condition exploit a lot harder. You can see what fail2ban is doing in the moment with fail2ban-client status sshd or use iptable -L to see the rules it’s creating and removing. Lol, just realized I log in with CGNAT. So some other Starlink user on the same IP address as me could conceivably block me from logging in. Oops.

Another option mentioned in the release is to set sshd’s LoginGraceTime to 0. That means “no limit”, so clients never get dropped if they hang during login. But that now opens you to a DDOS, I think by default sshd allows 100 simultaneous logins and if someone’s trying to exploit the race condition they’d quickly fill all those slots. Not positive.

The last thing I did was look at my bash history to see what hosts I ssh into to make sure they are all updated. Unfortunately you can’t read known_hosts anymore to see where you’ve logged in since the hostnames are hashed. Again Claude AI to the rescue, here’s what it recommended:

history | grep ssh | awk '{for(i=1;i<=NF;i++) if($i~/^[^-].@./) print $i}' | cut -d'@' -f2 | sort -u

I should probably disable ssh entirely on my public interfaces and require tailscale to log in. But despite a year+ of reliability I still don’t fully trust tailscale, what happens if it breaks for some reason and I can’t log in?

Ubuntu 23.10 upgraded: signed GRUB failed

Tried upgrading my main daily driver Ubuntu system from 23.04 to 23.10 and got left with a broken system. Upgrading grub-efi-amd64-signed failed with the error Unknown device "/dev/disk/by-id/*": No such device. I tried hacking around to get it working and failed. Finally reloaded from the Proxmox VM backup I’d thankfully made before trying the upgrade. I filed an Ubuntu bug.

I’m totally guessing here but I think the underlying cause is from when I virtualized the Linux server from physical hardware to a VM. That worked, including Secure Boot and ordinary kernel updates and update-grub, but now upgrading the GRUB packages fails. On the virtual system there really is no /dev/disk/by-id filesystem right now after rebooting back to 23.04. This discussion says that’s working as intended, that virtio devices don’t have serial numbers. I assume my old physical server had entries in /dev/disk/by-id. Those old entries are referenced in the hard-to-find /var/cache/debconf file, which contains the actual configuration options chosen at apt install time. And so now when I go to update the grub package it picks up the old config which is no longer valid.

If my diagnosis is right the fix is to get the working GRUB install to reconfigure itself somehow to use whatever new path is relevant, to stop referencing /dev/disk/by-id. And only then attempt an Ubuntu release upgrade.

Update: I tried just running dpkg-reconfigure grub-efi-amd64-signed. That just prints the error about /dev/disk/by-id missing. That seems like a usability bug; the reconfigure tool should recover gracefully if the configuration is bad. I tried various other methods of convincing apt to reconfigure GRUB but the best I could do was change the menu entries or Linux command line, never change which device it thought GRUB should be installed on.

Update 2: I may have found a fix using debconf-set-selections to reconfigure GRUB. It sort of worked but not entirely.

It’d be awfully nice if the package installer had better error messaging and recovery.

Detailed notes

Some extra details that are poorly edited but I’m capturing anyway.

Looking around on the Internet I found lots of posts about upgrades failing on this package going back to Ubuntu 18.04. Lots of various cargo cult solutions. This one is clearer than most. See also here or here. All of them boil down to forcing apt to remove and reinstall GRUB.

Here’s what I did in my failed attempt to reinstall GRUB after the upgrade had failed.

apt remove --allow-remove-essential grub-efi-amd64-signed shim-signed
apt install grub-efi
update-grub

This succeeded in that it installed a new, unsigned GRUB. But the Proxmox OVMF BIOS refused to boot it. The BIOS had secure boot turned on; turning that off it still refused to boot. Probably what I really should have done was force a proper reconfigure of the signed GRUB install instead. I tried to do that but various methods of reinstalling grub-efi-amd64-signed kept failing on the missing /dev/disk/by-id/. Need to look up how to force a full reconfigure of that package.

Boy do I hate messing with GRUB.

Dump of error logs:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Setting up grub-efi-amd64-signed (1.197+2.12~rc1-10ubuntu4) ...
Unknown device "/dev/disk/by-id/*": No such device
dpkg: error processing package grub-efi-amd64-signed (--configure):
installed grub-efi-amd64-signed package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of shim-signed:
shim-signed depends on grub-efi-amd64-signed (>= 1.191~) | grub-efi-arm64-signed (>= 1.191~) | base-files (<< 12.3); however:
Package grub-efi-amd64-signed is not configured yet.
Package grub-efi-arm64-signed is not installed.
Version of base-files on system is 13ubuntu2.1.
shim-signed depends on grub-efi-amd64-signed (>= 1.187.2~) | grub-efi-arm64-signed (>= 1.187.2~); however:
Package grub-efi-amd64-signed is not configured yet.
Package grub-efi-arm64-signed is not installed.

dpkg: error processing package shim-signed (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
grub-efi-amd64-signed
shim-signed
needrestart is being skipped since dpkg has failed
E: Sub-process /usr/bin/dpkg returned an error code (1)

Here’s the entries in /var/cache/debconf that reference the missing path

Name: grub-efi/install_devices

Template: grub-efi/install_devices
Value: /dev/disk/by-id/nvme-eui.002538b22140b542-part1
Owners: grub-common, grub-efi-amd64, grub-pc
Flags: seen
Variables:
CHOICES = /dev/nvme0n1p1 (1127 MB; /boot/efi) on 2000398 MB Samsung SSD 980 PRO with Heatsink 2TB
RAW_CHOICES = /dev/disk/by-id/nvme-eui.002538b22140b542-part1

Name: grub-pc/install_devices
Template: grub-pc/install_devices
Value: /dev/disk/by-id/nvme-Samsung_SSD_980_PRO_with_Heatsink_2TB_S6WRNS0T220037X
Owners: grub-pc
Flags: seen

This might be the original install log that shows what path was chosen. If so, it gives a choice for an alternate name for the device.

2022-08-09 23:28:45,261 - cc_grub_dpkg.py[DEBUG]: considering these device symlinks: /dev/disk/by-id/nvme-Samsung_SSD_980_PRO_with_Heatsink_2TB_S6WRNS0T220037X,/dev/disk/by-id/nvme-eui.002538b22140b542,/dev/disk/by-path/pci-0000:01:00.0-nvme-1

2022-08-09 23:28:45,261 - cc_grub_dpkg.py[DEBUG]: filtered to these disk/by-id symlinks: /dev/disk/by-id/nvme-Samsung_SSD_980_PRO_with_Heatsink_2TB_S6WRNS0T220037X,/dev/disk/by-id/nvme-eui.002538b22140b542
2022-08-09 23:28:45,261 - cc_grub_dpkg.py[DEBUG]: selected /dev/disk/by-id/nvme-Samsung_SSD_980_PRO_with_Heatsink_2TB_S6WRNS0T220037X

More info on how debian is configured

# debconf-get-selections | grep dev/disk
grub-common grub-efi/install_devices multiselect /dev/disk/by-id/nvme-eui.002538b22140b542-part1
grub-efi-amd64 grub-efi/install_devices multiselect /dev/disk/by-id/nvme-eui.002538b22140b542-part1
grub-pc grub-efi/install_devices multiselect /dev/disk/by-id/nvme-eui.002538b22140b542-part1
grub-common grub-efi/install_devices_disks_changed multiselect /dev/disk/by-id/nvme-eui.002538b22140b542-part1, /dev/vda1
grub-efi-amd64 grub-efi/install_devices_disks_changed multiselect /dev/disk/by-id/nvme-eui.002538b22140b542-part1, /dev/vda1
grub-pc grub-pc/install_devices string /dev/disk/by-id/nvme-Samsung_SSD_980_PRO_with_Heatsink_2TB_S6WRNS0T220037X

Ubuntu: slow login / sudo after changing hostname

Amazing Stack Exchange answer that solved a mystery for me: sudo and ssh logins were taking a few seconds. Turns out if you change your hostname on an Ubuntu box with hostnamectl it doesn’t add an entry to 127.0.0.1 for the new hostname. So you have to add it manually.

The delay isn’t so bad you can’t live with it. Maybe 2 seconds? But it’s annoying! I felt like it was DNS related but was assuming it had to do with the DNS server my datacenter was setting. But there’s no reason sudo should involve network DNS at all.

While I’m here, trying to change the DNS servers on Ubuntu is still a total clusterfuck. Not sure if the problem is netplan or systemd-resolve. resolvectl status is helpful but the output is confusing. I’m not sure if I’m getting the “global” setting or the “link” setting. I wish there were some easy way to test it. nlsookup just tells me I’m using systemd’s goofy 127.0.0.53 as the resolver.

# resolvectl status
Global
           Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
    resolv.conf mode: stub
  Current DNS Server: 8.8.8.8
         DNS Servers: 8.8.8.8 8.8.4.4
Fallback DNS Servers: 1.1.1.1 1.0.0.1

Link 2 (enp2s0)
    Current Scopes: DNS
         Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.187.107.16
       DNS Servers: 192.187.107.16
        DNS Domain: nocix.net

Link 3 (tailscale0)
Current Scopes: none
     Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Chromebook, Ubuntu, Crostini and other containers

ChromeOS has nice support for running your own Linux distro in an LXC container. By default it installs Debian in a container named “penguin” and there’s a Terminal app to connect to a shell in it. I’d rather use Ubuntu. There’s lots of instructions on how to do this online but most of what you’ll find are using the outdated Crouton container environment.

The 2023 way of setting up Ubuntu on a Chromebook is with Crostini. This Reddit Wiki has thorough instructions. This article is also fairly good as is this outdated gist. It boils down to launching a special Termina shell to control containers. Then to install Ubuntu in a new container, then to install some Chromebook specific stuff, then to set up your user login.

All that being said I could easily set up a container with a different Linux distro but I couldn’t get it to connect nicely to the Terminal GUI app. This is all pretty complicated tinkerhacking. One reason I’m excited about ChromeOS is you don’t really need to do this kind of thing for an ordinary experience. But I’m being a little extra about a Linux environment.

Alternate distro support is a work in progress and there’s lots of notes about current development online. I stopped about here, which was instructions on telling Terminal how to connect to a different container. This is related to the crostini-multi-container flag in about:flags. That’s a feature that gives you a GUI for accessing multiple containers but is not complete. See also discussion here.

A failed Ubuntu install

Unfortunately the online instructions didn’t work for me with Ubuntu 23.04 and ChromeOS Beta 114.0.5735.18.

One problem is the Chromebook-specific stuff (cros-ui-config and friends) failed to install, either using the fancy script or just running “apt install” and hoping for the best. The Reddit Wiki has complicated instructions and a script for installing cros-ui-config. I guess the packages are still not working quite right but different hacks are needed than what that script did. These didn’t work for me with Ubuntu 23.04 and ChromeOS Beta 114.0.5735.18. Simply running apt install cros-ui-config got fairly far but failed in the end.

Worse, even a vanilla Ubuntu 23.04 install (without cros-tools) didn’t work right for me. It seemed to be fine, I could get a working shell with lxc exec. But then I couldn’t connect to it via the Terminal app, the little spinning progress thing ran and stalled without giving me a shell. It’s like whatever connects the ChromeOS UI to the containers wasn’t working. I couldn’t even completely wipe the Linux development environment from the Settings app, it also hung, although the wipe did work after a reboot. At least I didn’t have to powerwash the whole system and start over.

For now I’m just going to settle for Debian. When I feel like tinkering again I’ll revisit Ubuntu, maybe update this blog post.

Other containers and VMs in ChromeOS

It’s not just a Linux environment that uses a container on a Chromebook.

Modern Chromebooks run android apps in a container called ARCVM. I don’t know much about how this works, it’s all pretty opaque. Folks complained it uses more resources than the old method but it seems fine to me.

ChromeOS 108 got the ability to run Steam games. It does this with a VM environment called Borealis. From what I’ve read this is Ubuntu 18.10 and using Valve’s Proton stuff to emulate enough Windows API to run a lot of games. Ie: similar to what a SteamDeck is doing.

This is all a lot like what Windows does, btw; WSL is the Windows equivalent of Crostini, and Windows can run Android apps in a VM too.

Fixing Samba for Sonos v1 (Ubuntu 22.04, 22.10)

To make Samba in Ubuntu 22.04 jammy and 22.10 kinetic work with Sonos v1, add these lines to the global config:

server min protocol = NT1
unix extensions = no

On Sonos the login works fine with a blank username and blank password (assuming your music volume is a guest volume). I think username guest, password blank also works.

That first line has been necessary for awhile because Sonos v1 has an ancient SMBv1 client baked into it and the company won’t update it. The second line about unix extensions is new; it wasn’t necessary in the Samba included in Ubuntu 20.04. I don’t know what changed. Ubuntu 20.04 uses 2:4.13.17~dfsg-0ubuntu1.20.04.1; Ubuntu 22.04 installs 2:4.15.9+dfsg-0ubuntu0.3.

I think the “unix extensions = no” setting is reasonably safe. The docs suggest it does something to make Unix SMB clients happier; I don’t have any of those.

I’ve been low-key chasing a problem for months. It’s been super frustrating. So much so I even considered creating an alternate server. I don’t know if the problem is a change in Samba itself or if it’s specific to the Ubuntu build. I build Samba 4.17.3 from source on Ubuntu 22.10 and had this problem, so that suggests a change of behavior in the sources.

The unix extensions config options seems to have to be in [global]; it didn’t work to put it in the share definition. Here’s the full share definition I am using:

[musicshare]
follow symlinks = yes
wide links = yes
path = /home/nelson/Music
read only = yes
printable = no
guest ok = yes

The stuff in there about symlinks and wide links might not work with unix extensions turned off.

Ubuntu 20.04 to 22.10 upgrade

I upgraded my old Intel NUC home server from Ubuntu 20.04. To 22.04 first, then to 22.10. Went smoothly, no problems.

Below are my running notes as I do the work. Good time to remind folks this is my secret work blog; you’re welcome to read, but there’s no pretense these notes are of interesting to anyone else.

Services on the system I care about. netstat -l --program | grep tcp was a help for finding these, that --program flag is neat.

  • Influx and Grafana with a lot of old data
  • Plex
  • Samba
  • autossh for a tunnel to a public machine
  • tailscale
  • unifi / ubiquiti controller, which includes mongo

I had Home Assistant and Infinitude installed via Docker but didn’t want either of them. I removed them with help from docker ps --all and docker images. Some other things to remove: munin, motion.

I always forget to start do-release-upgrade under screen. Dumb of me! I’ve had bad experiences with it being interrupted in the past (because, say, my ssh terminal failed.) Also when the system says you need to reboot go ahead and reboot, don’t try to do a few things first; the system is in a slightly odd state.

Every time you do-release-upgrade it moves all your /etc/apt/sources.list.d to *.distsave versions and then edits the important .list files to disable third party repos. Doing an upgrade twice in a row means you lose the original file entirely (because *.distsave was copied to twice). It’s no big deal to hand-edit to fix it, but it’s a pain. It’s probably a good idea to refresh the sources anyway; most of the repos have a distro like “focal” hard coded in the paths. Ookla’s packagecloud repository is broken; it installs expecting “kinetic” which doesn’t have releases. “jammy” works, “stable” doesn’t.

A Sonos v1 SMB server

Summary: do you need a SMB server to serve your local library of music files to your v1 Sonos? Barry de Graaff has a solution, sonossmb. It’s a small Node implementation of SMB that works with Sonos. It works! It does take a bit of hacking to install though.

About sonossmb

I used Samba for years to serve music to the Sonos. The problem is the v1 systems are unsupported and have an ancient insecure SMBv1 client baked into them. And starting with Ubuntu 22 (which has Samba 4.17) it no longer works with Sonos, even with the special v1 config directives. No idea what’s wrong. That got me speculating that a simple stripped down anonymous-only SMBv1 server for Sonos might be a nice product. Which is what de Graaff created!

His server is based on Adobe’s Node SMB server, a project I never heard of and looks abandoned. He tells me it mostly works with Sonos just fine. He just made one tiny change to upcase the share’s name. The packaging and installation is a little trickier. He’s got some good docs and a script but it’s still something you might need to understand Linux pretty well to get running. More on that in a bit.

One problem I ran into; Ubuntu 22 ships Node 18. And that gives an error related to SSL ciphers I think because Node dropped support for old insecure SSL clients. The workaround of export NODE_OPTIONS=--openssl-legacy-provider worked for me.

Note that the share has a name like \\192.168.0.2\PUBLIC and you must log in with the username “guest”, no password. Empty username doesn’t work.

It’d be nice if Samba could be fixed. That SSL thing makes me wonder if that’s what broke on Ubuntu 22, that they too dropped some old SSL stuff that the Sonos ancient client needs. There’s some discussion on the Samba list. One happy thing is one of the Samba developers himself has a Sonos so someone in the know may work on the problem.

Packaging, Snap.

Barry’s server works but I can’t quite use it as-is on my LAN. I really need a full Samba server too. But I only have a single Linux box. And SMB doesn’t work well other than on a single port, 445. Some clients do work on other ports but I haven’t tested it with Sonos and am pessimistic. Maybe I need to just add a second IP address to my server and bind the special Sonos server there, but yuck.

All the drama of getting the thing installed makes me think a Snap container / image is the perfect way to run this server. There’s a snap for the web server Caddy so a daemon that accesses local files and serves them on the network is possible in Snap. But I’ve never built a Snap and have no idea how hard it’d be. I guess Docker would work too but Snap seems to be the choice for consumers on Ubuntu systems so I think starting there makes sense. I may give a go at building a Snap, we’ll see.

adobe/node-smb-server patch

Here’s the patch Barry sent me to upcase filenames:

diff -Naur node-smb-server-master/lib/smb/cmd/tree_connect_andx.js sonos-smb/lib/smb/cmd/tree_connect_andx.js
--- node-smb-server-master/lib/smb/cmd/tree_connect_andx.js	2021-06-22 17:20:12.000000000 +0200
+++ sonos-smb/lib/smb/cmd/tree_connect_andx.js	2022-12-09 08:21:10.674527000 +0100
@@ -10,6 +10,10 @@
  *  governing permissions and limitations under the License.
  */
 
+/* As required by original License I hereby notify you that I have made changes to this file.
+ * Copyright (C) 2022 Barry de Graaff
+ * */
+
 'use strict';
 
 var put = require('put');
@@ -76,7 +80,7 @@
 
   logger.debug('[%s] flags: %s, password: %s, service: %s, path: %s', SMB.COMMAND_TO_STRING[commandId].toUpperCase(), msg.flags.toString(2), msg.password.toString('hex'), msg.service, msg.path);
 
-  var shareName = msg.path.substring(msg.path.lastIndexOf('\\') + 1);
+  var shareName = msg.path.substring(msg.path.lastIndexOf('\\') + 1).toUpperCase();
   var shareLevelPassword = utils.bufferEquals(msg.password, Buffer.from([ 0x00 ])) ? null : msg.password;
   if (_.indexOf(server.getShareNames(), shareName) === -1) {
     result = {

Ubuntu vs NodeJS versions

Node seems to have some serious stability problems; various apps are sensitive to which version of Node you run. Here’s some recent versions:

  • Ubuntu 22.10 / kinetic: 18.7.0
  • 22.04 / jammy: 12.22.9
  • 20.04 / focal: 10.19.0

Nodesource packages different versions of NodeJS for Ubuntu. It’s basically a PPA but they want you to use their shell script to install them.

I ran into a problem with Nodesource where “apt install” really wanted to keep installing Ubuntu’s 18.7 despite having a PPA. I fixed that with apt install nodejs=14.21.1-deb-1nodesource1 to select a specific version.

Raspberry Pi 4 as a Ubuntu desktop

Update this whole post was written using Ubuntu 64 bit with Gnome on an RPi 4. I’m trying a second time now with Raspberry Pi OS (LXDE) and it’s going much better, new post coming.

I decided to give a Raspberry Pi 4 a go as a Ubuntu desktop. It did not go very well. I think the hardware is just too underpowered. Which is a little ridiculous given how much more capable this hardware is than the systems of 10 years ago. I’m using this on a stock RPi4 with 4GB of RAM and the basic boost overclocking enabled. The system is installed to a SSD connected with USB3 that gets 250MB/s in benchmarks. (Which itself is odd; it should be 500MB/s. RPi4 I/O is limited I guess). My screen is 3440x1440.

Installation is remarkably easy and clean. The Raspberry Pi people have a GUI app that installs bootable operating system images. Basically plug and play. Newer RPi4 can boot directly off USB, no need for an SD card at all. Which is good; SD card I/O is slow. Graphics and sound basically worked out of the box. Even Bluetooth audio.

Performance is very rough though. There’s regularly 5 second delays between typing something and it showing up on my screen; here in the Wordpress editor, in the URL bar of a browser, pretty much in any GUI. Sometims keystrokes get lost. It’s much better in a Gnome terminal but even then there’s sometimes a perceptible subsecond delay. I really don’t understand the terrible latency on user inputs, even when several CPUs are idle and I have 1.0GB RAM available (currently allocated to buffers and cache). I wonder if something more serious is wrong?

I’m using the default Ubuntu 22.04 Gnome desktop. I might have luck with lighter GUIs - Lubuntu and Xfce are both recommended. I briefly tried them and they did seem faster but they were also uglier.

Update: I tried LXDE on Ubuntu, the desktop environment Raspberry PI Desktop uses, and it’s much better. The ubuntu install I did is pretty janky but that’s probably my fault, I bet the integrated Raspberry Pi Desktop experience is nicer. Responsiveness is much better and memory usage is much lower although this Wordpress editor still drags. LightDM is a big improvement too; the Gnome Display Manager is a huge hog for something that’s just a freakin’ login box.

Update 2: Raspberry Pi Desktop is indeed better. It’s much lighter weight than Ubuntu Gnome and it’s coherent in the RPi build, much better than my janky LXDE. Bluetooth config works! Youtube audio playback is mostly fine but pauses every once in awhile when something else is happening. The wordpress editor is worse than ever though. Beginning to suspect a bug in their Javascript code exacerbated by the relatively low system.

I started with Firefox which was a mistake; the aarch64 build of that is really slow and memory hungry. Chromium is a little better, apparently someone put some real effort into optimizing it for the RPi. It’s still not good though. Super sluggish, regularly pins all 4 CPUs at 100%, and uses a lot of memory per tab. I can’t watch a single Youtube video at 240p even with nothing else going on and the window minimized (sound, no picture). CPUs aren’t overtaxed but the sound playback is choppy and awful. Again, maybe a symptom of something more serious being wrong than just system load.

Update: the fix for Youtube is apparently the h264ify Chrome extension, which forces Youtube videos to H.264 instead of VP9. Which allows for hardware decoding. Shame YouTube isn’t smart enough to do that for you.

Gnome on Ubuntu 22.04 looks fairly good. But the moment you start pushing on stuff it breaks down. There’s two separate programs called “Software Updater” but what you really want is a third program “Ubuntu Software” which installs Snap apps. 1Password requires a manual install; they haven’t built aarch64 packages (But do have a tarball). Lots of weird off-brand Linux choices for ordinary user apps. I never could get the Gnome system monitor to show up in my task bar.

I had a much better experience using this environment on my fast desktop PC. Ubuntu Gnome does at least work on RPi 4 but it’s so slow that it is a miserable experience. Maybe next time I try this I’ll use the Raspberry Pi OS build instead.

Grub, recordfail, 30 seconds

My new Ubuntu 22.04 system was pausing for 30 seconds every boot in the GRUB menu. Despite GRUB_TIMEOUT=0 being set in /etc/default/grub. The fix is to also set GRUB_RECORDFAIL_TIMEOUT=5 in the same file. (Or set it to 0 if you’re feeling sporty.) Read below for the ugly details or see Ubuntu bug 1918736.

GRUB has a nice thing where if a boot fails then on the next try it gives the sysadmin extra time to figure out what’s wrong. It’s common to have no menu or delay if the last boot worked. But if it fails then you get 30 seconds in a menu to press buttons.

The problem is Ubuntu has been broken for a very long time and every single boot GRUB uses this failure timeout. Check out this charming code from /etc/grub.d/00-header/

if [ \$grub_platform = efi ]; then
  set timeout=${GRUB_RECORDFAIL_TIMEOUT:-30}

What this says is “if your system boots with EFI then ignore the configured timeout and wait for 30 seconds”. They’ve been doing this for 3 years. EFI is the common case for PC hardware and I think every installed Ubuntu system every single time it boots waits for 30 seconds for no reason except someone hacked around some other problem in a clumsy way, then never cleaned it up. I’m not sure but the underlying problem may have something to do with detecting whether a boot failed or not. A similar problem shows up with LVM systems.

Update: I misunderstood; this code only runs when recordfail_broken is set, which happens if GRUB determines the boot media is not writable. The check_writable function says diskfilter, lvm, btrfs, cpiofs, newc, odc, romfs, squash4, tarfs, and zfs are all not writable. I guess that’s for a good reason; GRUB’s not able to record that the boot worked so it assumes it failed. Sure is a kludge though.

I set the timeout to 5 seconds because in the case of a real failure I need that time in the menu. It’s still 5 seconds longer than it should be but at least it’s not 30.

I am sure cranky about this. I’ve been encountering a lot of bugs like this setting up my new Linux system, probably because I’m paying such close attention. Part of being a successful tech worker is ignoring all the broken stuff that’s not a big deal because you’re doing something more important. But I have time to get into the details of GRUB, or fstabs, or whatever and what I find is alarming. I always wonder “why doesn’t the engineer working on this give a shit?”

In the Old Days nerds who installed Linux were very proud of one thing: their system uptime. Later on we started accepting reboots were part of life and so the focus shifted to making fast boots (the primary reason for systemd!). Now apparently Ubuntu developers care so little about EFI boot that no one minds that for three years it’s been wasting 30 seconds every single boot. I suspect that’s because of the shift in focus to cloud computing; the serious work is now all on systems that probably aren’t using GRUB at all, just booting in a VM.

I do wonder what this means for folks on laptops though; Ubuntu still seems serious about desktop Linux Maybe I misunderstand and somehow this bug is avoided in common installs? Update: see above, it only affects some types of boot volume.

New Ubuntu 22.04 homelab server notes

I set up my new home server with Ubuntu 22.0. Here’s notes on what I did in August 2022. See also January 2019 and July 2019. Still doing all this stuff by hand like a craftsman; no Docker for me! The Ubuntu docs are worse than ever and Google has gotten much worse for looking for info. Adding “arch” to Linux search terms often helps find useful docs.

Generic system things:

  • Install Ubuntu 22.04 server image, UEFI boot, btrfs for the root partition
  • Use tmpfs for /tmp
  • Enable universe packages, updated apt
  • Set up a static IP address
  • Install chrony
  • Install mainline kernel via the cappelikan PPA. 5.19 includes i5-12600K tweaks not in 5.15.
  • Set up watchdog daemon with iTCO_wdt hardware watchdog and watching ethernet. (Does not seem to actually be rebooting the system when needed.)
  • Install libnss-mdns so .local DNS queries work
  • Install mailutils and set up Postfix for Local only
  • Turn off sudo email spam
  • Install a bunch of command line software via apt
    joe stress-ng stress s-tui smartmontools zip unzip rsync openssl webp plocate ripgrep pigz
    python3 python-is-python3 python3-venv python3-dev pkg-config build-essential sqlite3
  • Install Samba, configure SMB1 (aka LANMAN) support. Gave up trying to make this work for Sonos.
  • Set up port forwarding on my router. Had to reboot the Ubiquiti Dream Machine; config changes weren’t taking.
  • Set up rsnapshot. I’ll eventually move to a btrfs-specific backup program if I can find one.
  • Verify BIOS allows virtualization
    apt install cpu-checker; kvm-ok

Special apps and personal configuration:

  • Set up my /home/nelson environment
  • Install jellyfin ffmpeg from a PPA for hardware accelerated transcoding
  • Install nodejs 18 from a PPA
  • Install plexmediaserver from the secret apt repository. Also install intel-opencl-icd. Reconfigure.
  • Set up a group nzb for various Usenet things to all belong to. Make sure to set up each system to use this group as its primary group and make things group writeable.
  • Install sabnzbdplus from the Ubuntu repository. Set up user nzb to run it. Copy config from old system. Manually install par2-tbb because there’s no jammy build in the PPA.
  • Install sonarr from Sonarr focal repository. Reconfigure and re-add all my data because they moved config files around too much.
  • Install radarr into /home/radarr by copying from my old install. They don’t have any sort of packaging for Linux.
  • Install syncthing from their apt repository. Copy config from old machine (which is risky); be sure the files are in place on the new system before starting to sync!
  • Install Caddy as a web server. Just couldn’t stomach another round of Apache config files. Caddy doesn’t support cgi-bin (easily) so it’s not a perfect fit for my “light dev server” need. But it’s definitely a lot simpler than Apache 2.4.

Things I didn’t have to do this time:

  • Configure fsck at boot. The default is now “preen” which means “fix safe things automatically”.

I’m a little cranky how hard some of this stuff was to get working. Particularly anything outside standard Ubuntu packages. Lots of things haven’t been updated for jammy / 22.04.

APT changed things so apt-key add is now deprecated but the new method is not clearly documented. Apparently I’m supposed to manage my own keys using gpg? See my blog post for info on what to do, or example here or instructions here. What a UX regression.

Ubuntu 22.04: apt keys

New version of Ubuntu has a massive usability regression in adding third party package repositories. There’s a legitimate security reason for the change but they’ve made no affordance for making it easy for users to migrate or understand the new way. I can’t even find docs on the official help. This is bad usability even by Unix standards; I suspect Canonical doesn’t care because they’re pushing their Snap package store so hard.

There’s good information here. Bottom line; the old way meant that the new key you were adding was trusted for all repositories. Rather than fix that design flaw in some sensible way they’ve just deprecated the feature entirely and left users to run gpg -dearmor or some such nonsense to manage keyfiles themselves. Really. It’s 2022 and Ubuntu thinks “just use PGP from the command line!” is a reasonable thing to tell someone. Some tool to do this file management for me would sure be a better choice.

The change seems for the better but they sure didn’t do anything to build tools for the new way or explain the transition. Pretty sure the Ubuntu devs just told me to go fuck myself.

Ubuntu, ffmpeg, and Intel GPU acceleration

My fancy new Linux box has an Intel 12th gen CPU (Alder Lake) with a GPU in it. I wanted to try using ffmpeg to transcode video from H.264 to H.265. Here’s how I got it working, it was not easy.

Transcoding commands

First, my old way of transcoding without GPU acceleration

ffmpeg -i "$1" -map 0 -c copy -c:v libx265 -crf 25 $2 "${1%.*} x265.mkv"

I get about 4x encoding speed on an i5-12600K (compare about 1.1x on a ten year old i7-2600). However all 16 cores are pegged at 80% ish and the machine is drawing 165 watts. Note we’re using the libx265 encoder, all CPU. It’s not bad.

The new hardware accelerated way (some of these arguments need tweaking)

sudo /usr/lib/jellyfin-ffmpeg/ffmpeg \
  -c:v h264_qsv \
  -i input.mkv
  -c:v hevc_qsv
  -c:a copy out.mkv

This runs much nicer! I get 7.5x encoding speed. But now I’m only using 1-2 cores and the machine is drawing only 55 watts. I haven’t looked closely at encoding options or video quality but a quick preview looks plausible.

The primary change here is different codecs; h264_qsv and hevc_qsv. These are Intel Quick Sync codecs that are hardware accelerated using the GPU. The h264_qsv decoder uses about 10 watts less than the default CPU decoder (and 1-2 cores). The hevc_qsv is where the big savings are, some 90 watts.

The other change is I’m using jellyfin’s build of ffmpeg. Installing all this was a bit of a trick. Note also I had to be root to run this; I think there’s a way to change permissions so you can open the video device without root. Update: the devices are in /dev/dri which are usable by group “render”.

Installing prerequisites

I’m starting with an Ubuntu 22.04 server install running the 3.19 mainline kernel. Probably any kernel is fine.

I installed these packages from the default Ubuntu repository:

$ apt install onevpl-tools vainfo intel-media-va-driver-non-free
$ sudo vainfo
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 22.3.1 ()

OneVPL is Intel’s userspace for Quick Sync, the GPU accelerator. The non-free driver is recommended. vainfo is probably not necessary but is a handy tool for verifying the graphics driver.

With this I thought the stock ffmpeg would work. But it did not. I finally gave up and installed the jellyfin-ffmpeg package with the Ubuntu Repository instructions. Jellyfin is an open source media server, sort of like Plex. Its hardware acceleration docs are a lot clearer than ffmpeg’s wiki docs and apparently their build of ffmpeg has something important that Ubuntu’s does not.

Updates

intel_gpu_top (from intel-gpu-tools) is handy for seeing what’s running on the GPU

UEFI, ESP, secure boot, and GRUB

I haven’t really thought about how a Linux system booted in years, back in the old MBR days. (“Load the first block and run the code”, more or less). Modern PCs are much more complicated with secure boot and UEFI. Some notes on what I learned reading about it. I’m cranky about all of this complexity; particularly the idea there’s some security layer in my firmware that prevents me from booting disk images I installed on purpose. I realize this is to protect against malware that installs itself in the boot chain, but I’m not honestly that worried about that risk.

Summary: modern motherboards boot with UEFI. The BIOS looks to mount a drive with an EFI System Partition (ESP) on it. The ESP is a fat32 filesystem with signed .efi blobs that are executed. GRUB’s update tool (run in user space when installing itself or new kernels) creates an ESP with GRUB EFIs on it. When loaded, GRUB in turn loads the Linux kernel and runs it. The rest of these notes are more confused because I took them while I was learning all this.

First off, can you just turn all this UEFI stuff off? Maybe. ASUS motherboards have ways to turn off “safe boot” (which I think means ignore keys) and enable “compatibility support module” which disables UEFI. However CSM mode does not work with Intel integrated graphics. The option to do that is greyed out. I also have no option to just turn off safe boot. I think no CSM means I can’t boot from an MBR, I must have GPT partitioned disks. And no way to turn off safe boot means whatever I want to boot via GPT/UEFI must be a signed binary blessed by the spirit of Ballmer himself. I did see some references that if you deleted all the secure keys in ASUS BIOS that would enable booting anything unsigned, but I was too scared to try.

But I got ahead of myself. What are MBR and GPT? Those are two ways to create partition tables on a PC hard drive. MBR is the old way and partitions are marked with very sparse data (like a single byte for type); see BIOS boot partition for more info. (I can swear in the very olden days you didn’t need a boot partition at all; LILO’s bootstrap was tiny but enough to load the kernel off the root partition). GPT is the modern way. It’s the GUID Partition Table, so everything has verbose GUID names. There’s no reason to use MBR any more on PCs. GPT is some 20 years old, ubiquitous, cleaner, has no weird size limits, and is now required for complicated things. In Linux you can see what kind of partition table you have with parted -l.

I just set up Ubuntu on a new hard drive (USB, spinning) and let it install. It created two partitions. /dev/sdb2 is what I expected, a big disk formatted with ext4 with my Linux root filesystem. /dev/sdb1 is a boot partition; 537MB, FAT32, named “EFI System Partition” with the flags “boot, ESP”. That’s the EFI System Partition.

What’s on the ESP? You can mount it just like any fat32 file system. Inside are directories EFI/BOOT and EFI/ubuntu. Apparently this is all UEFI boot stuff, various .EFI files have signatures checked and then are loaded and run. Some details here. The Ubuntu directory has a couple of small GRUB config files and what I think must be a copy of the GRUB executable itself.

So now we get to UEFI itself. Useful resources for that: Ubuntu docs, Arch Wiki, Arch Wiki: GRUB, Wikipedia, Windows Boot and UEFI, this Stack answer. For something more complex see this proposal for a new secure boot.

Greatly simplified, my understanding is UEFI’s job is to find boot code someone installed and run it. The UEFI BIOS finds a boot manager (perhaps chosen from the BIOS boot menu or set up via a command line tool like efibootmgr), which then finds a boot loader like GRUB, which then loads the operating system kernel. In theory all this stuff works on both MBR and GPT file systems but in practice you usually see UEFI used with GPT. Note that UEFI is basically a whole operating system with its own shell. One fancy thing you’ll see is the BIOS logo on the screen along with the Ubuntu screen and a loading spinner as various parts of the boot process are all drawing on the screen.

One Linux I installed ended up telling the existing Windows Boot Manager on my SSD about the GRUB boot loader for my new Ubuntu install on a USB drive. I think Ubuntu chose that because I already had Windows on the system. The BIOS menu let me choose which of the two OSes to launch but the Windows Boot Manager was in the path of the process. In another case I had no OS at all and Ubuntu just put GRUB directly on the USB drive; I guess it was acting both as boot manager and boot loader? “Manager” vs “Loader” is not used consistently in the stuff I’ve read, so I may have the details wrong.

From Linux’ point of view, all this UEFI rigamarole is to boot GRUB. GRUB is basically a mini operating system whose job it is to launch the Linux kernel. (There was an older GRUB v1; all modern systems are using GRUB 2.) I don’t really understand GRUB very well, it has menus you can configure to do complicated things and behind the scenes has enough code to find and load the kernel from a bunch of different device types. So it loads that kernel and hands off control to it.

If this all sounds overly complicated it is. BIOS picks a boot loader which runs GRUB which picks a Linux kernel to load? It’s possible to bypass GRUB entirely and have Linux load directly with EFISTUB. I find GRUB sort of comforting though and see no reason to remove it. It’s the way Ubuntu prefers to let you choose between kernels when booting.

First practical question; is your Linux system booting via UEFI? These docs have a nice hint; look for the presence of a /sys/firmware/efi directory. Another way to tell is use parted and look at flags; my UEFI boot partition is flagged boot, esp whereas my MPT style boot partition is flagged bios_grub.

Second practical question: how do I update / install UEFI booting? There are procedures for converting a system to boot via UEFI, see the Ubuntu docs. They sound scary. They reference a tool called Boot Repair which is a handy rescue disc. It has a sort of wizard which is basically “fix my boot”. It’s also 4 years old but is apparently still the recommended tool? The Ubuntu Server install ISO also has a repair mode.

Third practical question: is secure boot really an obstacle? I don’t think so. Modern Linux distributions have some signed shim that allows the Linux boot code to pass the security checks. I have no idea how this works or why it’s considered acceptable in the face of malware. But I think in practice if a Linux tool installs an ESP at all, it will have the needed signatures.

Update: an August 2022 update has revoked a bunch of signing keys, rendering some systems signed with older keys unbootable. Including Ubuntu 20.04 (reportedly).

Python and Ubuntu versions

I’m upgrading from Ubuntu 20.04 to 22.04 which means Python versions are changing. Ubuntu 20.04’s last version they distribute is Python 3.9. Ubuntu 22.04 starts with Python 3.10. My own code isn’t particularly version sensitive but venv makes it a mess. I’ve chosen to go ahead and move to Python 3.10 for everything.

My main problem is when you create a virtual environment it’s locked to a specific verison of Python. All venv is doing is installing stuff to venv/lib/python3.9 or whatever. If you created the venv in python3.9 and try to use it with python3.10, it will not work. So you have two choices: either rebuild the venv for the Python version you have, or install the Python version the venv was set up for.

Installing Python versions is very easy thanks to the deadsnakes PPA. They port older and newer versions of Python to older and newer Ubuntu. Their 3.10 build works just fine in Ubuntu 20.04.

The other problem is the venv needs to have been set up to invoke the right Python binary. If you create a venv with python -m venv venv, then the important symlink in venv/bin/ will be to /usr/bin/python. No version number. But the rest of the venv is version specific, so that’s really the wrong thing. The solution is to create the venv with python3.10 -m venv venv. That way the symlink for the binary is to /usr/bin/python3.10 which will work whatever a system’s default Python version is. Also pays to be careful with pip; I now invoke pip as python3.10 -m pip instead of relying on /usr/bin/pip or whatever.

Here’s my “create venv” bash function now

python3.10 -m venv venv;
source venv/bin/activate;
python3.10 -m pip install -U setuptools pip wheel

Ubuntu 20.04 motd

I was trying to figure out how Ubuntu systems print the Message of the Day at login. In ye olden days this was a static file, /etc/motd. But it’s dynamic now.

The online references I found talk about the update-motd package. That was indeed how it worked in 2008 or so but is no longer the case in 2021. I don’t even have it installed on my Ubuntu 20.04 system.

The newer Debian docs seem to be correct. The motd is being created and shown by pam-motd. PAM is the code that defines what all happens when a user logs into a Linux system. It has this configuration:

# Print the message of the day upon successful login.
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session    optional     pam_motd.so  motd=/run/motd.dynamic
session    optional     pam_motd.so noupdate

That first line means “run the scripts in /etc/update-motd.d and write their output to the file /run/motd.dynamic. Then display the output.” The second line means “don’t run anything, just display the contents of the default file /etc/motd.”

The actual messages come from scripts in /etc/update-motd.d. You can use run-parts to run them all dynamically. This most fork like 100 processes every login shell, what a waste! But it’s sure flexible. 10-help-text is the one that prints the URLs advertising Ubuntu stuff. I removed mine.

There are some other motd things too.

sshd has an option for PRINTMOTD. The docs say it only prints /etc/motd.

systemd does not have any MOTD code, surprisingly. Ubuntu does have a systemd timer configured to run 50-motd-news a couple of times a day.

login has a couple of options for .hushlogin files to suppress the MOTD.

The ubuntu package show-motd drops a script in /etc/profile.d which will display the MOTD once a day. It does this using update-motd, not PAM, but it seems to work the same way with the /etc/update-motd.d scripts. It has various triggers to stop it from printing the MOTD:

  • .hushlogin
  • a MOTD_SHOWN environment variable (PAM sets this.)
  • Timestamp on $HOME/.motd_shown: only show if it’s the first shell after 00:00
  • If the shell is not interactive. (It does not check if it’s a login shell.)

WSL doesn’t run login or PAM for shells so some of this stuff doesn’t happen in the WSL context. But WSL seems to install show-motd by default and so you get a MOTD once a day.

Ubuntu and Netplan: gotchas

I finally figured out a networking configuration problem on my Ubuntu 20.04 system.

In theory all Ubuntu systems since 2017 have been configured with Netplan. It’s some simplified high level configuration language that systemd applies. Like any Unix thing built after 1993 or so I reflexively hate it, I kinda miss the old days of /etc/interfaces and hacking stuff in /etc/rc.local. But I gotta admit Netplan is pretty good. When it works; the problem I’ve had is my config gets overridden.

The first problem is cloud-init, some thing that Ubuntu ships to configure “cloud servers” from yet other files. I believe default Ubuntu systems are configured via /etc/netplan/50-cloud-init but if you edit that file, joke’s on you; it gets rewritten by something else. The solution is to create a file /etc/cloud/cloud.cfg.d/99-custom-networking.cfg with the contents network: {config: disabled}. That will prevent cloud-init from rewriting your files.

Having done that you can either delete 50-cloud-init or replace it with your own stuff. Note that config files are additive; I ended up configuring my ethernet twice until removing the cloud-init file.

The bigger problem I ran into is that I had a dhcpcd installed, the package dhcpcd5. I don’t quite know why, it’s probably something I did manually. But if that’s installed it will override the netplan files. You can have dhcp4: no right there in your netplan file and dhcpcd will still override your static configuration. I fixed this by uninstalling dhcpcd. I think the modern systemd world uses dh-client anyway.

Once that’s done netplan seems to operate as it’s supposed to, without mysterious other things overriding my configuration.

WSL Ubuntu: essential developer packages

I just rebuilt my WSL Ubuntu environment and had forgotten how little is installed by default. Big help if you are a software developer:

apt-get install python3 python-is-python3 python3-venv python3-dev pkg-config build-essential

No doubt I forgot something, but that was most of what I needed to be able to build pycairo-dev which apparently doesn’t just have a wheel?!

Unifi Network Controller on Ubuntu 20

Ubiquiti’s Network Controller comes in an apt installable version for Ubuntu. For the most part their instructions just work. The one wrinkle I ran into with my Ubuntu 20 system is that the service wouldn’t start with systemctl having an error “Cannot locate Java Home”.

The solution for this was to manually install an older Java.
apt install openjdk-8-jre-headless
Their controller seems to require Java 8. The apt page has some confusing instructions about preventing Java 11 from being installed with apt-mark, but at this point we’ve moved on to openjdk-14 in Ubuntu land. Anyway Ubuntu lets you have multiple JREs installed with no drama.

The network controller is running as an HTTP interface on port 8080. Terrible choice of port (this is changeable). Once you do initial setup though it seems to start redirecting you to port 8443 instead.

I needed to migrate the devices from the previous network controller I’d installed. This all seems to be anticipated in the UniFi system, there’s instructions here on “adopting” the device on the new controller. I had to stop the old controller from running for the new controller to see the devices before adoption.

I also set it up to email me alerts for important things on the network. That requires an SMTP server. I grudgingly gave it a Gmail password, but only after creating a specific app password at Google only for this device.

Why am I doing all this? I’m upgrading some parts of my home network (finally installing a cellular backup for the ISP) and am finally fully embracing UniFi, Ubiquiti’s current platform for their networking equipment. I have UniFi access points and ran their controller software once, grudgingly, to install them. But I still have an old EdgeMAX router that predates UniFi. Or rather will for one more day.

The UniFi Network Controller has turned into a pretty good piece of software, btw. I was impressed when it helped me diagnose a WiFi performance problem I had with an old 802.11n device.

Ubuntu 20 vs Sonos: SMBv1

After I upgraded to Ubuntu 20.04 my music library stopped working on my Sonos. Turns out this is a Samba problem. Somewhere along the line Samba disabled SMBv1 by default; apparently it’s insecure and old. However some clients like Sonos only support SMBv1, so the result sucks.

The fix is easy. Add this to your smb.conf and restart Samba

server min protocol = NT1

I also have these lines lurking around for other obsolete clients, but I’m not sure they even work any more. They aren’t necessary for Sonos.

ntlm auth = yes
nltm auth = ntlmv1-permitted

Sonos sure could do a nicer job of error handling. The only error you get is “it failed” with a link to some irrelevant docs about Windows stack size. I figured out the real problem in this Reddit thread.

Apparently this is also a problem with Synology servers, which recently switched to SMBv2 or above only.

I don’t know if there’s a security risk in exposing SMBv1 this way. It’s all behind my firewall so I’m kind of hoping the Maginot line keeps me safe. Also it’s a freakin guest read only fileshare, why is there any login protocol at all? Ugh.

It’d be nice if Sonos upgraded to a newer SMB client, but apparently they’re not in a hurry to. And now given the major platform switch plus their emphasis on streaming services over local music, I’m a little afraid SMB may never be updated on Sonos.

Ubuntu 19.10 to 20.04 upgrade failure

I seem to be cursed when it comes to Ubuntu updates. I just tried upgrading Ubuntu 19.10 to 20.04 (ie: eoan to focal) on a ordinary home server. Once again do-release-upgrade failed right as systemd was being updated. In the past that’s because the systemd upgrade broke my network configuration, because of course I’m doing the upgrade via ssh. (In a screen session though!) This time around it was worse, because the system wouldn’t boot:

- - -[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]- - -z

Well that’s exciting.

Turns out this is a well known problem with an easy solution. Basically if something interrupts an apt upgrade of the kernel at the wrong time, the kernel will be installed and chosen as the default but the matching initrd ramdisk to make it bootable won’t be properly installed. (ramdisk creation seems to be deferred to the very end of the apt process). The result is the system won’t boot with the new kernel. UEFI may be part of what makes this a challenge.

Fortunately there are usually other older kernels also installed that still work on the hard drive, so all you have to do is convince GRUB or whatever boot loader you’re using to boot an older kernel. Then you can go in and fix things.

The command that seems most clearly to fix things is
dpkg --triggers-only linux-image-5.4.0-29-generic
Of course you need to substitute the right package name there, for the latest kernel that’s not booting. You can find it this way by listing all packages installed with “triggers pending”:
dpkg -l | grep ^it
Another bit of advice on that Stack Overflow page is to run
dpkg --configure -a
This will force any packages that were installed but not configured to configure themselves. My aborted Ubuntu upgrade seems to have left me with ~40 unconfigured package, this fixed them all in a jiffy.

I sure wish I knew why upgrading systemd sometimes breaks networking on Ubuntu. It’s happened on two different systems of mine. And it’s an absolute disaster if you only have local access to the machine. Hilariously, do-release-upgrade still advises against running it if you’re ssh into the machine. How am I supposed to update the machine, fly to the datacenter and type at the keyboard?!

I also wish that apt or do-release-upgrade were a little more robust in leaving you with a bootable kernel.

The good thing here is that apt and dpkg are very robust themselves. This is the third time I’ve had do-release-upgrade fail on me now, but each time I can pretty much rely on apt and dpkg to fix whatever mess was created.

Bonus round: USB keyboards

This whole ordeal got a lot more complicated because I couldn’t find a keyboard to plug into the Intel NUC hardware to access the boot console. I use an old USB wired Apple Mac 101 key keyboard on my regular computer. For some bizarre reason that fails to work when plugged in to the NUC for accessing the BIOS. I ended up having to wait two days for Amazon to ship me a cheap $10 Chinese keyboard. That’ll teach me to not have a bunch of old computer parts lying around the house.

Upgrading from an unsupported Ubuntu (18.10 to 19.10)

Update (March 2020): I’ve heard from 10+ people who say these instructions work for them, I think it’s reliable. See also this Ask Ubuntu post. Some folks are finding their way to this blog searching for “An upgrade from ‘cosmic’ to ‘eoan’ is not supported with this tool.” That makes sense, it’s the error the upgrade tool gives. Finally, if you see an error about “Upgrades from 18.04 on the i386 architecture are not supported” that is sadly true; 32 bit support stopped in 18.04. I don’t know how to help you with that.

A couple of weeks ago I blogged about being unable to upgrade from Ubuntu 18.10 (cosmic) to 19.10 (eoan), or even 19.04 (disco). Ubuntu 18.10 is fully end of life and deprecated and the do-release-upgrade tool we normally use to upgrade things refused to run. (Note that this tool is bundled in the ubuntu-release-upgrader-core package) Fortunately one of my readers Alejandro saw my post and suggested a solution. I just tried it and it works. Details below.

The underlying problem is do-release-upgrade on 18.10 was trying to upgrade directly from 18.10 → 19.10. But that’s not possible. And it’s no longer possible to upgrade 18.10 → 19.04 because 19.04 is also not supported. So you’re stuck.

The gist of the solution is to hack a config file to force an 18.10 → 19.04 update. It turns out Ubuntu’s do-release-upgrade tool is a generic program, the version installed on an 18.10 system is not 18.10 specific. Instead it downloads metadata files from the Internet and uses those to figure out what to do. Alejandro’s suggestion boils down to intercepting those metadata files after download and hacking them to point to 19.04 instead of 19.10. The packages needed to do the 18.10 → 19.04 upgrade are still online, do-release-upgrade just wasn’t finding them.

Needless to say, the instructions below come with a big warning this may break your system. It worked for me, but no idea if it will work for you.

18.10 → 19.10 steps

  1. zRun do-release-upgrade on the 18.10 system. This will give you an error about being unsupported. But behind the scenes, the tool will download some metadata files we want to modify.
  2. As root, go in to /var/lib/update-manager and copy the file meta-release to a new file meta-release2. This file was downloaded by do-release-upgrade from the Internet and tells the upgrader how to upgrade.
  3. Edit meta-release2. Remove all entries for eoan entirely. Modify the disco entry so it says Supported: 1
    Update April 2020: reader F.K. write to say “I found that ubuntu repo returns 404 and `do-release-upgrade` can’t run update. I changed all link in meta-release2 for disco to  http://old-releases.ubuntu.com/  and its works.” I can’t test this but it seems plausible of Ubuntu finally moved the disco update files out of the live repo (say, in preparation for the 20.04 release.)
  4. Edit the file /usr/lib/python3/dist-packages/UpdateManager/Core/MetaRelease.py. Change this line of code
    self.metarelease_information = open(self.METARELEASE_FILE, "r")
    To read
    self.metarelease_information = open(self.METARELEASE_FILE + "2", "r")
    That will tell the upgrader to use your modified file instead of the original. (It will also avoid any redownloads overwriting your changes.)
  5. Run do-release-upgrade. It should now be doing an upgrade 18.10 → 19.04. Let that run as normal and reboot.
  6. Congratulations! You’re now running 19.04. Remove the /var/lib/update-manager/meta-release2 you made.
  7. Since 19.10 is supported, all you have to do to upgrade 19.04 → 19.10 is run do-release-upgrade again. No hacks necessary, you’re back on the main path.

Like I said, it worked for me. I’m a little surprised Ubuntu doesn’t support this officially out of the box, it seems simple enough. I suspect they just want to have nothing at all to do with older systems. Still if it were me I’d add some flag to enable at-your-own-risk upgrades for people like me who were stuck.

I think I also could have upgraded my system simply by editing /etc/apt/sources files and relying on apt dist-upgrade. That’s the underlying tool that’s doing all the work anyway. But the Ubuntu upgrade scripts have a little extra stuff in them and it’s nice to be able to run it just in case it’s important.

I’m very grateful to Alejandro for his emailing me the suggestion on the fix.

Can’t upgrade Ubuntu 18.10 to 19.10

(Major update: see this blog post for a workaround to upgrade from 18.10.)

I’ve got an Ubuntu 18.10 (cosmic) system. I want to upgrade it to the latest (19.10, eoan). I understand I probably have to upgrade it to 19.04 (disco) first, that’s fine.

Except I can’t.

# do-release-upgrade
Checking for a new Ubuntu release
Your Ubuntu release is not supported anymore.
...
An upgrade from 'cosmic' to 'eoan' is not supported with this tool.

That’s it. No options to help. I get it, 18.10 isn’t supported anymore. But it’s only 15 months old. Surely the old upgrader files are lying around somewhere?

So off to the cargo cult Internet I go.

First thing that looks promising is “How to install software or upgrade from an old unsupported release?” They advise using the old-releases sources as a way to get, well, old releases. That seems promising except following the advice about updating sources.list and running apt update doesn’t work

# apt update
Err:9 http://old-releases.ubuntu.com/ubuntu cosmic Release
  404  Not Found [IP: 91.189.88.153 80]
E: The repository 'http://old-releases.ubuntu.com/ubuntu cosmic Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.

So something about the source repo directory structure doesn’t match what apt wants? Or did Ubuntu somehow screw up the release signatures? Beats me.

So I went in to sources.list and tried hacking them all to include [trusted=yes], to ignore this error. Yeah, that’s a scary idea. Doesn’t work though. Or rather “apt update” seems to run an O(n^2) update on 124 different URLs, for ~15,000 separate updates. Or something, I dunno, it’s clearly wrong.

I’m stuck. I understand Ubuntu’s support window, or I thought I did. I didn’t realize that being just a few months out of date left you out in the cold forever. I think a full reinstall is my only option.

Update

I tried asking on FreeNode #ubuntu. No one there knew an answer. Got some suggestions on things to try though. By far the best solution is a full reinstall, but I really hope not to do that. The other suggestion is sort of documented here: basically you just hack your sources list and rely on apt-get dist-upgrade to correctly upgrade the system, bypassing the do-release-upgrade script entirely.

My concern is that do-release-upgrade does some extra thing, like modifying config files, that the dist-upgrade won’t do. But after talking about it I think that’s not true, apt really should be able to do the job. I also remember now I had trouble with do-release-upgrade once before and relied on apt to finish an upgrade for me and it worked fine. It may be it’s OK not to run that script.

Update 2

I updated a different system from 19.04 to 19.10 using do-release-upgrade. It sure didn’t look like that script was doing much other than setting up sources and running apt. I think doing this by hand for my 18.10 system (to 19.04 first, then 19.10) is OK.

Update 3

I went a little further down the rabbit hole of “what does do-release-upgrade” actually do. Useful resources: this old Stack question, this gist essay.

A key thing it does is download an updater from a metadata file and presumably run it. (There’s a shell script named “disco”). It might work to do that by hand, or else you can inspect it to try to figure it out. It’s a lot of code though.

I downloaded the disco updater (which is for 18.10 -> 19.04) and took a quick look. A specific thing to inspect is DistUpgradeQuirks.py. The disco updater has a couple of quirks. IT checks if you’re on an i386 and refuses to run. And it runs a function called _replaceDebsWithSnaps(), which is sort of self explanatory. I didn’t bother trying to figure out which debs were involved. There’s also a list of demoted packages which I imagine is a way to remove obsolete stuff. The powerpc build chain features prominently in the disco version.

So anyway, I now know that do-release-upgrade is doing more than just setting up sources and running apt. But it’s not doing a lot more, at least than I can see, and ignoring that stuff may be safe.

Updating nameservers in Ubuntu 19, Pi Hole edition

For some reason, every time I reboot my Ubuntu 19 box had /etc/resolv.conf configured to point the name server at 127.0.0.1. There’s no nameserver running there, so it fails. I want it set to 192.168.0.1. Where is this coming from? Is it related to having had Pi Hole installed at one time? systemd? What?

tl;dr: there’s like 5 things in an Ubuntu 19 system that might be modifying your name server, and tracking it down is really terrible.

In the old days you edited /etc/resolv.conf and were done. (libc knows to read this file and use it when resolving names. Crazy, huh?) That works transiently but is undone if you reboot. If you look at the file there’s a dire notice

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 127.0.0.1

OK, so systemd is a DNS resolver too now? Awesome. Don’t let the 127.0.0.53 surprise you; that’s basically another name for 127.0.0.1, localhost. Only they’re being sorta clever. But my system is broken; it’s not set to .53, it’s set to .1.

Then you go down the rabbit hole. That command systemd-resolve --status is giving you systemd’s idea of how to resolv names. That in turn seems to be configured by files in /etc/netplan, something you may have created if you configured static networking. Changing those will (presumably) alter the behavior of systemd’s DNS server.

But my problem is my /etc/resolv.conf was being regenerated at boot time to point to 127.0.0.1, not 127.0.0.53. systemd’s resolver is never involved. How to fix that? Second rabbit hole; there’s a system called resolvconf that might be overwriting it with information in /etc/resolvconf. Only what’s on my system isn’t the real (old) resolvconf, it’s actually systemd’s resolvectl running in a resolvconf-compatibility mode. I fiddled with it for awhile and I still don’t understand how this stuff works, but it seems to not be writing this entry.

I finally did a grep and found even though I’d uninstalled Pi Hole, it left behind a /etc/init.d/pihole-FTL script. Which is running resolvconf at boot time to re-set the nameserver to 127.0.0.1. This script shouldn’t still be on my system, and removing it should stop the clobbering. So I removed and rebooted.

Hah, joke’s on me! Every reboot, the 127.0.0.1 entry gets rewritten. Where is it coming from? I found it in /run/resolvconf/interface/enp3s0.dhcp. I’m not using DHCP, I have a static IP address. But that encouraged me to pay attention to /etc/dhcpcd.conf which, yes, is the actual source of the text overriding resolv.conf. I changed it from “static domain_name_servers=127.0.0.1” to 192.168.0.1 and name service works on reboot! Who knows why this matters.. dhcpcd is still running; it appears to be used to configure interfaces with static addresses even if DHCP isn’t involved.

But systemd still has one joke left on me. Now when I cat /etc/resolv.conf there are two name servers.

nameserver 192.168.0.1
nameserver 127.0.0.53

I have no idea why systemd decided to inject its .53 in there. It didn’t when the DHCP wrote 127.0.0.1 in there, but change that number to 192.168.0.1 and now systemd’s all in a hurry to put itself there. It may be coming from files I’m afraid to edit in /run. Anyway now half the queries go directly to my name server, half are looped through systemd first.

Fortunately the systemd loop seems to be working. I can’t dig @127.0.0.53 but no ordinary query ever hangs in a way consistent with a broken nameserver. systemd-resolve --status suggests that resolver is configured usefully (forwarding all requests to 192.168.0.1). So I’m just gonna leave it alone since it’s working, even if it’s not what I want.

The problem with systemd isn’t just that it’s a giant beast that tries to do everything. It’s that it’s also magic and poorly documented.

Update (DHCP edition)

I went through this ordeal again on another Ubuntu 18.10 box that I’d installed PiHole on. It took me forever to figure out where the bogus entry in /etc/resolv.conf was coming from. I finally found it in /etc/dhcpcd.conf

Ubuntu’s network configuration is a serious dog’s breakfast of competing files overwriting each other. AFAICT, any of these subsystems might be responsible for configuring /etc/resolv.conf:

I have not found this documented clearly anywhere. The way things overwrite config files quietly is really awful.

Upgrading systemd kills Ubuntu networking

Two or three times this year I’ve had a bug in a relatively fresh Ubuntu install where upgrading systemd kills the networking. I’ve got no idea what’s wrong and no physical console on the machine to inspect it. It feels like something simple like the upgrade script shut down networking but then didn’t bring it back again, but of course it could be anything.

So far this is happening only on my 18.10/19.04 box in San Francisco. Fortunately I have physical access so at least I can reboot it (usually). I haven’t seen it happen on my 18.04 box in a datacenter.

Ubuntu has a couple of recent bugs about this. Bug 1803391 boils down to a one time bug in an upgrade script in systemd. Bug 1782709 is open and confirmed with many reports and no clear idea what might be wrong. It looks like the kind of bug report that stays open for 4 years until someone closes it as irrelevant :-(

I do not want to learn so much about the guts of systemd and dpkg to diagnose this. systemd is particularly gnarly to debug since it does so much. Among other things it’s also capturing system logs, so there’s a risk whatever is being logged about the error is disappearing during the upgrade. Or not, who knows?

Again, I’ve made my peace with systemd, but this bug is a great example of the danger of centralizing so many functions into one component.

Edit I’ve placed a hold on systemd upgrades for now. Never upgrading systemd is not a solution, but this will serve as a reminder for me to only do the upgrade if I’m able to access the physical machine.

Ubuntu, DNS, and sudo

I’m confused about something in Ubuntu 18.10. Why does sudo require DNS to be working? And is that appropriate in the face of Ubuntu’s default network configuration?

First, the fun part. If DNS is broken on an Ubuntu host then you can’t sudo.

$ sudo bash
sudo: unable to resolve host gvl: Resource temporarily unavailable
[sudo] password for nelson:
hostname: Temporary failure in name resolution

I’ve seen discussions of this problem going back to 2006 and vaguely recall it being even older than that. It’s not clear if it’s even a bug; /etc/sudoers does have network-based restrictions. But it sure makes it hard to fix a system with a broken network if you can’t become room in the first place.

The usual advice / workaround for this problem is to add your system’s hostname to /etc/hosts. That way you can always resolve the name via the file even if networking / DNS is down. The dumb advice suggests adding it as an alias for 127.0.0.1, the smarter ones have you using the real IP address. However Ubuntu 18.10 doesn’t seem to have any way of adding that hostname for you, neither at install time nor at boot time via netplan. I’ve added this manually, is it a bad idea? I do worry it could get out of sync if I renumber my network some day.

Confounding this problem is DNS is kind of complicated on Ubuntu 18.10. My 18.10 system has an /etc/resolv.conf that lists “nameserver 127.0.0.53”. (Which is sort of equivalent to localhost, 127.0.0.1, but a different number.) systemd has grabbed this port and is providing DNS service via systemd-resolved. That’s a name service daemon that mostly just forwards requests to an upstream name server. The configuration for that is confusing because a lot of files in /etc get rewritten at boot time by Netplan, but in my case it boils down to “we get our DNS servers from DHCP”. All well and good and I think systemd-resolved may even be answering the host’s own name internally, not forwarding it to the DNS server.

The problem is I stopped systemd-resolved via systemctl (while I was experimenting with Pi-Hole DNS). Then I had no way to sudo to start it again. Oops.


Ubuntu 18.10 install notes

I’m updating my venerable home Linux server to Ubuntu 18.10. Installing on an SSD, and I figured I’d take the advantage to start over rather than bring along this Ubuntu install I’ve been coddling since 2011. Nothing like a little spring cleaning.

It’s remarkably tough to tell what all is running on a crusty old barnacle server like mine. I found the output of “ps -xaf” and looking at crontabs to be most useful. systemctl’s output is so noisy to not be very helpful. nmap is a good backstop for checking out network services.

All told it took about 2 hours to get the software environment set up more or less like I used to have it. That seems incredibly fast to me! It took 2-3 more hours to install more persnickety things and I am still apt installing various random command line tools I’m missing.

Boy SSDs are nice. The machine boots in about 6 seconds. Really 3, but then we waste 3 seconds (or more) waiting on the buggy r8169 Realtek driver for the ethernet to come up. I tried ordering a replacement Intel NIC but the one that arrived from Amazon was counterfeit.

The drive I’m replacing has run for 61289 hours, or just about 7 years. Been turned off and on 41 times. Smart has logged 0 errors for it. Not bad, li’l WD Blue!

Things I did and random notes

“curtin” is the name of the Ubuntu installer. It leaves a couple of little named turds behind in /etc/apt/, /etc/cloud, and /etc/default/grub.d.

A lot of Ubuntu wiki docs are seriously outdated, often describing things that were only relevant in 2014 in the pre-systemd days. Caveat lector.

Configuration change

Immediately run apt update; apt upgrade. No idea why this isn’t done automatically.

Add a static IP configuration in /etc/netplan, removing the old 50-cloud-init.yaml that was there. The default DHCP configuration is perfectly reasonable but I want my server to work even if DHCP is down.

Edit /etc/default/grub to add fsck.repair=yes to the kernel command line. I’m not certain but I think this is the systemd way to ensure the boot disk is really fscked at boot time. Note there’s a bug in Ubuntu where /etc/default/grub.d/50-curtin-settings.cfg overrides the setting of GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub. I swore a little and then edited the offending 50-* file. This bug may be fixed in December 2018.

Stuff I installed

python3.7 and python3.7-venv. Cosmic (18.10) defaults to 3.6.

chrony to replace the crappy systemd NTP implementation.

plexmediaserver from their Ubuntu repo. Bless their hearts, this is still buggy so many years later, but it mostly works. Ignore any weird warnings about “Conflicting distribution”.

postfix as a local machine. this means mail stays entirely local, so mostly useless, but lets cron errors get through

munin. good ol’ system monitoring. I love the inscrutable graphs.

rsnapshot for backups both local and remote. I like the idea of Duplicati but after its last install corrupted itself I’m not in a hurry to install it again.

samba. This just worked?! I borrowed bits of my config from before but that was pretty simple, just set up a couple of shares. Samba used to be such a heartache to get working, amazing.

SABnzbd for Usenet downloads. This turned out to be remarkably complicated. Ubuntu 18.10 has a recent version in the repo, but the setup script is not great.

  1. Install sabnzbdplus. Ignore the suggested packages
  2. Create a nzb user. useradd -r nzb; usermod --lock -s /usr/sbin/nologin nzb
  3. Edit /etc/default/sabnzbdplus. You have to change USER. Default port is localhost:8080, I changed that too.
  4. service sabnzbdplus start
  5. point a web browser at the instance, use the configuration wizard
  6. if you had an old config, it’s stored in ~nzb/.sabnzbd/sabnzbd.ini. Server passwords are helpfully in plaintext.

Stuff I didn’t have to do

Some things I’m used to doing on new systems, but weren’t necessary.

Install locate, the doodad that lets you do a fast find for a filename. Ubuntu 18.10 comes with mlocate already installed.

Set up unattended-upgrades for security fixes. It was already installed for me.

Set up powersaving. The default configuration is powersaving for the CPU, you can verify via cat /sys/devices/system/cpu/cpu$FIRSTCPU/cpufreq/scaling_available_governors. (To configure this see systemd ondemand or else cpufrequtils).

Change the I/O scheduler. CFQ looks to be the default now.

Kernel module blacklist

Ran across a fun part of my Ubuntu system today, /etc/modprobe.d/blacklist*. It comes from the kmod package and contains a list of kernel modules which are included in the Linux sources, were compiled and shipped with Ubuntu, but nevertheless are being banned because someone made the choice they didn’t like the module. It’s kind of hilarious.

I can’t find a web-linkable version of the default Ubuntu files, but here are some gems from them. I suspect each entry here is a series of hard-earned lessons.

# causes no end of confusion by creating unexpected network interfaces
blacklist eth1394

# ugly and loud noise, getting on everyone's nerves; this should be done by a
# nice pulseaudio bing (Ubuntu: #77010)
blacklist pcspkr

# Framebuffer drivers are generally buggy and poorly-supported, and cause
# suspend failures, kernel panics and general mayhem.  For this reason we
# never load them automatically.

# Many less commonly used network protocols have recently had various
# security flaws discovered. In an effort to reduce the scope of future
# vulnerability exploitations, they are being blacklisted here so that
# unprivileged users cannot use them by default. System owners can still
# either modify this file, or specifically modprobe any needed protocols.

I was looking for this because I’m reinstalling Linux on my server and there’s still some drama about the r8169 driver, with some suggestions to lacklist it and build a vendor driver from source.

In the grand old days I used to build my own Linux kernels. But I always statically linked them, no loadable drivers, no init ramdisks. One kernel carefully sculpted to work on my one particular computer. It’s kind of a dumb way to make a system work.

Ubuntu 18, Samba, and ntlmv1

I have a security camera that writes videos to my Ubuntu 18 machine, mounting the disk via Samba. it stopped working recently. Turns out Bionic Beaver shipped a tiny little security patch which includes this:

  * SECURITY UPDATE: Weak authentication protocol allowed
    - debian/patches/CVE-2018-1139-*.patch: Do not allow ntlmv1 over SMB1
      and add tests.
    - CVE-2018-1139

They’re not wrong to change this; ntlmv1 is a terrible ancient insecure authentication protocol. But it’s just the kind of thing some old firmware is likely to require, like my camera.

The simple workaround is to restore ntlmv1 by adding this to the smb.conf:

ntlm auth = yes

Don’t do this if you don’t trust your network. For that matter don’t run Samba at all if you don’t trust your network. I mean it’s supposed to work, but I sure wouldn’t.

 

autossh in Ubuntu 18

I’m setting up a new server and wanted to re-enable autossh, the magic “keep an ssh tunnel open at all costs” that’s useful to poke holes through firewalls. I ended up following my old notes pretty much exactly, down to using /etc/rc.local. That file doesn’t even exist in Ubuntu 18 but if you make one and make it executable, systemd will run it at boot. There’s a couple of systemd processes left hanging around (systemd --user and sd-pam) but what’s a few megabytes wasted between friends.

I did try to make this harder though. I spent some time trying to make this systemd service work, for instance. Never could get it to work. Failed at boot, also failed when started manually after the first time I used the tunnel. systemd is doing more magic than I understand.

It’s not clear you even  need autossh if you’re using systemd. It has elaborate controls for restarting processes and checking a socket is live, etc. Here’s a sample of using systemd to keep an ssh tunnel open. I didn’t try it though. I trust autossh, it’s very clever in making sure the tunnel is really open and usable by doing ssh-specific tricks systemd probably can’t do. Also I already had certificate management working, so screw it.

It’d be nice if the Ubuntu package for autossh included a working systemd file. Ubuntu switched to systemd, what, 5 years ago? But I guess not all the packages have been made to support it.

 

python 3.6 on Ubuntu 16.04 LTS

I want to use python 3.6 on my Ubuntu 16.04 LTS box; they only have python3.5. It’s pretty simple following these instructions but here’s the details.

Step 1: install python 3.6 from Jonathon Fernyhough’s PPA.

add-apt-repository ppa:jonathonf/python-3.6
apt-get update
apt-get install python3.6 python3.6-venv python3.6-dev

Step 2: set up a 3.6 venv

python3.6 -m venv venv
source venv/bin/activate
pip install -U setuptools pip
python -V

Now when you activate venv, you’ll automatically get python 3.6 in that environment.

In addition to the jonathonf PPAs there’s also the deadsnakes PPA which has old versions of Python as well as new ones.

ConEmu + ubuntu on windows: bell

I’m pretty happy with how my Unix setup on Windows is working. But there’s one horrible thing; the awful bell sound in the terminal emulator. Every time I hit tab in bash to complete it plays a good old ASCII 0x7 BEL, and it’s some earth-farty three tone loud sound that is just awful.

The solution is simple; go to the volume mixer and set the volume for “Console Window Host” to 0. Now your shells won’t make any audible noise. Of any kind. Peace and quiet.

What I really wanted was to reconfigure the bell sound. PuTTY has a whole set of options for this. I think it’s not really possible though. ConEmu can’t or won’t do it, as the author angrily keeps telling users. Apparently his code isn’t playing the bell at all, it’s being passed through to a lower level Windows console handler of some sort. There is an option for intercepting the bell but it’s not working for me for some reason, at least not on Ubuntu-on-Windows. It does seem to work for msys.

Another option often suggested is to configure your Unix programs not to use a bell for alerts. You can set it in bash, and GNU readline, and vim, and less, and... that way lies madness.

It turns out the sound is actually being played by Microsoft’s software, somewhere deep in their version of Bash or WSL or something. And it’s apparently not configurable. But you can find it in the volume mixer and cut off its air supply.

God that sound was awful.

Keeping time, time, time,
In a sort of Runic rhyme,
To the tintinnabulation that so musically wells
From the bells, bells, bells, bells,
Bells, bells, bells --
From the jingling and the tinkling of the bells.

Update: the plot thickens. The sound that’s being played is supposed to be a honest-to-good beep, the one generated by the motherboard with its integrated trashy speaker. Not your fancy stereo sound system. Modern hardware doesn’t have speakers, and starting in Windows 7 there was a special “beep driver” written to intercept this low level beep system ability and replace it by playing a wav file.

The sound Windows 10 seems to be playing is the sound event “Critical Stop” which is set to play “Windows Foreground.wav”, that horrible sound. I replaced it with “Windows Ding” and it’s better.

Unix environments for Windows

One thing I miss about my Mac is having a usable Unix environment. Now I have two on my Windows machine, with different significant flaws. MacOS isn’t a great Unix, but it’s perfectly adequate for basic stuff. And it’s really handy having tools like rsync and command line ssh around. Windows has its own command line world with the venerable CMD.EXE (DOS) and the newer PowerShell. But screw that, I want Unix. Here are options.

Ubuntu-on-Windows (WSL)

This is the new hotness from Microsoft and is very nice. It feels like a legitimate Ubuntu environment. Except so far it doesn’t support networked filesystems.

WSL sits as its own OS on top of the NT kernel, just like Windows is an OS on the NT kernel. There’s not a proper Linux kernel running, instead Microsoft has emulated the Linux kernel at the syscall interface. The userspace then runs stock Ubuntu, actual Ubuntu x64 binaries unmodified. It’s an impressive piece of work.

The drawback is not everything works. ping doesn’t work unless you run bash as Administrator. (Some docs I’ve read say ICMP isn’t implemented at all.) Filesystems are limited. USB drives don’t work. Network file shares don’t work. There’s no NFS support in the Linux image, nor is there FUSE support. The view of the underlying Windows filesystem (in /mnt/c) is a bit strange too, like I can’t see a proper view of my Desktop folder. In general stuff that works seems to work right, and the Microsoft team is moving fast in adding new features. I’m tempted to join Windows Insider just to start running betas, but I think I have to get a whole new Windows version, not just an upgrade to WSL.

There is an honest /sbin/init process running in WSL, PID 1, but its only child by default is the bash shell you start the thing with. So no init scripts / systemd running services. You can open multiple bash processes that can all see each other and share a filesystem. But if you close the last bash, you lose the whole WSL environment, which makes daemons a bit awkward.

Other names for this system are Windows Subsystem for Linux (aka WSL) and “Bash on Ubuntu on Windows”. Note these make for awkward search terms on Google.

Cygwin

The granddaddy of Unix emulation for Windows. I haven’t tried it in a few years, but I used to hate its package manager and its approach to Windows integration. Weird path names and environment. But it works pretty well and has a significant set of tools. MobaXterm bundles Cygwin in with an X server and terminal emulator.

msys2

The other venerable Unix option for Windows, some evolution of msys / msys2 / MinGW / mgwin32 / MinGW-w64. It has some Cygwin roots in it too, I’m not sure how much, but the mingw philosophy is to make things more like Windows and less like Unix. The result is a lighter weight Unix environment with some compromises. For instance symlinks aren’t supported because they wouldn’t work in Win32 apps. So instead creating a symlink makes a copy of the file, which is pretty damn broken but you can live with it. The crazy neat thing is the Unix programs like make are actually Windows executables like MAKE.EXE and will work fine in Windows, without bootstrapping a Unix environment. Handy for ssh.

There’s no visible init process, you just have a naked bash running according to ps, although its PPID shows as 1. Software is managed via pacman (as used in Arch Linux), there’s a large variety of packages and a toolchain for building your own. I’m not wild about the package and software versions and a bunch of basic stuff isn’t installed by default (like tar). Also some of the tools have idiosyncracies. And I have some problems like Ctrl-C not interrupting IO bound bash scripts. But it’s definitely a usable Linux environment, just not Ubuntu.

Git for Windows (aka msysGit)

This shows up as a recommended Unix option. It’s a tight, easy to install bash shell plus enough related utilities to run git. It is based on msys2, some of the history is here. It does not include much though, like there’s no rsync. And no compiler toolchain, no package manager for installing more stuff. It’s great for providing a git command line though.

Terminal window

Unix programs really want to be running in an xterm/vt100 emulator. There’s a bunch out there. I’m liking Cmder, which is an enhancement wrapper for ConEmu. mintty is another option, that’s what msys2 uses by default. wsltty is a customization of mintty for WSL. MobaXterm is also popular. Note that PuTTY/SecureCRT is not really needed any more. They are a combination of terminal emulator + ssh, but now you can just use a simple emulator plus OpenSSH command line. Still working on a good ssh-agent solution though.

History

As a historical footnote, WSL is not the first unmodified Ubuntu to run on Windows. There’s also andLinux, based on coLinux, a cooperative VM. There’s some other Unix-alike Windows options out there too, I think mostly abandoned. See also Interix and Windows Services for UNIX.

Ubuntu 16 NTP notes

I love NTP. What’s it look like in Ubuntu 16? ntpd is pretty much the same, but some change or things I’ve never noticed before.

Debug mode 7 queries are now entirely disabled. The ntpdc program basically doesn’t work; you use ntpq instead. Given the number of times this protocol has been used in a UDP amplification DDOS, it’s a necessary change.

ntpd is started with the -g flag. This flag allows NTP to set the system clock once no matter how far out of sync it is. The default behavior is to never move the clock more than 1000s as a sort of sanity check. In practice it’s usually the client that’s insane, not the server.

servers are now configured like this

pool 0.ubuntu.pool.ntp.org iburst

“iburst” means the ntpd will try 8 times in 16 seconds to reach an unreachable server. The “pool” directive is not in the man pages, but these docs explain it. It tells ntpd to use DNS differently, to look up random new IP addresses every time. I’m not positive but I think ntpd still isn’t smart enough to look up a new pool IP address every few days or when a server goes offline. But at least it’ll get different IP addresses for the same hostname.

In addition to ntpdate/ntpd, Ubuntu also now provides timedatectl and systemd-timesyncd, part of the systemd hydra. It’s not very well documented; see Arch’s docs and this announcement. It’s a lightweight client-only time synchronizer. That seems like a good idea for security / client footprint. But it may be a bit too lightweight. It sounds like it only gets time from one server, for instance, and I wonder if they’re doing the PLL clock syncing that makes ntpd so good. systemd’s stuff gets out of the way if you are running ntpd.

Ubuntu 14.04 to 16.04 notes

I had a moment of foolish optimism and decided to upgrade my development machine from Ubuntu 14 (Trusty) to Ubuntu 16 (Xenial). “Just run do-release-upgrade”, the motd has been encouraging me for months now. So I did.

And it failed. And then I tried to fix it by hand and I thought I did. And then the machine didn’t reboot. So that’s discouraging. But then the second time I tried to reboot (after hauling the machine over to a monitor) it rebooted fine. And now the machine is fine. No idea what that was about, but yay for Ubuntu robustness! My reboot problem may have nothing to do with Ubuntu, but rather be a problem with my ethernet. Anyway, some notes.

On the upgrade scripts

  • do-release-upgrade runs in a screen session. Some of the upgrades prompt you to compare changes in config files, and will helpfully propose spawning a shell to let you inspect the situation. But your tty is occupied in some weird way with screen and/or scripts running in the background. I was getting all sorts of random crap on my screen and I panicked and aborted the upgrade script. Do not make this mistake.
  • You can’t run do-release-upgrade a second time. The system thinks it was already upgraded and it aborts.
  • Fortunately mostly do-release-upgrade does stuff up front, then relies on apt and dpkg to do the real work. Those tools are robust. I’m not really clear on what all do-release-upgrade does, but here’s a reference. I sure hope there wasn’t anything crucial that didn’t happen because I aborted.
  • I fixed things by running dpkg-configure by hand, then running apt-get upgrade a bunch of times. apt-get dist-upgrade is probably not a bad idea either.
  • I also improved things by removing a bunch of PPAs from /etc/apt/sources.list.d.
  • There are some install logs in /var/log/dist-upgrade, including a full screen recording.

On changes in Ubuntu 16

  • Welcome to systemd! Everything about how the machine boots is different. I mostly noticed this with warning messages printed at boot time about funky scripts in /etc/rc that weren’t up to snuff. These came from me or PPAs, not the core code.
  • “systemctl” seems like an important new command to learn. Useful commands: enable/disable, start/stop, status. Also “journalctl” to see systemd’s logs.
  • some init scripts were broken / old / weird. I have a bunch of old cruft! I fixed these by purging the packages and reinstalling them. Culprits included screen and mongodb.
  • My 2012 lm-sensors install included some kernel modules that no longer exist. Fixed by re-running detect-sensors and removing the old entries from /etc/modules
  • I’m getting an error about mount options in dmesg that I can’t understand. It doesn’t seem to be hurting anything though, so ignoring it.
  • grep thinks my syslog is a binary file, it has some nulls in it (which is terrifying!). So i have to use “grep -a” to see the whole thing.

On user programs

  • I run Crashplan which makes extensive use of inotify. The default Linux settings only allow 8192 files/directories to be watched, not enough. Here’s how to update the limit.
  • I had to manually install python3-venv with apt. Then my existing venv directories were broken and I had to rebuild them.
  • My plex server was broken. Difficulty level: systemd. I finally traced the problem down with help from here; “systemctl status” told me it was having a problem with the group. Turns out the server wants to run as group plex, not just user plex, but no one had set up a group plex. BTW hooray! The Plex team finally has an official apt repository
  • I somehow ended up with Postgres 9.1, 9.3, and 9.5 all on my system. With 9.3 and 9.5 daemons fully running. I don’t have any permanent data on the development machine so I went with a full wipe and reinstall of all Postgres. The stock Ubuntu 16 versions of GDAL and PostGIS seem to work nicely.

Ubuntu name lookup: DNS vs NSS

Usually when I want to look up a domain name, I use the “dig” or “host” command. This issues a live DNS request to the configured DNS servers and you get a response from DNS. Sometimes I use “whois” on the domain first to find the domain authority, then do a “dig @server name” to find the actual live authoritative response, bypassing whatever cache my usual resolver (Google DNS) has.

But client programs on Ubuntu don’t issue DNS queries directly. They use NSS, the Name Service Switch, as configured in /etc/nsswitch.com. (In the long long ago a similar system was named YP, for Yellow Page). NSS often ends up using DNS to resolve a hostname. But it also uses local files like /etc/hosts. I’ve always had some fear it did its own caching too, although I don’t think my system does. There’s a daemon called nscd that would do caching, but I don’t have it installed.

Anyway, ordinary programs like “ssh” or “ping” don’t use DNS directly, they use NSS to look up IP addresses. So how do you query what NSS would do? The getent program.

$ getent ahosts google.com
216.58.194.142 STREAM google.com
216.58.194.142 DGRAM
216.58.194.142 RAW
2607:f8b0:4000:80d::200e STREAM
2607:f8b0:4000:80d::200e DGRAM
2607:f8b0:4000:80d::200e RAW

That’s returning a lot of data! “getent hosts google.com” returns a single address, which is generally what you mean. But for Google that gives you an IPv6 address. The “ahosts” command prints all possible matches, which is useful for debugging.

I’m digging into all this because of a frustrating problem with a freedns dynamic DNS name I use for my home machine. Every six months they decide I’m inactive and change the address to some domain parking page. In theory they email me a warning but it never gets through. So it breaks scripts I have that use the name to access to my home network. And I dutifully log in an re-enable my account, but it takes awhile for the changes to propagate.

After I re-enabled my account, “host” and “dig” would show the right address but “ping” or “ssh” would use the wrong address. Turns out if a domain is disabled freedns sets its A records to both 127.0.0.1 and 87.98.255.18, their parking web server. So that’s confusing. On top of that they set a TTL for one hour, which is kind of awful for something you’re trying to update. But I think my real problem was that one Google name server had cached the old bad address but another had cached the good new address, so queries were giving me random ones.

I’m going to just add a manual entry to /etc/hosts for now until that hour period is up.

Things I learned about systemd

systemd is the Linux startup system for Ubuntu 16.04, so I figured it’s time I learned about it. I’m very late to the party; systemd started some 6 years ago and became a real thing many Linux distributions used years ago. Ubuntu is the last big distro to include it by default except Gentoo, and even Ubuntu switched last year with 15.

There’s been a years-long debate in the Linux community about systemd. A younger me would have cared about that, maybe participated. These days I don’t care, I just want to use the consensus tech. The bummer is the flamewars dominate the conversation, it’s hard to learn just what systemd is. Here’s my effort to just understand it.

Disclaimer:  I’m not an expert and have undoubtedly made a mistake here somewhere. I reiterate my reminder that I really only write this blog as notes for myself. You’re welcome to comment, but please don’t waste my time with heated opinions.

References

I don’t have more links on actually using systemd in practice because I don’t yet have a system running it myself. That’s how out of date I am. The key pragmatic thing seems to be the unit files which configure how systemd launches services. systemd can also still launch stuff with old SysVInit-style scripts, including parsing the LSB headers.

Stuff I learned

systemd is init, the first user process on a Linux system, PID #1. Once the kernel is done it runs PID 1 whose job it is to then run all the other user stuff that makes a Unix system; mounting filesystems, configuring networking, starting daemons, etc.

The init most of us know is SysVInit, the shell scripts in /etc/rc.d. It hasn’t aged well in a modern era of multiple cores, dynamic devices, etc. Upstart is another Linux init system that Ubuntu has used for a long time, but no one seems to love it. Launchd is the MacOS init and deserves some respect for its speed and power; the systemd authors explicitly acknowledge launchd for inspiration.

systemd is a full rewrite of the idea of init. The primary goal seems to be mostly about efficiency. In the bad old days a Unix system could take 90 seconds to boot. With systemd (and MacOS launchd) < 1 second is possible and < 10 seconds is common. systemd is faster because it can do things in parallel. Also it avoids all the overhead of interpreting shell scripts. And supposedly it’s just modern and new and “better”, which I can’t really evaluate but can believe given the mess of stuff that preceded systemd.

systemd is Linux-only. It uses a bunch of non-POSIX APIs to do things like work with devices, configure security capabilities, etc.

I still haven’t used systemd hands-on so I haven’t learned much else. But my understanding is a whole bunch of Unix config gets consolidated into unit files in one place, which then tells systemd how to configure and launch user space programs.

I’m a little terrified of the Ubuntu 14 to 16 upgrade, it has to replace all the old stuff with the new. Will it work? Particularly reminded of an Ubuntu 12 to 14 upgrade I did where I manually installed something that changed the name of my ethernet device, making the machine unable to reboot with networking. Oops.

Opinions

I really don’t care about the history of the controversy; systemd’s a fait accompli. But it’s helpful to look at the debate to understand better what systemd is.

The big complaint about systemd everyone has is complexity. It does a lot of stuff in one big nest of 60+ interlocking binaries. It’s not just forking daemons. It’s got udev inside it to manage devices. It’s got its own logging system (in a binary format), a cron equivalent, an inetd equivalent, an atd equivalent, virtual terminals, a login daemon, watchdogs, etc. When you look at all the old Unix software that’s replaced it’s sort of astonishing and I can understand why believers in the “lots of little tools” philosophy don’t like it.

OTOH, the way the old components fit together in sysvinit was quite a hairball too. The shell hackery required to mount devices, then filesystems, then get networking up so you could access other filesystems and start other daemons in the right order and blah blah blah. Sure udev and mount might have been separate software, but they could only run correctly in one specific relationship to each other. That complex set of interdependencies had a lot of cost and somewhat made a lie of “lots of little tools”. Also there’s something to be said for unifying init and cron and inetd and login and the like; they’re all about launching programs in response to events, why not share the code?

There’s still a cultural concern that systemd, being a monolithic project, comes from one mindset only. Some of the choices seem odd to me; a binary log format for instance. That’s the part of the debate I can cheerfully withdraw from. For whatever reason most Linux distros have agreed on using systemd, and I trust that they all have the influence to shape it the way they need. That seems like a reasonable path to working software.

 

Ubuntu guest VM frustrations

I’m trying to set up Ubuntu in a virtual machine. My goal is to recreate locally an environment a little like I might get from Amazon EC2, so I can do rapid testing of deploy scripts. I don’t need an exact Amazon AMI, but a clean Ubuntu image is close enough I can get stuff working before dealing with a remote environment.

I’ve got a VM host running. It’s Ubuntu 14.04 running KVM. Seems to work.

I’ve previously gotten Ubuntu’s new Snappy working as a guest. It boots fine and I can access ports. Unfortunately this environment is a strange Ubuntu 15, which has replaced apt with the “snappy” tool. Not enough like an EC2 host to be useful.

I tried using an Ubuntu Cloud image as a guest. They ship 14.04. But it doesn’t boot cleanly:

2015-05-03 18:25:26,540 - url_helper.py[WARNING]: Calling 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [119/120s]: request error [(&lt;urllib3.connectionpool.HTTPConnectionPool object at 0x7f0f325e58d0&gt;, 'Connection to 169.254.169.254 timed out. (connect timeout=17.0)')]
2015-05-03 18:25:27,542 - DataSourceEc2.py[CRITICAL]: Giving up on md from ['http://169.254.169.254/2009-04-04/meta-data/instance-id'] after 120 seconds
2015-05-03 18:25:27,550 - url_helper.py[WARNING]: Calling 'http://10.0.2.2//latest/meta-data/instance-id' failed [0/120s]: bad status code [404] [404]

The init scripts are waiting on some network resources to load. The IP addresses are on the local network, and I guess it’s some sort of Ubuntu cloud server configuration thing. I don’t want all that! I just want a basic Ubuntu unmanaged instance to boot. Unfortunately ssh is still refusing logins. It does finally give up but it takes about 4 minutes, way too long for the rapid iteration I have in mind. And then I can’t log in. Apparently there is no default password. This image is really not designed for the quick and dirty hackery I want.

I did learn something about how QEMU/KVM’s networking stuff works. The default IP is provided by slirp, which among other limitations does not support ICMP. So that’s why ping doesn’t work! Also it’s outbound connections only, although the “-redir” flag to kvm seems to offer some basic port forwarding.

I found this guide to using libvirt sort of interesting, it’s simple stuff for managing the virtual machine image. Although again way overkill for what I want.

At this point I think I’m going to give up on running my own KVM guests and hope that EC2 gives me a new machine fast enough that testing machine setup scripts using throwaway instances isn’t too annoying.

Update: my friend Jeff says that I should look at ubuntu-vm-builder. It will apparently make me an image. I sure would be glad to just download one someone made already though.

Ubuntu on a Mac Mini

I finally gave up on MacOS for a Mac mini server I have and wiped it and installed Ubuntu 14.04LTS. It mostly went pretty smoothly, Ubuntu makes bootable images for Mac hardware that work fine off of USB keys. And I just wiped the whole disk and removed any vestiges of the MacOS boot loader, I imagine it’s a bit trickier if you care to preserve MacOS.

The one real problem I ran into was the new system hung at boot right after adding swap. That error is a red herring though; really it’s hanging trying to change video modes. Dumb, particularly the lack of a useful console message. The solution is to add nomodeset to the kernel command line in GRUB.

Also a few minor problems. The WiFi adapter doesn’t work, of course, although maybe the non-free drivers I was advised I could install fix that. Ubuntu’s automagic partitioner doesn’t give you a way to resize the swap partition, you’re stuck with it being the size of system RAM. And it did enough other magic things on repartitioning I was afraid to try to roll my own.

I’m pretty unimpressed with how slow this Mini is, now that I have an OS I understand on it. The Plex server seems OK, and it can transcode 1080p video at 5x real time or better. But trying to rsync 300GB of files over gigabit ethernet to it basically pegged the machine; the poor SSH process with the network connection was using 50% CPU even after I told it to use arcfour encryption, supposedly the fastest available. And terminal responsiveness was like 10 seconds at a time, although maybe it’s partly the Linux scheduler to blame for that. Anyway the system has a i5-3210M CPU which apparently is pretty weak, despite having 2 honest cores in it. Will be fine for a file server but I’m glad I built a beefy compute server for real work.

NFS: Ubuntu server, MacOS client

I’m finally fed up with Mavericks broken SMB implementation. It’s appalling how bad it is. For awhile I had it working by forcing SMB 1 via cifs:// share naming, but that stopped working. Suddenly SublimeText and TextEdit were creating files with mode 0764, god knows why. MacOS touch was creating 0644 as expected. Anyway, fed up, it’s broken, so I’m going back to NFS. (Apparently Yosemite is shipping a new SMB 3 stack, maybe that’s better? Yosemite is broken in so many other ways though...)

I used NFS 3 years ago and those notes still apply. However, some changes.

Ubuntu server: as simple as can be. The wrinkle is that unless you want to get all fancy with Kerberos or idmapd or something user IDs don’t get mapped. Last time I just changed my numeric IDs on my Mac to match the Linux server. This time I’m trying something new, this cheese in /etc/exports:

/home/nelson 192.168.0.0/24(rw,insecure,async,no_subtree_check,all_squash,anonuid=30193,anongid=30193)

I’m abusing NFS anonymous ID mapping to force all requests to look like user ID 30193 and group ID 30193, my personal IDs on my Ubuntu box. It looks wrong on the Mac client, and it’s not appropriate for a multiuser server. But it gets the basic job done.

Mac client: more confusing now. Mavericks removed the graphical NFS configuration tool that I used to use. However the default automounter setup is not so bad. The path /net/ub/home/nelson is magically the NFS share ub:/home/nelson and seems to automount usefully. I think it’s using NFSv3. Haven’t needed to tune any parameters yet.

It wasn’t my primary goal, but as a bonus I get better speed out of NFS. The SMB 1 implementation seemed limited to about 10 megabits / second when writing to the server. NFS is running at the full 100 megabit link speed.

kvm and Ubuntu snappy

I just launched my first Linux virtual machine ever, thanks to Ubuntu Snappy. Ubuntu 14.04 as the host and the stripped-down Snappy as the guest OS. The “locally with kvm” instructions worked fine except I had to add -nographic to the kvm command line to get it to launch headless.

The guest image has 512MB of RAM available, but the host qemu process has 940MB mapped. Wonder what that’s about? Presumably there’s ways to configure the resources availalbe on the guest machine.

I like the idea of Snappy, an Ubuntu distribution specially stripped down for VM guests, Docker, etc. I don’t know the market well enough to know if it’s competitive. I am much more inclined to use a guest OS if it feels like Ubuntu though. Confused about what snappy is doing as a package manager. apt-get is not enabled. dpkg is there and a bunch of stuff is installed, but I think you manage the Ubuntu core OS with snappy.

The guest reboots in about 11 seconds.

python-pip is broken in Ubuntu 14.04

Running pip on my Ubuntu 14.04 box gives the error “ImportError: cannot import name IncompleteRead” when trying to import the requests module. Turns out this is a known bug going back to at least April. It’s subtle though; a different Ubuntu box with the same versions of python-pip and python-requests is fine. It’s apparently a bug in python-requests, see also Migurski’s workaround.

A quick workaround is to remove Ubuntu’s python-pip and install pip manually.

running tcpcrypt on Ubuntu

Excited by the new TCPINC effort, I went to build and install tcpcrypt, a sample implementation of a proposal. The GitHub project has recent activity and the code mostly builds.

I had to install these packages to get it to build:
autoconf libssl-dev libcap-dev libnetfilter-queue-dev.

It runs, too, and installs OK. Funky way it works using iptables to redirect traffic. The tcpcryptd self tests to check.tcpcrypto.org worked, but using curl to load the check page at http://tcpcrypt.org/test.php didn’t. Turns out the problem was curl doesn’t follow redirects and that’s the only way you know the test works, “curl -L” or “wget” works. I ended up setting up an SSH tunnel to test from my Mac and was able to get http://tcpcrypt.org/fame.php to work correctly and register as #809 on the Hall of Fame.

I’m curious if anyone plans to use this code as the basis for a real implementation. If so would be worth my time to make the build process easier. Also maybe remove some of the swear words from the code :-P

Ubuntu 14.04: converting m4a audio to mp3

I want to convert a bunch of .m4a files that youtube-dl created to MP3 files. The files are audio only, 128kbps, AAC encoding. They play in VLC but a lot of AAC-supporting software like Sonos can’t read the .m4a files and I don’t care why, just want to convert it to the shitty 18 year old format that works everywhere.

First challenge is that ffmpeg has completely disappeared from Ubuntu 14.04. It’s been replaced with avconv. There was some nerd fight and a fork, no idea what or why or which fork is better. Sigh. Ubuntu went with the fork avtools, so I will too. (There is an ffmpeg PPA). “ffmpeg” is now “avconv”, and “ffprobe” is now “avprobe”.

sudo apt-get install libav-tools

for f in *; do
  avconv -i "$f" -metadata album="Album Title" "${f%.m4a}".mp3;
done

I realize this is all very basic, but every time I try to do any AV codec stuff I get very confused. I wasted a lot of time playing with quality options before deciding avconv was choosing a reasonable setting that I couldn’t really override, probably based on the source material. (Although apparently there’s at least two MP3 codecs buried in there being autoselected.) Also I tried using “-threads auto” to speed things up but no luck, maybe the MP3 encoder is single threaded or maybe it’s all IO bound anyway. It’s re-encoding about a megabyte a second, fast enough for my small job. GNU parallel is another solution here.

Sadly the source tracks have no useful metadata in them like song title or artist. I did throw in an album name at least.

Calistore 0.8 quickstart (Ubuntu) and thoughts

I’ve been curious about Camlistore for awhile, a project from a lot of smart people like Brad Fitzpatrick and Aaron Boodman and the like. It’s a content addressable filestore “for life”, a sort of Dropbox / Lifestreams kind of thing for storing all your personal data. Ambitious and necessary. My immediate use case is as a replacement for the horrible Unison and rsync tricks I do with a USB drive to keep two Macs sort of in sync.

They’re up at 0.8 now and have fewer dire warnings about how it’s not ready for users yet. I just asked Brad F and he said “I’d wait a bit for 0.9.”, which I good-naturedly take to mean “sure 0.8 is worth looking at” :-) Quick start on getting it going in Ubuntu, based on the Camlistore docs

  1. Install the Go Language. Don’t bother looking for an APT repository, the official one is out of date and the third party PPAs are all abandoned. Just install straight from the golang site.
  2. Download and build Camlistore from the github repo
  3. Run the camlistore daemon. It should advise there’s a UI on http://localhost:3179/ui/
  4. I had a problem with the UI requiring a basic auth HTTP login; maybe the “allow localhost” stuff was fooled by my ssh port forwarding. So I edited ~/.config/camlistore/server-config.json to add a username and password

I also watched Brad’s video from Feb 2014 to FOSDEM. Nice overview and some demos.

The main takeaway is the way Camlistore works is a blob server + a metadata indexing system. The blob server is a simple content addressable file system, keeps track of syncing raw data whose only name is the SHA1 hash of the data. Then there’s other metadata blobs which contain things like “blob with SHA1 f392... is actually IMG_0902.jpg, a 3000x2000 JPEG with this creation data”. The problem with content addressable file systems is that the moment you change the file it’s basically a brand new file. They have a concept of “permanode” that provides permanent identity for things independent of their content. It sounds like a lot of work is put into the indexer system to make it a usable filesystem.

Speaking of usable, the main UI they show off is a Web UI. Fancy real time updating searches. Demo was managing a bag of phonecam images. There’s also a FUSE filesystem that in the demo seemed very slow because it was syncing to a remote server. (Slow, like “touch foo” took 5+ seconds.) Not sure if there’s a faster way to sync to a local server, then have it sync those updates to the remote server. Seems like you’d have a consistency problem for the metadata on permanodes. Maybe they rely on timestamps to sort out a merge?

There was also a quick demo of “thirdleg”, a sync from one store to another through a third thing, like a portable drive you’d carry from A to B. That’s exactly what I need for my use-case above, but I’m not sure if I’d want to rely on FUSE to be my filesystem for actually using my synced files.

My main takeaway is that they have a pretty good take at a low level distributed data store suitable as a sort of synced remote filesystem. I was a little less convinced about the applications demoed, like that Camlistore will end up being most useful as an underlying layer for something and we haven’t quite seen the apps that use it yet. For near term usefulness the key thing is probably how responsive that FUSE file system is. Need to try it out.

ubuntu 14.04, udev, ethernet

After 10 years of fiddling with remote servers, I finally killed one so I couldn’t access it on reboot. The system came up fine but not the network. The nice remote admin logged in and found that the Ethernet device was now named /dev/p4p1 and the config files were expecting /dev/eth0. He updated the config and it works, for now. I’m scared to reboot again since I don’t understand what caused it to change in the first place.

tl;dr: installing biosdevname causes devices to be renamed at boot.

Summary: I installed biosdevname and I think that caused my ethernet device to get a different name after reboot. A fresh Ubuntu 14.04 system uses biosdevname to give Ethernet devices names like /dev/p4p1. These names are based on the physical location of the adapter on the PCI bus. An old Ubuntu system upgraded to 14.04 may not install biosdevname and instead use older working names like /dev/eth0 that are configured by MAC address in /etc/udev/rules.d/70-persistent-net.rules.

Some detailed notes on what may have broken it:

  • The system started as Ubuntu 10.10, I did two do-release-upgrades to bring it to 14.04. After installing 14.04 it booted correctly at least once, configured as /dev/eth0 for ethernet. Now it wants /dev/p4p1
  • After the working boot I installed a few packages that I regret installing. Specifically biosdevname libsystemd-daemon0 systemd-shim systemd-services discover linux-image-3.13.0-36-generic.
  • I removed the 3-13.0-36 kernel and then had to do some awkward stuff to fix grub to use the linux-image-3.13.0-37-generic I already had. I think I got that right.
  • I don’t think the systemd packages would cause any problems, but I don’t know for sure. I don’t think I’m running systemd as a whole.
  • I’m not sure what discover does. My hope is it’s an install-time thing only.
  • biosdevname’s whole job is to give names to devices, so it seems a likely troublemaker. One theory is that the mere presence of it being installed alters the boot methods of Ubuntu in some way. But that’s a total guess. This forum post gives some credence to things.
  • /proc/cmdline says
    BOOT_IMAGE=/vmlinuz-3.13.0-37-generic root=UUID=e7833d2a-17a4-4598-95e2-65d354589db9 ro quiet splash

Some notes on how it’s supposed to work:

  • /etc/udev/rules.d/70-persistent-net.rules is supposed to give a persistent name to the device. Mine seems to be saying “call this eth0”. That may be a legacy from the 10.10 or 12.04 history of the system, and was apparently working until yesterday
  • I have another system that began life as ubuntu 14.04. Its ethernet is /dev/p2p1. It has no files in /etc/udev/rules.d
  • My system appears to be booting with Upstart, not systemd. (PID 1 is init, not systemd). Details on systemd and Ubuntu
  • These Arch Linux notes on the upgrade to the new persistent naming scheme are interesting. Also these systemd docs. But since I’m not using systemd, they are probably not relevant.
  • This GenToo doc on udev upgrades is also useful.
  • Here’s an Ubuntu bug saying the 14.04 docs have not been updated to reflect that 70-persistent-net.rules is no longer used. Also here
  • biosdevname installs /lib/udev/rules.d/71-biosdevname.rules which may override that 70-persistent-net.rules thing.
  • Apparently the kernel has a command line parameter biosdevname=0 to disable renaming. (net.ifnames=0 in Fedora). 71-biosdevname.rules also can be edited to do that.

After 2+ hours of reading I convinced myself it was safe to reboot. It was! I removed the /etc/udev/rules.d/70-persistent-net.rules file that was effectively being ignored after biosdevname was installed.

I filed a bug: https://bugs.launchpad.net/ubuntu/+source/biosdevname/+bug/1382600

Related: bless Arch Linux. I’ve never run it, but their incredibly detailed Wiki documentation on how Linux systems work is so useful. Sometimes you have to go to the low level tools manufacturers to understand how something works.

Notes on setting up a new Ubuntu 14.04 box

I’ve now recovered from my server hardware failure on Saturday. I can’t say enough good things about my remote rsnapshot setup. I’d kind of forgotten that backup even was running and it totally saved my ass. The hard drive had failed, the system wouldn’t reboot, would have been a nightmare getting it back. And while I don’t have any essential data on the remote server I do have a bunch of logsoflag logs I’d hate to have lost. Not to mention the server setup at all.

I ordered a new machine and set up Ubuntu 14.04 on it. I have no automation for building these servers, the overhead is hard. Couldn’t even easily import crap over from my backup of the Ubuntu 12.04 box, too much has changed like the shift to Apache 2.4.

Here’s a dump of the journal I kept as I set up the new server, the steps I took. Nowhere near complete.

Change root password and reboot
Set hostname, reboot
Edit /etc/network/interfaces to use Google DNS. “ifdown p2p1; ifup p2p1” and hold breath.
Edit /etc/default/rcS to set FSCKFIX=yes
Partition the extra disk, make file system, add to fstab
Create user nelson, add nelson to sudoers, also to group sudo.
Restore /home files from backup, put /home/nelson in order

Install unattended-upgrades
Install mg git gcc make munin nmap rtorrent screen mtr traceroute zip unzip curl optipng graphicsmagick gawk libimage-size-perl ntp
Install munin munin-node sensors
Install postfix bsd-mailx

Set up remote rsnapshot

Install apache2
enable a lot of mods
reconfigure deflate to not be stupid

http://nelsonslog.wordpress.com/2011/03/13/gzip-encoding-chrome-dev-tools-bug/

apache2 2.4 auth changes http://httpd.apache.org/docs/2.4/upgrading.html
set up backups

Set up web sites

Restore /var/www/* from backups
Reinstall sites in /etc/sites-available/* and enable
/etc/logrotate.d/apache2

Restore user contrabs from /var/spool/cron

Some notes from old setups:

http://nelsonslog.wordpress.com/2012/01/07/ubuntu-server-notes-from-an-old-debian-user/

http://www.somebits.com/weblog/tech/blosxom/server-migration.html

Starting a Node server in Ubuntu

My Node server sort of works and I’m ready to put it into production. I need some sort of start script. What to do? Naturally, the Node world has to reinvent everything and there’s no standard way to do this. But most docs talk about using Upstart (the Ubuntu variant of init scripts), plus monit or forever to keep the Node process running when it inevitably crashes. (Because of course, this is new tech, it’s gonna crash!).

Also some scary notes about catching exceptions globally so your server doesn’t fail simply because of a bug in one user request, but I think Express takes care of that me. Update haha joke’s on me, by default the whole server crashes if you have an unhandled error because “By the very nature of how throw works in JavaScript, there is almost never any way to safely pick up where you left off, without leaking references, or creating some other sort of undefined brittle state.” Apparenly Node domains are the way to deal with this, some notes here.

I ended up just using a trash shell script for /etc/rc.local because it’s too much bother to do it right. I wish that here in 2014 we finally had a basic simple standard way to deploy and run server scripts in production. So many solutions that are either too ad hoc (upstart) or too complex (Puppet and friends)

Some resources:

 

 

PostGIS upgrades in Debian / Ubuntu

Repeat after me: I will dump my databases before upgrading PostgreSQL or PostGIS. I will dump my databases before upgrading PostgreSQL or PostGIS. I will dump my databases before upgrading PostgreSQL or PostGIS.

I got fed up with the 2 year old versions of GIS software in Ubuntu 12.04 so I upgraded to versions from the awesome Ubuntu GIS PPAs. However after upgrading PostGIS any spatial query gave me the error

ERROR:  could not access file “$libdir/postgis-2.1”: No such file or directory

No idea why that says “2.1” when I installed PostGIS 2.0.1 (2.0.1-2~precise3), but there it is. Googling around I realized this is a symptom of not reinstalling the PostGIS functions in the database. There’s a variety of confusing database upgrade options, and the Debian packages are very clear about not injecting any SQL for you “for safety”.

However, there is a better way! Starting with Postgres 9.1 and PostGIS 2.0, PostGIS can be installed as a simple database extension. No more futzing with template databases on creation or importing lots of .sql files in a new database. All you need to do to spatialize a new database is

create extension postgis
create extension postgis_topology

I’m not sure you can use these commands to rescue an old database that didn’t survive an upgrade, but it works great with new databases. IIRC there’s even an upgrade path for extensions. I dropped my old template_postgis2 just so I never get confused again.

Ubuntu resolv.conf

In the old days setting up DNS was easy. You edited /etc/resolv.conf, put your nameservers in there, and you were done. Sadly it’s gotten more complicated as time goes on; DHCP provides nameservers, computers have multiple network interfaces, you want different DNS servers on a laptop depending on where you are.

But the resolvconf(8) system in Ubuntu is impenetrably complex to configure. I’ve found a bunch of random places where name servers are stored or written. I thought that /etc/network/interfaces is canonical. But there’s stuff in /etc/resolvconf/ too, and things cached in /run/resolvconf/, and I have no idea how to just add a name server. Various “obvious” things fail with old configs coming from some cache.

AskUbuntu has a decent answer that while it may not be correct, works. Edit /etc/resolvconf/resolv.conf.d/head (ignoring the warning about autogeneration), add your entry, then run resolvconf -u. I just tried it and it worked, even put my entries first in the list.

My real goal was to replace my ISP’s flaky DNS server with Google’s 8.8.8.8. It’s stupid in the modern era that DNS is still a sequential operation with a 5 second timeout. This Ask Ubuntu answer suggests installing a fancy caching DNS server like pdns.

Ubuntu upgrade to PostGIS 2 with data preservation

I thought it’d be “fun” to upgrade from PostGIS 1.5 to 2.x on my Ubuntu box. I forgot how byzantine Postgres extensions are and the fundamental rule of database upgrades; you have to take a dump with the old version first. I didn’t take careful notes, but here’s what sort of worked for me.

  • Read the PostGIS instructions on upgrading, in particular the notes about doing a “hard upgrade”. Create a dump before changing PostGIS 1.5.
  • Follow these instructions on installing PostGIS 2.x from sharpie’s PPA. You really need postgis-nightly; he has a PPA called postgis-stable too but I don’t think it’s fully populated.
  • Restore the dump with pg_restore, to a new database name. Pay close attention to stderr.
  • I got an error about ST_* functions being “not unique”. This report suggested that the restore brought over some 1.5 versions of functions and the solution is to run postgis_upgrade_20_minor.sql. Running that threw errors because I had a view depending on some of the functions; I ended up just dropping the view.

Honestly this is all pretty messy and I don’t have full confidence that PostGIS 2 is really installed properly. There’s too many spooky places PostGIS stuff gets loaded into the database. But all my old code still seems to work and gives the same results (at least, visually) so maybe it worked out.

I tried playing with ST_ConcaveHull that I wanted. It’s very, very slow on a GPS track with 50 points in it. Like 1.5 seconds to do a single track to a target percent of 0.5. I guess it’s doing some optimization algorithm? target percent of 0 doesn’t even work, throws a TopologyException. This function may not be what I need to do my calculation.

select
ogc_fid,
ST_NPoints(ST_Simplify(wkb_geometry, 0.0002)),
ST_ConcaveHull(ST_Simplify(wkb_geometry, 0.0002), 0.5) as wkb_geometry,
name
from tracks
limit 1;

interactive fsck on Ubuntu

My headless server in Kansas didn’t reboot properly. The nice guys at the datacenter plugged in a console and found fsck waiting for them to press “Y”, which they did, and the system came back. Interactive fsck is pretty much always a terrible idea, particularly for a headless server, why was it waiting?

I can’t find good docs on this for Ubuntu. I’ve asked a question on StackExchange and started digging through code. I think the important setting is FSCKFIX /etc/default/rcS:

When the root and all other file systems are checked, fsck is invoked with the -a option which means “autorepair”. If there are major inconsistencies then the fsck process will bail out. The system will print a message asking the administrator to repair the file system manually and will present a root shell prompt (actually a sulogin prompt) on the console. Setting this option to yes causes the fsck commands to be run with the -y option instead of the -a option. This will tell fsck always to repair the file systems without asking for permission.

So Ubuntu already partially runs fsck in non-interactive mode; the -a flag (aka -p) “This option will cause e2fsck to automatically fix any filesystem problems that can be safely fixed without human intervention.” I guess something was wrong enough with the filesystem on reboot that -p was afraid to fix it. But in my case I don’t care; I have a backup, I need the server up under any circumstance, and I never knew how to answer fsck’s questions anyway.

I found this by reading through code. Ubuntu mounts filesystems via a program called mountall. Init invokes mountall and uses a shell script to set options. Here’s relevant bits of code:

/etc/init/mountall.conf:

[ "$FSCKFIX" = "yes" ] && fsck_fix="--fsck-fix"

mountall.c:

if (fsck_fix || mnt->fsck_fix) {
  NIH_MUST (nih_str_array_add (&amp;args, NULL, &amp;args_len, "-y"));
} else {
  NIH_MUST (nih_str_array_add (&amp;args, NULL, &amp;args_len, "-a"));
}

So there we have it, I think setting FSCKFIX=yes in /etc/default/rcS is my solution. And I’m glad to see even with that not set Ubuntu mostly runs fsck non-interactively.

Ubuntu 12.04 power savings

This is kind of neat; Ubuntu 12.04 is saving me 10-15 watts or about 25% of my server’s power consumption. I upgraded from Ubuntu 11.10 and my UPS is telling me my server uses 45W now instead of 58W, or thereabouts. The system is a few degrees cooler, too.

I suspect the important change is from the 3.0 Linux kernel to the 3.2 kernel, and the subsequent Power Saving Tweak where the Intel chipset is told to shut down the built in GPU. That’s a win for a lot of folks; headless servers (without weird code using the GPU) and desktop computers with “real” graphics cards. I’m surprised it’s so much an improvement though.

A second possibility is CPU affinity; there’s been some work on multicore systems trying to keep some cores shut down more often if the workload is light. Details on Less Watts tips. I enabled sched_smt_power_savings a few hours after upgrading Ubuntu, but I didn’t see any difference, so maybe not. The CPU frequency scaling graph suggests that maybe something’s changed.

The one alarming thing is that the IO Service Time went way up, from .00001s to .05s. Huh? I’m not doing much IO, so maybe this is a bogus measurement, and I can’t really understand what Munin is measuring anyway. This may be an artifact of the disks being put to sleep more often, or maybe the measurement changed scale, or who knows what. Simple disk benchmarks suggest nothing’s really wrong.

Update: turns out this was a change in the Munin scripts, a fix for an eight year old bug. The Ubuntu 11.10 version was reporting bogus numbers that were backwards and too small. Supposedly the new numbers are correct, and also report no data correctly now. Just reading the numbers off the graph, my system now says writes take about 20ms when before it was saying 0.1ms. Disk seeks are roughly 10ms, so I’m inclined to believe the new numbers are more correct. The bug comments also note that the various disk stats graphs contain similar information but are better.

Fixing a slow Samba server on Ubuntu 12.04

I recently upgraded my Ubuntu from 11.10 to 12.04. Mostly worked fine, the usual little config mishaps. But then one really bad problem: my SMB server on the Ubuntu box was terribly slow with my Mac client. Like reading a file would get 100kbytes/second. This on a gigabit ethernet where I used to be able to do SMB at the disk speed of 30Mbytes/second.

I ruled out some basic stuff: local disk access was fine, and copying the file via nc was super fast so it wasn’t the network. I started at guessing things. The final fix was to remove this line I’d previously put in my smb.conf

socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192

Not sure why those settings would be harmful, nor which specific setting is the problem. The smb.conf man page suggests TCP_NODELAY is the default so I’m guessing it’s the buffers. Anyway, SMB is fast again.

New kernel fail

I decided to build a custom Linux kernel on my Ubuntu 10.10 Oneiric box. 3.0.0 feels awfully old, and I’ve been having trouble with a couple of things (well documented here). I was hoping a modern 3.2 kernel from Ubuntu precise would fix both my ethernet driver problem and, by building specifically for a modern Intel CPU, enable sched_mc_power_savings. No such luck.

Building a Linux kernel has gotten remarkably complex. I mostly quit trying myself back in 2.2 or so; once loadable kernel modules got reliable there was little reason for a top end developer like me to muck with the kernel. These Ubuntu-specific instructions got me there, although it’s a long winded and complex thing involving a lot of configuration management.

Then I got it built and installed and rebooted and miracle! It worked. Only with the same old bugs. 10+ seconds to initialize the ethernet, and that power savings sysctl still missing. I gave up and removed my custom kernel. I’ll wait for the Ubuntu release to upgrade.

 

Realtek ethernet drivers: r8169 vs r8168

Update Jan 2013: this driver issue was fixed in Ubuntu 12.04 / kernel 3.2.0-14 or so.

Ubuntu doesn’t work out of the box with my ethernet adapter. The ethernet interface is very slow to come up after boot, taking 10-120 seconds. The problem is the Realtek 8111 or 8168, a very common motherboard ethernet adapter. The motherboard docs say it’s a Realtek 81111E. The Linux drivers are broken. Apparently this is a common problem across many Linux variants and people report other problems, too, packet loss and dropped packets. It’s a four year old bug in Ubuntu! How to fix it? (Other than buying a new NIC; Realtek NICs are not well loved.)

I did a lot of research. One proposed fix is to get a different device driver, from Realtek, not the Linux kernel sources. (More notes). Another suggestion is to enable Wake-on-LAN (via Windows), but I don’t really believe that will work. A third option is to upgrade kernels, there’s some possibility that the mainline Linux driver is better. (Most recent Ubuntu bug is 864196).

I decided to try Realtek’s driver. r8168-8.027.00. md5sum:
98155ce1ad5c248eeb7a93c9954d8344  /tmp/r8168-8.027.00.tar.bz2

Sadly, it doesn’t fix my problem. The NIC still takes 10-200 seconds to come up after boot. I also tried enabling wake-on-lan (via Linux, ethtool) and that didn’t fix it either. No surprise but I thought I’d give it a shot. I’m left with the conclusion there is no fix for this bug right now, despite the superstitions about Wake-on-LAN, or r8168 drivers, or whatever.

BTW, the autorun.sh script that comes with the r8168 driver from Realtek is pure evil. First, it unloads your ethernet driver. Completely killing your machine if you’re logged in via ssh and don’t have physical access! Then it goes and rewrites a bunch of stuff in /lib/modules and rebuilds your initram disk. It seems to get this right, but it’s awfully intrusive. I finally removed r8168.ko by hand and did an “apt-get install --reinstall  linux-image-3.0.0-15-server” to set things back.

I’m going to try living with this bug; I never reboot the box anyway. The first time I experience massive packet loss, or the ethernet doesn’t come up after boot, I’m getting a real NIC and putting it in a PCI slot. And never again buying a motherboard with a Realtek NIC for Linux use.

Details from lspci -v from stock Ubuntu, before I tried adding the r8168 driver:

03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06)
 Subsystem: ASUSTeK Computer Inc. P8P67 and other motherboards
 Flags: bus master, fast devsel, latency 0, IRQ 45
 I/O ports at e000 [size=256]
 Memory at d0004000 (64-bit, prefetchable) [size=4K]
 Memory at d0000000 (64-bit, prefetchable) [size=16K]
 Capabilities: <access denied>
 Kernel driver in use: r8169
 Kernel modules: r8169

Ubuntu server cron jobs

Here’s all the cron jobs on my relatively vanilla Ubuntu Server setup. I’ve added Apache and a few other minor things to the default install.

Daily:

  • htcacheclean, for Apache’s mod_cache disk cache
  • apport, cleans up old reports in /var/crash
  • apt, cache management
  • aptitude, making logs of what’s installed
  • dpkg, also making logs of what’s installed
  • popularity-contest, telling Ubuntu what people installed
  • bsdmainutils, managing user’s ~/calendar files
  • logrotate
  • man-db, managing the man page database
  • mlocate, an efficient implementation of good ol’ locate for fast finds
  • ntp, managing ntpstats (which aren’t enabled by default)
  • passwd, making backups of /etc/passwd and friends. (wtf?)
  • standard, the “standard daily maintenance script”. backs up /etc/passwd (again?) and looks for lost+found files. Dumb script, and redundant
Weekly:
Logrotate is configured to back up weekly and keep 4 weeks worth of logs and, surprisingly, not compress old logs. Apache overrides this to keep 52 weeks of logs and to compress them. I’m pleased to see the Ubuntu logrotate has a dateext and dateformat option to name logfiles like “access.log-20120108” rather than “access.log.3” and then renaming that to “access.log.4” the next week. That should be the default behavior but apparently that option isn’t available in older versions of logrotate.

Ubuntu and FQDNs

Setting the fully qualified domain name on an Ubuntu host is way too hard. The Internet is full of confusing advice. Most people first seem to notice the FQDN isn’t right when setting up Apache, but it’s a broader problem than that. (You can fix Apache just by giving an explicit ServerName directive.) “hostname -f” should return the right thing.

My solution:

  • /etc/hostname contains just the system name, “wi”
  • /etc/hosts contains an entry like this:
    208.110.64.210  wi.nelson.monkey.org wi
  • /etc/resolv.conf contains an entry like this:
    domain nelson.monkey.org

And now “hostname” returns “wi”, “hostname -f” returns “wi.nelson.monkey.org”. Note I don’t have a reverse DNS entry for that IP address. (I do have forward DNS so wi.nelson.monkey.org resolves, but I don’t think it’s used.)

Part of the confusion is a lot of people (and Ubuntu by default) want you to do something like

127.0.1.1 wi.nelson.monkey.org wi

This kind of works, despite the odd loopback address number. But it’s not really correct: your FQDN should resolve to a routeable IP address, not a loopback.

 

 

Ubuntu server notes from an old Debian user

I’m setting up a new Linux server and using Ubuntu for it for the first time. I’ve been a Debian guy for a long time now (and before then, Red Hat), so Ubuntu is both new and old. I switched to it because it’s got a faster upgrade cycle than Debian, but I like all the extra tools they’ve added, too.

Here’s some of the new things in Ubuntu I’ve learned about. The Ubuntu server docs are an excellent place to start.

  • upstart, a replacement for SysV init scripts that runs things in parallel. The configuration files live in /etc/init. There’s still old SysV stuff in /etc/rc2.d and /etc/init.d being run. The new service command is nice, ie “service --status-all”. There’s plans for upstart to replace cron and at, too. Docs: UbuntuBootupHowto, original rationale, upstart tutorial, and cookbook. (Ubuntu does not use systemd, another modern init replacement).
  • plymouth, the graphic splash boot screen. For some reason this is complicated and intertwined with upstart.
  • ureadahead (aka Über-readahead), a clever system to improve boot times by reading all necessary user files off of disk in one big transfer at the beginning of boot. The boot image is kept in /var/lib/ureadahead and there’s clever stuff to invalidate and re-write the files when new things are installed. It seems to save a few seconds on boot for me, not positive. More info here.
  • ext4fs is the default filesystem. It has various incremental improvements to ext3fs, many of them aimed at efficiently handling big files and disks.
  • AppArmor, a security mechanism. It lets the kernel restrict what access various programs have. For instance, ntpd is only allowed to write to certain log files so if there’s ever an exploit against ntpd it won’t go writing random files as root. It seems like a fairly limited security mechanism given how big the attack surface of Linux is, but also harmless and potentially useful.
  • ufw, Uncomplicated Firewall, is a friendlier interface for firewall rules than iptables.
  • Automatic software updates. The setup process is embarrassingly manual, but you can have Ubuntu install security updates (or all updates) automatically.
  • pam_motd, the absurd thing that makes /etc/motd show current system stats. It seems to update on login. If it ever breaks I will be very angry if I can’t log into my system.
  • JeOS is a stripped down Ubuntu server for running as a guest in a virtualization environment. I have no need for this now, but it’s a good idea.
  • Bacula, a fancy backup system. I will probably stick with rsnapshot and rsync.
  • Launchpad, a website where many Ubuntu projects are hosted. Bug tracking, etc.

One thing they haven’t improved is libresolv; it still queries nameservices serially, one at a time. Worse, the first entry in /etc/resolv.conf for me named 192.168.1.100 as the nameserver, a bogus entry from the initial setup in a different DHCP environment. So every DNS query was waiting 5 seconds for that to time out. I fixed it by putting Google’s 8.8.8.8 as the first nameserver.

My next project is to automate all my deployment of my own stuff to the server using Puppet or maybe Chef Solo. I’m trying to avoid the thing where my servers become an irreproducible rat’s nest of random crap I’ve collected over time. OTOH, I can tell already it’s going to be a lot of work for one little personal projects server.

 

Ubuntu 11.04 notes

Time for my yearly experiment running Linux as a Desktop OS. I installed Ubuntu 11.04 beta1 (“Natty Narwhal”). And immediately hit graphics corruption and system crashes. To be fair I have a weird graphics card that Windows hates too, a Radeon HD 2400 PRO AGP.

So first order of business was switching from the ATI binary driver to the open source VESA driver. There are no docs on this I could find anywhere; there’s no longer an xorg.conf to edit. I finally just used apt-get to uninstall xserver-xorg-video-ati; happily, Ubuntu is smart enough to drop back to the VESA driver if the ATI driver is not around.

The second problem is Unity, the fancy new GUI, doesn’t run on the VESA driver. Too much GL or something. The old UI is there but if you want Unity the solution for that is to install unity-2d, a simpler UI.

With that all done, things sorta work. As with every time I try to use Linux as a desktop, it was a disaster. I can’t really blame Ubuntu for not handling my weird graphics card well, but I can blame it for there being no clear path to diagnose and fix the mistake. Also I’d say unity-2d ought to be a default option, not some weird thing to install.