Author Archive

The raspberry pi (rpi) is perfect to drive home built hardware. The lego mindstorms ev3 set with its LabVIEW based software is perfect to create simple controlling programs. And this software allows to send and receive messages by bluetooth. This lead to the idea to attach a bluetooth dongle to the raspberry pi and to add some software to receive and send ev3 bluetooth messages.

Reference 1 is the LEGO® MINDSTORMS® EV3 Communication Developer Kit mentioned in this blog post (download second (smaller) file). Reference 2 is a C# project for bluetooth communication from windows pc to ev3 brick. Reference 3 is a python script to receive ev3 bluetooth messages on the raspberry pi. Reference 4 is a blog post giving a summary of the format of the ev3 bluetooth messages (which is also found in pdf of reference 1 on page 21; comment in capitals is result from sniffing; official documentation is not correct here):
bb bb mm mm tt ss ll aa aa … LL LL pp pp … with

bb bb = bytes in the message (excluding the two size bytes), little endian (2 bytes long)
mm mm = message counter
tt = 0×81 (type of message: reply not required)
ss = 0x9E (system command: write to mailbox)
ll = mailbox name length INCLUDING the \0 terminator
aa aa … = mailbox name, should be terminated with a \0
LL LL = payload length INCLUDING the , little endian
pp pp … = payload: either logical: 1 byte; or number: 4 byte, single precision float; or text: should be terminated with the \0

This tutorial shows how to manually pair bluetooth devices using the linux command line (some additional details can be found here). On the ev3 brick side the labVIEW based software has ‘bricks’ to switch bluetooth on or off and to create or delete a bluetooth connection to a named device; create and delete should not be used! See below. (If your pi has hostname mypi then it’s default bluetooth name is mypi-0). To pair use first the menu on the ev3 brick: Turn bluetooth on; (no need to turn the iPhone/iPad variant of bluetooth on); set bluetooth to visible. Then run on the raspberry pi:

bluetooth-agent 1234 &; hcitool scan; rfcomm connect hci0 aa:bb:cc:dd:ee:ff (using address displayed by hcitool scan).

The rfcomm connect command should trigger a pairing key popup on the ev3 brick display, where the number given to bluetooth-agent has to be entered. (Key 1234 should be used because time to enter the key is limited and 1234 is the default key in the ev3 brick menu.) After successful pairing visibility can be switched off again.

On the rpi /var/lib/bluetooth/…./ contains the settings for the bluetooth dongle. File config defines the bluetooth device name.

For a simple test run the program shown below on the ev3 brick and use receive.py on rpi.
(hostname of my rpi is rpico; so bluetooth-name is rpico-0; Hello … is the message and EV3Test is the ‘mailbox name’). First activate bluetooth on ev3. Then (re)start bluetooth on rpi (/etc/init.d/bluetooth restart). Now run:

receive.py  -a aa:bb:cc:dd:ee:ff test1.bin (receive.py can be edited to set the bluetooth address of the ev3 brick as default)

 Then start the program on the ev3 brick.

This writes the message to test1.bin; (use mc to view the file):

To send the message test1.bin back to the ev3 brick: first run the program shown below; on rpi then run send.py:

send.py  -a aa:bb:cc:dd:ee:ff test1.bin (send.py can be edited to set the bluetooth address of the ev3 brick as default)

This displays Hello world! on the screen of the ev3 brick.

Important: Bluetooth only works if connections are always initiated from rpi and never from ev3 (brick or software: do not use the bluetooth ‘software brick’ of the ev3 software to connect or disconnect!) This is the result of current testing (firmware 1.03H or unofficial firmware 1.04H with support for edimax ew-7811un wifi dongle). – Initiating the connection from ev3 brick seems to change something in the bluetooth configuration of the ev3 brick which causes errors. A  possibility to get rid of these errors is to delete the directories /var/lib/bluetooth/AA:BB:CC:DD:EE:FF on both devices. (Either needs shell access to ev3 brick; possible with wifi adapter and telnet: user root with empty password. Or use the ev3 software on your  computer, open the memory browser of ev3 brick and download reset_bluetooth.rbf (source: reset_bluetooth.lms)  to ev3 brick and use the ev3 brick menu to run reset_bluetooth.rbf) Then reboot the ev3 brick, restart bluetooth on rpi and do again the pairing process described above. Afterwards reboot the ev3 brick again.

Instead of sending messages to the ev3 brick it is possible to use send.py to send commands (as described in reference 1 mentioned above).

send.py led9.bin; sleep 20; send.py led0.bin (the ledN.bin files, N=0,1,2…9, can be found here)

As documented here the LED on the ev3 brick is controlled by a byte pattern. For instance the file led9.bin containing the hex values
08 00 00 00 80 00 00 82 1B 09
makes the LED pulse orange and led0.bin (with 0 instead of 9 as last byte) switches the LED off; (byte code reference 1: search for LED 2 : search for opUI_WRITE, 3: page 96 of firmware development pdf).

It is even possible to transfer command sequences of byte codes with send.py. First the program has to be written in “ev3 byte code assembler language” (helloworld.lms). This has to be compiled (helloworld.rbf). Second the trailing 0x0A byte has to be removed and the header (28 bytes) has to be replaced (nn NN 00 00 80 00 00; nn = lower byte and NN = higher byte of  L-2; L = size of file): helloworld.bin. A good reference for the first step is here. All files required to create the example program hello world are here (sources 1, 2, byte codes.h). The second program in this archive which allows to run a linux program from sd card has its origin here. Examples for the second step are on pages 26-31 of the LEGO® MINDSTORMS® EV3 Communication Developer Kit (mentioned in this blog post;download second (smaller) file)

Raspbian (current version, 2014-03) on raspberry pi comes preinstalled with oracle jdk. Using a lightweight replacement for Eclipse
java programs for lego mindstorm ev3 with lejos firmware can  be developed on the raspberry pi.

This tutorial was used to get started. More about IDE Geany can be found on www.geany.org.

apt-get install geany

apt-get install ant

apt-get install libjsch-java

cd /usr/share/ant

ln -s /usr/share/java/jsch-0.1.42.jar jsch.jar

 

assuming ev3 classes are installed with eclipse as described in lejos.org wiki:

On raspberry pi create a subdirectory ev3 in your geany projects folder (e.g. /home/pi/Projekte/ev3 in german localized version of geany)

cd into this directory and use scp to copy DBusJava and ev3classes from eclipse ev3 folder on your computer with eclipse:

scp -r your_ip_address:/your_eclipse_ev3/folder/DBusJava .
scp -r your_ip_address:/your_eclipse_ev3/folder/ev3classes .

Open geany and create a new project ev3. Open the file ev3/DBusJava/build.xml. Then open the Terminal tab at the bottom of the geany window.
Use cd to change into your projects folder; then cd into ev3/DBusJava
Run ant jar
If the command did complete successfully use cd to change into ev3classes directory and open the file ev3/ev3classes/build.xml from geany menu.
Run ant jar
Use scp to copy some example project from eclipse to geany. Create a new geany project with the same name.
Use command ant jar in geany Terminal to compile the project. Finally use ant copy to transfer the jar archive to raspberry pi.

Result on iPad with bluetooth keyboard (using the steps described here):

Mathematica comes preinstalled on raspbian and is free for personal use. Adding a vnc or rdp server to a raspberry pi running raspbian allows to display and control Mathematica with an iPad. If the raspberry pi is configured as wlan access point you get a free and rather mobile installation of Mathematica.

Required hardware: raspberry pi model B, 16 GB sd(hc) card (at least 4 GB), ew-7811un wireless usb adapter; device running a vnc or rdp  viewer (e.g. iPad with RD Client app).

  1. Installation of raspbian to sd card:
    download raspbian image http://downloads.raspberrypi.org/raspbian_latest
    unzip the file
    copy it to the sd card (linux: dd if=your_file of=/dev/sdX bs=1M; sdX is the device name of the sd card)
  2. Configuration of raspbian on raspberry pi:
    for the first run plug monitor, keyboard, lan and usb current source into raspberry pi;
    raspi-config gets started automatically on first boot
    resize raspbian partition to full size of sd card (using the menu of raspi-config)
    set hostname, keyboard, language, timezone, password; enable ssh server; boot into console
    login as user pi and become root with sudo su. Run apt-get update and then apt-get upgrade
  3. Add software to raspbian (as root user)
    apt-get install mc (I cannot live without)
    apt-get install xrdp
    apt-get install tightvnc-server
    apt-get install hostapd dnsmasq
  4.  The xrdp server works with the default configuration. Alternatively use tightvnc-server as described here:
    with  VNC_USER=”pi”, HOME=”/home/pi”,FOO_ID=1
    and set as user pi a password for vnc with vncpasswd;
    after reboot the vnc server will listen on port 5901
  5. Configure the wlan router function as described here, but make the following changes:
    the program /usr/bin/hostapd installed by raspian has to be replaced by  a self compiled version (mine is here – having used these instructions); (or you might use this file mentioned in this note)
    add dns server 8.8.8.8 to /etc/dnsmasq.conf: dhcp-option=6,8.8.8.8
    (ios clients seem to be picky about non standard network masks. So configure wlan0 with 255.0.0.0 and adapt dnsmasq.conf.
    dhcp-range=interface:wlan0,10.0.0.2,10.0.0.20,10.254.254.20,255.0.0.0,infinite)
    add modules to /etc/modules (one per line):
    nf-conntrack-ipv4 iptable-nat ipt-MASQUERADE (optional iptable-filter )
    do not create the file /etc/network/ifup.d/router.sh, but add the 2 lines of this file to /etc/rc.local
    ifup wlan0
    iptables –table nat -A POSTROUTING –out-interface eth0 -j MASQUERADE
    #optional: iptables -A FORWARD –in-interface wlan0 -j ACCEPT
    #optional: iptables -I INPUT -i wlan0 -p udp –dport 67:68 –sport 67:68 -j ACCEPT
    (and make sure that the newly added lines are above the line “exit 0”)
    Remark: long iptables options have — which tends to get displayed as unicode long hyphen; (has to be replaced manually when using copy and paste):
    To test hostapd and/or dnsmasq run it on the console: hostapd /etc/hostapd/hostapd.conf
    and/or dnsmasq -u dnsmasq –conf-file=/etc/dnsmasq.conf -d
  6. Plug the mini wlan adapter ew-7811un into the raspberry pi and reboot
    try to join wlan Himmbeerhacks and try to connect with rdp to 10.0.0.1 or open 10.0.0.1:5901 with a vnc viewer (like  RD Client or Remoter VNC on iPad).

Further trial and error shows that with a bluetooth keyboard rdp works better than vnc. Especially square brackets (alt+5, alt+6) do not work well with vnc – at least in my setup with locale swiss german. That is why I started to use xrdp and the free microsoft remote desktop client for iOS.

Installation notes:

DebianEdu wheezy uses 10.0.0.0/8 with gateway 10.0.0.1
(e.g. spblinux with ifconfig eth1 10.0.0.1; cfg_nat start;
in vbox eth0 bridged, eth1 internal connected to tjener)

Installation of ltsp-server:

  • only non automatic partitioning (using guided partitioning) works (21.8.13)

phpldapadmin (https://10.0.2.2/phpldapadmin/)

  • apt-get install phpldapadmin
  • changes in /etc/phpldapadmin/config.php
    Uses tls which starts with default port 389 (not ssl, 636, ldaps):
    – $servers->setValue(‘server’,’host’,’ldap‘)
    //$servers->SetValue(‘server’,’port’,’636′)
    Login with ou=ldap-access (with password of unix system user root)
    – $servers->setValue(‘login’,’bind_id’,’cn=admin,ou=ldap-access,dc=skole,dc=skolelinux,dc=no’)

Add ltspserver in gosa (https://10.0.2.2/gosa/
(login as user which has been created during installation of tjener)

  • Systems: Action Add
    Generic:
    – Server name: ltspserver00
    – Mode activated
    – Base /
    – IP-address 10.0.2.10
    – MAC_address: 12:34:ab…
    (might be looked up by first booting ltspserver:
    and dhcp gives name auto-mac-12-34-ab…)
    – Enable DHCP true and parent node (tjener) dhcp
    – Enable DNS true and Zone TJENER/intern
    Apply.
    Services:
    – add Terminal service
    Apply and start the service.
    NIS Netgroup:
    Add group ltsp-server-hosts
    – seems to get set in ldap directory, but does not display in gosa
    (netgroup/ltsp-server-hosts/nisNetgroupTriple)
    netgroup gets used as nfs4 authentication.

Nagios (https://10.0.2.2/nagios3/):

  • Add ltspserver00 to nagios by running sitesummery-update-nagios
  • Set password for user nagiosadmin with
    htpasswd /etc/nagios3/htpasswd.users nagiosadmin
    (and apache2ctl graceful)

Thin clients:

  • when used with vbox: needs vbox extension pack

 

JavaFX: java-jdk + SceneBuilder + eclipse + e(fx)clipse

  • download current java 7 jdk from oracle
    (java.com / Developers / JDK download / 64 bit)
  • unpack into /usr/lib/jvm and
    ln -s jdk1.7.0_xx java-7-oracle-amd64
  • update-alternatives –install /usr/bin/java java /usr/lib/jvm/java-7-oracle-amd64/bin/java 1
  • update-alternatives –install /usr/bin/javac javac /usr/lib/jvm/java-7-oracle-amd64/bin/javac 1
  •  update-alternatives –config java (select java-7-oracle-amd64)
  • update-alternatives –config javac (select java-7-oracle-amd64)
  • download Scenebuilder (64 bit) from java.com
    (currently http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html)
    and unpack it into /opt
  • download eclipse (64bit, standard edition, tar archive) from eclipse.org
    und unpack it into /usr/lib
  • run (alt+F2) kdesu /usr/lib/eclipse/eclipse
    – Help / Install new software / Add
    Name: e(fx)clipse
    Location: http://download.eclipse.org/efxclipse/updates-nightly/site
    – select e(fx)clipse Kepler

A generic rescue system should boot in bios mode and in (u)efi mode. It should boot from usb and it should use the same boot menu config file for bios and for efi boot mode. Grub2 has a nice boot menu and supports bios and efi boot mode.

Because the installation scripts of grub2 might have side effects and might affect installed systems, only grub images (=files) are created.
(Installation for efi boot, if secure boot is disabled: copy grub core image to EFI/BOOT; bios boot: chainload from syslinux + ldbsd.com.)

Steps to create such an usb stick using linux (e.g. ubuntu or opensuse): bios boot and efi boot with disabled secure boot
(it is possible to use clonezilla stable (=debian version): choose run shell; sudo su; ifconfig eth0 YOURIP netmask YOURMASK; route add default gw YOURGATEWAYIP; use mc to edit /etc/resolv.conf: nameserver 8.8.8.8; apt-get update; apt-get install grub-efi; use wget to fetch other files)

  • backup existing data because the usb stick will be repartitioned (erasing existing data)
  • run linux and use gdisk to create a gpt partition table with one fat32 partition
    (which will be marked bootable for bios boot). Run gdisk as root user:
    gdisk /dev/sdX (X=your usb stick; ensure that you use the intended usb stick – and not an existing hard disk)
    – p (prints existing partition table)
    – o (creates a new empty partition table)
    – n (create partition: use default start and end sectors, set type to 0700)
    – x (switch to expert menu)
    – a (add flags:  use 2 = “legacy BIOS bootable”)
    – w (writes the new partition table to the usb stick)
  •  format the new partition with fat32 (and set partition label name to SPB2; this label will be used by grub2 to identify the partition)
    mkfs.msdos -n SPB2 /dev/sdX1 (X=your usb stick)
  • mount the new partition and create some directories:
    – mkdir mnt
    – mount /dev/sdX1 mnt (X=your usb stick)
    – mkdir -p mnt/EFI/BOOT
    – mkdir -p mnt/grub/fonts
    – mkdir syslinux
    – mkdir mnt/grub/i386-pc (optionally for additional grub2 modules, bios mode)
    – mkdir mnt/grub/x86_64-efi (optionally for additional grub2 modules, efi mode)
  • install syslinux (has to be version <5.0, binaries here: syslinux.zip) to the new partition /dev/sdX1 and copy the sylinux boot loader gptmbr.bin to /dev/sdX
    – umount /dev/sdX1 (X=your usb stick)
    – syslinux -d syslinux /dev/sdX1 (X=your usb stick)
    –  dd if=/usr/lib/syslinux/gptmbr.bin of=/dev/sdX
    or
    dd if=/usr/share/syslinux/gptmbr.bin of=/dev/sdX
    – mount /dev/sdX1 mnt
  • contents of configuration file for grub core image in bios boot mode embed.cfg:
    search.fs_label SPB2 root
    set prefix=($root)/grub
    configfile $prefix/grub.cfg
  • the  configuration file for grub core image in efi boot mode embed_efi.cfg currently has the same contents as embed.cfg.
  • both configuration files, embed.cfg and embed_efi.cfg are stored in mnt/grub/
  • install grub2 (needs installed grub2 packets for i386-pc and for x86_64-efi;
    e.g. apt-get install grub-pc and apt-get install grub-efi-amd64; older debian based linux calls grub2 grub and grub-1.x grub-legacy).
    This step creates only grub image files (given by “-o”).
    – cp /usr/share/grub/unicode2.pf2 mnt/grub/fonts/
    or
    cp /usr/share/grub2/unicode.pf2 mnt/grub/fonts
    –  grub-mkimage -O i386-pc -p /grub -c mnt/grub/embed.cfg -o mnt/grub/core.img configfile fat part_gpt part_msdos biosdisk cat echo test search search_label search_fs_uuid boot chain linux reboot halt normal vbe font gfxterm
    or
    grub2-mkimage ….
    –  grub-mkimage -O x86_64-efi -p /grub -c mnt/grub/embed_efi.cfg -o mnt/EFI/BOOT/bootx64.efi configfile fat part_gpt part_msdos cat echo test search search_label search_fs_uuid boot chain linux reboot halt normal efi_gop efi_uga font gfxterm
    or
    grub2-mkimage ….
  • in bios boot mode syslinux is used to chainload core.img of grub2 (with an intermediate ldbsd.com from grml project which does only work with syslinux versions <5.0)
    – contents of syslinux.cfg (to be copied to mnt/syslinux/syslinux.cfg):
    default grub2
    timeout 1
    totaltimeout 3
    label grub2
    say using bsd4grml/ldbsd.com as loader
    kernel ldbsd.com
    append echo Loading GRUB2…`machine exec grub /grub/core.img
    – unpack ldbsd.com.zip and copy ldbsd.com to mnt/syslinux/ldbsd.com
  • finally we need grub.cfg (to be stored in mnt/grub/):
    set menu_color_normal=white/black
    set menu_color_highlight=black/light-gray
    set default=0
    loadfont ($root)/grub/fonts/unicode.pf2
    if [ x$grub_platform = xefi ]; then
    set gfxmode=auto
    set gfxpayload=keep
    set boottype=efi
    else
    set gfxmode=800x600x16
    set gfxpayload=keep
    set boottype=bios
    fi
    terminal_output gfxterm
    menuentry “linux on sdb1 ($boottype; partition SPB2 on($root); $gfxmode)” {
    linux ($root)/vmlinuz root=/dev/sb1 …
    initrd ($root)/initrd
    }
  • the example assumes that linux kernel and ramdisk are copied to mnt/
    (that is, to the root directory of the usb stick)
  • both boot modes can be tested with virtualbox (>=4.2.12); system settings allow to switch to efi boot mode.
    Give access to usb device with
    VBoxManage internalcommands createrawvmdk -rawdisk /dev/sdX -filename raw_usb_sdX.vmdk

If the same virtual machines should be used on a multi boot system there are at least 3 choices:

  • A fat32 partition with virtual disk files. But disk size is limited to 4GB.
  • An iSCSI disk connected by network. Speed is limited by network throughput.
  • Direct access to hard disk partitions used as virtual disks. With windows a separate hard disk has to be used.

The third choice is described below. Thus a second hard disk only used with virtual machines is required. To allow hard disks with more than 2 TB capacity the disk is partitioned as gpt disk.

Warning: the commands described below can erase the whole data of your hard disks if a mistake is made. Do not continue unless you have a full backup of your system.

========================================

(Yes I am prepared to restore my system in case of a mistake …):

Attach an additional hard disk to your computer which is only used for virtual box images (tested with internal disk; should work with usb disk).
(At least the currently running (host) operating system must not be installed on the same disk).
Add a new partition to the additional hard disk. (If the new virtual disk has 25 GB then the size of the new partion is 25 GB.) In case of a gpt partioned disk up to 128 partitions can be created.

  • with a linux host using gdisk the type of the new partition can be set to 0x8301 (linux reserved)
    (internally translated by gdisk to 8DA63339-0007-60C0-C436-083AC8230908)

In case of windows 7 as virtual machine the hardware uuid of the vm must be the same
in the three hosts (linux, osx, windows). (Else the activation of windows 7 cannot be kept.)

  •  to display the hardware uuid of the activated vm (with name W7) use:
    VBOxManage showvminfo W7 |grep Hardware
  • to set the hardware uuid of a vm (with name W7_1) use the uuid displayed by showvminfo:
    VBoxManage modifyvm W7_1 –hardwareuuid 12345678-1234-abcd-0123-0123456789ab

 

Using this partition as virtual hard disk with a linux host:

  • determine the device name of the new partition, e.g. /dev/sdb7
    (cat /proc/partitions, gdisk -l /dev/sdb …)
  • either ad the current user to group disk to allow raw access to all disks
    (has only to be done once; is effective after re-login; but is potentially dangerous).
    Or change the group of /dev/sdb7 to vboxusers
    (to be repeated after reboot)
  • run as root user:
    VBoxManage internalcommands createrawvmdk -rawdisk /dev/sdb7 -filename my_filename.vmdk
    and change the ownership of this file to the current user
  • run VirtualBox and add my_filename.vmdk as hard disk to the virtual machine

 

Using this partition as virtual hard disk with a OS X host:

  • determine the device name of the new partition, e.g. /dev/disk1s7
    (ls -l /dev/disk* …)
  • ad the current user to group operator to allow raw access to all disks
    (is effective after re-login; is potentially dangerous):
    dseditgroup -o edit -a name_of_current_user -t user operator
  • Change permission of group from read access to write access
    sudo chmod g+w /dev/disk1s7
    (to be repeated after reboot)
  • run as root user:
    VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk1s7 -filename my_filename.vmdk
    and change the ownership of this file to the current user
  • run VirtualBox and add my_filename.vmdk as hard disk to the virtual machine
  • if OS X auto mounts partitions which should be used by virtualbox: try to deactivate them with disk utility; in case that does not work you can run disk arbitrator which blocks auto mount

Using this partition as virtual hard disk with a Windows 8 64 bit host:

  • requires to run VirtualBox with administrative privileges
  • determine the device name of the new partition, e.g. diskpart
    list disk
    select disk 1
    list partition
    select partition 7
    detail partition
  • windows blocks raw access to the hard disk if the disk is online; use diskpart to switch the disk offline:
    list disk
    select disk 1
    offline disk
  • if the disk is mbr partioned open a console window with administrative privileges and run:
    “C:\Program Files\Oracle\VirtualBox\VBoxManage internalcommands createrawvmdk -rawdisk \\.\PhysicalDrive1 -filename my_filename.vmdk -partitions 7
    if the disk is a gpt disk VBoxManage will crash (with VirtualBox 4.2.12) and you have to run this command using a linux host
    VBoxManage internalcommands createrawvmdk -rawdisk /dev/sdb -filename my_filename.vmdk -partitions 7
    (the resulting file my_filename.vmdk hast to be copied to the windows host)
  • use wordpad to edit the vmdk file, so that partition 7 is seen as a whole virtual disk:
    (once again a warning: an editing mistake might erase all data of your hard disks)
    change createType to “fullDevice”
    between the lines “# Extent description” and “# The disk Data Base”
    delete all lines except the one refering to partition 7 (e.g. RW 52428800 FLAT “\\.\PhysicalDrive1” 482756608)
    If the vmdk file has been created with linux then the linux device name (e.g. /dev/sdb) has to be replaced
    by the windows device name (e.g. \\.\PhysicalDrive1)
  • run VirtualBoxwith administrative privileges and add my_filename.vmdk as hard disk to the virtual machine

 

 

Harddisks with form factor 2,5 inch have capacities of 1 or 2 terabyte nowadays. And usb 3.0 connectors supply enough current to run these harddisks. If it is possible to boot from such a harddisk into the imaging program you get a very compact backup and recovery system. Useful for snapshots of installed operating systems (allowing bare metall recovery).

Example of such a system with WD my passport 2,5′ USB 3.0 harddisk and TrueImage home 2013:

– use trueimage media builder to create a bootable usb stick (1GB)
– use diskpart in windows to repartition the my passport harddisk (with mbr partition table): create 2 primary partitions, make the first 1000 MB big, make this partition active and (quick) format it with fat32. The second partition takes the rest of the harddisk.

– open trueimage (inside windows) backup the first partition of the usb stick which has been made bootable by media builder.

– restore this backup to the first partition of the my passport harddisk

– boot into linux (a live cd could be used), format the second partition of the my passport harddisk with ext3 filesystem and create a folder for backups on this partition.

– verify that file /usr/share/syslinux/mbr.bin exists. (Else install syslinux). Then check the device name of the my passport harddisk, e.g. sdb and run as root user
dd if=/usr/share/syslinux/mbr.bin of=/dev/sdb
(Make sure that sdb is the my passport disk!).
In case of a gpt disk use gptmbr.bin and set the type of the second partition to 0700 (else trueimage does not save tib-files on this partition);
(additional remark: use gdisk /dev/sdb to set the legacy BIOS bootable flag on partition 1 (inside gdisk: p   x   a   1   2   <enter>   w);
this makes the gpt disk BIOS bootable, at least syslinux works as bootloader on this partition and syslinux may load trueimage …).

– now you should have a bootable harddisk with space for backups

– tested with mac mini (6.1 = ‘late 2012’). – In case of usb reset errors it might be worth to try another usb cable; the bootable version of trueimage uses linux.

installation snippets

goal: efi-bootable installation of OS X, Windows 8, Linux (opensuse 12.3)

backup harddisk:

  • unused 16 GB usb stick
  • use os x disk utility to create a guid partition table with two partitions (first with 1 GB size, formatted mac os extended journaled)
  • download os x recovery tool from apple here
  • run the recovery tool (in os x) and format the usb stick
  • use os x disk utility to create a second partition on the usb stick
  • use this second partition as time machine backup and let time machine create a full backup (might take some hours with usb 2 sticks);
    – needs about 12 GB to backup the preinstalled os x of mac mini;
    – change energy settings in system settings that this backup does not get interrupted by automatic sleep mode.
  • make sure that the usb stick is bootable:
    boot with pressed option/alt-key

reformat hard disk as gpt disk without (protective) mbr

  • warning: a backup is required because all data on the disk will be erased
  • in order to get as second os windows with efi boot the disk is formated with windows diskpart (following this helpful tutorial)
  • boot with some windows 8 install media (windows 7 or vista should work as well)
    – press shift+F10 to get a console window
    (it might be neccessary to enter repair options screen first)
    – run diskpart with

    • list disk
    • select disk 0
    • clean
    • convert gpt
      in case convert gpt fails with error write protected
      and attr dis shows read-only yes, then run
      attr dis clear readonly
      now convert gpt should work
    • create partition efi size=256
    • format fs=fat32 quick label=EFI
    • create partition primary size=51200 [size of your OS X partition in MB; Ex. 50GB = 51200]
    • list partition
    • create partition msr size=128
    • create partition primary size=30720 (desired size of your Windows partition; Ex. 30GB = 30720)
    • format fs=ntfs quick label=Windows
    • exit

    – reboot

restore os x

  • boot with pressed option/alt-key, select the usb stick with osx recovery tool
    – restore os x using the time machine backup
  • reboot into os x
    – run boot camp to download windows drivers
    (store the drivers in your os x home folder)
    – do not use boot camp to prepare your hard disk!
    – install rEFIt 0.14 boot loader from sourceforge
    -the configuration file of rEFIt allows to set os x as default os
    (/efi/refit/refit.conf on the os x system partition
    default_selection M)

prepare efi-bootable windows 8 install medium

  • warning: in bios-mode the installer does not accept the disk and windows partition created with diskpart
    (only windows 8 64 bit properly prepared install media support (u)efi-mode )
  • steps to create a efi-bootable usb stick from only bios-bootable dvd (as described here)
    – unused 4 GB usb stick
    – run diskpart (from windows vista/7/8 or from a windows 7/8 installer)
    – run diskpart with

    • list disk
    • select disk X (make sure X corresponds to the 4 GB usb stick!)
    • clean
    • create partition primary
    • select partition 1
    • active
    • format fs=fat32 quick
    • assign
    • exit

    – copy files from existing bios-bootable windows 8 64 bit install medium to the new usb stick

    • xcopy E:\*.* /s/e/f F:\

    – this assumes the existing install medium has drive letter E: and the new medium has drive letter F:
    – reboot into os x and copy the folder with bootcamp drivers to the new usb stick

install windows 8

  • boot with the efi bootable windows 8 pro 64 bit install medium
  • select the windows partition created before
    (if the installer displays that this partion is not formatted then efi-boot failed; you have to retry to boot into efi-mode)
  • after installation of windows 8 install bootcamp drivers (enables networking)
  • to get rEFIt boot manager back
    – either boot with pressed option/alt-key into osx and use system settings to select start volume “os x”
    – or use the windows 8 bootcamp system tray applet to select the start volume “os x”

opensuse 12.3 installation

  • burn an OpenSuse 12.3 64 bit install dvd (full installer, not only network installer)
  • efi-boot with this dvd (using grubx64.efi)
  • select user defined install
  • add linux partitions to the hard disk
    – an additional fat32 data partition which has rw access by os x, windows and linux might be useful
    – the partioning summary should show that /dev/sda1 is used as boot device
  • in boot manager settings select “test for other systems”, use grub2-efi and ignore the error message
  • install linux
    – should be successful except network
  • to get rEFIt boot manager back boot into windows and use bootcamp system try applet
    (windows should be displayed in the grub2 boot menu; eles use pressed option/alt key during boot)
opensuse 12.3 enable wired network
  • the tg3 network module has to be recompiled with additional pci id lines
    (the same issue is in Desinfec’t 2013 published by german c’t magazine: patched ubuntu tg3.ko: tg3_desinfect2013)
  • boot into linux and use yast to install from dvd build tools and linux kernel source and linux headers:
    – the rightmost tab in yast software install tool (“Schemata” in german version) allows to select
    – basic development tools
    – c/c++ development
    – linux kernel development
  • the file tg3.c has to be patched as decribed here
    (lspci -nn gives [14e4:1686] which corresponds in tg3.h to TG3PCI_DEVICE_TIGON3_57766
    but the device id TG3PCI_DEVICE_TIGON3_57766 is missing in tg3.c)
    – copy /usr/src/linux/drivers/net/ethernet/broadcom/tg3.c to tg3.c.orig and add the lines marked with +
    (without writing the ‘+’ sign)

    {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57762)},
    + {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57766)},
    + {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57782)},
    + {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57786)},
    - then recompile tg3.ko; run inside a konsole window:
    cd /usr/src/linux
    make clean
    make oldconfig
    cp /usr/src/linux-obj/x86_64/desktop/Module.symvers /usr/src/linux/
    (or cp /boot/symvers-3.xyz.gz /usr/src/linux; cd /usr/src/linux; gunzip symvers-3.xyz.gz;
    ln -s symvers-3.xyz Module.symvers)
    make scripts
    make prepare
    cd drivers/net/ethernet/broadcom/
    make -C /usr/src/linux SUBDIRS=$PWD modules
    su
    cp tg3.ko /lib/modules/3.7.10-1.1-desktop/kernel/drivers/net/ethernet/broadcom/
  • finally re-insert tg3 kernel module:
    - rmmod tg3
    - insmod tg3
  • use command dmesg and ifconfig -a to verify that network interface eth0 is now available
  • use yast to setup wired network eth0

opensuse 12.3 enable wireless network

  •  kernel module b43 needs firmware files which should be downloaded by
    sudo /usr/sbin/install_bcm43xx_firmware
    (as diplayed by:
    rmmod b43
    modprobe b43
    dmesg
    )
  • currently (2013-03) install_bcm43xx_firmware does not install all required files
    (ucode29_mimo.fw is missing)
  • download these firmware files (which claim to be part of netgear wndr4500 gpl source package)
  • open this archive and extract linux/wl_apsta.o to /lib/firmware/broadcom-wl-firmwares/
  • open a konsole window with root rights and run
    cd /lib/firmware/broadcom-wl-firmwares
    b43-fwcutter -w /lib/firmware/ wl_apsta.o
  • now run:
    rmmod b43
    modprobe b43
    dmesg
    This should display Broadcom 4331 WLAN found
  • then use yast or network manager to configure wireless network
bluetooth not working: lsusb ID 05ac:828a Apple, Inc. probably solved like done for
ID 05ac:8286 Apple, Inc. (Macbook Pro): see https://lkml.org/lkml/2012/7/9/473

+++ b/drivers/bluetooth/btusb.c
@@ -84,6 +84,9 @@ static struct usb_device_id btusb_table[] = {
+ /* Apple MacBookPro10,1 */
+ { USB_DEVICE(0x05ac, 0x8286) },
+

Steps to get  dovecot 2.1.17 on qnap ts 119p II NAS (firmware 3.8.1 or 4.x) up and running:

dovecot has to be compiled from source:

  • qnap web admin: qpkg center: available / more / Optware IPKG: install and activate it. Or with newer firmware, 4.x, follow these instructions (using HDA_DATA instead of MD0_DATA and replacing cs05q3armel = gcc-3.4.4 by cs08q1armel = gcc-4.2.3).
  • enable ssh on qnap and connect as user admin
  • cd /opt
  • ./Optware.sh start. Or with newer firmware:
    PATH=/opt/bin:/opt/sbin:$PATH
  • ipkg update
  • ipkg install mc
    (my preferred editor and file manager)
  • ipkg install libidn
    ipkg install optware-devel
    (pulls in many tools used for compilation of packages)
  • mkdir src
    cd src
    wget http://www.dovecot.org/releases/2.1/dovecot-2.1.17.tar.gz
    tar -xzf dovecot-2.1.17.tar.gz
    cd dovecot-2.1.17
    (download dovecot source)
  • export PATH=/opt/bin:/opt/sbin:$PATH
    (compilation might fail if tools in /bin or /usr/bin are used instead of the ones in /opt/bin)
    ./configure –prefix=/opt –with-storages=maildir
    make
    make install
    (if configure does not find a required library foo the run ipkg list |grep foo and install libfoo-dev with ipkg install)
  • child processes of dovecot use /lib and ignore /opt/lib
    (maybe this can be avoided with CPPFLAGS=”-I/opt/include” LDFLAGS=”-L/opt/lib -ldl” ./configure …)
    qnap firmware 3.8.1 installs libssl 0.97 in /lib but ipkg installs libssl 0.98 in /opt/lib; workaround:
    ln -s /opt/lib/libssl.so.0.9.8 /lib/
    ln -s /opt/libcrypto.so.0.9.8 /lib/
    (to be moved into dovecot startup script)
  • mkdir /opt/var/log
    addgroup dovenull
    addgroup dovecot
    adduser -D -H -G dovenull dovenull
    adduser -D -H _G dovecot dovecot
  • cd /opt/etc
    mkdir dovecot
    mkdir dovecot/conf.d
    (now copy config files from /opt/share/doc/dovecot/example-config to /opt/etc/dovecot, e.g. using mc)
    dovecot.conf: protocols = imap and listen = *
    10-auth.conf: disable_plaintext_auth = no
    10-logging.conf: log_path = /opt/var/log/dovecot.log
    10-mail.conf: mail_location = maildir:/share/dovecot/%n
    10-master.conf: unchanged
    10-ssl.conf: ssl = no and #ssl_cert… and #ssl_key… (disable ssl; might be enabled in a later step)
    20-imap.conf: unchanged
    auth-system.conf.ext: comment out the section driver = pam and uncomment the section driver = shadow
    and add args = blocking=no
    newer firmware 4.x:
    do not use blocking=no because /etc/shadow needs a worker thread which is allowed to access /etc/shadow; so add to auth-system.conf.ext:
    service auth-worker {
    group = administrators
    }
    (mail users will be created with qnap web interface)
  • from qnap web interface: access control
    user-groups: create group mail
    shared folders: add folder dovecot (use automatic path and do not share it)
    shared folders: permissions for folder dovecot:
    user: create the mail user yourname with password  and add it to group mail
  • start dovecot manually
    dovecot -c /opt/etc/dovecot/dovecot.conf
    and test it with telnet as described in the dovecot wiki (with mail user yourname)
    finally try to connect with a mail client like thunderbird
  • start and stop dovecot automatically: there are optware start/stop scripts in /opt/etc/init.d
    but the qnap firmware (currently 3.8.1) does not execute them.
    – mkdir /tmp/config
    – mount /dev/mtd5 /tmp/config
    firmware 4.x: use /dev/mtdblock5
    – add executable file autorun.sh to /tmp/config:
    #!/bin/sh
    #
    for f in /tmp/config/K*.sh; do
    [ -x $f ] && $f start &
    [ -x $f ] && cp $f /etc/rcK_init.d/
    done
    – enable autorun.sh with
    /sbin/setcfg Misc Autorun TRUE
    /sbin/setcfg Misc Autorun TRUE -f /tmp/config/uLinux.conf
    (reference /etc/rcS.d/S98init_nas)
    – copy K010optstartstop.sh to /tmp/config (with extension ‘.sh’, not with extension.txt; partly found here and here)
    – chmod +x /tmp/config/K010optstartstop.sh
    – umount /tmp/config
    this will execute   start/stop scripts in /opt/etc/init.d.
  • /opt/etc/init.d/S59dovecot may contain
    #!/bin/sh
    if [ -f /opt/var/run/dovecot/master.pid ] ; then
    kill `cat /opt/var/run/dovecot/master.pid`
    else
    killall dovecot 2>/dev/null
    fi
    rm -f /opt/var/run/dovecot/master.pid
    ln -s /opt/lib/libssl.so.0.9.8 /lib/
    ln -s /opt/libcrypto.so.0.9.8 /lib/
    /opt/sbin/dovecot -c /opt/etc/dovecot/dovecot.conf
  • /opt/etc/init.d/K41dovecot may contain
    #!/bin/sh
    if [ -f /opt/var/run/dovecot/master.pid ] ; then
    kill `cat /opt/var/run/dovecot/master.pid`
    else
    killall dovecot 2>/dev/null
    fi
    rm -f /opt/var/run/dovecot/master.pid
    or simply
    #!/bin/sh
    /opt/bin/doveadm stop
  • both scripts have to be executable
    chmod +x /opt/etc/init.d/S59dovecot
    chmod +x /opt/etc/init.d/K41dovecot

To be continued with py25-getmail to collect mails from pop3 servers
(getmail delivers mails directly into the maildir folders used by dovecot)

  • ipkg install py25-getmail
  • instructions for getmail configuration (not written for qnap)

Preparing a NAS for backup with rsync I wanted to copy initial data with nfs because of higher transfer speed.

The NAS nfs export mounts fine on a linux box but not from osx 10.5.8. Some search revealed that

  • /etc/hosts on the NAS should have an entry for the osx machine [1]
    (e.g. 1.2.3.9 my_osx_box)
  • instead of mount 1.2.3.4:/share /mnt use mount_nfs -P 1.2.3.4:/share /mnt [2]
    (or add insecure to /etc/exports on the NAS)