Mounting a Pi with Wheezy read-only

April 6, 2016

A while back, I had a need to make a Raspberry Pi have a read-only filesystem. I used the instructions at: github.com/tvdzwan/hyperion/wiki/Make-Raspbian-Read-Only to do so.

Just in case that goes away or changes, here’s what I did:

dphys-swapfile swapoff
dphys-swapfile uninstall
update-rc.d dphys-swapfile disable
aptitude install unionfs-fuse

Then create an executable script as follows in /usr/local/bin/mount_unionfs:

#!/bin/sh
DIR=$1
ROOT_MOUNT=$(awk '$2=="/" {print substr($4,1,2)}' < /etc/fstab)
if [ $ROOT_MOUNT = "rw" ]
then
  /bin/mount --bind ${DIR}_org ${DIR}
else
  /bin/mount -t tmpfs ramdisk ${DIR}_rw
  /usr/bin/unionfs-fuse -o cow,allow_other,suid,dev,nonempty ${DIR}_rw=RW:${DIR}_org=RO ${DIR}
fi

Next, make / read-only and mount /etc and /var as ramdisk in /etc/fstab:

/dev/mmcblk0p1  /boot           vfat    ro                0       2
/dev/mmcblk0p2  /               ext4    ro,noatime        0       1
mount_unionfs   /etc            fuse    defaults          0       0
mount_unionfs   /var            fuse    defaults          0       0

Finally, make the magic directories:

cp -al /etc /etc_org
mv /var /var_org
mkdir /etc_rw
mkdir /var /var_rw
reboot

Recently, I had to add a user to a group. To do that, I used:

umount /etc
mount -o remount,rw /

to make /etc/ writable again.


Turning a Raspberry Pi 2 into a packet station

March 31, 2016

I keep thinking it’s a good idea for emergency communications to have a packet station. Since I’m cheap, I didn’t want to get extra hardware – instead I wanted to use what I had. Luckily, Dire Wolf is better than any hardware packet decoder out there. Here’s how I got a working packet station on a Pi 2 running Raspbian Jessie Lite.

  1. Connect the radio to the Pi. In my case, I had a spare Signalink SL1+ hanging around which made things easier. I  bought a Syba CMedia USB sound card to talk from the Pi to the Signalink, and a Kenwood speaker mic cable to talk from the Signalink to the radio. Here’s a useful hint: the diameter of the wires in the speaker mic cable are roughly the same as the diameter of the wires in regular Ethernet cable – meaning that you can (if you’re careful) strip the outer jacket, put the inner wires in the right places of an RJ-45 connector and crimp direct to them with no soldering at all.
  2. Download and build Dire Wolf. Instructions for doing so on a Pi are here. I mounted my home directory on a networked drive to make life easier.
  3. Configure Dire Wolf with your callsign (I used the SSID -15 after my call) and sound card. Be sure to avoid the “# ADEVICE – plughw:1,0” line – it looks a lot like the correct “ADEVICE  plughw:1,0” line, but takes input from stdin instead of the sound card.
  4. Run “direwolf” and tune the radio to 144.390 (APRS). Make sure you’re decoding packets. You might have to go to alsamixer and adjust input/output. Mine ended up being 51 for speaker, 29 and 12 for mic. Also adjust the radio volume so it’s not too high or too low. (Hit F6 to get your sound card, then F5 to see all devices. I’m not sure which mic I was using; I had two – a stereo and a mono one. The mono one was 29, the stereo one was 12.) It’s probably a good idea to turn off the squelch on the radio as well.
  5. sudo apt-get install ax25-tools ax25-apps
  6. Edit /etc/ax25/axports and set one line to:
    vhf   mycall-15 1200 255 2 VHF link (1200 bps)
  7. Make sure all the other lines in axports have # in front of them (it doesn’t like blank lines).
  8. Run “direwolf -p” to get the KISS port. It will show up as something like /dev/pts/2. Once it’s running, move to another terminal window.
  9. Change frequency to the freq that you’re going to use.
  10. sudo /usr/sbin/kissattach /dev/pts/2 vhf (your IP address in AMPR 44.0.0.0)
  11. sudo /usr/sbin/kissparms -p vhf -t 200 -s 20 -r 64 -l 50 -f n
    These parameters took a little tweaking. If the transmit delay (-t) was too big, things timed out. If it was too small, things stepped on each other. I had to adjust transmit tail delay as well (-l). I found this page useful for some values.
  12. sudo route del -net 44.0.0.0 netmask 255.0.0.0
    (because I’d set up a route beforehand and needed to nuke it)
  13. sudo /sbin/route add -net 44.0.0.0 netmask 255.0.0.0 dev ax0
  14. ping -i 10 (someone else’s IP who also has a machine on the AMPR 44.0.0.0 net)
  15. Assuming that works, you might want to apt-get install telnet telnetd talk talkd and try to log into your friend’s machine or have your friend log into yours.
  16. Last but not least: I ran into problems with arp. I increased the arp timeout in /etc/sysctl.d/local.conf:net.ipv4.neigh.default.base_reachable_time_ms=1200000

Turning a Raspberry Pi 3 into an iBeacon

March 29, 2016

Wow, that was easy. Straight out of the box, you can turn your Raspberry Pi 3 into an iBeacon. All you need is Raspbian Jessie – it’s got hcitool installed.

Here’s how to do it. First, decide on your iBeacon UUID and major/minor. For instance, I picked at random:

UUID: c9407f30-f5f8-466e-aff9-25556b57fe6d
Major: 179
Minor: 3

Next, convert the UUID to 16 byte big-endian hex, and convert major/minor to 4 byte big-endian hex:

UUID: C9 40 7F 30 F5 F8 46 6E AF F9 25 55 6B 57 FE 6D
Major: 00 B3
Minor: 00 03

Plug those numbers into the magic command:

sudo hcitool cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 UUID Major Minor C8

For example:

sudo hcitool cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 C9 40 7F 30 F5 F8 46 6E AF F9 25 55 6B 57 FE 6D 00 B3 00 03 C8

Finally, turn advertising on with:

sudo hcitool cmd 0x08 0x000A 01

or turn it off with

sudo hcitool cmd 0x08 0x000A 00

That was too easy!

Incidentally, the 4C 00 is the magic bit that says it’s an Apple product, 02 means iBeacon, 15 is the (hex) length of the remaining data. The trailing C8 is the two’s complement of the transmit power at 1m, so c8 is -56. More details can be found at:
https://stackoverflow.com/questions/18906988/what-is-the-ibeacon-bluetooth-profile.


Controlling T-Series Vector Impedance Analyzer from a netbook

March 21, 2016

I’ve been using the T-Series Vector Impedance Analyzer program from Times Technology Company to control my dad’s MFJ-226 antenna analyzer (aka Times Technology T200). Both he and I ran into problems with it on a netbook with a screen size of 1024×600. Most of the “interesting” buttons were off screen!

The right solution for Windows 7 and higher appears to be to allow scaling of the netbook’s screen. That’s documented here. But for those unfortunates who are stuck on Windows XP or for some other reason can’t increase the screen size, here’s what I ended up doing.

To start/stop the connection to the analyzer:

  • Click the “SWR” button
  • Press [Tab] [Tab] [Cursor back <-] [Space]

To load a file from the analyzer:

  • Click the “Save to File” button
  • Click “Cancel”
  • Press [Tab] [Tab] [Tab] – you are now on the file to load
  • Press [Backspace] [Backspace] [Backspace] [Del] [Del] [Del]
  • Enter the file you want to load from the analyzer (1, 3, 12, etc.)
  • Press [Shift-Tab]
  • Press [Enter]
  • Now you can click the “Save to file” button and save the data.

Increasing Netbook Screen Size

March 21, 2016

I’ve got an old Acer Aspire One 521 netbook that I’ve had for ages. One of the downsides of netbooks is that their screen resolution is 1024×600 – which is too low for a lot of programs. In particular, all the interesting buttons of the MFJ-226 control program “T-Series Vector Impedance Analyzer” are below the bottom of the screen.

I found a workaround that appears to work on Windows 7 and higher. I found it here: http://www.tlbhd.com/how-to-get-better-resolution-on-your-standard-10-inch-netbook-2772/

The solution: use regedit to search for all instances of “Display1_DownScalingSupported” and change the value 0 to 1. (According to various things I’ve read, you’ll need to do that for all instances, not just one.) Then reboot. When I did this, I ended up in 1024×768 (which looks strange).

Strange isn’t bad, though. Now I can change resolutions to 1024×768 or 1152×864 if an inconsiderate programmer decides he wants to use more than my screen.

 


Setting up Raspian Jessie on a Pi

March 15, 2016

There are a few changes to setting up Raspian Jessie on a Pi. Here’s what I do:

Burn the image

  1. Get the Raspbian image from the Raspberry Pi downloads page. I’ve been using Jessie Lite, since I don’t need the full package.
  2. Unzip it on a Linux box (mine saw the SD card as /dev/sdb, use your SD card device and don’t wipe your hard drive)
  3. Pop the card out of the Linux box and into the Pi

The command to write that I used:

sudo dd if=2015-01-31-raspbian.img of=/dev/sdb bs=4M

Configure the Pi

When the Pi boots into raspi-config, do the following:

  1. Expand Filesystem
  2. Change User Password
  3. Internationalisation Options / Change Locale, pick en_US UTF-8
  4. Internationalisation Options / Change timezones, pick yours
  5. Internationalisation Options / Change Keyboard Layout, pick US PC 104, accept defaults

Set up the network

I have my Pi configured with a static IP. The first time I boot I attach a network cable.

  1. Edit /etc/dhcpcd.conf (not /etc/network/interfaces) so the wired interface is static
  2. My /etc/resolv.conf was configured automatically by dhcp and was mostly right (missing domain and search, but I guess I can live with that)
  3. Now would be a good time to edit /etc/hostname as well
  4. Edit /etc/hosts to use the new hostname and hostname.domainname

(Thanks to https://pi-hole.net/faq/how-do-i-set-a-static-ip-address-in-raspbian-jessie-using-etcdhcpcd-conf/ for the revised instructions for a static IP.)

I added the following to the end of my /etc/dhcpcd.conf:

# Configure eth0 to be static
interface eth0
static ip_address=192.168.17.5
static routers=192.168.17.1
static domain_name_servers=192.168.17.1
static domain_name=mydomain.foo

Install an editor

I can do a few things like adding users while updates are happening. So:

sudo aptitude update
sudo aptitude install zile

Update the OS

This takes a while, but you can continue on while this is happening.

sudo apt-get install rpi-update
sudo aptitude dist-upgrade

Add my user

I don’t like to use the default user, so I add my own.

  1. sudo adduser myuser
  2. edit /etc/group to add my user to all the pi groups (including sudo). Note that since newer versions of zile have removed replace-string, you have to use query-replace.
  3. log out, log in – make sure I can sudo with the new user
  4. prevent login as pi

To prevent the pi login, I do:

sudo vipw -s

and replace the password for pi with *.

Update everything else

Once the dist-upgrade has completed and it’s time to reboot:

sudo /sbin/shutdown -r now

Now you can log in again and upgrade the firmware:

sudo rpi-update
sudo /sbin/shutdown -r now

Get things I know I’ll need

I like to have an emacs clone:

zile ~/.bash_aliases
alias emacs='zile'

I also like tightvncserver on non-Lite images:

sudo aptitude install tightvncserver
tightvncserver
(set password)

Finally, make emacs the default editor by appending this to ~/.bashrc:

export EDITOR=/usr/bin/zile

Mounting a CIFS drive

I don’t like to do more writing than I have to, so:

sudo mkdir /etc/samba/credentials
sudo chmod 700 /etc/samba/credentials
sudo chown root.root /etc/samba/credentials
sudo mkdir /shared
sudo zile /etc/fstab
sudo zile /etc/samba/credentials/myserver

In /etc/fstab, I add:

//myserver/shared /shared cifs credentials=/etc/samba/credentials/myserver 0 0

While in /etc/fstab, I change the following to reduce wear on the SD card:

/dev/mmcblk0p1  /boot           vfat    ro,noatime 0 0
/dev/mmcblk0p2  /               ext4    defaults,noatime 0 2

In /etc/samba/credentials/myserver, I add:

username=myuser
password=mypass

I also have to add a group for my user so it has the right ID in /etc/group:

myuser:x:2000:

Then fix up the user I created (sigh)

sudo chgrp -R /home/myuser
sudo vipw

That’s about it.


Formatting an SD card as exfat

December 17, 2015

On Android, by default SD cards with 64M or more on them are formatted as exfat, while smaller cards are formatted as fat32. But what if you want to force an SD card to be exfat? Here’s how to do it. You’ll need a Linux box.

  1. sudo apt-get install fuse-exfat exfat-utils
  2. Partition the card if it’s not already partitioned
  3. sudo mkfs -texfat /dev/sdf1

Mostly this post is to remind me that the new format is called exfat, since I keep forgetting that.


Follow

Get every new post delivered to your Inbox.