Enabling ACPI shutdown on OpenWRT 14.07 (Barrier Breaker)

I use OpenWRT VMs as micro routers to build private internal networks inside my Linux workstations using KVM and openvswitch. The problem is that when the libvirt shuts guests down is sends an ACPI shutdown button press (the physical equivalent of pressing the power button) which OpenWRT ignores.

On previous versions of OpenWRT you needed to install the acpid package but now you only need to install the kmod-button-hotplug package.

opkg update
opkg install kmod-button-hotplug

My Travel Kit

Every geek has something like this, a travel kit for when you get asked by people “oh you know about computers can you email this photo from the top of a Spanish mountain?”

IMG_4051It’s nice to be able to say “yes I can”

_MG_5228_DxOMy basic travel kit consists of

  • Mobile phone charging battery (has 2x USB ports, 1 is a 2A port)
  • TP-Link WR703N running OpenWRT with 64MB RAM / 16GB Flash Mod from slboat (£25 delivered from China)
  • USB serial port that provides power and a serial console for the WR703R
  • USB 3G stick, unlocked has a PAYG 3 SIM in for UK usage
  • Short Micro USB cable for other gadgets and the wife’s phone and to charge the battery from a standard USB port
  • Apple Lightning cable for my gadgets, why can’t you use a standard Apple?
  • Short ethernet cable
  • Bootable 32GB memstick, gives me a few standard Linux options for fixing computers as well as a set of portable apps.

The WR703N is setup to run as an AP and access the internet via 3G dial up. Because it’s got a serial port on it I can tinker to solve lots of different problems without needing network access.

The OpenWRT install on the WR703N also dials into my OpenVPN hosted on this server. It means I can browse as if I am in the UK from anywhere in the world, It’s amazing how much better hotel wifi is when you can tunnel out of it and run a proper DNS server and web proxy.

The battery will run the AP for 4 days, drops to 2 days with the 3G dongle plugged in and working and gives portable data without having to pay a kidney a megabyte to the mobile carriers. The battery gives a couple of iPhone 5S / Nexus 5 charges and about a 2/3 charge on my iPad mini retina.


Finding my wife’s missing phone with OpenWRT

A few weeks ago my wife and I where visiting some friends in Sweden, they own a small cottage in the woodland near Stockholm. The location is lovely but slightly out of the way with a small lake about 200m from the cottage.

Swedish LakeWe went for a walk round the lake to enjoy the glorious weather and take some photos of the mirror smooth lake. About 1/2 way round the lake my wife realised that she didn’t have her phone. We did the obvious things of retracing our steps looking at the floor and trying to work out which of the little paths we took round the lake. We found a number of things
including large numbers of frogs and my sunglasses which I didn’t even realise I had lost, but no phone.

Normally the next step would be to get the phone to make some noise, either by ringing it or using the anti-theft product that was installed on it. Both of these ideas had problems, the phone was on silent meaning ringing the phone was a waste of time. The problem with the anti-theft product was that it needed a data connection and because the phone was
connected to a foreign network it was in roaming mode and the data connection was disabled to avoid massive bills. So what next?

The phone has WIFI and will automatically join an AP it knows about, but which SSIDs could I be certain it would join and how would I get an AP close enough to the phone in the middle of the Swedish woodland?

I always carry a little bag of tricks and I thought there might be something in there that could to help. In the bag I had a mobile phone charging battery, a TP-Link WR703 with OpenWRT installed and I had an ssh client (Prompt from Panic Inc) on my iDevices.

So I can build a mobile AP (WR703 + USB Battery) and because it’s running OpenWRT I can customize and monitor the AP. Next I needed some configuration for the AP particularly an SSID that the missing phone is guaranteed to join. The obvious option is the SSID from home. So I logged into the AP at home via OpenVPN copied /etc/config/wireless to the WR703 I had running. After I reboot I had an AP that appear to be the same as the one at home and my iDevices joined straight away, step one completed.

We loaded my rucksack with all of the kit and set off for another walk round the lake. I had logged into AP from my iPhone and was running logread -f to monitor the logs on the AP. We repeated the route again, debating about which path we took and poking about in bushes looking for a phone. We where getting towards the point where my wife realised she has lost her phone and starting to give up hope. Then another device joined the access point, authenticated and got an IP from the DHCP server it was an Android device. This was a big step forward, we knew that there was an Android phone within about 100m of us, that had our WIFI password set on it.

Because of the way that radio works with a bit of walking about with my iPhone and my bag hung on a tree we could map the edge of the wifi from the AP. Once we had a clear idea where we should be looking we had another good hard look at the 100m or so of path that my mapping suggested the phone could be in. No luck and it was starting to get dark
and the phone’s battery would probably not last the night, time for some more thinking. The real thing that would help would getting an internet connection on the phone, so back to the cottage for another think.

One of our friends in Sweden had a Windows phone that includes mobile AP, which unlike the iPhone you could set the SSID and password on. After typing in the long random WPA password I set on the home AP, I set off again with a mobile AP in my bag but this time with internet access.


After a little detour to take photos of the moonlight on the lake, I returned to the tree where the missing phone got WIFI marked with a Swedish napkin. I triggered off another round of alerts to the phone over the internet but no luck, no noises from the undergrowth and it was finally getting dark even in Sweden and it was time to head back to the cottage.

Now was the time for any last good ideas, after a bit of thought I had an idea! Wifi works in a circle and while I could be pretty sure that the phone wasn’t 100m into the lake I should really check if there was another path further into the woodland. I went a bit further along the path and there was a fork leading back into the woodland that looked promising. I set off down the path and after a minute I could hear something ahead and sure enough there was the missing phone.

More storage on an OpenWRT router

Even with a modified WR703N you will still likely run out of space quite quickly if you try and use some of the larger OpenWRT packages like Samba or Asterisk. The best way to add more storage is one of the tiny USB flash drives that fit in side the USB port on the router, something like a 16GB SanDisk Cruzer Fit flash drive.

You can also do clever things such as using different memory sticks for different setups, so you have a memory stick setup that starts up as a PirateBox, while a different one setup to join your wireless and share files from the USB memory stick. Because of the way that the overlay works, effectively the entire system state is stored on the overlay filesystem.

I have a little script that does all the setup for you, it assumes that the drive is setup with 2 primary partitions, the first one formatted with ext4 and the second as swap, you will need to do the partitioning and formatting on a normal Linux box. Once the drive is setup you just need to run the following script, it downloads and installs the correct packages and sets up the usb memory stick as an overlay.

packages="kmod-fs-ext4 kmod-usb-storage block-mount"

echo "Stopping automounting"
/etc/init.d/fstab stop

opkg update
opkg install $packages

sleep 10

while [ ! -b /dev/$dev ] ; do
echo "/dev/$dev not found please insert the USB storage device"
read junk

mkdir -p /mnt/$dev
mount /dev/$dev /mnt/$dev -t $fstype -o $options

tar -C /overlay -cvf - . | tar -C /mnt/$dev -xf -

uci add fstab mount
uci set fstab.@mount[-1].device=/dev/sda1
uci set fstab.@mount[-1].options=$options
uci set fstab.@mount[-1].enabled_fsck=0
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/overlay
uci set fstab.@mount[-1].fstype=$fstype

uci add fstab swap
uci set fstab.@swap[-1].device=/dev/sda1
uci set fstab.@swap[-1].enabled=1

uci commit fstab

/etc/init.d/fstab enable

echo "Overlay enabled, you need to reboot to activate it"


The script can be downloaded here: http://www.night-shade.org.uk/~tim/OpenWRT/usb-overlay.sh.gz