Epics@GSI Webhome

Epics Installation At Raspberry Pi From Scratch

Introduction

Installing Raspbian/Debian image

see e.g. https://www.raspberrypi.org/documentation/installation/installing-images/

    Download Image, Write Image, First Boot, Login

    1. Consult e.g. http://elinux.org/RPi_SD_cards#Working_.2F_Non-working_SD_cards to not purchase wrong SD cards.
    2. Download Image
    3. Write Image to the SD card
    4. Plug SD card into the Raspberry PI
    5. Connect Monitor via HDMI and Keyboard/Mouse
    6. Power on
    7. JESSIE image already ends up at the Desktop GUI logged in as user pi
    8. open a terminal, either by
      • mouse click or
      • CTRL-ALT-F2
        • login, if necessary : pi/raspberry


Configurations

    raspi-config

    1. raspi-config - Raspberry Pi Software Configuration Tool, current settings
      1. sudo raspi-config
      2. If connected to the internet, then update
        • Advanced OptionsUpdate
      3. Boot OptionsConsole Autologin
      4. Wait for Network at BootFast Boot ...
        • requires some action on network connection
      5. Internationalisation Options
        1. Change TimezoneEuropeBerlin
        2. Change Keyboard Layout, (if needed)
          1. Generic 105-key (Intl) PC__→ __Other, (if not English) → GermanGerman
          2. Key to function as AltGr: Right Alt (AltGr)
          3. Compose key: No compose key
          4. Use Control+Alt+Backspace to terminate X server <No>
      6. Advanced Options
        1. SSH<Enable>
        2. Device Tree<Yes>
        3. Serial<Yes>
        4. Memory Split : 0
    2. Check current settings by rebooting:
      sudo reboot
    3. Then power off:
      sudo poweroff


    Saving and Resizing the Image

    1. Remove SD card and save the current image.
      1. Since the readout takes the whole content of the SD card as image, but the amount of data is still the same, only the configuration changed, a resize of the image to about the size of the original image + a few MB for is recommended.
        See:
      2. current resized image file at:
        2015-11-21-raspbian-jessie_configured_resized.7z - 19 Jan 2016
    2. Reinsert SD-Card
    3. Expand Filesystem
      • Either use sudo raspi-config
        • Expand Filesystem to expand to full SD-size, or

          #!/usr/bin/perl -w
          #
          # Author: P.Zumbruch@gsi.de 
          # January 22, 2016
          
          use strict;
          use File::Temp qw/ tempfile tempdir /;
          
          #find location of 'raspi-config'
          open CMD,'-|', 'which raspi-config'
             or die $@;
          my $raspiConfigLocation = ;
          close CMD;
          
          #read 'raspi-config'
          open FILE, $raspiConfigLocation
             or die "Cannot open '$raspiConfigLocation': $!";
          my $raspiConfig = do { local $/;  };
          close FILE;
          
          ###
          #define additional code segments to leave some space of 256MB at the very end of the SD card
          # - size calculations
          my $partSizeCommands = << 'EOF';
          
          #additional code segment to leave some space of 256MB at the very end of the SD card
          if [ -z "$PART_SIZE" ]
          then 
              local DEVICE_SIZE=$(parted MY_DEVICE -ms unit s p | grep MY_DEVICE | cut -d: -f 2 | sed -e 's/[A-Z]//ig');
              local DEVICE_SECTOR_SIZE=$(parted MY_DEVICE -ms unit s p | grep MY_DEVICE | cut -d: -f 4 | sed -e 's/[A-Z]//ig');
              local PART_SIZE=$(( $DEVICE_SIZE - ( 1 + 256 * 1024 * 1024 / $DEVICE_SECTOR_SIZE) ));
          fi
          EOF
          ;
          #replace dummy "MY_DEVICE" by real device name used in 'raspi-config'
          my $partSizeCommandsDevice = $raspiConfig =~ s/.+parted (\/dev\/.+?)\s.+/$1/sr;
          $partSizeCommands =~ s/MY_DEVICE/$partSizeCommandsDevice/g;
          
          # - unmodified fdisk sequence 
          my $fdiskCommands = << 'EOF';
          p
          d
          $PART_NUM
          n
          p
          $PART_NUM
          $PART_START
          
          p
          w
          EOF
          ;
          
          # generate modified fdisk sequence including PART_SIZE
          my $fdiskCommandsInsert = $fdiskCommands =~ s/(\$PART_NUM\n\$PART_START\n)(\n)/$1\$PART_SIZE$2/rm;
          # generate search pattern
          my $fdiskCommandsSearch = $fdiskCommands =~ s/\$/\\\$/rg;
          
          #replace fdisk sequence
          $raspiConfig =~ s/(.*?\n)$fdiskCommandsSearch/$partSizeCommands$1$fdiskCommandsInsert/m;
          #print $raspiConfig;
          
          #create new enhanced 'raspi-config' to temporary file
          my $filename;
          (undef, $filename) = tempfile( "", SUFFIX => '.raspi-config', TMPDIR => 1, OPEN => 1 );
          
          open OUTPUT, ">$filename" or die "Cannot create output file: $!";
          print OUTPUT $raspiConfig ."\n";
          close OUTPUT;
          
          chmod 0755, "$filename";
          
          #execute vi sudo new 'raspi-config'
          !system "sudo $filename --expand-rootfs" or warn "sudo $filename --expand-rootfs failed:$!\n";
          
          #delete temporary 'raspi-config' file
          unlink $filename or warn "failed removing $filename: $!\n";
          

          1. conservative expand of rootfs
          2. Reboot to apply changes
          sudo reboot


    more configurations, tools, installs

    1. Change default Password of user pi
      • passwd
        • pi/raspberry.GSI

    Packages

      Detailed

        1. Update & Safe-Upgrade
          sudo aptitude update
          sudo aptitude -y safe-upgrade
          • takes ~1h or more
            ncurses sudo aptitude -y install ncurses-bin ncurses-dev libncurses-dev libncurses5
            readline sudo aptitude -y install libreadline-dev
            tecla sudo aptitude -y install libtecla-dev
            htop sudo aptitude -y install htop
            (m)locate sudo aptitude -y install locate mlocate
            tmux sudo aptitude -y install tmux
            procServ & telnet sudo aptitude -y install procserv telnet
            vim sudo aptitude -y install vim
            git sudo aptitude -y install vim-fugitive qgit python-git gitk git-all
            ntpdate sudo aptitude -y install ntpdate
            re2c sudo aptitude -y install re2c
            pcre sudo aptitude -y install libpcre3-dev libpcre++-dev
            WiringPi sudo aptitude -y install wiringpi
            __picocom / microcom sudo aptitude -y install picocom microcom
            ca-certificates sudo aptitude -y install ca-certificates
            python-dev python.gpio sudo aptitude -y install python-setuptools ipython python-dev python-gpiozero
            postgres client &amp server sudo aptitude -y install postgresql-all postgresql-autodoc postgresql-client postgresql-client-common postgresql-doc pgadmin3 pgadmin3-data phppgadmin
            tightvncserver sudo aptitude -y install tightvncserver
            i2c-tools sudo aptitude -y install i2c-tools
            7z sudo aptitude -y install p7zip-full
            avr sudo aptitude -y install avr-libc avrdude avrp binutils-avr gcc-avr gdb-avr simulavr avarice
            munin_node sudo aptitude -y install munin-node lm-sensors munin-plugins-extra
            ntp sudo aptitude -y install ntp
        1. Finally update & Safe-Upgrade & autoclean
          sudo aptitude update &&
          sudo aptitude -y safe-upgrade &&
          sudo aptitude -y autoclean

      r16 - 2018-04-27 - 14:43:03 - PeterZumbruch

Compact

    sudo aptitude update  &&  
    sudo aptitude -y safe-upgrade  &&  
    sudo aptitude -y install ncurses-bin ncurses-dev &&  
    sudo aptitude -y install libncurses-dev libncurses5 &&  
    sudo aptitude -y install libtecla-dev libreadline-dev  &&  
    sudo aptitude -y install htop   &&  
    sudo aptitude -y install locate mlocate    &&  
    sudo aptitude -y install tmux procserv  &&  
    sudo aptitude -y install telnet  &&  
    sudo aptitude -y install vim  vim-fugitive  &&  
    sudo aptitude -y install qgit python-git gitk git-all   &&  
    sudo aptitude -y install ntpdate  &&  
    sudo aptitude -y install re2c libpcre3-dev libpcre++-dev  &&  
    sudo aptitude -y install wiringpi  &&  
    sudo aptitude -y install picocom microcom  &&  
    sudo aptitude -y install ca-certificates  &&  
    sudo aptitude -y install python-setuptools ipython python-dev python-gpiozero  &&  
    sudo aptitude -y install postgresql-all postgresql-autodoc postgresql-client postgresql-client-common postgresql-doc pgadmin3 pgadmin3-data phppgadmin   &&  
    sudo aptitude -y install tightvncserver  &&  
    sudo aptitude -y install i2c-tools && 
    sudo aptitude -y install p7zip-full &&  
    sudo aptitude -y install avr-libc avrdude avrp binutils-avr gcc-avr gdb-avr simulavr avarice &&  
    sudo aptitude -y install munin-node lm-sensors munin-plugins-extra && 
    sudo aptitude -y install ntp &&
    sudo aptitude update  &&  
    sudo aptitude -y safe-upgrade && 
    sudo aptitude -y autoclean
       

    r16 - 2018-04-27 - 14:43:03 - PeterZumbruch

Image ("Packages")

    ssh_
    • delete and regenerate global keys

    ([ -f /var/log/regen_ssh_keys.log ] && sudo rm /var/log/regen_ssh_keys.log || : ; ) && 
                      sudo rm /etc/ssh/ssh_host* && 
                      sudo ssh-keygen -A
                     

    • check ~/.ssh/authorized_keys
      • optionally delete it :
        [ -f ~/.ssh/authorized_keys ] && rm ~/.ssh/authorized_keys
    • check ~/.ssh/known_hosts
      • optionally delete it :
        [ -f ~/.ssh/known_hosts ] && rm ~/.ssh/known_hosts

    clear logs
    • Before creating the next image,
      • Remove zipped files,
        clear all logs:, and
        history
        sudo su -c '(find /var/log -name "*.gz" -delete && for item in $(find /var/log/ -type f | grep -v git-daemon | grep -E -v '\.1$' ); do sudo cat /dev/null > $item;  done && history -c )'
           
        history -c

r6 - 2018-05-03 - 12:51:30 - PeterZumbruch
    Image location
    Current resized image file at:
    2015-11-21-raspbian-jessie_configured_2_resized.7z - 10 Feb 2016


Others

    udev/udevadm serial permissions - udev/udevadm - dynamic device symlink and proper access rights
    printf 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", SYMLINK+="$env{ID_SERIAL}", GROUP="users", MODE="0666"\n 
                  SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A100*", RUN+="/usr/bin/stty -F/dev/$kernel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 115200 "\n 
                  SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A801*", RUN+="/usr/bin/stty -F/dev/$kernel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 115200 "\n' > /tmp/99-serial-permissions.rules && 
          sudo chown root:root /tmp/99-serial-permissions.rules && 
          sudo mv /tmp/99-serial-permissions.rules /etc/udev/rules.d/
        
    update hostname on network connect via dhclient-exit-hook
    ... see the details at: dhclient - dynamic hostname

    Provided you have root privileges this can be achieved by creating a script file hostname created in /etc/dhcp/dhclient-exit-hooks.d/ (on Debian), which is sourced by dhclient after having updated/received its DHCP informations.

    #!/bin/sh
       # Filename:     /etc/dhcp/dhclient-exit-hooks.d/hostname
       # Purpose:      Used by dhclient-script to set the hostname of the system
       #               to match the DNS information for the host as provided by
       #               DHCP.
       #
          
       # Do not update hostname for virtual machine IP assignments
       if [ "$interface" != "eth0" ] && [ "$interface" != "eth1" ] && [ "$interface" != "wlan0" ]
       then
               return
       fi
          
       if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
       then
          return
       fi
       
       echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
       hostname=$(a=$(host $new_ip_address) || { false; } && { echo -n $a | cut -d ' ' -f 5 | cut -d "." -f 1; true; }) || unset hostname &&
       echo ${hostname?} > /etc/hostname &&
       hostname $hostname &&
       export HOSTNAME=$hostname &&
       echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname
    

    Applying those code lines:
    %sudo% curl -s https://wiki.gsi.de/foswiki/pub/Epics/TipsLinuxDhclientDynamicHostname/_etc_dhcp_dhclient-exit-hooks.d_hostname -o /etc/dhcp/dhclient-exit-hooks.d/hostname && 
      %sudo% dos2unix /etc/dhcp/dhclient-exit-hooks.d/hostname && 
      %sudo% chmod a+r /etc/dhcp/dhclient-exit-hooks.d/hostname
    

    ntp.conf
      adjust timeservers at /etc/ntp.conf to German de.pool.ntp.org
      sudo perl -pi.bak -e 's/^(server [0123])\..*?\.pool\.ntp\.org/\1.de.pool.ntp.org/g' /etc/ntp.conf
      add (local) timeservers to /etc/ntp.conf
      e.g.
      • local network servers==server 192.168.100.50 iburst==
      • site server server timeserver1.gsi.de iburst
      • not recommeded, german main time server server ptbtime1.ptb.de iburst

    force update of time on network (re)connect via dhclient-exit-hook
    ... see the details at: dhclient - forced time update

    Provided you have root privileges this can be achieved by creating a script file ntp_force_update created in /etc/dhcp/dhclient-exit-hooks.d/ (on Debian), which is sourced by dhclient after having updated/received its DHCP informations.

    #!/bin/sh
       # Filename:     /etc/dhcp/dhclient-exit-hooks.d/ntp_force_update
       # Purpose:      Used by dhclient-script to set the time of the system
       #
           
       # Do not update hostname for virtual machine IP assignments
       if [ "$interface" != "eth0" ] && [ "$interface" != "eth1" ] && [ "$interface" != "wlan0" ]
       then
               return
       fi
           
       if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
       then
          return
       fi
         
    	service ntp status >/dev/null 2>&1 && 
       (
         sleep 5 && 
         service ntp stop && 
         ntpd -qg ; 
         service ntp start; 
         touch /tmp/force_update
       ) &
       
        systemctl status systemd-timesyncd.service >/dev/null 2>&1 && 
       (
         sleep 5 && 
         systemctl status systemd-timesyncd.service stop && 
         timedatectl ; 
         systemctl status systemd-timesyncd.service start; 
         touch /tmp/force_update
       ) &
    Applying those code lines:
    %sudo% curl -s https://wiki.gsi.de/foswiki/pub/Epics/TipsLinuxDhclientForceTimeUpdate/_etc_dhcp_dhclient-exit-hooks.d_ntp_force_update -o /etc/dhcp/dhclient-exit-hooks.d/ntp_force_update && 
      %sudo% dos2unix /etc/dhcp/dhclient-exit-hooks.d/ntp_force_update && 
      %sudo% chmod a+r /etc/dhcp/dhclient-exit-hooks.d/ntp_force_update
    

    bash_completion
    * edit /etc/bash.bashrc and uncomment bash_completion section
    sudo vi /etc/bash.bashrc

    bugfix: rsyslogd /dev/xconsole default behaviour
    ... see details in here
    • Found in version rsyslog/7.6.3-1
    • Fixed in version rsyslog/8.14.0-2
    • but we currently have 8.4.2
    • so comment out the last block in the /etc/rsyslog.conf
      --- /etc/rsyslog.conf.orig	
      +++ /etc/rsyslog.conf	
      @@ -115,7 +115,7 @@
       # NOTE: adjust the list below, or you'll go crazy if you have a reasonably
       #      busy site..
       #
      -daemon.*;mail.*;-	news.err;-	*.=debug;*.=info;-	*.=notice;*.=warn	|/dev/xconsole
      +#//#daemon.*;mail.*;+#//#	news.err;+#//#	*.=debug;*.=info;+#//#	*.=notice;*.=warn	|/dev/xconsole
      

    • avahi-daemon - deactivate ?
    • ssh-key -a only once at startup ?
    • ssh-key-copy
    • .bashrc / .profile


1-wire support module

TODO

Image ("Packages + "Others"")

    ssh_
    • delete and regenerate global keys

    ([ -f /var/log/regen_ssh_keys.log ] && sudo rm /var/log/regen_ssh_keys.log || : ; ) && 
                      sudo rm /etc/ssh/ssh_host* && 
                      sudo ssh-keygen -A
                     

    • check ~/.ssh/authorized_keys
      • optionally delete it :
        [ -f ~/.ssh/authorized_keys ] && rm ~/.ssh/authorized_keys
    • check ~/.ssh/known_hosts
      • optionally delete it :
        [ -f ~/.ssh/known_hosts ] && rm ~/.ssh/known_hosts

    clear logs
    • Before creating the next image,
      • Remove zipped files,
        clear all logs:, and
        history
        sudo su -c '(find /var/log -name "*.gz" -delete && for item in $(find /var/log/ -type f | grep -v git-daemon | grep -E -v '\.1$' ); do sudo cat /dev/null > $item;  done && history -c )'
           
        history -c

r6 - 2018-05-03 - 12:51:30 - PeterZumbruch
    Image location
    Current resized image file at:
    2015-11-21-raspbian-jessie_configured_3_resized.7z - 02 Mar 2016


EPICS

    Users

    • adduser epics:
      sudo adduser epics
      • epics/r p i - c t r l
      • epics, add to groups, amongst other, become "sudoer"
        (
          myGROUPS="adm dialout cdrom sudo audio video plugdev games users input netdev spi"; 
          for group in $myGROUPS; 
          do 
             sudo adduser epics $group; 
          done; 
          unset myGROUPS;
        ) 
        
    • set epics's sudoer actions
      1. open visudo to change sudoer settings: visudo
      2. add this line at the end of the file, close to pi's settings: epics ALL=(ALL) NOPASSWD: ALL


    Directory

    mkdir -p ~epics/EPICS/{EPICS-3.15.3,bin,programs}


    . epics

    sudo ln -s ~/EPICS/bin/epics /usr/local/bin/epics


    Base

    • readline -> EPICS CONFIG

    Extensions


    Modules


Notizen

Options:

Firmware update

First, no since read this:
https://www.raspberrypi.org/documentation/raspbian/updating.md

But if you want the upmost, experimental Firmware
http://raspberrypiguide.de/howtos/raspberry-pi-firmware-update/

Kernel building

First, no since read this:
https://www.raspberrypi.org/documentation/raspbian/updating.md
optionally
https://www.raspberrypi.org/documentation/linux/kernel/building.md

U-Boot

http://elinux.org/RPi_U-Boot

Device Tree


-- PeterZumbruch - 03 Mar 2016
-- PeterZumbruch - 2016-03-18
Edit | Attach | Print version |  PDF | History: r51 | r33 < r32 < r31 < r30 | Backlinks | View wiki text | Edit WikiText | More topic actions...
Topic revision: r32 - 2016-03-18, PeterZumbruch
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)