Skip to content

How to create a custom Raspberry PI Images with HashiCorp Packer. The image will have SSH enabled , Default jre,Node js,Redis server, Access point and wifi enabled and docker already installed when you boot up your Raspberry Pi. Everything is done in Ubuntu.

Notifications You must be signed in to change notification settings

jalajp1991/Raspberry-Pi-image-with-HashiCorp-Packer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Raspberry Pi image with HashiCorp Packer

In this wiki I will show you how to create a custom Raspberry PI Images with HashiCorp Packer. The image will have SSH enabled ,Default jre,Node js,Redis server, Access point and wifi enabled and docker already installed when you boot up your Raspberry Pi. Everything is done in Ubuntu. (28.04.2020).

Contents

Setup

  • Windows 10 with a clean Ubuntu 18.04.3 server installation.
  • Raspberry Pi 4

Steps

  • Install HashiCorp Packer 1.3.5
  • Install Go above version 1.11
  • Install Packer ARM builder
  • Build the image

Install HashiCorp Packer

Download Packer from HashiCorp in Version 1.3.5. Do not install version 1.4.5. since it is not compatible with the ARM builder version we are going to use for Packer. Unzip the package in /usr/local/packer.

  1. Update apt-get dependencies

    sudo apt-get update
  2. Install unzip

    sudo apt-get install -y unzip
  3. Download Packer from HashiCorp

    wget https://releases.hashicorp.com/packer/1.3.5/packer_1.3.5_linux_amd64.zip
  4. Unpack Packer

    sudo unzip packer_1.3.5_linux_amd64.zip -d /usr/local/packer
  5. Cleanup your workspace and delete the archive

    rm packer_1.3.5_linux_amd64.zip
  6. Add it to the PATH

    sudo -i
    printf '#!/bin/bash \nexport PATH=$PATH:/usr/local/packer \n' > /etc/profile.d/packer.sh
  7. Logout by pressing STRG+D

    source /etc/profile.d/packer.sh
  8. Check if Packer works

    packer version

Install GoLang

Install GoLang above version 1.11 since it adds module support.

  1. Download Go from google

    wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
  2. Unpack go

    tar xvf go1.13.4.linux-amd64.tar.gz
  3. Change the owner

    sudo chown -R root:root ./go
  4. move it

    sudo mv go /usr/local
  5. Cleanup your workspace and delete the archive

    rm go1.13.4.linux-amd64.tar.gz
  6. Add it to the PATH

    sudo -i
    printf '#!/bin/bash \nexport GOPATH=$HOME/work \nexport PATH=$PATH:/usr/local/go/bin:$GOPATH/bin \n' > /etc/profile.d/go.sh
  7. Logout by pressing STRG+D

    source /etc/profile.d/go.sh
  8. Check if Go works

    go version

Install Packer ARM builder

  1. Install dependencies for ARM builder

    sudo apt-get install -y kpartx qemu-user-static
  2. Clone repository

    git clone https://github.com/solo-io/packer-builder-arm-image
  3. Checkout the commit that worked for me

    cd packer-builder-arm-image
    git checkout b1c268e9d33105634c899e9095f0af097e1af432
  4. Build the Packer ARM builder

    go mod download
    go build
  5. Copy the finished build to Packer directory

    sudo cp packer-builder-arm-image /usr/local/packer/
  6. Cleanup your workspace and delete the source

    cd ..
    sudo rm -r packer-builder-arm-image/

Create the ARM image with Packer

Now it is time to build the image for the Raspberry PI. The image will have SSH enabled and docker already installed. It is necessary to be root user. Create a json file for packer.

sudo -i
nano raspberrypi-docker.json

raspberrypi-docker.json

apandwifi.sh

base.sh

cleanup.sh

jre.sh

node.sh

redis.sh

This configuration file tells packer to downloads the Raspbian OS image. Packer checks the checksum and starts the scrips commands. Now run packer to build the image (as root user):

keep the above files in Scripts folder.

packer build raspberrypi-docker.json

Ignore errors and warnings if the image was created…

Build 'arm-image' finished.
==> Builds finished. The artifacts of successful builds are:
--> arm-image: output-arm-image/image

The image is located under ./output-arm-image/image Copy it with WinSCP or any other tool to windows. Rename it to raspberry-pi-with-ssh-and-docker.bin Now we can use “balenaEtcher” to write the image to the Raspberry Pi.

SSH is enabled and docker should work out of the box.

Conclusion

Building an ARM Image with HashiCorp Packer isn’t that hard. With this example we get an Raspberry Pi image with enabled SSH enabled ,Default jre,Node js,Redis server, Access point and wifi enabled and docker already installed. Flashing it to the SD Card, plugging it in and everything works as expected.

Since the image is always the same, the network name will always be the same and has to be changed manually or with some script.

About

How to create a custom Raspberry PI Images with HashiCorp Packer. The image will have SSH enabled , Default jre,Node js,Redis server, Access point and wifi enabled and docker already installed when you boot up your Raspberry Pi. Everything is done in Ubuntu.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages