Category Archives: Tutorials

Cubieboard TimeCapsule

This tutorial will show you how to use a Cubieboard + one 2.5″ hard drive to backup your Mac (or your Hackintosh), just like you would use an Apple TimeCapsule. I will assume that you already have a Cubieboard or Cubieboard 2 with Cubian installed, some kind of terminal access (for instance via SSH), and a SATA hard drive connected to the SATA port. An USB connected hard drive should work fine too.

You can learn how to install Cubian on your SD-card here: https://github.com/cubieplayer/cubian/wiki/Install-Cubian. Instead of using Image Writer, I recommend using Win32 Disk Imager.

To make your Cubieboard work like a TimeCapsule, you need to:

  • configure and connect your hard drive, install support for the HFS+ filesystem
  • install and configure the Avahi and Netatalk daemons

Connecting your hard drive

The hard drive needs to be formatted as Mac OS Extended (Journaled). To do that, connect it to your Mac (probably via USB), open Disk Utility, select your drive in the left side box, and click Partition on top. In the Partition Layout box select 1 Partition, in the Name field type a name (like Data, TimeMachine, or Backup), in the Format box select Mac OS Extended (Journaled), and click Apply. Please note that this erases everything on the selected disc, so make sure the right drive is selected. Once the operation is complete, you can unplug the drive from your Mac and get back to the Cubieboard.
HDD Setup for Cubieboard TimeCapsule

With that out of the way, connect the hard drive to your Cubieboard, start it up and connect via SSH.

Let’s install the support for the HFS+ filesystem by issuing the following command:

sudo apt-get install hfsplus

Once the process is complete, let’s try to identify and mount the disc:

sudo blkid

The above command should output something like this:

cubie@Cubian:/$ sudo blkid
/dev/nanda: SEC_TYPE="msdos" LABEL="Volumn" TYPE="vfat"
/dev/nandd: UUID="57f8f4bc-abf4-655f-bf67-946fc0f9f25b" TYPE="ext4"
/dev/nande: UUID="57f8f4bc-abf4-655f-bf67-946fc0f9f25b" TYPE="ext4"
/dev/nandh: UUID="57f8f4bc-abf4-655f-bf67-946fc0f9f25b" TYPE="ext4"
/dev/nandi: UUID="57f8f4bc-abf4-655f-bf67-946fc0f9f25b" TYPE="ext4"
/dev/nandj: LABEL="NUCLEAR" UUID="38DC-07B2" TYPE="vfat"
/dev/sda1: LABEL="EFI" UUID="67E3-17ED" TYPE="vfat"
/dev/sda2: UUID="07291167-3ca6-3be7-8ddb-6e83fcc58186" LABEL="Data" TYPE="hfsplus"
/dev/mmcblk0p1: LABEL="cubieboard" UUID="68ed2b81-d507-4d85-a8ed-261bff7666bf" TYPE="ext4"

Look for the label you used when you formatted the drive (Data, TimeMachine etc.) and the TYPE=”hfsplus”. On my board it gives this line:

/dev/sda2: UUID="07291167-3ca6-3be7-8ddb-6e83fcc58186" LABEL="Data" TYPE="hfsplus"

Note down the UUID too, because we will need it later (you can actually issue the command again when you need it), and use the following commands to mount /dev/sda2:

sudo mkdir /mnt/TimeMachine
sudo mount -o force /dev/sda2 /mnt/TimeMachine

The partition should now be mounted under /mnt/TimeMachine, so you can change to that directory, and create some files to make sure it’s working correctly. You may need to change permissions/ownership on /mnt/TimeMachine or use sudo. To change ownership do:

sudo chown cubie:cubie /mnt/TimeMachine

If everything checks, let’s make sure the drive is mounted automatically on reboot. Edit /etc/fstab and add the following line at the end:

UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" /mnt/TimeMachine hfsplus rw,force,exec,auto,users 0 3

Don’t forget to replace xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx with your actual UUID, as shown by blkid. Your /etc/fstab file should look something like this:

#<file system>  <mount point>   <type>  <options>       <dump>  <pass>
/dev/mmcblk0p1  /               ext4    defaults        0       1
tmpfs   /tmp    tmpfs   defaults        0       0
tmpfs   /var/tmp        tmpfs   defaults        0       0
UUID="07291167-3ca6-3be7-8ddb-6e83fcc58186" /mnt/TimeMachine hfsplus rw,force,exec,auto,users 0 3

You should now reboot and see if the disc is correctly mounted. After the reboot, issue the command mount and you should get something like this:

/dev/root on / type ext4 (rw,relatime,data=ordered)
devtmpfs on /dev type devtmpfs (rw,relatime,size=414336k,nr_inodes=103584,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=82892k,mode=755)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=165780k)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /tmp type tmpfs (rw,relatime)
tmpfs on /var/tmp type tmpfs (rw,relatime)
/dev/sda2 on /mnt/TimeMachine type hfsplus (rw,nosuid,nodev,noexec,relatime,umask=22,uid=0,gid=0,nls=utf8)

We are interested in the last line. It shows that the partition is mounted under the correct directory, as read-write, which is important.

Install Netatalk and Avahi on the Cubieboard

We now have to install the services and libraries that the Cubieboard needs to communicate with the Mac:

sudo apt-get install avahi-daemon libavahi-client-dev libdb-dev db-util db-util libgcrypt11 libgcrypt11-dev make

This may take a while, since it installs some dependencies too. Grab a tea.

We need to install Netatalk from source. No need to be scared, I’ll hold your hand. First, download Netatalk. At the moment of writing this, the latest stable version is 3.1.0:

wget http://prdownloads.sourceforge.net/netatalk/netatalk-3.1.0.tar.gz?download -O netatalk.tar.gz

Make sure you’re in your home folder before downloading.

tar xzf netatalk.tar.gz
cd netatalk*
./configure --with-init-style=debian --with-zeroconf
make
sudo make install

Building Netatalk will take a while too. Why not grab another cup of tea?
Cubieboard HDD TimeCapsule
With everything installed, all we need to do now is configure Netatalk:

sudo nano /usr/local/etc/afp.conf

Delete everything and replace with:

;
; Netatalk 3.x configuration file
;

[Global]
; Global server settings
hostname = TimeCapsule Cubie
afp listen = 192.168.0.18   <-- replace with your Cubieboard static IP
log file = /var/log/netatalk.log
log level = default:info

[Homes]
basedir regex = /home
cnid scheme = dbd
; Display each user home directory in this format
home name = Home: $u

[Time Machine]
; Our Time Machine volume
path = /mnt/TimeMachine
cnid scheme = dbd
file perm = 0660
directory perm = 0770
time machine = yes

And Avahi:

sudo nano /etc/avahi/services/timecapsule_afpd.service

Write this in the above file:

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
      <name replace-wildcards="yes">TimeCapsule Cubie</name>
      <service>
          <type>_afpovertcp._tcp</type>
          <port>548</port>
      </service>
      <service>
          <type>_device-info._tcp</type>
          <port>0</port>
          <txt-record>model=TimeCapsule</txt-record>
      </service>
</service-group>

Now start the services:

sudo /etc/init.d/netatalk start
sudo /etc/init.d/avahi-daemon start

Ensure the services are started at every boot:

cd /etc/init.d/
sudo update-rc.d netatalk defaults

That’s it! Now grab your Mac. You should already see the new TimeCapsule Cubie share.
TimeCapsule Cubieboard Setup
Select the share, click Connect As… in the top right corner and enter your Cubieboard credentials (default for Cubian is username: cubie, password: cubie).
TimeCapsule
It takes a little while to authenticate…
Cubieboard Tutorial
…and you should see something like this…
timecapsule-setup-4
Now open Settings…
Cubieboard Project TimeCapsule
…click Time Machine…
TimeCapsule with Cubieboard
…then click Select Backup Disk and you should see your new Time Machine:
Cheap TimeCapsule Cubieboard
Select it and then click Use Disk.
Cubieboard TimeCapsule similar to Raspberry Pi
Confirm your credentials or enter them if they weren’t saved…
timecapsule-setup-9
…and you’re done! Backup should begin shortly. If you want to back up your files while on battery, make sure to click Options and set that up.
timecapsule-setup-a

Cubieboard Voice Recognition

Motivated by this post, I played with a similar setup with our beloved Cubieboard. Although I only tested the speech recognition, the results are pretty encouraging so far.

Cubieboard Speech Recognition

Since I don’t have an USB microphone (yet), I used a very cheap webcam (about $10 or so). Details about the webcam I used are available here. No drivers are required. I have to note that the Cubieboard does have a line-in input that can probably be used with additional electronics.

To reproduce my experiment, the first step is to get Cubian text mode SD-card image, available here: http://cubian.org/downloads/. I used the latest version, which at the time of writing this is Cubian-base-r7-arm-a10.img.7z.

Directions on how to install Cubian on your SD-card are available here: https://github.com/cubieplayer/cubian/wiki/Install-Cubian. Instead of using Image Writer, I used and I highly recommend Win32 Disk Imager.

Once you have Cubian up and running, login via SSH. The default username is cubie with the password cubie. To avoid frustration, also note that the SSH port is not the default 22, but 36000.

Cubieboard arecord -L

If your webcam is connected and recognized by the Cubieboard, by issuing the following command:

arecord -L [enter]

you should get the following output:

null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=sunxicodec
    sunxi-CODEC, sunxi PCM
    Default Audio Device
sysdefault:CARD=sunxicodec
    sunxi-CODEC, sunxi PCM
    Default Audio Device
default:CARD=Camera
    USB 2.0 Camera, USB Audio
    Default Audio Device
sysdefault:CARD=Camera
    USB 2.0 Camera, USB Audio
    Default Audio Device
front:CARD=Camera,DEV=0
    USB 2.0 Camera, USB Audio
    Front speakers
surround40:CARD=Camera,DEV=0
    USB 2.0 Camera, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Camera,DEV=0
    USB 2.0 Camera, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Camera,DEV=0
    USB 2.0 Camera, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Camera,DEV=0
    USB 2.0 Camera, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Camera,DEV=0
    USB 2.0 Camera, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Camera,DEV=0
    USB 2.0 Camera, USB Audio
    IEC958 (S/PDIF) Digital Audio Output

Just like in the Raspberry Pi tutorial, I used the Google voice recognition functions. First, install ffmpeg using:

sudo apt-get install ffmpeg [enter]

The same script works:

#!/bin/bash

echo "Recording... Press Ctrl+C to Stop."
arecord -D "plughw:1,0" -q -f cd -t wav | ffmpeg -loglevel panic -y -i - -ar 16000 -acodec flac file.flac  > /dev/null 2>&1
echo "Processing..."
wget -q -U "Mozilla/5.0" --post-file file.flac --header "Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium" | cut -d\" -$
echo -n "You Said: "
cat stt.txt
rm file.flac  > /dev/null 2>&1

script source via the above mentioned post

Save the above script to something like stt.sh and make it executable with:

chmod +x stt.sh [enter]

Start the script with:

./stt.sh [enter]

and say something in the microphone. If everything works as it should, you should see something like this:

Cubieboard Voice Recognition

To use a different language, replace the lang parameter, like this:
http://www.google.com/speech-api/v1/recognize?lang=ro-ro&client=chromium

It actually works amazingly well.

This can probably be used with small changes for home automation. Next, add some brains and voice, to get something similar to Siri. Stay tuned.