pull/4/merge
Charles Cross 2016-05-02 21:28:23 +00:00
commit e4aa699043
14 changed files with 304 additions and 4 deletions

View File

@ -8,3 +8,7 @@
#Dependencies
`quilt kpartx realpath qemu-user-static debootstrap zerofree`
# Example usage to build a bootable raspbian lite image:
sudo ./build.sh
sudo ./create-image.sh --path=./work/2016-05-02-raspbian/stage3 --name="raspbian-lite"

View File

@ -3,8 +3,13 @@
run_sub_stage()
{
log "Begin ${SUB_STAGE_DIR}"
pushd ${SUB_STAGE_DIR} > /dev/null
# Loop through each substage
for i in {00..99}; do
# Check for debconf stage
if [ -f ${i}-debconf ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-debconf"
on_chroot sh -e - << EOF
@ -14,6 +19,8 @@ SELEOF
EOF
log "End ${SUB_STAGE_DIR}/${i}-debconf"
fi
# Install any packages with no-install-recommends set
if [ -f ${i}-packages-nr ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
PACKAGES=`cat $i-packages-nr | tr '\n' ' '`
@ -24,6 +31,8 @@ EOF
fi
log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
fi
# Install any packages normally
if [ -f ${i}-packages ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-packages"
PACKAGES=`cat $i-packages | tr '\n' ' '`
@ -34,6 +43,8 @@ EOF
fi
log "End ${SUB_STAGE_DIR}/${i}-packages"
fi
# Apply any patches
if [ -d ${i}-patches ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-patches"
pushd ${STAGE_WORK_DIR} > /dev/null
@ -60,11 +71,15 @@ EOF
popd > /dev/null
log "End ${SUB_STAGE_DIR}/${i}-patches"
fi
# Run the substages run script
if [ -x ${i}-run.sh ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-run.sh"
./${i}-run.sh
log "End ${SUB_STAGE_DIR}/${i}-run.sh"
fi
# Run the substages chroot script
if [ -f ${i}-run-chroot ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-run-chroot"
on_chroot sh -e - < ${i}-run-chroot
@ -77,49 +92,77 @@ EOF
run_stage(){
log "Begin ${STAGE_DIR}"
pushd ${STAGE_DIR} > /dev/null
# Unmount this stage's folder on the filesystem
unmount ${WORK_DIR}/${STAGE}
# Set the working directory for this stage
STAGE_WORK_DIR=${WORK_DIR}/${STAGE}
# Set the root directory for this stage
ROOTFS_DIR=${STAGE_WORK_DIR}/rootfs
# Check to see if we should skip this stage (seemingly never)
if [ ! -f SKIP ]; then
# Clean the rootfs, if requested
if [ "${CLEAN}" = "1" ]; then
if [ -d ${ROOTFS_DIR} ]; then
rm -rf ${ROOTFS_DIR}
fi
fi
# Run the pre-run script
if [ -x prerun.sh ]; then
log "Begin ${STAGE_DIR}/prerun.sh"
./prerun.sh
log "End ${STAGE_DIR}/prerun.sh"
fi
# For each substage, run the run_sub_stage command for it
for SUB_STAGE_DIR in ${STAGE_DIR}/*; do
if [ -d ${SUB_STAGE_DIR} ]; then
run_sub_stage
fi
done
fi
# Unmount the stag again
unmount ${WORK_DIR}/${STAGE}
# Set the previous stage info to this stage for the next stage to use
PREV_STAGE=${STAGE}
PREV_STAGE_DIR=${STAGE_DIR}
PREV_ROOTFS_DIR=${ROOTFS_DIR}
popd > /dev/null
log "End ${STAGE_DIR}"
}
# Require Root to run
if [ "$(id -u)" != "0" ]; then
echo "Please run as root" 1>&2
exit 1
fi
# Source a config file if it exists
if [ -f config ]; then
source config
fi
# Set image name
#TODO: Add way to set this, plus defaults. Defaulting to raspbian for now
IMG_NAME="raspbian"
if [ -z "${IMG_NAME}" ]; then
echo "IMG_NAME not set" 1>&2
exit 1
fi
# Set other env variables
export IMG_DATE=${IMG_DATE:-"$(date -u +%Y-%m-%d)"}
export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@ -151,9 +194,11 @@ export -f on_chroot
export -f copy_previous
export -f update_issue
# Create working directory
mkdir -p ${WORK_DIR}
log "Begin ${BASE_DIR}"
# Successively build each stage
for STAGE_DIR in ${BASE_DIR}/stage*; do
STAGE=$(basename ${STAGE_DIR})
run_stage

156
create-image.sh Executable file
View File

@ -0,0 +1,156 @@
#!/bin/bash
for i in "$@"
do
case $i in
# Path to the working directory from which to build the image
-p=*|--path=*)
WORKSPACE_PATH="${i#*=}"
shift
;;
# Name for image
-n=*|--name=*)
IMAGE_NAME="${i#*=}"
shift
;;
# unknown option
*)
;;
esac
done
if [ ${EUID} -ne 0 ]; then
echo "this tool must be run as root"
exit 1
fi
if [ -z "$IMAGE_NAME" ]
then
echo "No image name specified, defaulting to \"raspbian\""
IMAGE_NAME="raspbian"
fi
if [ -z "$WORKSPACE_PATH" ]
then
echo "You must specify a workspace path. Ex) --path=./work/2016-05-02-openrov/stage3"
exit 2
fi
work_path=$(readlink -f $WORKSPACE_PATH)
if [ ! -d "$work_path" ]
then
echo "Error resolving workspace path. Does not exist: work_path=\"${work_path}\""
exit 3
fi
echo "Creating image using rootfs in: ${work_path}"
bootsize="64M"
deb_release="jessie"
# define destination folder where created image file will be stored
buildenv="${PWD}/rpi"
# Set directory of rootfs and bootfs
rootfs="${buildenv}/rootfs"
bootfs="${buildenv}/boot"
today=`date +%Y%m%d`
mkdir -p ${buildenv}
mkdir -p ${buildenv}/images
# Construct image name
image="${buildenv}/images/${IMAGE_NAME}_${deb_release}_${today}.img"
# Create a blank image file
dd if=/dev/zero of=${image} bs=1MB count=3800
# Mount it on the loop back adapter
device=`losetup -f --show ${image}`
echo "image ${image} created and mounted as ${device}"
# Set up partition descriptor
fdisk ${device} << EOF
n
p
1
+${bootsize}
t
c
n
p
2
w
EOF
if [ "${image}" != "" ]; then
# Delete the loopback device
losetup -d ${device}
# Mount the disk image
device=`kpartx -va ${image} | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
echo device
device="/dev/mapper/${device}"
echo device
# Get paths to boot and root partitions
bootp=${device}p1
rootp=${device}p2
fi
# Create the filesystems
mkfs.vfat ${bootp}
mkfs.ext4 ${rootp}
# Set the path to the rootfs
mkdir -p ${rootfs}
# Mount the rootfs to the root partition
mount ${rootp} ${rootfs}
# copy
rootfs_work="${work_path}/rootfs"
rsync -a ${rootfs_work}/ ${rootfs}
# Remove the contents of the boot folder, but not the boot folder itself
rm -rf ${rootfs}/boot/*
#unmount
umount ${rootp}
sync
bootfs_work="${rootfs_work}/boot"
mkdir -p ${bootfs}
mount ${bootp} ${bootfs}
cp -R ${bootfs_work}/* ${bootfs}
umount ${bootfs}
sync
rm -rf ${rootfs}
rm -rf ${bootfs}
# Remove device mapper bindings. Avoids running out of loop devices if run repeatedly.
dmsetup remove_all
echo "finishing ${image}"
if [ "${image}" != "" ]; then
kpartx -d ${image}
echo "created image ${image}"
fi
echo "done."

View File

@ -63,6 +63,11 @@ on_chroot() {
chroot ${ROOTFS_DIR}/ "$@"
}
# This should be used if building on a system that uses systemd (?)
on_chroot2() {
systemd-nspawn -D ${ROOTFS_DIR}/ "$@"
}
update_issue() {
echo -e "Raspberry Pi reference ${DATE}\nGenerated using Pi-gen, https://github.com/RPi-Distro/Pi-gen, ${1}" > ${ROOTFS_DIR}/etc/rpi-issue
}

View File

@ -1,8 +1,10 @@
#!/bin/bash -e
# Install source lists
install -m 644 files/sources.list ${ROOTFS_DIR}/etc/apt/
install -m 644 files/raspi.list ${ROOTFS_DIR}/etc/apt/sources.list.d/
# Set up proxy, if it exists
if [ -n "$APT_PROXY" ]; then
install -m 644 files/51cache ${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache
sed ${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache -i -e "s|APT_PROXY|${APT_PROXY}|"
@ -10,8 +12,13 @@ else
rm -f ${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache
fi
# Add the raspberry pi gpg key
on_chroot apt-key add - < files/raspberrypi.gpg.key
# Update and dist upgrade
on_chroot sh -e - << EOF
apt-get update
apt-get dist-upgrade -y
EOF

View File

@ -3,7 +3,7 @@
install -d ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d
install -m 644 files/noclear.conf ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/noclear.conf
install -m 744 files/policy-rc.d ${ROOTFS_DIR}/usr/sbin/policy-rc.d
#install -v -m 644 files/fstab ${ROOTFS_DIR}/etc/fstab TODO: Necessary in systemd?
install -v -m 644 files/fstab ${ROOTFS_DIR}/etc/fstab
on_chroot sh -e - <<EOF
if ! id -u pi >/dev/null 2>&1; then

View File

@ -1,3 +1,5 @@
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p1 /boot vfat defaults,noatime 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
tmpfs /tmp tmpfs defaults,noatime,nodev,nosuid,mode=1777 0 0
tmpfs /var/log tmpfs defaults,size=20m,noatime,nodev,nosuid,mode=1777 0 0

File diff suppressed because one or more lines are too long

View File

@ -10,6 +10,11 @@ install -m 644 files/ttyoutput.conf ${ROOTFS_DIR}/etc/systemd/system/rc-local.
install -m 644 files/50raspi ${ROOTFS_DIR}/etc/apt/apt.conf.d/
install -m 644 files/98-rpi.conf ${ROOTFS_DIR}/etc/sysctl.d/
on_chroot sh -e - <<EOF
# Update locales
dpkg-reconfigure --frontend=noninteractive locales
update-locale LANG=en_US.UTF-8
EOF
on_chroot sh -e - <<EOF
systemctl disable hwclock.sh

View File

@ -0,0 +1,5 @@
#!/bin/bash -ex
install -m 644 files/cmdline.txt ${ROOTFS_DIR}/boot/
install -m 644 files/config.txt ${ROOTFS_DIR}/boot/
install -m 644 files/interfaces ${ROOTFS_DIR}/etc/network/

View File

@ -0,0 +1 @@
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

View File

@ -0,0 +1,59 @@
# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# Some settings may impact device functionality. See link above for details
# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1
# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1
# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16
# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720
# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2
# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4
# uncomment for composite PAL
#sdtv_mode=2
#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi
# Additional overlays and parameters are documented /boot/overlays/README
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# Disable bluetooth and move UART back to the original pllc
dtoverlay=pi3-disable-bt

View File

@ -0,0 +1,11 @@
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug eth0
iface eth0 inet dhcp
metric 0
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1