photography, coffee, technology and more

Boot Arch Linux from USB on Raspberry Pi 2

At the moment I’m setting up a backup system in Arch Linux and minimise the risk of sd-card corruption, I’m going to run the OS from a usb stick (you can also use an usb drive if you want). I’m using this guide as a basis. It’s meant for Raspbian, but I adapted the procedure below to Arch linux.

In the guide above we are going to follow the extended procedure. Because that way we are sure that every time we boot we have the correct stick.

To make sure our stick is recognised by Arch we run lsblk

you should see something similar like this:

   sda           8:0    1  7.6G  0 disk 
   `-sda1        8:1    1  7.6G  0 part 
   mmcblk0     179:0    0  3.7G  0 disk 
   |-mmcblk0p1 179:1    0  100M  0 part 
   `-mmcblk0p2 179:2    0  3.6G  0 part /

The drive we want in my case the sda drive. Make note we are going to need that drive name.

Let us first install gdisk

sudo pacman -S gdisk

once that finishes, we are going to use gdisk on the usb stick.

sudo gdisk /dev/sda

Enter d to delete partion(s).

Enter n to create a new primary partition (number 1) and use the full capacity by hitting return a few times until done note: if you want more partitions use +xxxM to create a different size and repeat n till there is no space left or you have your number of partitions

Now write the new information to the stick by entering “w”

You should get something like this output

  Command (? for help): d
  Using 1
  Command (? for help): n
  Partition number (1-128, default 1): 
  First sector (34-15826910, default = 40) or {+-}size{KMGTP}: 
  Last sector (40-15826910, default = 15826910) or {+-}size{KMGTP}: 
  Current type is 'Linux filesystem'
  Hex code or GUID (L to show codes, Enter = 8300): 
  Changed type of partition to 'Linux filesystem'
  Command (? for help): w
  Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
  Do you want to proceed? (Y/N): y
  OK; writing new GUID partition table (GPT) to /dev/sda.
  The operation has completed successfully.

Now repeat the gdisk command and use i

sudo gdisk /dev/sda

you’ll get an output like:

  Using 1
  Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
  Partition unique GUID: 0ED53DE0-0BD6-4F15-AC97-A4D0494CEF18
  First sector: 40 (at 20.0 KiB)
  Last sector: 15826910 (at 7.5 GiB)
  Partition size: 15826871 sectors (7.5 GiB)
  Attribute flags: 0000000000000000
  Partition name: 'Linux filesystem'

The Partition unique GUID is the one we need, in the next step:

sudo cp /boot/cmdline.txt /boot/cmdline.txt.old

let’s copy the original cmdline.txt file and edit it:

sudo nano /boot/cmdline.txt

replace the root=/mnt/… with root=PARTUUID=youruniqueidentifier

  root=PARTUUID=0ED53DE0-0BD6-4F15-AC97-A4D0494CEF18 rw rootwait console=ttyAMA0,115200 console=tty1 selinux=0 plymouth.enable=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 kgdboc=ttyAMA0,115200 elevator=noop

We now continue with formatting, mounting, installing rsync (which we use later on again as backup system) and the mirroring

   sudo mke2fs -t ext4 -L rootfs /dev/sda1
   sudo mount /dev/sda1 /mnt
   sudo pacman -S rsync
   sudo rsync -axv / /mnt

Now we need to get a unique identifier for the fstab drive information:

sudo tune2fs -l /dev/sda1

You get a lot of info, but the most important part is the Filesystem UUID

  Filesystem volume name:   rootfs
  Last mounted on:          /mnt
  Filesystem UUID:          b8389d09-e7a6-4358-9501-9a309938d30d
  Filesystem magic number:  0xEF53
  Filesystem revision #:    1 (dynamic)

Next we can enter the information into the filesystem table, /etc/fstab (on the stick, not the SD card). Add the following line:

   /dev/disk/by-uuid/b8389d09-e7a6-4358-9501-9a309938d30d    /   ext4    defaults,noatime  0       1

That should be it, try to reboot now, if it boots, type lsblk if you see a / under MOUNTPOINT next to your usb drive, it means you are running from the usb.

   sda           8:0    1  7.6G  0 disk 
   `-sda1        8:1    1  7.6G  0 part /
   mmcblk0     179:0    0  3.7G  0 disk 
   |-mmcblk0p1 179:1    0  100M  0 part 
   `-mmcblk0p2 179:2    0  3.6G  0 part

Banggood: ATmega328P Arduino Nano V3

ATmega328P Arduino Compatible Nano V3

This worked at the moment of writing, I can’t guarantee it will work for future versions of the boards nor OS X

For those just wanting the tutorial, go here

I while ago I discovered the chinese website Banggood, which has almost everything you want at low prices. Which is very good for my new arduino hobby.

So next to some other components I ordered the ATmega328P Arduino Compatible Nano V3 5-pack which means I got 5 Arduino nano clones for 15 euro + free shipping, which is just a steal. I have to be honest I was a bit scared to order them, because of all the mixed reviews on the net. On the other hand the max I would loose is 15 euro.

I knew however before ordering that the USB chipset was probably going to require some extra attention.

So once I received the order yesterday, I immediately tried the solutions offered in the comments on Banggood, but I did not manage to get it working. So I turned to google for the rescue. There were several other solutions, but none worked as it should. However the one that got it all working for me was the tutorial of kiguino.

I’m saying nothing new here, but just because it took me some time on google, I’m reblogging it here, for future reference and maybe help somebody else.

Tutorial for install on Mac OS X Yosmite (latest test 10.10.3)

  1. Download the driver at the developers website (!! Only the driver from december 2013, works with 10.10)
  2. Unzip and install by right clicking and selecting open.
  3. Do NOT restart yet
  4. Open terminal and paste sudo nvram boot-args="kext-dev-mode=1"
  5. Reboot
  6. The driver should be installed, on my arduino’s it installed as /dev/cu.usbserialmodem1410 or /dev/cu.usbserialmodem1420 depending on the port it was connected to and the device I was using.

Terminal: Git commands cheat sheet

To start a repository from the command line:

git init
git add .
git commit -m "initial import"

When files are added to .gitignore and are not removed, use following commands and commit.

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

Openhab install on Raspberry Pi

Openhab logo

This post is my guide for installing and configuring Openhab on the Raspberry Pi.

Install openhab

  1. Upgrade and update apt-get sudo apt-get update && sudo apt-get upgrade

  2. do a update of the firmware. These are 2 steps you should always do before installing something new. sudo rpi-update

  3. make directory and download and unzip openhab (get link from Openhab/downloads). Replace x.x.x in the command below with the version number you copied. sudo mkdir /opt/openhab && cd /opt/openhab/ && sudo wget "get download link" && sudo unzip && sudo rm

  4. Download and install bindings for openhab. This installs all possible addons available. Replace x.x.x in the command below with the version number you copied. cd addons && sudo wget "downloadlink addons" && sudo unzip && sudo rm

  5. copy the config file and make the startup script executable cd .. && sudo cp configurations/openhab_default.cfg configurations/openhab.cfg && sudo chmod +x

  6. Edit the config file and start the server. sudo nano openhab.cfg sudo ./opt/openhab/

  7. Make a startup item with screen, so that you can always access the OSGI console.

sudo nano /etc/init.d/openhab

  1. Paste following code in there on line 14 change the user to your openhab user:

`#! /bin/sh ### BEGIN INIT INFO # Provides: openHAB # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Should-Start: $network # Should-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start and stop openHAB in screen Session # Description: This runs openHAB continuously in screen. ### END INIT INFO # Set OH-User OHUSER=openhab # Set OH-Path OHPATH=/opt/openhab

case "$1" in

        PID=`ps -ef | grep openHAB | grep -v grep | awk '{print $2}'`
        if [ "${PID}" != "" ]
          echo openHAB-Screen is already open, use: sudo -u openhab screen -r `pidof SCREEN`
          echo "Starting openHAB"
          cd ${OHPATH}
          sudo -u ${OHUSER} screen -S openHAB -dm  sh ./
        echo "Stopping openHAB"
        sudo -u ${OHUSER} screen -S openHAB -p 0 -X stuff "exit$(printf \\r)"
        sudo -u ${OHUSER} screen -S openHAB -p 0 -X stuff "y$(printf \\r)"
        sudo -u ${OHUSER} screen -S openHAB -p 0 -X stuff "exit$(printf \\r)"
        PID=`ps -ef | grep openHAB | grep -v grep | awk '{print $2}'`
        while [ `ps -ef | grep $PID | wc -l` -gt 1 ]
          echo -n .
          sleep 2
        echo .
        echo "Restarting openHAB"
        $0 stop
        $0 start
        echo "Usage: $N {start|stop|restart}" >&2
        exit 1
exit 0`
  1. Make the script executable and configure to run on boot

    sudo chmod a+x /etc/init.d/openhab sudo update-rc.d openhab defaults

    Whenever you want to use the OSGI console, just type

    screen -x and to leave the screen you do ctrl+a d

  2. Normally your server should run now and you should be able to access the demo content through:

    http://<openHAB server ip>:8080/

Raspberry Pi scrapbook

I’m trying to setup a sort of internet of things sensor network at home.

For this project I’m using raspberry pi and Arduino boards.

As I already had to start over, I’m going to use this post as a scrapbook:

Pi setup:

  1. install Noobs on Raspberry Pi
  2. Select Raspbian as OS
  3. apt-get:
    • tightvncserver
    • upstart
  4. reboot
  5. this probably gives a weird Login screen, ssh to Pi and chown pi:pi .Xauthority in home dir.
  6. reboot again
  7. apt-get:
    • arduino
    • python-pip
  8. install adafruit webide
  9. install pyserial:
    • by downloading latest version (atm 2.7) in tar.gz ->
    • untar -> install with sudo python install
  10. Make startup script for scripts:

Startup scripts:

  • cd /etc/init
  • nano scriptname.conf
  • copy/paste this code and fill in

    # Program_explanation
    description "Your_description"
    author "User"
    start on runlevel [2345]
    stop on runlevel [016]
    chdir path_to_dir_with_script
    exec python
  • start script with sudo service scriptname start, it starts every reboot and when it quits it respawns.