commit 45bcaa9172790390a4ac2b38575128ae6a39b0b9 Author: Benjamin Böhmke Date: Sat Nov 2 14:41:03 2019 +0100 initial version diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..16cb457 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM alpine:3.10 + +RUN apk update && \ + apk add automake build-base git autoconf confuse-dev linux-headers \ + findutils mtools e2fsprogs-extra alpine-sdk dosfstools && \ + rm -rf /var/cache/apk/* + +RUN git clone https://github.com/pengutronix/genimage.git /tmp/genimage && \ + cd /tmp/genimage && \ + ./autogen.sh && \ + ./configure CFLAGS='-g -O0' --prefix=/usr && \ + make install && \ + cd && \ + rm -rf /tmp/genimage + + +ADD ./resources/genext2fs /genext2fs + +RUN cd /genext2fs && \ + abuild-keygen -a -i -q && \ + abuild -F -P /tmp/pkg && \ + apk add /tmp/pkg/x86_64/genext2fs-1*.apk && \ + rm -rf /tmp/pkg/ + +ADD ./resources /resources + +WORKDIR /work diff --git a/resources/build.sh b/resources/build.sh new file mode 100755 index 0000000..f6bac4c --- /dev/null +++ b/resources/build.sh @@ -0,0 +1,283 @@ + #!/bin/bash +set -e + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# User config +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +: ${ALPINE_BRANCH:="3.10"} +: ${ALPINE_MIRROR:="http://dl-cdn.alpinelinux.org/alpine"} + +: ${TIME_ZONE:="Etc/UTC"} +: ${HOST_NAME:="alpine"} +: ${ROOT_PASSWORD:="alpine"} +: ${IMG_NAME:="alpine-${ALPINE_BRANCH}-sdcard.img"} + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# static config +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +RES_PATH=/resources/ +BASE_PACKAGES="alpine-base tzdata parted ifupdown e2fsprogs-extra util-linux coreutils linux-rpi2" + +WORK_PATH="/work" +OUTPUT_PATH="/output" +ROOTFS_PATH="${WORK_PATH}/root_fs" +BOOTFS_PATH="${WORK_PATH}/boot_fs" +DATAFS_PATH="${WORK_PATH}/data_fs" +IMAGE_PATH="${WORK_PATH}/img" + + +# ensure work directory is clean +rm -rf ${WORK_PATH}/* + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# functions +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +chroot_exec() { + chroot "${ROOTFS_PATH}" "$@" 1>&2 +} + +make_image() { + [ -d /tmp/genimage ] && rm -rf /tmp/genimage + genimage --rootpath $1 \ + --tmppath /tmp/genimage \ + --inputpath ${IMAGE_PATH} \ + --outputpath ${IMAGE_PATH} \ + --config $2 +} + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# create root FS +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +echo ">> Prepare root FS" + +# update local repositories to destination ones to ensure the right packages where installed +cat >/etc/apk/repositories < ${ROOTFS_PATH}/etc/resolv.conf + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +echo ">> Configure root FS" + +# set root password +chroot_exec passwd << EOF +${ROOT_PASSWORD} +${ROOT_PASSWORD} +EOF + +# Set time zone +echo "${TIME_ZONE}" > ${ROOTFS_PATH}/etc/timezone +chroot_exec ln -fs /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime + +# Set host name +chroot_exec rc-update add hostname default +cat >${ROOTFS_PATH}/etc/hosts <${ROOTFS_PATH}/etc/hostname <${ROOTFS_PATH}/etc/conf.d/local <${ROOTFS_PATH}/etc/network/interfaces < local brings up the interface +sed -i '/^\tneed/ s/$/ local/' ${ROOTFS_PATH}/etc/init.d/networking + +# bring up eth0 on startup +cat >${ROOTFS_PATH}/etc/local.d/11-up_eth0.start <${ROOTFS_PATH}/etc/local.d/10-remount_root.start <${ROOTFS_PATH}/etc/fstab <> Configure boot FS" + +# download base firmware +mkdir -p ${BOOTFS_PATH} +wget -P ${BOOTFS_PATH} https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin +wget -P ${BOOTFS_PATH} https://github.com/raspberrypi/firmware/raw/master/boot/fixup.dat +wget -P ${BOOTFS_PATH} https://github.com/raspberrypi/firmware/raw/master/boot/fixup_cd.dat +wget -P ${BOOTFS_PATH} https://github.com/raspberrypi/firmware/raw/master/boot/fixup_x.dat +wget -P ${BOOTFS_PATH} https://github.com/raspberrypi/firmware/raw/master/boot/start.elf +wget -P ${BOOTFS_PATH} https://github.com/raspberrypi/firmware/raw/master/boot/start_cd.elf +wget -P ${BOOTFS_PATH} https://github.com/raspberrypi/firmware/raw/master/boot/start_x.elf + +# copy linux kernel and overlays +cp ${ROOTFS_PATH}/usr/lib/linux-*-rpi2/*.dtb ${BOOTFS_PATH}/ +cp -r ${ROOTFS_PATH}/usr/lib/linux-*-rpi2/overlays ${BOOTFS_PATH}/ +cp ${ROOTFS_PATH}/boot/initramfs-rpi2 ${BOOTFS_PATH}/ +cp ${ROOTFS_PATH}/boot/vmlinuz-rpi2 ${BOOTFS_PATH}/ + +# write boot config +cat >${BOOTFS_PATH}/config.txt <${BOOTFS_PATH}/cmdline.txt <> Configure data FS" +mkdir -p ${DATAFS_PATH} + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# create image +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +echo ">> Create SD card image" + +# boot partition +cat >${WORK_PATH}/genimage_boot.cfg <${WORK_PATH}/genimage_root.cfg <${WORK_PATH}/genimage_data.cfg <${WORK_PATH}/genimage_sdcard.cfg < +pkgname=genext2fs +pkgver=1.4.1 +pkgrel=0 +pkgdesc="Tool for generating an ext2 filesystem as non-root" +url="http://genext2fs.sourceforge.net/" +arch="all" +license="GPLv2" +depends="" +depends_dev="" +makedepends="$depends_dev" +install="" +subpackages="$pkgname-doc" +source="http://downloads.sourceforge.net/project/genext2fs/genext2fs/$pkgver/genext2fs-$pkgver.tar.gz" +_builddir="$srcdir"/genext2fs-$pkgver +prepare() { + local i + cd "$_builddir" + for i in $source; do + case $i in + *.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;; + esac + done +} +build() { + cd "$_builddir" + ./configure \ + --build=$CBUILD \ + --host=$CHOST \ + --prefix=/usr \ + --sysconfdir=/etc \ + --mandir=/usr/share/man \ + --infodir=/usr/share/info \ + --localstatedir=/var \ + || return 1 + make || return 1 +} +package() { + cd "$_builddir" + make DESTDIR="$pkgdir" install || return 1 +} +md5sums="b7b6361bcce2cedff1ae437fadafe53b genext2fs-1.4.1.tar.gz" +sha256sums="404dbbfa7a86a6c3de8225c8da254d026b17fd288e05cec4df2cc7e1f4feecfc genext2fs-1.4.1.tar.gz" +sha512sums="1b9ec7044014423345ae6b09862ba6903f5b3e0f68fb8bbcf97daf2705471cc1633a9fdbc5e00afe1b191e1af7bed87bde2e538bc7365469218f2a00b062845c genext2fs-1.4.1.tar.gz" diff --git a/resources/resizedata.sh b/resources/resizedata.sh new file mode 100755 index 0000000..a43544e --- /dev/null +++ b/resources/resizedata.sh @@ -0,0 +1,63 @@ +#!/bin/sh -e +logger -t "rc.resizedata" "Expanding root partition" + +# Detect root partition device +ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p') +if [ -z "$ROOT_PART" ] ; then + log_warning_msg "unable to detect root partition device" + return 1 +fi + +# Extract root device name +case "${ROOT_PART}" in + mmcblk0*) ROOT_DEV=mmcblk0 ;; + sda*) ROOT_DEV=sda ;; +esac + +# get last partition +LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:) +LAST_PART="${ROOT_DEV}p${LAST_PART_NUM}" + + +# unmount if mounted +if grep -qs "/dev/${LAST_PART}" /proc/mounts; then + umount /dev/${LAST_PART} +fi + +# Get the starting offset of last partition +PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${LAST_PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g') +if [ -z "$PART_START" ] ; then + logger -t "rc.resizedata" "${ROOT_DEV} unable to get starting sector of the partition" + return 1 +fi + +# Get the possible last sector for the root partition +PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }') +if [ -z "$PART_LAST" ] ; then + logger -t "rc.resizedata" "${ROOT_DEV} unable to get last sector of the partition" + return 1 +fi + +### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit +echo "resize partition" +fdisk /dev/${ROOT_DEV} > /dev/null <