Skip to content

Commit

Permalink
Merge branch 'RPi-Distro-dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Landrash committed Feb 7, 2018
2 parents 501d03c + 23963b9 commit f167815
Show file tree
Hide file tree
Showing 39 changed files with 296 additions and 117 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
output/
work/
deploy/
apt-cacher-ng/
.git/objects/*
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ work/*
config
postrun.sh
SKIP
SKIP_IMAGES
.pc
*-pc
apt-cacher-ng/
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM debian:jessie
FROM debian:stretch

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -y update && \
apt-get -y install \
git vim parted \
quilt realpath qemu-user-static debootstrap zerofree pxz zip dosfstools \
bsdtar libcap2-bin rsync grep \
bsdtar libcap2-bin rsync grep udev xz-utils curl xxd \
&& rm -rf /var/lib/apt/lists/*

COPY . /pi-gen/
Expand Down
File renamed without changes.
101 changes: 96 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The Haspbian image is built with the same script that generates the official [Ra

By default the Haspbian image is built on a Debian 8 droplet on Digital Ocean and takes about 30 minutes to build on the cheapest droplet. Dependencies and everything is handled by the build script with the exception of `git`.

<<<<<<< HEAD
Since this image is based on [Raspbian](https://www.raspberrypi.org/downloads/raspbian/) it keeps the default password and username from [Raspbian](https://www.raspberrypi.org/downloads/raspbian/). Default user for use locally or over ssh is `pi` and the password is `raspberry`.

Build instructions:
Expand All @@ -16,13 +17,19 @@ Build instructions:
- Retrieve your freshly built Raspberry Pi image from the `rpi_gen\deploy` folder.


=======
>>>>>>> 066eb03d52868290661e813738a9a66eda263aa9
## Dependencies

On Debian-based systems:
pi-gen runs on Debian based operating systems. Currently it is only supported on
either Debian Stretch or Ubuntu Xenial and is known to have issues building on
earlier releases of these systems.

To install the required dependencies for pi-gen you should run:

```bash
apt-get install quilt parted realpath qemu-user-static debootstrap zerofree pxz zip \
dosfstools bsdtar libcap2-bin grep rsync
dosfstools bsdtar libcap2-bin grep rsync xz-utils
```

The file `depends` contains a list of tools needed. The format of this
Expand Down Expand Up @@ -51,6 +58,12 @@ The following environment variables are supported:
will not be included in the image, making it safe to use an `apt-cacher` or
similar package for development.

If you have Docker installed, you can set up a local apt caching proxy to
like speed up subsequent builds like this:

docker-compose up -d
echo 'APT_PROXY=http://172.17.0.1:3142' >> config

* `BASE_DIR` (Default: location of `build.sh`)

**CAUTION**: Currently, changing this value will probably break build.sh
Expand All @@ -65,19 +78,72 @@ The following environment variables are supported:
be built and cached. Note, `WORK_DIR` stores a complete copy of the target
system for each build stage, amounting to tens of gigabytes in the case of
Raspbian.

**CAUTION**: If your working directory is on an NTFS partition you probably won't be able to build. Make sure this is a proper Linux filesystem.

* `DEPLOY_DIR` (Default: `"$BASE_DIR/deploy"`)

Output directory for target system images and NOOBS bundles.

<<<<<<< HEAD
A simple example for building Hassbian:
=======
=======
* `USE_QEMU` (Default: `"0"`)

This enable the Qemu mode and set filesystem and image suffix if set to 1.


A simple example for building Raspbian:
>>>>>>> 066eb03d52868290661e813738a9a66eda263aa9
```bash
IMG_NAME='Hassbian'
```


## How the build process works

The following process is followed to build images:

* Loop through all of the stage directories in alphanumeric order

* Move on to the next directory if this stage directory contains a file called
"SKIP"

* Run the script ```prerun.sh``` which is generally just used to copy the build
directory between stages.

* In each stage directory loop through each subdirectory and then run each of the
install scripts it contains, again in alphanumeric order. These need to be named
with a two digit padded number at the beginning.
There are a number of different files and directories which can be used to
control different parts of the build process:

- **00-run.sh** - A unix shell script. Needs to be made executable for it to run

- **00-run-chroot.sh** - A unix shell script which will be run in the chroot
of the image build directory. Needs to be made executable for it to run.

- **00-debconf** - Contents of this file are passed to debconf-set-selections
to configure things like locale, etc.

- **00-packages** - A list of packages to install. Can have more than one, space
separated, per line.

- **00-packages-nr** - As 00-packages, except these will be installed using
the ```--no-install-recommends -y``` parameters to apt-get

- **00-patches** - A directory containing patch files to be applied

* If the stage directory contains files called "EXPORT_NOOBS" or "EXPORT_IMAGE" then
add this stage to a list of images to generate

* Generate the images for any stages that have specified them

It is recommended to examine build.sh for finer details.


## Docker Build

```bash
Expand Down Expand Up @@ -135,11 +201,11 @@ maintenance and allows for more easy customization.
modification to prevent ssh from being disabled.

There are a few tools that may not make a whole lot of sense here for
development purposes on a minimal system such as basic python and lua
development purposes on a minimal system such as basic Python and Lua
packages as well as the `build-essential` package. They are lumped right
in with more essential packages presently, though they need not be with
pi-gen. These are understandable for Raspbian's target audience, but if
you were looking for something between truly minimal and Raspbian-lite,
you were looking for something between truly minimal and Raspbian-Lite,
here's where you start trimming.

- **Stage 3** - the HASSbian stage. This is where all the Home Assistant
Expand Down Expand Up @@ -169,6 +235,31 @@ from `./stage2` (if building a minimal system).
# Example for building a lite system
echo "IMG_NAME='Raspbian'" > config
touch ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP
rm stage4/EXPORT*
rm stage4/EXPORT* stage5/EXPORT*
sudo ./build.sh # or ./build-docker.sh
```
<<<<<<< HEAD
=======

If you wish to build further configurations upon (for example) the lite
system, you can also delete the contents of `./stage3` and `./stage4` and
replace with your own contents in the same format.


## Skipping stages to speed up development

If you're working on a specific stage the recommended development process is as
follows:

* Add a file called SKIP_IMAGES into the directories containing EXPORT_* files
(currently stage2, stage4 and stage5)
* Add SKIP files to the stages you don't want to build. For example, if you're
basing your image on the lite image you would add these to stages 3, 4 and 5.
* Run build.sh to build all stages
* Add SKIP files to the earlier successfully built stages
* Modify the last stage
* Rebuild just the last stage using ```sudo CLEAN=1 ./build.sh```
* Once you're happy with the image you can remove the SKIP_IMAGES files and
export your image to test

>>>>>>> 066eb03d52868290661e813738a9a66eda263aa9
29 changes: 17 additions & 12 deletions build-docker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash -e

DOCKER="docker"
set +e
$DOCKER ps >/dev/null 2>&1
Expand All @@ -12,9 +13,9 @@ if ! $DOCKER ps >/dev/null; then
fi
set -e

config_mount="/dev/null:/dev/null"
config_file=()
if [ -f config ]; then
config_mount="$(pwd)/config:/pi-gen/config:ro"
config_file=("--env-file" "$(pwd)/config")
source config
fi

Expand All @@ -23,15 +24,15 @@ CONTINUE=${CONTINUE:-0}

if [ "$*" != "" ] || [ -z "${IMG_NAME}" ]; then
if [ -z "${IMG_NAME}" ]; then
echo "IMG_NAME not set in 'build'" 1>&2
echo "IMG_NAME not set in 'config'" 1>&2
echo 1>&2
fi
cat >&2 <<EOF
Usage:
build-docker.sh [options]
Optional environment arguments: ( =<default> )
CONTAINER_NAME=pigen_work set a name for the build container
CONTINUE=0 continue from a previously started container
CONTINUE=1 continue from a previously started container
EOF
exit 1
fi
Expand All @@ -45,31 +46,35 @@ fi
if [ "$CONTAINER_EXISTS" != "" ] && [ "$CONTINUE" != "1" ]; then
echo "Container $CONTAINER_NAME already exists and you did not specify CONTINUE=1. Aborting."
echo "You can delete the existing container like this:"
echo " docker rm -v $CONTAINER_NAME"
echo " $DOCKER rm -v $CONTAINER_NAME"
exit 1
fi

$DOCKER build -t pi-gen .
if [ "$CONTAINER_EXISTS" != "" ]; then
trap "echo 'got CTRL+C... please wait 5s';docker stop -t 5 ${CONTAINER_NAME}_cont" SIGINT SIGTERM
trap "echo 'got CTRL+C... please wait 5s'; $DOCKER stop -t 5 ${CONTAINER_NAME}_cont" SIGINT SIGTERM
time $DOCKER run --rm --privileged \
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
-e IMG_NAME=${IMG_NAME}\
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
cd /pi-gen; ./build.sh;
rsync -av work/*/build.log deploy/" &
wait
wait "$!"
else
trap "echo 'got CTRL+C... please wait 5s'; docker stop -t 5 ${CONTAINER_NAME}" SIGINT SIGTERM
$DOCKER run --name "${CONTAINER_NAME}" --privileged \
trap "echo 'got CTRL+C... please wait 5s'; $DOCKER stop -t 5 ${CONTAINER_NAME}" SIGINT SIGTERM
time $DOCKER run --name "${CONTAINER_NAME}" --privileged \
-e IMG_NAME=${IMG_NAME}\
-v "$(pwd)/deploy:/pi-gen/deploy" \
-v "${config_mount}" \
"${config_file[@]}" \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
cd /pi-gen; ./build.sh &&
rsync -av work/*/build.log deploy/" &
wait
wait "$!"
fi
echo "copying results from deploy/"
$DOCKER cp "${CONTAINER_NAME}":/pi-gen/deploy .
ls -lah deploy
$DOCKER rm -v $CONTAINER_NAME

echo "Done! Your image(s) should be in deploy/"
18 changes: 12 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ run_stage(){
unmount ${WORK_DIR}/${STAGE}
STAGE_WORK_DIR=${WORK_DIR}/${STAGE}
ROOTFS_DIR=${STAGE_WORK_DIR}/rootfs
if [ -f ${STAGE_DIR}/EXPORT_IMAGE ]; then
EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}"
if [ ! -f SKIP_IMAGES ]; then
if [ -f ${STAGE_DIR}/EXPORT_IMAGE ]; then
EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}"
fi
fi
if [ ! -f SKIP ]; then
if [ "${CLEAN}" = "1" ]; then
Expand Down Expand Up @@ -119,6 +121,7 @@ if [ "$(id -u)" != "0" ]; then
exit 1
fi


if [ -f config ]; then
source config
fi
Expand All @@ -128,6 +131,7 @@ if [ -z "${IMG_NAME}" ]; then
exit 1
fi

export USE_QEMU=${USE_QEMU:-0}
export IMG_DATE=${IMG_DATE:-"$(date +%Y-%m-%d)"}

export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Expand Down Expand Up @@ -177,10 +181,12 @@ for EXPORT_DIR in ${EXPORT_DIRS}; do
source "${EXPORT_DIR}/EXPORT_IMAGE"
EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename ${EXPORT_DIR})/rootfs
run_stage
if [ -e ${EXPORT_DIR}/EXPORT_NOOBS ]; then
source ${EXPORT_DIR}/EXPORT_NOOBS
STAGE_DIR=${BASE_DIR}/export-noobs
run_stage
if [ "${USE_QEMU}" != "1" ]; then
if [ -e ${EXPORT_DIR}/EXPORT_NOOBS ]; then
source ${EXPORT_DIR}/EXPORT_NOOBS
STAGE_DIR=${BASE_DIR}/export-noobs
run_stage
fi
fi
done

Expand Down
5 changes: 4 additions & 1 deletion depends
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ mkdosfs:dosfstools
capsh:libcap2-bin
bsdtar
grep
rsync
rsync
xz:xz-utils
curl
xxd
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '2'

services:
apt-cacher-ng:
restart: unless-stopped
image: sameersbn/apt-cacher-ng:latest
ports:
- "3142:3142"
volumes:
- ./apt-cacher-ng:/var/cache/apt-cacher-ng
1 change: 1 addition & 0 deletions export-image/00-allow-rerun/files/policy-rc.d
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh

exit 101
6 changes: 3 additions & 3 deletions export-image/01-set-sources/00-patches/0-sources.diff
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Index: export-jessie/rootfs/etc/apt/sources.list.d/raspi.list
--- export-jessie.orig/rootfs/etc/apt/sources.list.d/raspi.list
+++ export-jessie/rootfs/etc/apt/sources.list.d/raspi.list
@@ -1,3 +1,3 @@
-deb http://archive.raspberrypi.org/debian/ jessie main ui staging
+deb http://archive.raspberrypi.org/debian/ jessie main ui
-deb http://archive.raspberrypi.org/debian/ stretch main ui staging
+deb http://archive.raspberrypi.org/debian/ stretch main ui
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspberrypi.org/debian/ jessie main ui
#deb-src http://archive.raspberrypi.org/debian/ stretch main ui
2 changes: 1 addition & 1 deletion export-image/02-network/01-run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#/bin/bash -e
#!/bin/bash -e

install -m 644 files/resolv.conf ${ROOTFS_DIR}/etc/
3 changes: 2 additions & 1 deletion export-image/03-set-partuuid/00-run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash -e

IMG_FILE="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img"

IMGID="$(fdisk -l ${IMG_FILE} | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p')"
IMGID="$(dd if=${IMG_FILE} skip=440 bs=1 count=4 2>/dev/null | xxd -e | cut -f 2 -d' ')"

BOOT_PARTUUID="${IMGID}-01"
ROOT_PARTUUID="${IMGID}-02"
Expand Down
Loading

0 comments on commit f167815

Please sign in to comment.