Monday, August 17, 2026

Standard

I run Ubuntu 24.04 with ZFS on my ThinkPad X1 Carbon, and I have an encrypted ZFS dataset for my workspace. By default, ZFS prompts for a passphrase at every login — annoying, but secure. This post explains how I wired it up to the TPM2 chip so the dataset unlocks automatically at boot, without storing the passphrase anywhere on disk.

The idea

Modern laptops have a TPM (Trusted Platform Module) chip that can seal a secret against the current state of the boot chain. The secret can only be unsealed if the firmware, bootloader, and Secure Boot state are identical to when it was sealed. If someone tampers with the boot chain — or steals just the drive — the TPM refuses to hand over the secret.

PCRs (Platform Configuration Registers) are the values the TPM measures during boot. I bind to:

  • PCR 0 — UEFI firmware
  • PCR 2 — Option ROMs
  • PCR 4 — Bootloader (GRUB)
  • PCR 7 — Secure Boot policy and signing certificates

With UEFI Secure Boot enabled, PCR 7 is particularly strong — booting a live USB or disabling Secure Boot changes PCR 7 and makes unseal impossible.

Prerequisites

  • Ubuntu 24.04 with ZFS
  • An encrypted ZFS dataset (mine is rpool/USERDATA/workspace)
  • TPM2 chip (/dev/tpm0)
  • UEFI Secure Boot enabled
  • tpm2-tools installed: sudo apt install tpm2-tools
  • Your user in the tss group: sudo usermod -aG tss $USER

Step 1 — Find a free TPM persistent handle

tpm2_getcap handles-persistent

Pick a handle in the 0x81000000–0x8100FFFF range that isn't listed. I used 0x81000002.

Step 2 — Seal the passphrase

I wrote a script that reads the passphrase interactively (no echo, confirmation prompt), writes it only to /tmp (tmpfs = RAM, never hits disk), seals it into the TPM, then shreds the temp file immediately.

#!/usr/bin/env bash
set -euo pipefail

HANDLE="${1:-0x81000002}"
WORKDIR="$(mktemp -d)"
trap 'rm -rf "$WORKDIR"' EXIT

IFS= read -rs -p "Enter ZFS passphrase: " PASSPHRASE; echo ""
IFS= read -rs -p "Confirm passphrase:   " PASSPHRASE2; echo ""

[[ "$PASSPHRASE" == "$PASSPHRASE2" ]] || { echo "Mismatch" >&2; exit 1; }

tpm2_createpolicy --policy-pcr -l sha256:0,2,4,7 -L "$WORKDIR/policy.digest"
tpm2_createprimary -C e -g sha256 -G rsa -c "$WORKDIR/primary.ctx" >/dev/null

printf '%s' "$PASSPHRASE" > "$WORKDIR/secret"
tpm2_create -g sha256 -u "$WORKDIR/obj.pub" -r "$WORKDIR/obj.priv" \
    -C "$WORKDIR/primary.ctx" -L "$WORKDIR/policy.digest" \
    -i "$WORKDIR/secret" >/dev/null
shred -u "$WORKDIR/secret"
unset PASSPHRASE PASSPHRASE2

tpm2_load -C "$WORKDIR/primary.ctx" -u "$WORKDIR/obj.pub" \
    -r "$WORKDIR/obj.priv" -c "$WORKDIR/seal.ctx"
sudo tpm2_evictcontrol -C o -c "$WORKDIR/seal.ctx" "$HANDLE"

echo "Sealed at $HANDLE"

Save it, chmod 700, and run it. You'll be prompted for your ZFS passphrase and then your sudo password for the final persist step.

Verify it worked:

tpm2_getcap handles-persistent        # should now include 0x81000002
tpm2_unseal -c 0x81000002 -p pcr:sha256:0,2,4,7   # should print your passphrase

Step 3 — Auto-unlock at boot via systemd

Ubuntu's ZFS tooling auto-generates a systemd unit that prompts for the passphrase. We override it with a drop-in that tries the TPM first and falls back to a password prompt if unseal fails (e.g. after a firmware update).

sudo mkdir -p /etc/systemd/system/zfs-load-key-rpool-USERDATA-workspace.service.d

sudo tee /etc/systemd/system/zfs-load-key-rpool-USERDATA-workspace.service.d/tpm-unseal.conf <<'EOF'
[Service]
ExecStart=
ExecStart=/bin/sh -c '\
  set -eu; \
  keystatus="$(/sbin/zfs get -H -o value keystatus "rpool/USERDATA/workspace")"; \
  [ "$keystatus" = "unavailable" ] || exit 0; \
  if tpm2_unseal -c 0x81000002 -p pcr:sha256:0,2,4,7 2>/dev/null \
     | /sbin/zfs load-key "rpool/USERDATA/workspace"; then \
    exit 0; \
  fi; \
  echo "TPM unseal failed, falling back to passphrase prompt" >&2; \
  count=0; \
  while [ $count -lt 3 ]; do \
    systemd-ask-password --id="zfs:rpool/USERDATA/workspace" \
      "Enter passphrase for rpool/USERDATA/workspace:" \
      | /sbin/zfs load-key "rpool/USERDATA/workspace" && exit 0; \
    count=$((count + 1)); \
  done; \
  exit 1'
StandardError=journal
EOF

sudo systemctl daemon-reload

Step 4 — Test without rebooting

sudo zfs unload-key rpool/USERDATA/workspace
sudo systemctl restart zfs-load-key-rpool-USERDATA-workspace.service
zfs get keystatus rpool/USERDATA/workspace

If keystatus shows available with no password prompt — it works.

What happens after a kernel or firmware update?

PCR 4 changes when GRUB is updated. The TPM unseal will fail, and the fallback password prompt kicks in. After entering your passphrase manually, just re-run the seal script to update the sealed blob against the new PCR values.

Security summary

ThreatProtected?
Drive stolen, put in another machine✅ Yes — wrong TPM
Boot from live USB✅ Yes — PCR 7 changes (Secure Boot)
Tampered bootloader✅ Yes — PCR 4 changes
Disabled Secure Boot in UEFI✅ Yes — PCR 7 changes
Normal boot, attacker has root access❌ No — they can run tpm2_unseal too

For a laptop used on the go, this covers the realistic threat: theft of the device while powered off. The data is inaccessible without the original, unmodified hardware and boot chain.

Saturday, June 27, 2026

FreeCLI - LLM agnostic ncurses based CLI

Standard

FreeCLI — A Terminal Chat UI for All the LLMs, Written in C

I've been building a small open-source project over the past few weeks that scratched a personal itch: I wanted a fast, keyboard-driven terminal UI for chatting with large language models — one that wasn't locked to a single provider and didn't pull in a Python runtime or an Electron app just to show me a text box.

The result is FreeCLI, and it's now on GitHub under the GPL-3 license.

→ github.com/NikolajHansen/FreeCLI

What it is

 

FreeCLI is a three-pane ncurses application written in C. On the left you have a list of persistent chat sessions (auto-named by topic — so instead of "Chat 1" you get something like "#1 API Design"). In the middle is the scrollable conversation. On the right is a live view of background workers — because one of the more interesting features is that models can call other models mid-conversation.

It ships with four LLM providers out of the box:

  • xAI — Grok-3-fast, Grok-3, Grok-3-mini
  • Anthropic — Claude Opus, Sonnet, Haiku (3.5 and 4.5 families)
  • Google — Gemini 2.5 Flash/Pro, 2.0 Flash, 1.5 family
  • IBM watsonx — Granite 3, Llama 3.3/3.1 70B

You switch between them with /provider and /model — both pop up a small overlay right in the terminal.

The part I'm most proud of: LLM-to-LLM communication

The backend runs as a separate process and communicates with the TUI over a local TCP socket. When a model supports tools (currently xAI), it gets an ask_ai function injected into its context. It can then call that tool with a question and a target model name — say, asking Claude to review a piece of code while Grok is working through the broader problem.

Those sub-queries show up as indented entries in the workers pane with their own spinner, so you can watch the inter-AI conversation happen in real time. The sub-queries themselves have tools disabled to prevent infinite recursion.

Architecture

The split between the TUI binary (freecli) and the backend binary (freecli-backend) was a deliberate choice: the TUI has zero dependency on libcurl. It just renders, handles input, and talks IPC. The backend owns all the HTTP, JSON parsing, and provider logic. This keeps the ncurses side lean and means you could theoretically swap the backend for something else entirely.

The IPC wire format is simple: a 4-byte length prefix, a 4-byte message type, an 8-byte correlation ID, then the payload. Requests carry the session index, message history, model name, and provider ID. Replies come back as streamed tokens or structured events (worker start/end, session rename, etc.).

Session naming

After your first exchange in a new session, the backend silently fires off a one-shot call to a fast model with a prompt asking for a short topic label. The result comes back over IPC and replaces "Chat 1" with something descriptive. If the name is too long to fit in the sidebar, the selected entry scrolls like a marquee. Small detail, but it makes navigating a long list of sessions much more pleasant.

Building it

It uses autotools, which I know is not fashionable, but it handles the Linux/macOS/FreeBSD portability story well and adds zero runtime dependencies beyond what you already have on any Unix system.

 git clone https://github.com/NikolajHansen/FreeCLI
 cd FreeCLI
 ./bootstrap
 ./configure
 make -j4
 src/freecli
 

You'll need ncurses, libcurl, and a C compiler. On Debian/Ubuntu: apt install libncurses-dev libcurl4-openssl-dev. On FreeBSD: pkg install ncurses curl.

What's next

A few things on the list: streaming token output (so replies appear word by word rather than all at once), persisting the selected provider and model to a config file, a /delete command for sessions, and tool support for Anthropic (their tool format differs from OpenAI's so it needs its own implementation). Adding a new provider is fairly mechanical — one .c file and two registry entries — so if there's demand for OpenAI, Mistral, or Ollama support it shouldn't take long.

If you try it, open an issue or send a PR. Code is on GitHub, GPL-3.

https://github.com/NikolajHansen/FreeCLI

Sunday, March 30, 2025

Rackmount hardware of Rasberry PI4

Standard

Background.


After having had my Raspberry PIs in a box together with a lot of wiring spaghetti, its nice to finally have some decent rack mount enclosures to tidy up stuff.

This will be the first of two enclosures for a total of 10 nodes. I have not really decided if they are all going to be in the same cluster or two individual.

Hardware.

The nodes themselves are Raspberry PI4-B with 8 GB of memory. They each have 128 GB of internal storage via the onboard Micro SD card. I use some SANDISK high endurance cards, that are made for 24/7 operation and rated for 20.000 hours.

Between the nodes is a normal gigabit network switch with 10 gigabit fiber backbone. for now I have more than ample ports in one switch.

 
The enclosure model is the Rackmount RM-PI-T1. It is a 1U enclosure with room to add a fan or a HAT for the PIs if necessary.
 
If your rack cabinet already has fans I doubt it will be necessary.

Software.

The nodes run normal PI-OS which is a Debian derived Linux based OS specially tailored for the PI hardware. I use the lite version which is a headless version of the OS.

On this I use the K3S (Rancher) lightweight Kubernetes platform. I think some of the choices Canonical have made lately makes me doubt MicroK8s in a production environment and I think full on Kubeadm (Vanilla Kubernetes) is probably overkill for my needs.

I use no kind of hardware emulation. This is what is known as "bare metal" in Kubernetes terms. You could add this as an extra layer of abstraction. As it is here the images need to be built for the ARM architecture - and not for AMD64 which most ready made ones are. 

Something that has surprised a lot of developers after they got a new Macbook I think :-P.

You could add a hw virtualization layer - but I think the performance impact would be severe. 

Some of the nodes may convert to FreeBSD at a later stage. Mostly as an experiment. They will then not be part of the Kubernetes cluster but rather their own kind running the needed services via Jails on the physical host.

Images.

The Kubernetes images are built though Ainsible. The build environment hosted on Github and built via Github actions.

I plan to make a seperate more in depth post about this and also publish scripts and configs publicly on Github (once they fully do what I want).

Backend server.

For this purpose I currently have an older and much more powerful HP DL-585 FreeBSD server with storage, that attaches to the nodes for persistent storage. Also it currently runs any databases needed.

On this server each logical node is hosted in a Jail, that gives it its own IP stack and own ZFS pool area in the storage area. 

The total ZFS pool size is currently 14 TB.

This has been the way the services now in the Kubernetes cluster where all hosted in my old setup before the PI nodes.

Conclusion.

These small machines are remarkably capable and have a very low power consumption footprint. The new PI5 is arguably even more desirable with its built in interface to real SSD storage.

However the idea behind Kubernetes is to have the nodes stateless and that is negated if the different nodes have persistent data, that is not mirrored to all of the nodes.

If you have your own business and require flexible computing I highly recommend the approach of using cheaper HW like this, because you will be able to size your system in a way you can have multiple nodes fail and not even know about it except for the alarm the system will give you.

It is then very easy to simply replace a faulty node with new hardware, add the needed disk image and let it rejoin the cluster. 
 
And do not be alarmed at the prospects of having your own on site Kubernetes setup. If I can do it with of the self parts for less than 7500 DKK any company with a decent IT department can also run something similar. 
 
It is the most obvious way of complying to any GDPR legislation in the EU, and avoiding any worries how our US "ally" treat our data. Which you will have to if you use hosting with the hosting titans.

Tuesday, April 6, 2021

libvirt-dnsmasqd running as part of libvirt

Standard

Open DNS server on external IP

Background

When you run libvirt / KVM on Ubuntu it seems the framework starts up a second local DNS server beside systemd-resolved. Since only one server can occupy localhost port 53 (systemd-resolved) libvirt-dnsmasq uses HOSTNAME / Port 53. So that will be whatever IP the DHCP server assigns to your PC. 

This IP is accessible from all other sources on the network as a matter of fact and running an open DNS server on it is probably not a good idea.

Solution

Check the virtual net status:

# virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes

Check to see if libvirt-dnsmasq is running

# lsof -i TCP:53

Remove the default virtual network for your virtual hosts.

# virsh net-destroy default

Prevent it from autostarting at all

# virsh net-autostart --network default --disable

If you need it again start it with

# virsh net-start default

Result

libvirt-dnsmasq is no longer listening on port 53 / DNS on whatever IP your interface(s) have been given on your network.

# lsof -i TCP:53
COMMAND   PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 635 systemd-resolve   13u  IPv4  25136      0t0  TCP localhost:domain (LISTEN)

# virsh net-list
 Name   State   Autostart   Persistent
----------------------------------------





Wednesday, January 17, 2018

Citrix on linux

Standard

How to get the black address bar

1. Use Firefox. It works way better with the ICACLient than chromium. I have not tested chrome, buit I suspect it is the same.

1. Setup of local ICAClient

- Navigate to the root of the ICA installation. For me /opt/Citrix/ICACLient.
- Find the file All_Regions.ini 
- Under [Client Engine\GUI]
- Add ConnectionBar=* 

Restart your ICAClient and log on again. It should now be visible in the top of the screen.

Saturday, September 2, 2017

FreeBSD 11 - vt console debacle

Standard

Vt console in FreeBSD

Introduction

For some reason server distributions of *nix now have to have a vt based (compositing) console, so that you can get your console into the larger resolutions.

Personally I fail to see the need for this at all. When you connect to your server it is via ssh 95% of the time. Or probably more. And your client PC where off you run ssh probably has a hd display today. Using the actual console is something you do when there are problems. Usually in single user mode. This does not have to be bling bling.

What about us, that depend on the serial console? Or text mode without a compositor. Well it would seem FreeBSD is now going down the Ubuntu server road, and we have to do some fiddeling in order to make our Inside Lights out cards, serial consoles and what not working again.

At least for me, my iLO card on my HP server could no longer bridge to the console after an upgrade to FreeBSD 11. I was told the console was in an unsupported graphics mode and after plugging a monitor onto the server, it was in 640x480.

How to fix this.

Fortunately this is simple not requiring a custom kernel build or anything. In loader.conf put:

kern.vty=sc

And you are back to the old sc driver for the console. And I can again get a console via ethernet. Also in single user via the iLO.

Conclusion

Back to normal ..

Tuesday, July 25, 2017

HP inside lights out and OpenSSH

Standard

Problem

The sshd server implementation made by HP on ILO cards - especially older ones - can be notoriously difficult to use with newer versions of OpenSSH.

The main reason is algorithms rendered unsafe by old age combined with a very strange implementation by HPs hands.

Solution

The following configuration on the client side made my current version of OpenSSH play reasonably nice with ILO / SSH. There is some unexplained disconnects by the server I cannot figure out. 

In .ssh/config

Host <hostname>/<IP>
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication no
HostbasedAuthentication no
PubkeyAuthentication no
RSAAuthentication no
Compression no
ForwardAgent no
ForwardX11 no
Ciphers aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128
HostKeyAlgorithms ssh-rsa,ssh-dss
KexAlgorithms diffie-hellman-group1-sha1
MACs hmac-sha1
ServerAliveInterval 0

Result

You can now SSH to the ILO card and use the cmd line tool from HP. Issue a 

</>hpiLO-> remcons

To get a real HW console bridged over the network.


Friday, January 29, 2016

Automount with systemd

Standard

Automount with systemd 


Introduction 


As many others I have used autofs for automagically mounting nfs / cifs shares from my clients to my local servers for a while. You can see some of my experiments with this here.

However systemd has now got this as a standard feature with a few small steps. This all reqires nfs server to be configured at your local server before setting this up on your client.

/etc/fstab content 


You need to add you server to your local /etc/fstab 

my.server.com:/server/files /my/files nfs noauto,x-systemd.automount,soft,rsize=16384,wsize=16384,timeo=14,intr 0 0 

You can do this by restarting the system or using sysctl.

$> sudo systemctl daemon-reload 
$> sudo systemctl restart remote-fs.target 
$> sudo systemctl restart local-fs.target 

You need to add you server to your local /etc/fstab

Conclusion 


Your shares should now automount when you cd into the folder. Here that would me /my/files on the client.

Friday, October 23, 2015

Lenovo T440P + Ubuntu = driver hell .. And how I fixed it.

Standard

New laptop and the nasty suprises

I have purchased the Lenovo T440P in order to run Ubuntu for my development environment. I had a lot of initial issues using this laptop with external displays. The laptop display is too small to use on its own for development, so this was kind of a show stopper.

My target environment was:

  1. Lenovo T440P patched to a sensible BIOS level. I think mine is 2.31 or 2.32.
  2. Ubuntu 14.04.3 LTS
  3. 3.19.0-30-generic #34~14.04.1-Ubuntu SMP Fri Oct 2 22:09:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
  4. Gnome-Shell / not Unity
  5. Nvidia proprietary drivers
  6. Some sort of util to manage the use of the new daisy chaining of monitors on a single channel.
A lot of people spent many many hours getting this to work. This was what worked for me.

Installation of base system

  1. I started out with a system with no nonsense. That is the server release of Ubuntu. Install it, and you will get a system without any GUI at all.
  2. Install the package gnome-shell. This will give you the most basic gnome-shell install shaved down to the bones. No empathy, no Evolution. The downside is you have to add many of the usual tools by hand.
  3. Install nvidia-331 + Anything above this worked for me.
  4. Replace GDM with LightDM. This is the crucial point. GDM did not work for me on this laptop. I think LightDM is more advanced in managing the session with multiple monitors as of now. done by firstly installing the package lightdm and then dpkg-reconfigure lightdm. Select lightdm over GDM.
  5. See to it that the GRUB boot loader has no hokus pokus in it. You need a plain "quiet splash" no modeset changes unless you are fiddeling around and know what you are doing.
  6. The above should also have installed the package prime. So prime-select query should show you what GPU you are using.

Result

I am able to use both monitors with the Intel or the NVIDIA driver. Of cause the Intel card does not perform as well as the nvidia one. Some people have reported memory leaks / kernel crashes. I have not experienced this with the above setup. I am writing this from the lappie with an external monitor attached using the monitor on the laptop itself. 

It is really nice that the external monitors no longer tie hard to the discrete graphics card.

switching is done with prime-select <query|nvidia|intel>

For now I think I will use the intel card as it seems to be easily fast enough to power a developer workstation. In fact I struggle to see, why Lenovo does not produce a variant of the T440P with ONLY the Intel card. Seems to be more than what an old codegrunt like me need anyway.

Performance wise glxgears give me around 60 fps with the Intel driver and 2000+ fps when using the NVIDIA card. This goes for both screens.

Outstanding issues

I also have the advanced dock. The above setup does not work for me at all using this yet. I am able to get a text console (mirror) on both displays, but cannot get a GUI up and running on either screen using the advanced dock. I have read that the same is the issue with some versions of MS Windows. So in fact Lenovo has made a patch, that I have yet to flash onto the advanced dock.

https://support.lenovo.com/us/en/documents/ht081248)

I think the next step is to flash the firmware of the dock and see, what the outcome of that is. Right now I do not have a windows boot device compatible with the dock, so I probably have to create a boot partition for Windows on the lappie itself (which sucks) or replace the disk with another one and install on that.

What not to do ..

I have read some have had success downgrading to the 1.14 version of the BIOS. If you have a later version of the T440P I cannot emphasize enough how bad an idea that is.

The older BIOS is made for the older versions of the hardware, and even a minor version incompability in a device in your laptop could transform your laptop into the most expensive paperweight you ever owned.

Only do this if the laptop originally shipped with the early version of the BIOS.

Update:

It seems the above is not a problem on Ubuntu 15.10. On that release displays and dock work just as they are supposed to. I think this is mainly due to the major release upgrade of the kernel / 4.*.

For now the above fixes are still needed for the LTS product.



Update 2:

Distributor ID: Ubuntu
Description: Ubuntu 16.04 LTS
Release: 16.04
Codename: xenial

All works on this LTS out of the box. And it occurred to me that Cannonical actually ship a Gnome-Shell only dist now! Hell just froze over apparently. So forget about the steps to get a clean gnome env above. Just fetch the "gubuntu" distro. 

Sunday, March 31, 2013

DJBDNS and Netflix - Outside USA.

Standard

Introduction

In Europe most countries have access to Netflix by now. However the content presented is still lacking much compared to what is available in the USA.

Several services on the net offer DNS + VPN / Proxy solutions to circumvent this. However, if you are like me, you do not really feel ok with giving some service on the net your entire internet traffic for tunneling. In theory they could sniff logins to other services made from a device using their DNS / Tunnel setup.

Background

I was reading this article and decided to do it one better: In place of merely using the host file on a single pc or server I decided to configure it directly on my own DNS server and apply it network wide on my own LAN.

Goal

So the goal here is to *only* use their DNS/Proxy for Netflix specifically. The rest of the DNS lookups will resolve as they have done always.

The end result is a DNS setup that will allow you to use a Proxy Service in the USA for Netflix alone.

Prerequisites 

  1.  A DNS + Proxy / VPN service. I am currently using the excellent service from Unblock US. You could also buy a real VPN solution or even a VPS server in the USA, so that you could do the entire config by yourself.
  2. Your own configured DNS server on your local network. I am using DJBDNS. 
  3. A good understanding of things related to IP networking and DNS configuration.

DNS configuration


dnscache

You need to take over two domains for hosting on your own DNS:
  1. netflix.com
  2. netflix.net
[user@dnsserver /service/dnscache/root]$ ls -la servers/
total 1
drwxr-sr-x  2 root  wheel  512 17 mar 16:47 .
drwxr-sr-x  6 root  wheel  512  4 jan  2008 ..
-rw-r--r--  1 root  wheel   10 12 nov  2003 1.168.192.in-addr.arpa
-rw-r--r--  1 root  wheel  168  4 feb 20:06 @
-rw-r--r--  1 root  wheel   10 13 nov  2003 barnabas.dk
-rw-r--r--  1 root  wheel   10 17 mar 16:47 netflix.com
-rw-r--r--  1 root  wheel   10 17 mar 16:47 netflix.net

You will probably already have the two first files. The first one may be named differently because it is the reverse DNS entry for hosts on your local network. The "@" file contains a list of root nameservers on the net.

The barnabas.dk file contains the IP address of the DNS server hosting that particular domain. The domain resolves differently on my LAN than it does out on the net. This makes it easier to do development of new stuff locally without making DNS changes visible on the net. The DNS server is running on the loopback (127.0.0.1) interface of the DNS server host. So that is the IP put into it. Now edit a similar file to a netflix.com and a netflix.net.

Restart your server nicely with a kill -HUP <pid>.


tinydns

This is where things become a little more tricky, because we now want the netflix.com and netflix.net CNAME domains to point to the correct IP addresses with unblock-us. This is done to send IP traffic via their servers onto the ones with Netflix. So edit the "data" file in your tinydns server or use the DJBDNS tools to do this on the command line.

# Forward zone
Zbarnabas.dk:sauron.barnabas.dk:hostmaster.barnabas.dk::::::::
Znetflix.com:sauron.barnabas.dk:hostmaster.barnabas.dk::::::::
Znetflix.net:sauron.barnabas.dk:hostmaster.barnabas.dk::::::::

# NS records: primary nameservers
&barnabas.dk::sauron.barnabas.dk:::
&netflix.com::sauron.barnabas.dk:::
&netflix.net::sauron.barnabas.dk:::

#netflix aname
=www.netflix.com:54.243.127.15:36000::
=signup.netflix.com:23.21.78.133:36000::
=movies.netflix.com:204.12.200.61:36000:: 
=cbp-us.nccp.netflix.com:204.12.200.65:36000::
=movies.netflix.com:204.12.200.61:36000:: 
=cbp-us.nccp.netflix.com:204.12.200.65:36000::
=movies1.netflix.com:204.12.200.130:36000::
=movies2.netflix.com:204.12.200.104:36000::
=netflix.com:204.12.200.14:36000::
=moviecontrol.netflix.com:204.12.200.7:36000::
=api-global.netflix.com:204.12.200.88:36000::
=api-us.netflix.com:204.12.200.83:36000::
=api.netflix.com:204.12.200.2:36000::
=www2.netflix.com:204.12.200.100:36000::
=redirects-us.nccp.netflix.com:204.12.200.119:36000::
=redirects-eu.nccp.netflix.com:204.12.200.118:36000::
=nccp-nrdp-31.cloud.netflix.net:204.12.200.26:36000::
=ios.nccp.netflix.com:204.12.200.92:36000::
=atv.nccp.netflix.com:204.12.200.14:36000::
=uiboot.netflix.com:204.12.200.11:36000::
=signup.netflix.com:204.12.200.39:36000::
=iphone-api.netflix.com:204.12.200.14:36000::
=nccp-fuji.netflix.com:204.12.200.14:36000::
=nccp-fuji.cloud.netflix.net:204.12.200.27:36000::
=nccp-nato.cloud.netflix.net:204.12.200.22:36000::
=nccp-nato.netflix.com:204.12.200.14:36000::
=mcdn.netflix.com:204.12.200.14:36000::
=secure.netflix.com:204.12.200.12:36000::
=htmltvui-api.netflix.com:204.12.200.13:36000::
=nccp-ps3.netflix.com:204.12.200.14:36000::
=nccp-ps3.cloud.netflix.net:204.12.200.18:36000::
=api-user.netflix.com:204.12.200.17:36000::
=mobile-api.netflix.com:204.12.200.42:36000::
=api-public.netflix.com:204.12.200.14:36000::
=dvd.netflix.com:204.12.200.14:36000::
=android.nccp.netflix.com:204.12.200.93:36000::

If you bother you could setup an an ANAME record for each of the IPs in that list and then CNAME each of the hosts needed. That would be the nicest way to do it but I am lazy and like cut and paste ..

After editing the data file run make. This will produce the actual file for tinydns to use containing your new entries.

You should now restart your tinydns server like you did the dnscache server.


Conclusion

You should now be able to run your Netflix app using Unblock-US Proxy services and your *own* DNS server putting the control back where it belongs - in your own hands.

If you have corrections, improvements or additions to the above feel free to post them here.

FAQ

  1. Q: "What happens if I do this and Netflix or Unblock US changes IPs." A: "You are screwed basically. You asked for full control now you have it. You should proably use a different public DNS to find the correct ip values."
  2. Q: "This makes my xyz device do the two step shuffle instead of showing me Netflix, what should I do" A: "Fix the DNS setup and mail / post your findings here once you have a working solution"

Errata

It seems the later versions of the netflix app also requires:

api.crittercism.com

The list of CNAMES above is severely outdated. The method is, however, still sound.

Sunday, July 24, 2011

Mencoder webcam grab for youtube

Standard
I have been looking for an easy way to grab the signal from a regular USB webcam and get something from it that is usable on youtube. In the newer versions of ubuntu the /dev/audioN has been dropped from the kernel, so you have to use the audio signal from the ALSA layer instead. Here is how:


mencoder tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0:forceaudio:alsa:adevice=hw.1:amode=1:channel=3:fps=30:audiorate=32000 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1500:keyint=25 -oac mp3lame -lameopts cbr:br=128:mode=3 -fps 30 -o webcam.avi


The output will be in mpeg4.

Saturday, July 9, 2011

Google hosting of services and djbdns

Standard
Introduction
I have just completed a clean up of the config on my local dns server running dns service on my local network. The one in my house behind the firewall. I left a lot of configuration residue from many configuration hacks / tweaks and so forth over the time.

I host the barnabas.dk domain internally on the LAN as well as on a public dns server, that lead you to this blog.

The advantage is, that I am able to let services resolve to different things internally and externally.

However, I spent a lot of time finding a solution to making http://blog.barnabas.dk resolve correctly from my internal server onto the Google hosting where it lives. With blogger.com.

Here is how:
I use the djbdns tools (tinydns / dnscache) for hosting dns on my LAN. It has a low footprint and is much much much easier to live with than bind. Also it runs perfectly with the supervise service setup.

This is the config:


#
# REVERSE ZONE
#
# (reverse) dns servers: primary and secondary
Z1.168.192.in-addr.arpa:ns.barnabas.dk:hostmaster.barnabas.dk::::::::

# NS records
&1.168.192.in-addr.arpa::ns.barnabas.dk:::

#
# FORWARD ZONE:
#
# SOA record: primary nameserver is ns.example.net and hostmaster
# mail address is hostmaster@example.net
# (the 'Z' configuration line is the only one that
# allows specifying the hostmaster mail address)
Zbarnabas.dk:bar.barnabas.dk:hostmaster.barnabas.dk::::::::

# NS records: primary nameservers
&barnabas.dk::bar.barnabas.dk:::

# ANAME records
=bar.barnabas.dk:192.168.1.2:3600::

# CNAME records:
Cfoo.barnabas.dk:bar.barnabas.dk:::
Cblog.barnabas.dk:ghs.google.com:::


Just simply add the entry for the Google service as a CNAME. I spent a lot of time trying to make it work with an ANAME record. You can, but you have to refer the IP address of the Google service. That could change if Google configure new setup so refering the ghs.google.com cannonical name is the best way to do it.

Tuesday, June 14, 2011

Spotify, Wimp and TDC Play - a comparison

Standard
Introduction

I am using a Logitech Squeezecenter setup at home for listening to music. My goal is to only store the music locally that i have in lossless format. All the mp3 I have bought online earlier is really only a waste of space on my local server. It is a much better idea to have your lossy music streamed to you through a cloud music service. By now the quality is probably better than the mp3's I have been storing for years, there is a lot of new music for listening.

So in order to describe what my opinion is here is a short description of my setup

Hardware Setup

Old server running FreeBSD 6 with a couple of disks and a Squeezecenter server version 7.5.4. The architecture is i386.

Wimp

Activation of a trial account is very very easy. All you need is an active mobile phone number in order to start your trial period. In Denmark Telenor is a Wimp reseller and if you have two products (eg. phone and internet) through Telenor you will get a 50% discount. The normal price is 99 DKK a month, and you will be able to get it at 49 DKK.

I have neither so for me the price is 99 DKK which I find to be ok for access to 9 million songs online with new added regularly.

The quality of the streamed music is OK, but not fantastic. The format is 256 variable bit rate MP3. I am a bit particular with the quality of my music, so for me it is OK for streaming to a phone / stereo for general listening purposes. There is no DRM on the streams you recieve which is really nice. I still prefer my lossless flac tracks to this any day.

The app for android / iPhone is really really great. Easy to use and everything is cross referenced. If you are a Telenor customer you can stream directly to your phone without an extra cost - otherwise see to it you have a flatrate data plan.

One major drawback of Wimp is the necessity to activate, once your 30 day trial is over, through their Adobe Air application. There is no way at all I am typing in my credit card details in anything Adobe took part in making.

So currently I am hoping they take my advice and produce a simple http/ssl webapp for the customers to supply their billing details sometime soon.

TDC Play

I currently have a TDC mobile phone with data plan. This gives me access to TDC Play without any extra cost. As far as I know you cannot use this service as a non TDC customer.

Unfortunately the format is a windows infected WMA with loads of DRM. Even on a windows pc you cannot move your downloaded tracks to a new folder without invalidating them - making it necessary to fetch them again. The sound quality is also significantly lower that Wimp and especially Spotify Premium. This is really only usable on a mobile device.

From my Squeezecenter TDC play is unusable. Their answer is "buy one of our data lines and use our hardware box". Useless. I already have a hw box thank you.

I have tried the TDC play app on my Android and must say their app is not very good. Difficult to search and very little cross referencing between tracks and artists.

Spotify

Perhaps the most hyped music service out there. But the trees do not grow into the heavens.

Activations is quite difficult in Denmark since Spotify do not support Danish customers. This is not really the fault of the Spotify People, but rather due to some very technology scared people at the Danish music agency KODA. The danish RIAA.

This is easily fixed by creating a Swedish paypal account and then using this creating an account with Spotify. Easy Peasy.

The price is very acceptable at 99 SEK making it comparable in price with Wimp at 99 DKK.

The music library is impressive. Around 12 million songs.

The quality on the Spotify premium is excellent. 384 kbit ogg vorbis. This is the reason I really looked forward to trying this with my Squeeze center setup. However this turned out to be not so easy anyway.

The Squeezecenter today is either one you run on your own server or you can use the one supplied på Logitech "in the cloud". If you add your spotify account to this, then you have to select the cloud server when using spotify. Making it impossible to search your locally stored music. And vice verca.

Wimp handles this beautifully. You use the plugin in your server and you can search, mix and make playlists of your own music and wimp music as you see fit. You cannot with Spotify.

A fix is using the spotify backend on your server enabling this. However this is restricted to a narrow set of platforms and only in 32 bit. This requires a local install of libspotify and perhaps also the spotifyd server executable. I cannot really tell. This can then be accessed though a third party plugin to Squeezecenter and used like Wimp.

This is a list of supported platforms. They state Intel/Arm, but the list is in fact much shorter since they also require specific operating systems.

http://developer.spotify.com/en/libspotify/overview/

On FreeBSD it is not really even an option I am afraid. There is really no need for a binary client at all. Spotify needs to open up its client as open source and let ppl (re)implement it where needed. At least for premium accounts.

So on my setup I can only listen to spotify when using Logitechs cloud service. Not when using my own server. Bummer.

Conclusion

At least seen from a Squeezecenter user on Unix.

To put is short: Wimp 1 - Spotify 0 - TDC Play : No Contest.

Now if only the Wimp People would get rid of that Adobe Air thing.. Even introduce paypal perhaps?

Friday, May 20, 2011

Land Rover - A borrowed car from the shop

Standard
A borrowed set of wheels..
I recently had my brakes done at the Land Rover dealer. After getting my car back I noticed a disturbing use of brake fluid, and I subsequently had to take the car back to have the brakes fixed for both front wheels.



Apparently the dealer got a faulty set of refurbished calipers, and after a short while they started leaking heavily. In fact so much that the car had complete brake failure.

The issue was fixed on the guarantee, so aside from some driving back and forth and time spent on this little was lost.

As a small bonus I got to drive a tricked up Defender for a day.

The car was a 90" soft top van with the new 2.5 TD5 power plant. Additionally the car was equipped with a bull bar, snorkel, lift kit and large wheels with BF Goodrich T/A Mud Terrain.

It was very windy the day I had it and I have to say this car is by far the noisiest thing i have EVER tried. Not even my own Discovery 3.9 EFI v8 with its exhaust broken right after the manifold comes even close.

In fact I think it is about the same amount of db in the cabin at 100 km / h as my dads old Massey Ferguson 165 at 2500 rpm at plowing.

The diesel is quite noisy in itself. But if you add to this that the tires are very noisy on road and that the soft top makes an extreme amount of flapping noise - especially on the highway of cause - It really put me off considering a soft top Defender. It is really only usable on the African savanna.

My suggestion is to buy a hard top or a pickup version.

Aside from that the car has a good engine. It was the first try of the Defender 2.4 for me.

And I have to admit it does look quite nice on my driveway. I really like this car in white.

Thursday, April 21, 2011

Sunday, May 16, 2010

NFS version 3 on FreeBSD using unfsd

Standard
Introduction


I have had some problems reading files larger than 2 gb through nfs2. It is afaik a limitation of the standard it self. Therefore it is necessary to look at some of the later versions of this protocol for file operations on larger files.

I am not sure what the current standard in FreeBSD is (version 7.x.x) since I am still using the version 6 of FreeBSD. However this setup should also work with later versions of the OS.

Software installation

You should add the unfsd daemon using the ports collection or add it via a precompiled package. If you follow the attached link to this blog entry, it links to the installation page on freshports.org.

Subsequent configuration

The installation package does not include a rc script to start and stop the daemon, so i modified the system one in /etc/rc.d/nfsd to fit unfsd in /usr/local/etc/rc.d.

This is the rc file

# PROVIDE: unfsd
# REQUIRE: mountd
# KEYWORD: nojail

. /etc/rc.subr

name="unfsd"
rcvar=`set_rcvar unfs_server`
command="/usr/local/sbin/${name}"

load_rc_config $name
command_args="${unfs_server_flags}"
exports="${unfs_server_exports}"
pidfile=/var/run/${name}.pid
start_precmd="unfsd_precmd"
stop_cmd="unfsd_stop_cmd"
start_cmd="unfsd_start_cmd"
sig_stop="USR1"

unfsd_precmd()
{
    if ! sysctl vfs.nfsrv >/dev/null 2>&1; then
        force_depend nfsserver || return 1
    fi

    if ! checkyesno rpcbind_enable  && \
        ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
    then
        force_depend rpcbind || return 1
    fi

    if ! checkyesno mountd_enable  && \
        ! /etc/rc.d/mountd forcestatus 1>/dev/null 2>&1
    then
        force_depend mountd || return 1
    fi

    if checkyesno nfs_reserved_port_only; then
        echo 'NFS on reserved port only=YES'
        sysctl vfs.nfsrv.nfs_privport=1 > /dev/null
    fi
    return 0
}

unfsd_start_cmd()
{
    $command -e $exports -i $pidfile $command_args
}

unfsd_stop_cmd()
{
    if [ -f "$pidfile" ] ; then
        kill `cat ${pidfile}`
    fi
}

run_rc_command "$1"

This is the entries needed in /etc/rc.conf

unfs_server_enable="YES"
unfs_server_exports="/etc/uexports"

You should then add a /etc/uexports file to fit the format of unfsd. It is different from the system supplied nfsd from FreeBSD, so I suggest using a seperate file for this. In that way a rollback to the old version is a matter of re enabling it in rc.conf.

If you do not specify a named export file the unfsd will parse /etc/exports, and that will not work unless you edit it to fit the unfsd format.

Man unfsd will give you some examples of the format.

Conclusion

This will make it possible for you to use 2 gig plus files with nfs. In addition you will be able to use larger read and write sizes if you so choose.

Wednesday, March 3, 2010

ACPI brightness on Ubuntu with Nvidia cards and Intel Vpro chipset

Standard
Introduction
I have long had no response on my laptop, a HP 8510w on the brightness buttons. That is the fn+F9 and fn+f10.

It has been a source of irritation, and I decided to fix it.

Here is  how:
  1. Install nvclock
  2. Create nvclock wrapper scripts
  3. Create the necessary acpi config event mappers for acpid. 
Installation of nvclock

sudo apt-get install nvclock

Create nvclock wrapper scripts
Create file /etc/acpi/hp-brightness-up.sh:

#!/bin/sh
/usr/bin/nvclock -S +10


Create file /etc/acpi/hp-brightness-down.sh:

#!/bin/sh
/usr/bin/nvclock -S -10


 Create ACPID config files
Create file /etc/acpi/events/hp-brightness-up:

event=video C160 00000086 00000000
action=/etc/acpi/hp-brightness-up.sh
 

Create file /etc/acpi/events/hp-brightness-down:

event=video C160 00000087 00000000
action=/etc/acpi/hp-brightness-down.sh
 

 Restart ACPID subsystem
The acpid system is restarted like this:

sudo /etc/init.d/acpid restart


Final notes
If you have problems with this check to see if the event codes written above match the ones actually returned by the acpi subsystem of your laptop. The tools acpi_listen and acpital will both tell you more info. Start one of these programs in a terminal and to pressing the buttons you wish to configure.

Thursday, September 10, 2009

Python inheritance using object and class variables

Standard
Introduction:
When you have been working with Java for many years, it is sometimes fun to delve into other languages to get some new inspiration. For the past few days I have been meddeling around with Python / Django and Google App engine.

A discussion over MSN with a friend resulted in me coding this small example of how Python class and object variables differ greatly from what is normal in Java. Also this example illustrates very simple interitance from object->Vehicle->Car and Truck.

Code:
Package for vehicles:

'''
Created on Sep 10, 2009

@author: nikolaj
'''

class Vehicle(object):
'''
classdocs
'''
number_of_vehicles = 0

def __init__(self, color, number, weight):
self.number = number
self.weight = weight
self.color = color
Vehicle.number_of_vehicles += 1
print '(Initializing Vehicle %s which is of type %s)' % (self.number, type(self))


def __del__(self):
Vehicle.number_of_vehicles -= 1

if Vehicle.number_of_vehicles == 0:
print 'Vehicle: I am the last one on the streets now ...'
else:
print 'Vehicle: There are still %d of us left.' % Vehicle.number_of_vehicles

class Car (Vehicle):
'''
classdocs
'''
number_of_cars = 0

def __init__(self, color, number, passengers, weight):
Vehicle.__init__(self, color, number, weight)
self.passengers = passengers
Car.number_of_cars += 1

def __del__(self):
print 'Car: %s says bye. I am off to the scrap heap' % self.number
Car.number_of_cars -= 1

if Car.number_of_cars == 0:
print 'Car: I am the last Car on the streets now ...'
else:
print 'Car: There are still %d Cars left.' % Car.number_of_cars

def howmany (self):
print "Car: %d cars and %d vehicles in total" % (Car.number_of_cars, Car.number_of_vehicles)

class Truck (Vehicle):
'''
classdocs
'''
number_of_trucks = 0

def __init__(self, color, number, tonnage, weight):
Vehicle.__init__(self, color, number, weight)
self.tonnage = tonnage
Truck.number_of_trucks += 1

def __del__(self):
print 'Truck: %s says bye. I am off to the scrap heap' % self.number
Truck.number_of_trucks -= 1

if Truck.number_of_trucks == 0:
print 'Truck: I am the last Truck on the streets now ...'
else:
print 'Truck: There are still %d Trucks left.' % Truck.number_of_trucks

def howmany (self):
print "Truck: %d trucks and %d vehicles in total" % (Truck.number_of_trucks, Truck.number_of_vehicles)


Executable pyton main

from dk.hsys.model.vehicle import Car
from dk.hsys.model.vehicle import Truck

'''
Created on Sep 10, 2009

@author: nikolaj
'''

def main():

car = Car('Blue', 'RH20358', 4, 725)
car2 = Car('Yellow', 'DC79929', 2, 800)
car2.howmany()

truck = Truck('Red', 'CV34254', 22, 32)
truck2 = Truck('Green', 'BD7638', 2, 4)
truck3 = Truck('Black', 'HG76543', 30, 40)
truck.howmany()

if __name__ == '__main__':
main()



Output:


(Initializing Vehicle RH20358 which is of type )
(Initializing Vehicle DC79929 which is of type )
Car: 2 cars and 2 vehicles in total
(Initializing Vehicle CV34254 which is of type )
(Initializing Vehicle BD7638 which is of type )
(Initializing Vehicle HG76543 which is of type )
Truck: 3 trucks and 5 vehicles in total
Car: RH20358 says bye. I am off to the scrap heap
Car: There are still 1 Cars left.
Car: DC79929 says bye. I am off to the scrap heap
Car: I am the last Car on the streets now ...
Truck: CV34254 says bye. I am off to the scrap heap
Truck: There are still 2 Trucks left.
Truck: BD7638 says bye. I am off to the scrap heap
Truck: There are still 1 Trucks left.
Truck: HG76543 says bye. I am off to the scrap heap
Truck: I am the last Truck on the streets now ...

Tuesday, August 25, 2009

Automount with ssh and nfs

Standard
Introduction

I have for a long time mounted and unmounted network file systems by hand when ever I had a need for them. It is not a big thing, but you have to open a terminal in order to do this every time. I experimented a little with automount and autofs and found, that you can dynamically do things in the mount specification files.

Autofs dynamically executes mount commands triggered when you access a defined folder in your system. This folder then becomes the mount point for a given network or local file system. Another use for autofs is access of cd's, floppies and other removable block devices.

This is especially usefull from a Laptop computer, that sometimes are connected to network file systems behind a firewall, sometimes connected to ssh/sftp systems when you are on the road.

The goal is to be able to dynamically let the laptop figure out, what protocol to use: NFS or SSH/SFTP depending on the location of your connection.

Preparing the software

You will need to add the autofs system to your distribution of choice, this is for Debian / Ubuntu:

$ sudo apt-get install autofs

This will add the autofs system to the list of installed packages on your laptop PC.

You will now need to add netcat and sshfs to your system - it is used to check if a ssh server is accessible and mount the nfs share via SSH if it is:


$ sudo apt-get install netcat sshfs

Autofs will add a daemon to your system for monitoring your configured mount points. The deamon needs to be told to reload configurations whenever you change your configuration:



$ sudo /etc/init.d/autofs reload
Reloading automounter: checking for changes ...
Reloading automounter map for: /misc
Reloading automounter map for: /mnt/media


The configuration for the autofs system is held in files in /etc/auto.* where you can add you mount points as you need them. There is several good examples in the ones already added by default. However I produced a new named auto.media and added it to /etc/auto.master in order to access my media drive. This is the contents:



#!/bin/sh
# check to see if this host has a working internet connection and a IP address
MYIP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
ping -c 1 ${MYIP} >> /dev/null 2>&1
if [ "$?" -ne "0" ]
then
exit 1;
fi

# check to see if HOSTNAME can be pinged directly - if yes echo the mount lines for nfs
ping -c 1 HOSTNAME >> /dev/null 2>&1
if [ "$?" -eq "0" ]
then
echo "root -fstype=nfs,rw,sync,soft,intr,rsize=8012,wsize=8129 HOSTNAME:/foo/bar/&"
echo "data2 -fstype=nfs,rw,sync,soft,intr,rsize=8012,wsize=8129 HOSTNAME:/foo/bar/&"
echo "download -fstype=nfs,rw,sync,soft,intr,rsize=8012,wsize=8129 HOSTNAME:/foo/bar/&"
exit 0;
fi

# check to see if SSHHOST can be contacted - if yes use the ssh/nfs to mount using fuse
nc -z SSHHOSTNAME 22 > /dev/null 2>&1
if [ "$?" -eq "0" ]
then
echo "-fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#USER\@SSHHOST:/foo/bar/&"
exit 0;
exit 0;
fi


The file /etc/auto.media listed above should be made executable with permissions 755. When executed it will dynamically produce the contents of the auto.media file depending on the script execution. As a consequence the mount points will not be visible in /mnt until execution of the script has completed. So you will have to cd to a non existing folder like /mnt/media before you actually see it created in /mnt :-)


Conclusion and caveat

The above works fine for me. There could be a problem, if you are on a foreign network, where another server called HOSTNAME exists. You may need to add more intelligent identification check of the HOSTNAME server in order to make this work correctly in all networks.

Tuesday, June 9, 2009

Land Rovers with Perkins diesel?

Standard
In the old days I believe that I read somewhere that Land Rover actually considered using one of the Perkins diesel engines in the Defender models.

It never happened as far as I know.

Never the less: Nothing that can be done to a Defender will be left un done.

Here is a Defender pick up with a Perkins inline 6. The P6.



He must blow those half shafts as quick as he can exchange them ...

Or perhaps even with the great Cummins Turbo diesel also used in the Dodge Rams?