Portable headless Linux box

I have a Raspberry Pi that I’m using in different environments. The easiest way to use the Pi is by just connecting power and network and use SSH, but when theres no screen, it’s not always easy to know the IP address of my Pi.

To make life easier for myself i have put the following lines in a start.sh script and added it to my crontab with the @reboot option. This will make crontab run this script every time the Pi has been rebooted (or shut down)

sleep 30
echo “My IP is: $(ip addr | grep global | awk -F ‘ ‘ ‘{print $2}’)” | mail -s “Raspi reporting in…” someone@somewhere.org

The script will put in a 30 seconds delay to allow the Pi to pickup an address and then mail it for my mail address. Remember to make sure that your Pi is able to send mails, otherwise this will not work.

This will most likely ensure that i will get a mail with the IP address of my Pi, and I  am ready to login with SSH.


Playing with LXD containers

Lately I have been playing around with LXD containers, and its actually pretty cool.

Lets create a new container:

lxc-create -t download -n TestCont

This will download the default Ubuntu image from the official repository and create a container named TestCont.

Fire it up with “lxc-start -n TestCont”, connect to it with “lxc-attach -n TestCont”. Now you are in the shell of your new container.

Install dnsmasq, configure it for DHCP and DNS and assign IP’s to your containers based on Name or MAC address. The entry in the dnsmasq conf file should look something like this:


Lets create 10 new containers, have them set to autostart, fire them up, and watch the process go along:

for i in `seq 1 10`; do lxc-copy -n TestCont -N TestCont$i;echo “lxc.start.auto = 1” | tee -a .local/share/lxc/TestCont$i/config;lxc-start -n TestCont$i; done; watch -n 5 lxc-ls -f

Maybe we can also configure the dnsmasq at the same time:

for i in `seq 1 10`; do echo “dhcp-host=Cont$i,10.0.0.$i” | tee -a /etc/dnsmasq.d/static-hosts.conf;lxc-copy -n TestCont -N TestCont$i;echo “lxc.start.auto = 1” | tee -a .local/share/lxc/TestCont$i/config;lxc-start -n TestCont$i; done; watch -n 5 lxc-ls -f

As you can see my dnsmasq conf file is called static-hosts.conf. Now i got 10 new containers with fixed IP addresses in 5 minutes – thats cool 🙂

Before copying the original container I have some tips on what to install in it:


You could do it like this:

lxc-execute -n TextCont apt install ssh vim bash-completion -y

Now you got a nice base image with ssh for remote access, vim for file editing and bash completion. This image will have a ~420 MB footprint.
Another option is to put your public SSH key in the base image, now where getting somewhere 🙂



Kill unresponsive VM from ESXi cli

Sometimes a VM can go in an unresponsive mode and you cannot shut it down or reboot it from the vSphere client. When this happens we need to be more persuasive in telling the VM to shut down. Log in to the ESXi server with SSH, find the World ID for the unresponsive VM and kill the process, this is done like this:

esxcli vm process list

This will list all the running VMs on the server, use grep -A2 to filter the VM name and the world ID, like this:

esxcli vm process list |  grep -A2 “VM Name”

Kill the process with this command:

esxcli vm process kill -t=soft -w=”WORLD_ID”

This will kill the process in a “soft” way, use -t=hard to be even more persuasive and as a last resort attempt you can use -t=force. If none of the three shuts down the VM, a reboot of the host is required.
To automate things a bit i assembled this one-liner for easy use:

esxcli vm process kill -t=soft -w=`esxcli vm process list | grep -A2 “VM Name” | grep World | awk ‘{print $3}’`

This will softly shut down the VM with “VM Name”

Re-Volt, Wine, Multiplayer

My kids are beginning to play on their computers, and when one of them where invited to a socalled LAN-Party it woke up memories in my mind. I remembered how I used to play at LAN parties my self, and I remembered how simple it was to set up a game and play against each others. Todays gaming is all about joining public servers, creating accounts, and answering questions about this and that.

That made me think back on one of my favourite games from around 2000, Re-Volt. I searched the web and found that Re-Volt isn’t dead at all, fan communities are still alive, and theres even a small patch for the latest version that will support modern wide screens, easier multiplayer, etc. Check it out here: http://www.revoltrace.net/ where you will also be able to download the latest version and patch.

The kids are running Windows 7 and Windows 10 and we had no issues installing it, the installer will ask for the directplay module and download it when needed. In order to play multiplayer we had to allow some firewall ports to be used even though the firewall is disabled on the local network. When hosting a game I noticed that it’s using my public IP and not my private, thats probably why I had to allow additional ports to be used – 🙁

Now, lets get back to the actual point for my post. I am running Ubuntu Linux 14.04 on my laptop, and I thought I would be able to play Re-Volt using Wine. No problem at all, it installed just fine and worked like a charm, until I wanted to play multiplayer over the LAN. I got different erros depending if I wanted to host or join a game, but quickly I found out that on Linux I also needed the so-called directplay module, which is easily installed with winetricks that comes with the Wine installation on my system. After some googling I found out that all I needed to do was:

winetricks directplay

This command will install the directplay module and now the game is running smoothly with or without multiplayer. Wine documentation states to run “sh winetricks directplay” which will not work for the package-manager installed version.

Using Vim as editor in PowerShell

If you are used to using Vim or Vi as your editor, you might miss it when using powershell. Good news is, theres a way to get it. Download and install Vim for windows, create a profile.ps1 file in this path: (for me at least) c:\users\%username%\documents\WindowsPowerShell\ and type in the following:

$VIMPATH    = “C:\Program Files (x86)\Vim\vim74\vim.exe”

Set-Alias vi   $VIMPATH
Set-Alias vim  $VIMPATH

# for editing your PowerShell profile
Function Edit-Profile
vim $profile

# for editing your Vim settings
Function Edit-Vimrc
vim $home\_vimrc

Remember to change the $VIMPATH to your installation.

Now you have a fully functional vim from powershell.


Steam (and possible other) in 64 bit systems

Hi all.

I just tried to install Team Fortress 2 in Steam on my Ubuntu 15.04 64bit system, and I got this error message:

You are missing the following 32-bit libraries, and Steam may not run: libc.so.6

I asked google, and I found an article suggesting to do this: apt-get install lib6* – this will install a hell of a lot of software that you probably don’t need.

So instead of just following the suggestion I did an apt-search libc6, and found this package: libc6-i386, I installed it, and now I was able to install Team Fortress 2 in steam.


Forbinde til en VM i KVM med virsh console

En nem måde at forbinde til en KVM VM er ved brug af kommandoen virsh console ‘vm-name’. Man forbinder direkte til konsollen, og på den måde er man uafhængig af netværk. Mon ikke de fleste har prøvet at rive sig selv i håret, når man opdager at man har lukket sig selv ude fra SSH.

Når man først er inde skal man jo også ud igen, hvis man er vant til at arbejde med SSH skriver man naturligt exit når man vil ud, men så ender man bare i login prompten, stadig på den samme maskine. Når man logger ind kommer et fint lille hint der fortæller at “Escape character is ^]”, og hvad betyder så det? Jo, det må være noget med “Ctrl+AltGr+9”, jeg kan afsløre med det samme at det virker ikke. På min maskine med dansk tastatur layout er det “Ctrl+5”, det er jo dejligt nemt, når man først har brugt ½-1 time på at finde ud af det 🙂

Alt i alt en nem og hurtig måde at logge ind på de enkelte virtuelle maskine og måske endnu vigtigere en god backup, hvis man har dummet sig med netværket.

Installer MPEG-2 licens på Raspberry Pi

Raspberry Pi er lavet med henblik på at den skal kunne købes af alle, derfor er der sparet alle steder hvor det er muligt. En af de steder der er sparet er i CPU’ens mulighed for at decode visse codecs, istedet for bare at ligge en licens ind fra starten, der ville forhøje prisen for alle, har man valgt en model hvor man selv køber en licens, hvis man vil bruge raspberry pi som mediecenter og har brug forat afspille disse codecs.

For mit vedkommende gælder det primært de optagelser jeg laver med min mythtv server, de ligger tit i MPEG-2 format og dem kan jeg så ikke uden videre afspille på min OpenElec installation på raspberry pi.

Løsningen er at købe en licens her: http://www.raspberrypi.com/mpeg-2-license-key/

Omregnet koster den ca. 25 dkr, det er lige til at overkomme, men hvordan får man den så installeret?

Inden man bestiller skal man lige hav fundet serienummeret på sin CPU, det gøres således:

SSH til din raspberry pi. På en Openelec er std. kodeord openelec, og brugernavnet er root. Fra windows kan man bruge Putty, på Linux kan man bruge terminalen og skriv:

ssh -l root ip-adresse-på-raspberry-pi

Når man er logget ind kører man kommandoen:

cat /proc/cpuinfo

Det ser sådan her ud:

root@stuen’s password:
# OpenELEC – The living room PC for everyone #
# …… visit http://www.openelec.tv …… #

OpenELEC (official) Version: 4.0.6
Stuen:~ # cat /proc/cpuinfo
processor    : 0
model name    : ARMv6-compatible processor rev 7 (v6l)
Features    : swp half thumb fastmult vfp edsp java tls
CPU implementer    : 0x41
CPU architecture: 7
CPU variant    : 0x0
CPU part    : 0xb76
CPU revision    : 7

Hardware    : BCM2708
Revision    : 000f
Serial        : 0000000002529fb3
Stuen:~ #

Min raspberry hedder Stuen, bare for at undgå misforsatåelser 🙂

Når man har fået fat i serienummeret kan man bestille sin licens.

Efter et par dage dumper der en mail ind, med en specifik genereret kode der passer til din raspberry pi, nu skal den så installeres, det gøres som følger:

Log ind på din raspberry med ssh igen, i mappen /flash skal der være en config.txt fil, måske findes den allerede, ellers skal den laves. Men inden vi gør noget skal vi lige sikre os at vi kan skrive i /flash mappen, den er nemlig mounted “read only”, vi remounter den lige med “read write”. Gør dette fra root folderen (cd /)

mount /flash -o remount,rw

Nu kan vi skrive i mappen og enten editere den fil der allerede ligger der, eller lave en ny. Filen skal indeholde en linie med “decode_MPG2=den-kode-du-fiki-din-mail”

vi /flash config.txt

tryk på “i” for at skrive i filen

tryk :wq for at gemme (kolon efterfulgt af w og q write/quit)

Vi er en editor der kan virke lidt besværlig til at begynde med, men lær dig selv de mest basale kommandoer, den findes stort set på alle Unix/Linux systemer

Når du har gemt filen skriver du reboot i konsollen, systemet genstarter og du kan nu se MPEG2 filer 🙂