How to prepare a Raspbian based AGILE SD image

From AGILE IoT Wiki
Jump to: navigation, search
  1. Download Raspbian lite (https://www.raspberrypi.org/downloads/raspbian/)
  2. Burn to SD (e.g. with Etcher.io)
  3. Modify the SD (note that you might have to eject and insert the SD card again to access it from your PC)
    1. Enable SSH by placing a file named ssh, without any extension, onto the boot partition of the SD card. (based on https://www.raspberrypi.org/documentation/remote-access/ssh/ )
touch ssh
  1. At this point, put the SD card into your Raspberry Pi 3, and boot it by connecting the power. The following instructions should all be executed on the Pi. If the Pi is connected to your LAN with an Ethernet cable, in most cases you can log in with `ssh pi@raspberrypi.local`. Otherwise, you can connect a screen and keyboard to the Pi and log in directly.

 # Remove some bulk

 sudo apt-get purge libreoffice wolfram-engine sonic-pi scratch
 sudo apt-get autoremove

 # Change password from raspberry to agileiot
 passwd

 # Install prerequisites

 sudo apt-get update
 sudo apt-get install -y git

 # Install docker
 wget https://download.docker.com/linux/debian/dists/jessie/pool/edge/armhf/docker-ce_17.05.0~ce-0~debian-jessie_armhf.deb
 sudo dpkg -i docker-ce_17.05.0~ce-0~debian-jessie_armhf.deb
 rm docker-ce_17.05.0~ce-0~debian-jessie_armhf.deb
 sudo apt-get install -f -y
 sudo usermod -aG docker $USER

 # Install docker-compose

 sudo curl -L https://github.com/javabean/arm-compose/releases/download/1.16.1/docker-compose-Linux-armv7l -o /usr/local/bin/docker-compose
 sudo chmod +x /usr/local/bin/docker-compose
 ## Alternative method if the above doesn't work
 # apt-get install -qy python-pip --no-install-recommends
 # pip install pip --upgrade
 # sudo apt-get install python-setuptools 
 # pip install docker-compose

 # Change hostname to agilegw
 sudo sed -i 's/raspberrypi/agilegw/' /etc/hostname
 sudo sed -i 's/raspberrypi/agilegw/' /etc/hosts

 # Disable Bluetooth in the host, it will be running containerized
 sudo systemctl stop bluetooth.service
 sudo systemctl disable bluetooth.service

 # Enable the I2C bus on the RPi header
 sudo sed -i 's/#dtparam=i2c_arm=on/dtparam=i2c_arm=on/' /boot/config.txt
 #sudo dtparam i2c_arm=on # to enable also on the fly

 # Get AGILE
 git clone --recursive https://github.com/Agile-IoT/agile-stack.git
 git clone --recursive https://github.com/Agile-IoT/agile-cli.git
 cd agile-cli/
 cp agile.config.examples/agile.config.raspbian agile.config
 sudo ./agile install

 # reboot
 sudo reboot
 # downoad agile and make it start on boot
 agile start

 #shutdown
 sudo shutdown now


Enabling Docker remote management (optional)

Edit /lib/systemd/system/docker.service , changing ExecStart as follows:

 ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375

Prepare image from PC

 sudo umount /dev/mmcblk0p1
 sudo umount /dev/mmcblk0p2
 git clone https://github.com/cskiraly/PiShrink.git
 sudo PiShrink/pishrink.sh -i /dev/mmcblk0 agile-rpi23.img