diff options
author | Sven Gothel <[email protected]> | 2021-07-17 04:02:01 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-07-17 04:02:01 +0200 |
commit | 2b4a8503024e3c83ac4ed7380bddc371c8982619 (patch) | |
tree | 8b5a15f7b1d053954113be2ac46f47ac4f3a0f5c | |
parent | 5b08e3535f61ab7dde7c7651382b2095e25bc717 (diff) |
multi-arch: Support vanilla Debian for 'amd64' and 'i386' architecture incl. loop_rootfs using grub (WIP)
- Generic packages: nn-packages[-RELEASE] (using the optional '-RELEASE' variant)
- System packages: nn-packages-sys-(raspi|debian)[-RELEASE] (using the optional '-RELEASE' variant),
allow to distinguish not only for the RELEASE but the actual underlying distribution.
- On debian amd64, all required usb-storage etc modules are loaded for loop_rootfs/initrd
- loop_rootfs works on Raspi (Proprietary Bootloader) as well as on Debian (Grub Bootloader)
- loop_rootfs uses the first vfat block-device partition for /boot
- /boot will be mounted by loop_rootfs and handed over to new root-mount-point,
this avoids issues of using an undefined /boot partition (but the first)
- rotatelog_init_rootfs: Rotates /boot/init_rootfs.log if having more than 500 lines
- FIX export-image: Copy the rootfs.img to the exported full image,
which allows testing the image directly via qemu .. etc.
69 files changed, 1336 insertions, 655 deletions
@@ -40,9 +40,18 @@ package is `<tool>[:<debian-package>]`. ## Config -Upon execution, `build.sh` will source the file `config` in the current -working directory. This bash shell fragment is intended to set needed -environment variables. +Upon execution, `build.sh` will source the optional given config file, e.g.: + +```bash + build.sh -c myconfig.cfg +``` +The given config file is a bash shell fragment, intended to set needed environment variables. + +It is also possible to use default values for all or most variables, e.g.: + +```bash + IMG_NAME='Raspbian' build.sh +``` The following environment variables are supported: @@ -53,16 +62,42 @@ The following environment variables are supported: but you should use something else for a customized version. Export files in stages may add suffixes to `IMG_NAME`. -* `INSTALL_RECOMMENDS` (Default: unset) + * `TARGET_RASPI` (Default: `1`) + + If set to `0` (or other than `1`), the `Raspbian` `apt` source + and its packages are **not** being used, i.e. ending up with a vanilla `Debian` installation. + + Further `Raspberry` specific tasks are not performed: + * /boot/config.txt + * /boot/*/cmdline.txt + * /boot/ any specific `Raspberry` bootloader + + instead, the default tasks are being used: + * Install grub + + * `TARGET_ARCH` (Default: `arm64`) + + Maybe set to any valid and supported architecture, which are + * arm64 + * armhf + * i386 + * amd64 + +* `RELEASE` (Default: `buster`) + + The release version to build images against. Valid values are `jessie`, `stretch`, + `buster` and `bullseye`. + + * `INSTALL_RECOMMENDS` (Default: unset) If set to one, i.e. `INSTALL_RECOMMENDS=1`, installation process will install recommended packages. Otherwise (default): - * apt selection without recommended and suggested + * apt selection without recommended and suggested Note: `apt cache` is disabled for all target configurations. -* `ROOTFS_RO` (Default: unset) + * `ROOTFS_RO` (Default: unset) If set to one, i.e. `ROOTFS_RO=1`, the root filesystem will be set read-only, an `initramfs` is used to load it via `loopfs` @@ -78,27 +113,27 @@ The following environment variables are supported: the ssh host keys are retained while `regenerate_ssh_host_keys` is disabled and the final `/boot/config.txt` has `splash` disabled (no rainbow). -* `REDUCED_FOOTPRINT` (Default: unset) + * `REDUCED_FOOTPRINT` (Default: unset) If set to one, i.e. `REDUCED_FOOTPRINT=1`, installation will attempt to keep the footprint as small as possible. This is intended for small devices, perhaps in addition to `ROOTFS_RO=1`. The following efforts are made: - * apt selection without recommended and suggested - * [Reduced Disk Footprint (Ubuntu)](https://wiki.ubuntu.com/ReducingDiskFootprint#Documentation) for - most `/usr/share/doc` and most `locale`s but [ `en*`, `da*`, `de*`, `es*`, `fi*`, `fr*`, `is*`, `nb*`, `ru*`, `sv*`, `zh*` ], - i.e. includes [`locale`](https://www.localeplanet.com/icu/) for - * English `en` - * Danish `da` - * German `de` - * Icelandic `is` - * Spanish `es` - * Finnish `fi` - * French `fr` - * Norwegian Bokmål `nb` - * Russia `nb` - * Swedish `sv` - * Chinese `zh` + * apt selection without recommended and suggested + * [Reduced Disk Footprint (Ubuntu)](https://wiki.ubuntu.com/ReducingDiskFootprint#Documentation) for + most `/usr/share/doc` and most `locale`s but [ `en*`, `da*`, `de*`, `es*`, `fi*`, `fr*`, `is*`, `nb*`, `ru*`, `sv*`, `zh*` ], + i.e. includes [`locale`](https://www.localeplanet.com/icu/) for + * English `en` + * Danish `da` + * German `de` + * Icelandic `is` + * Spanish `es` + * Finnish `fi` + * French `fr` + * Norwegian Bokmål `nb` + * Russia `nb` + * Swedish `sv` + * Chinese `zh` It is also **recommended** to not include *stage3b* *stage4* and *stage5* for a small embedded system, as they contain heavy window-manager and broader desktop applications, etc. @@ -107,7 +142,7 @@ The following environment variables are supported: Note: `apt cache` is disabled for all target configurations. -* `BASE_QCOW2_SIZE` (Default: 15200M) + * `BASE_QCOW2_SIZE` (Default: 15200M) Size of the virtual qcow2 disk given in multiples of 1024, i.e. KiB, MiB or GiB. Note: it will not actually use that much of space at once but defines the @@ -126,11 +161,6 @@ The following environment variables are supported: Safe: 15200 MiB ``` -* `RELEASE` (Default: buster) - - The release version to build images against. Valid values are jessie, stretch, - buster and bullseye - * `APT_PROXY` (Default: unset) If you require the use of an apt proxy, set it here. This proxy setting @@ -173,7 +203,7 @@ The following environment variables are supported: Setting to '1' enables the QEMU mode - creating an image that can be mounted via QEMU for an emulated environment. These images include "-qemu" in the image file name. - * `LOCALE_DEFAULT` (Default: "en_GB.UTF-8" ) + * `LOCALE_DEFAULT` (Default: "en_US.UTF-8" ) Default system locale. @@ -181,7 +211,7 @@ The following environment variables are supported: Setting the hostname to the specified value. - * `KEYBOARD_KEYMAP` (Default: "gb" ) + * `KEYBOARD_KEYMAP` (Default: "us" ) Default keyboard keymap. @@ -189,7 +219,7 @@ The following environment variables are supported: keyboard-configuration` and look at the `keyboard-configuration/xkb-keymap` value. - * `KEYBOARD_LAYOUT` (Default: "English (UK)" ) + * `KEYBOARD_LAYOUT` (Default: "English (US)" ) Default keyboard layout. @@ -197,7 +227,7 @@ The following environment variables are supported: keyboard-configuration` and look at the `keyboard-configuration/variant` value. - * `TIMEZONE_DEFAULT` (Default: "Europe/London" ) + * `TIMEZONE_DEFAULT` (Default: "Europe/Berlin" ) Default keyboard layout. @@ -220,13 +250,17 @@ The following environment variables are supported: Setting to `1` will enable ssh server for remote log in. Note that if you are using a common password such as the defaults there is a high risk of attackers taking over you Raspberry Pi. - * `PUBKEY_SSH_FIRST_USER` (Default: unset) + * `PUBKEY_SSH_FIRST_USER` (Default: unset) Setting this to a value will make that value the contents of the FIRST_USER_NAME's ~/.ssh/authorized_keys. Obviously the value should therefore be a valid authorized_keys file. Note that this does not automatically enable SSH. - * `PUBKEY_ONLY_SSH` (Default: `0`) + * `PUBKEY2_SSH_FIRST_USER` (Default: unset) + + Same as `PUBKEY_SSH_FIRST_USER`, but providing an optional second key for the first user. + + * `PUBKEY_ONLY_SSH` (Default: `0`) * Setting to `1` will disable password authentication for SSH and enable public key authentication. Note that if SSH is not enabled this will take @@ -236,67 +270,82 @@ The following environment variables are supported: If set, then instead of working through the numeric stages in order, this list will be followed. For example setting to `"stage0 stage1 mystage stage2"` will run the contents of `mystage` before stage2. Note that quotes are needed around the list. An absolute or relative path can be given for stages outside the pi-gen directory. -A simple example for building Raspbian: + * `SKIP_STAGE_LIST` (default: `""`) -```bash -IMG_NAME='Raspbian' -``` + Space separated list of stages, which shall not be processed, i.e. skipped. -The config file can also be specified on the command line as an argument the `build.sh` or `build-docker.sh` scripts. + * `SKIP_IMAGES_LIST` (default: `""`) -``` -./build.sh -c myconfig -``` + Space separated list of stages, which shall not produce file images. -This is parsed after `config` so can be used to override values set there. ## How the build process works -The following process is followed to build images: +The following process is performed 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" + * Move on to the next directory if this stage directory basename is listed within `SKIP_STAGE_LIST`. * 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: + * In each stage directory, loop through each subdirectory in alphanumeric order + and then process each of the files it contains. Both, the subdirectories as well as + the files to be processed need to be prefixed with a two digit padded number. - - **00-run.sh** - A unix shell script. Needs to be made executable for it to run. + The subdirectory's files to be processed are looped through `{00..99}`, + used as the two-digit loop index. - - **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. + If existing in the subdirectories, the following files will be processed + in the given order during one iteration, where `nn` refers to the current two digit loop index: - - **00-debconf** - Contents of this file are passed to debconf-set-selections + - ***nn*-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. + - ***nn*-packages-sys-(raspi|debian)[-*RELEASE*]** - List of system specific packages to install. + In case `TARGET_RASPI = "1"` (default), `nn-packages-sys-raspi` are being used, if existing. + + Otherwise `nn-packages-sys-debian` are being processed, if existing. - - **00-packages-nr** - As 00-packages, except these will be installed using - the ```--no-install-recommends -y``` parameters to apt-get. + If a `RELEASE` specific variant exists, e.g. `00-packages-sys-raspi-bullseye`, it will be used instead + of the generic `00-packages-sys-raspi`. - - **00-patches** - A directory containing patch files to be applied, using quilt. + - ***nn*-packages-nr[-*RELEASE*]** - A list of packages to install. Can have more than one, space + separated, per line. Will always use ```--no-install-recommends -y``` parameters + for apt-get, ignoring `INSTALL_RECOMMENDS`. + + If a `RELEASE` specific variant exists, e.g. `00-packages-nr-bullseye`, it will be used instead + of the generic `00-packages-nr`. + + - ***nn*-packages[-*RELEASE*]** - A list of packages to install. Can have more than one, space + separated, per line. Depending on `INSTALL_RECOMMENDS`, recommended packages will be + installed or not. + + If a `RELEASE` specific variant exists, e.g. `00-packages-bullseye`, it will be used instead + of the generic `00-packages`. + + - ***nn*-patches** - A directory containing patch files to be applied, using quilt. If a file named 'EDIT' is present in the directory, the build process will be interrupted with a bash session, allowing an opportunity to create/revise the patches. - * If the stage directory contains files called "EXPORT_NOOBS" or "EXPORT_IMAGE" then - add this stage to a list of images to generate + - ***nn*-run.sh** - A unix shell script. Needs to be made executable for it to run. - * Generate the images for any stages that have specified them + - ***nn*-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. + + * If the stage directory contains a file named `EXPORT_NOOBS` or `EXPORT_IMAGE` + and the stage directory basename is not listed within `SKIP_STAGE_LIST`, + the file images for this stage will be generated. It is recommended to examine build.sh for finer details. ## Docker Build +*Currently untested within this branch of pi-gen!* + Docker can be used to perform the build inside a container. This partially isolates the build from the host system, and allows using the script on non-debian based systems (e.g. Fedora Linux). The isolate is not complete due to the need to use @@ -305,8 +354,8 @@ some kernel level services for arm emulation (binfmt) and loop devices (losetup) To build: ```bash -vi config # Edit your config file. See above. -./build-docker.sh +vi myconfig.cfg # Edit your config file. See above. +./build-docker.sh -c myconfig.cfg ``` If everything goes well, your finished image will be in the `deploy/` folder. @@ -345,9 +394,9 @@ and `--privileged` options are already set by the script and should not be redef ## Stage Anatomy -### Raspbian Stage Overview +### Build Stage Overview -The build of Raspbian is divided up into several stages for logical clarity +The build is divided up into several stages for logical clarity and modularity. This causes some initial complexity, but it simplifies maintenance and allows for more easy customization. @@ -368,7 +417,7 @@ maintenance and allows for more easy customization. really usable yet in a traditional sense yet. Still, if you want minimal, this is minimal and the rest you could reasonably do yourself as sysadmin. - - **stage2** - lite system. This stage produces the Raspbian-Lite image. It + - **stage2** - `lite system`. This stage produces the `Lite image`. It installs some optimized memory functions, sets timezone and charmap defaults, installs fake-hwclock and ntp, wireless LAN and bluetooth support, dphys-swapfile, and other basics for managing the hardware. It also @@ -377,61 +426,55 @@ maintenance and allows for more easy customization. Python and Lua are included here, as they are often required by certain setup scripts. - - **stage3a** - litex system. Contains a minimal *xserver-xorg* subset and *dwm* with *stterm*, + - **stage3a** - `litex system`. Contains a minimal *xserver-xorg* subset and *dwm* with *stterm*, suitable for embedded systems using graphics. - - **stage3a_dev** - litexdev system. Contains full commandline development tools + - **stage3a_dev** - `litexdev system`. Contains full commandline development tools and developer library packages based on *stage3a* inclusive *build-essential*, gcc, clang, OpenJDK 11, etc. - - **stage3b** - desktop system. Contains a complete desktop system - with X11 and LXDE, web browsers, git for development, Raspbian custom UI - enhancements, etc. This is a base desktop system, with some development - tools installed. + - **stage3b** - `desktop system`. Contains a complete desktop system + with X11 and LXDE and web browsers. - - **stage4** - Normal Raspbian image. System meant to fit on a 4GB card. This is the - stage that installs most things that make Raspbian friendly to new - users like system documentation. + - **stage4** - `Python image`. System meant to fit on a 4GB card. This is the + stage that installs most things to be friendly to new + users like system documentation and most of `python`. - - **stage5** - The Raspbian Full image. More development + - **stage5** - Full image. More development tools, an email client, learning tools like Scratch, specialized packages like sonic-pi, office productivity, etc. ### Stage specification -If you wish to build up to a specified stage (such as building up to stage 2 -for a lite system), place an empty file named `SKIP` in each of the `./stage` -directories you wish not to include. +If you wish to build up to a specified stage (such as building up to `stage2` +for a lite system), include the stage directory basename in space separated variable `SKIP_STAGE_LIST`. -Then add an empty file named `SKIP_IMAGES` to `./stage4` and `./stage5` (if building up to stage 2) or -to `./stage2` (if building a minimal system). +If you wish to not build the file images of a stage, +include the stage directory basename in space separated variable `SKIP_IMAGES_LIST`. ```bash # Example for building a lite system -echo "IMG_NAME='Raspbian'" > config -touch ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP -touch ./stage4/SKIP_IMAGES ./stage5/SKIP_IMAGES -sudo ./build.sh # or ./build-docker.sh +echo "IMG_NAME='Raspbian'" > myconfig.cfg +echo "SKIP_STAGE_LIST='stage3 stage4 stage5'" >> myconfig.cfg +echo "SKIP_IMAGES_LIST='stage4 stage5'" >> myconfig.cfg +sudo ./build.sh -c myconfig.cfg # or ./build-docker.sh -c myconfig.cfg ``` 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. +system, you can create your own custom stages and specify `STAGE_LIST` accordingly. ## 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 +follows, assuming using `myconfig.cfg` for configuration: + + * Skip image production for all stages but your build target stage: + Add stage basenames to space separated variable `SKIP_IMAGES_LIST` in `myconfig.cfg`. + * Run `sudo build.sh -c myconfig.cfg` to build all stages + * Skip whole stages passed: Add stage basenames to space separated variable `SKIP_STAGE_LIST` in `myconfig.cfg`. * 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 + * Rebuild just the last stage using `sudo ./build.sh -c myconfig.cfg` + * Once you're happy with the image you can uncomment the `SKIP_STAGE_LIST` in your `myconfig.cfg` and export your image to test # Regarding Qcow2 image building @@ -1,8 +1,13 @@ #!/bin/bash -e +export DEBIAN_FRONTEND=noninteractive +export APT_GET_INSTALL_OPTS='-o APT::Acquire::Retries=3 -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"' + # shellcheck disable=SC2119 run_sub_stage() { + local packfile; + local PACKAGES; log "Begin ${SUB_STAGE_DIR}" pushd "${SUB_STAGE_DIR}" > /dev/null for i in {00..99}; do @@ -16,6 +21,47 @@ EOF log "End ${SUB_STAGE_DIR}/${i}-debconf" fi + if [ "${TARGET_RASPI}" = "1" -a \( -f "${i}-packages-sys-raspi" -o -f "${i}-packages-sys-raspi-${RELEASE}" \) ]; then + if [ -f "${i}-packages-sys-raspi-${RELEASE}" ]; then + packfile="${i}-packages-sys-raspi-${RELEASE}" + else + packfile="${i}-packages-sys-raspi" + fi + log "Begin ${SUB_STAGE_DIR}/${packfile}" + PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${packfile}")" + if [ -n "$PACKAGES" ]; then + on_chroot << EOF +echo "Installing ${packfile} '${PACKAGES}'" +apt-get ${APT_GET_INSTALL_OPTS} install --no-install-recommends -y $PACKAGES +EOF + if [ "${USE_QCOW2}" = "1" ]; then + on_chroot << EOF +apt-get clean +EOF + fi + fi + log "End ${SUB_STAGE_DIR}/${packfile}" + elif [ "${TARGET_RASPI}" != "1" -a \( -f "${i}-packages-sys-debian" -o -f "${i}-packages-sys-debian-${RELEASE}" \) ]; then + if [ -f "${i}-packages-sys-debian-${RELEASE}" ]; then + packfile="${i}-packages-sys-debian-${RELEASE}" + else + packfile="${i}-packages-sys-debian" + fi + log "Begin ${SUB_STAGE_DIR}/${packfile}" + PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${packfile}")" + if [ -n "$PACKAGES" ]; then + on_chroot << EOF +echo "Installing ${packfile} '${PACKAGES}'" +apt-get ${APT_GET_INSTALL_OPTS} install --no-install-recommends -y $PACKAGES +EOF + if [ "${USE_QCOW2}" = "1" ]; then + on_chroot << EOF +apt-get clean +EOF + fi + fi + log "End ${SUB_STAGE_DIR}/${packfile}" + fi if [ -f "${i}-packages-nr" -o -f "${i}-packages-nr-${RELEASE}" ]; then if [ -f "${i}-packages-nr-${RELEASE}" ]; then packfile="${i}-packages-nr-${RELEASE}" @@ -27,7 +73,7 @@ EOF if [ -n "$PACKAGES" ]; then on_chroot << EOF echo "Installing ${packfile} '${PACKAGES}'" -apt-get -o APT::Acquire::Retries=3 install --no-install-recommends -y $PACKAGES +apt-get ${APT_GET_INSTALL_OPTS} install --no-install-recommends -y $PACKAGES EOF if [ "${USE_QCOW2}" = "1" ]; then on_chroot << EOF @@ -49,10 +95,10 @@ EOF on_chroot << EOF echo "Installing ${packfile} '${PACKAGES}'" if [ "${INSTALL_RECOMMENDS}" != "1" -o "${REDUCED_FOOTPRINT}" = "1" ]; then - apt-get -o APT::Acquire::Retries=3 install --no-install-recommends -y $PACKAGES + apt-get ${APT_GET_INSTALL_OPTS} install --no-install-recommends -y $PACKAGES else # "${INSTALL_RECOMMENDS}" = "1" -a "${REDUCED_FOOTPRINT}" != "1" - apt-get -o APT::Acquire::Retries=3 install -y $PACKAGES + apt-get ${APT_GET_INSTALL_OPTS} install -y $PACKAGES fi EOF if [ "${USE_QCOW2}" = "1" ]; then @@ -107,9 +153,19 @@ EOF } +contains() { + if [[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]]; then + echo -n "1" + else + echo -n "0" + fi +} + run_stage(){ - log "Begin ${STAGE_DIR}" STAGE="$(basename "${STAGE_DIR}")" + SKIP_STAGE=`contains "${SKIP_STAGE_LIST}" ${STAGE}` + SKIP_IMAGES=`contains "${SKIP_IMAGES_LIST}" ${STAGE}` + log "Begin ${STAGE} ${STAGE_DIR} SKIP(STAGE ${SKIP_STAGE}, IMAGES ${SKIP_IMAGES})" pushd "${STAGE_DIR}" > /dev/null @@ -117,17 +173,17 @@ run_stage(){ ROOTFS_DIR="${STAGE_WORK_DIR}"/rootfs if [ "${USE_QCOW2}" = "1" ]; then - if [ ! -f SKIP ]; then + if [ "${SKIP_STAGE}" != "1" ]; then load_qimage fi fi - if [ ! -f SKIP_IMAGES ]; then + if [ "${SKIP_IMAGES}" != "1" ]; then if [ -f "${STAGE_DIR}/EXPORT_IMAGE" ]; then EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}" fi fi - if [ ! -f SKIP ]; then + if [ "${SKIP_STAGE}" != "1" ]; then if [ "${CLEAN}" = "1" ] && [ "${USE_QCOW2}" = "0" ] ; then if [ -d "${ROOTFS_DIR}" ]; then rm -rf "${ROOTFS_DIR}" @@ -139,7 +195,7 @@ run_stage(){ log "End ${STAGE_DIR}/prerun.sh" fi for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do - if [ -d "${SUB_STAGE_DIR}" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then + if [ -d "${SUB_STAGE_DIR}" ]; then run_sub_stage fi done @@ -164,17 +220,13 @@ fi BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export BASE_DIR -if [ -f config ]; then - # shellcheck disable=SC1091 - source config -fi - while getopts "c:" flag do case "$flag" in c) EXTRA_CONFIG="$OPTARG" # shellcheck disable=SC1090 + echo "Reading config from ${EXTRA_CONFIG}" source "$EXTRA_CONFIG" ;; *) @@ -215,18 +267,22 @@ export TARGET_HOSTNAME=${TARGET_HOSTNAME:-raspberrypi} export FIRST_USER_NAME=${FIRST_USER_NAME:-pi} export FIRST_USER_PASS=${FIRST_USER_PASS:-raspberry} export RELEASE=${RELEASE:-buster} + +export TARGET_RASPI="${TARGET_RASPI:-1}" +export TARGET_ARCH="${TARGET_ARCH:-arm64}" + export WPA_ESSID export WPA_PASSWORD export WPA_COUNTRY export ENABLE_SSH="${ENABLE_SSH:-0}" export PUBKEY_ONLY_SSH="${PUBKEY_ONLY_SSH:-0}" -export LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_GB.UTF-8}" +export LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_US.UTF-8}" -export KEYBOARD_KEYMAP="${KEYBOARD_KEYMAP:-gb}" -export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (UK)}" +export KEYBOARD_KEYMAP="${KEYBOARD_KEYMAP:-us}" +export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (US)}" -export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}" +export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/Berlin}" export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"} @@ -310,6 +366,12 @@ mkdir -p "${WORK_DIR}" log "Begin ${BASE_DIR}" STAGE_LIST=${STAGE_LIST:-${BASE_DIR}/stage*} +echo "Running stages: \"${STAGE_LIST}\"" + +SKIP_STAGE_LIST=${SKIP_STAGE_LIST:-} +SKIP_IMAGES_LIST=${SKIP_IMAGES_LIST:-} +echo "Skipping stages: \"${SKIP_STAGE_LIST}\"" +echo "Skipping images: \"${SKIP_IMAGES_LIST}\"" for STAGE_DIR in $STAGE_LIST; do STAGE_DIR=$(realpath "${STAGE_DIR}") diff --git a/export-image/04-finalise/01-run.sh b/export-image/04-finalise/01-run.sh index 24b2728..c7ffea6 100755 --- a/export-image/04-finalise/01-run.sh +++ b/export-image/04-finalise/01-run.sh @@ -14,9 +14,9 @@ IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img" INFO_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.info" IMG_FILE_ROOT_EXT4="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-ext4.img" -IMG_FILE_ROOT_SQFS_GZ="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-sqfs_gz.img" +#IMG_FILE_ROOT_SQFS_GZ="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-sqfs_gz.img" IMG_FILE_ROOT_SQFS_LZO="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-sqfs_lzo.img" -IMG_FILE_ROOT_SQFS_ZSTD="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-sqfs_zstd10.img" +#IMG_FILE_ROOT_SQFS_ZSTD="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-sqfs_zstd10.img" INFO_FILE_ROOT="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root.info" on_chroot << EOF @@ -107,11 +107,28 @@ make_bootable_image "${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.qcow2" \ if [ "${ROOTFS_RO}" = "1" ] ; then mount -o ro "$IMG_FILE_ROOT_EXT4" "${ROOTFS_DIR}" - mksquashfs "${ROOTFS_DIR}" "${IMG_FILE_ROOT_SQFS_GZ}" -comp gzip + #mksquashfs "${ROOTFS_DIR}" "${IMG_FILE_ROOT_SQFS_GZ}" -comp gzip mksquashfs "${ROOTFS_DIR}" "${IMG_FILE_ROOT_SQFS_LZO}" -comp lzo - mksquashfs "${ROOTFS_DIR}" "${IMG_FILE_ROOT_SQFS_ZSTD}" -comp zstd -Xcompression-level 10 + #mksquashfs "${ROOTFS_DIR}" "${IMG_FILE_ROOT_SQFS_ZSTD}" -comp zstd -Xcompression-level 10 umount "${ROOTFS_DIR}" - cp -a "$INFO_FILE_ROOT" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_arm64_000/rootfs.inf" + cp -a "$INFO_FILE_ROOT" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_${TARGET_ARCH}_000/rootfs.inf" + + # cp -a "$IMG_FILE_ROOT_EXT4" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_${TARGET_ARCH}_000/rootfs.img" + cp -a "$IMG_FILE_ROOT_SQFS_LZO" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_${TARGET_ARCH}_000/rootfs.img" + # cp -a "$IMG_FILE_ROOT_SQFS_ZSTD" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_${TARGET_ARCH}_000/rootfs.img" + + echo "Mount image ${IMG_FILE}" + MOUNTROOT=${STAGE_WORK_DIR}/tmpimage + mkdir -p $MOUNTROOT + mount_rawimage "${IMG_FILE}" $MOUNTROOT + if [ ! -d "${MOUNTROOT}/root" ]; then + echo "Image damaged or not mounted. Exit." + exit 1 + fi + cp "$IMG_FILE_ROOT_SQFS_LZO" "${MOUNTROOT}/boot/sys_${TARGET_ARCH}_000/rootfs.img" + echo "Umount image ${IMG_FILE}" + sync + umount_image $MOUNTROOT fi mv "$INFO_FILE" "$INFO_FILE_ROOT" "$DEPLOY_DIR2/" @@ -127,16 +144,12 @@ fi mv "$IMG_FILE" "$DEPLOY_DIR2/" if [ "${ROOTFS_RO}" = "1" ] ; then - # cp -a "$IMG_FILE_ROOT_EXT4" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_arm64_000/rootfs.img" - cp -a "$IMG_FILE_ROOT_SQFS_LZO" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_arm64_000/rootfs.img" - # cp -a "$IMG_FILE_ROOT_SQFS_ZSTD" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_arm64_000/rootfs.img" - ( cd "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}"; zip -r0 "../${IMG_FILENAME}${IMG_SUFFIX}.sdcard.zip" . ) mv "$IMG_FILE_ROOT_EXT4" "$DEPLOY_DIR2/" - mv "$IMG_FILE_ROOT_SQFS_GZ" "$DEPLOY_DIR2/" + #mv "$IMG_FILE_ROOT_SQFS_GZ" "$DEPLOY_DIR2/" mv "$IMG_FILE_ROOT_SQFS_LZO" "$DEPLOY_DIR2/" - mv "$IMG_FILE_ROOT_SQFS_ZSTD" "$DEPLOY_DIR2/" + #mv "$IMG_FILE_ROOT_SQFS_ZSTD" "$DEPLOY_DIR2/" fi rm -f "${STAGE_WORK_DIR}/SHA256SUMS" diff --git a/on_chroot.sh b/on_chroot.sh index da2f533..3d52bb8 100755 --- a/on_chroot.sh +++ b/on_chroot.sh @@ -37,9 +37,10 @@ if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/sys)"; then sudo mount --bind /sys "${ROOTFS_DIR}/sys" fi -if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/usr/local/projects)"; then - sudo mount --bind /usr/local/projects "${ROOTFS_DIR}/usr/local/projects" -fi +#if ! mount | grep -q "$(realpath "${ROOTFS_DIR}"/usr/local/projects)"; then +# mkdir -p "${ROOTFS_DIR}/usr/local/projects" +# sudo mount --bind /usr/local/projects "${ROOTFS_DIR}/usr/local/projects" +#fi sudo /sbin/capsh --user=$username --drop=cap_setfcap "--chroot=${ROOTFS_DIR}/" -- -c "$*" diff --git a/scripts/01-build-raspi-rw-lightxdev-jau.cfg b/scripts/01-build-raspi-rw-lightxdev-jau.cfg new file mode 100644 index 0000000..9826f5d --- /dev/null +++ b/scripts/01-build-raspi-rw-lightxdev-jau.cfg @@ -0,0 +1,48 @@ +#! /bin/bash + +export TARGET_RASPI="1" +export TARGET_ARCH="arm64" + +export RELEASE=bullseye +# export RELEASE=buster + +# Produce a read-only rootfs +# export ROOTFS_RO=1 +# export REDUCED_FOOTPRINT=1 + +export APT_PROXY=http://jordan:3142 + +export CUSTOM_NAME="RaspiArm64LightDevJau" +export CUSTOM_VERSION="1.1-rw" + +export PI_GEN="pi-gen (jau branch)" + +export IMG_NAME="${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}" +export WORK_DIR="/data/${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}-work" +export IMG_FILENAME=${IMG_NAME} + +export DEPLOY_DIR=/data/diskimages +export DEPLOY_ZIP=0 + +#export USE_QEMU=1 + +export TARGET_HOSTNAME=raspi04 + +export LOCALE_DEFAULT=en_US.UTF-8 +export KEYBOARD_KEYMAP=us +export KEYBOARD_LAYOUT="English (US)" +export TIMEZONE_DEFAULT="Europe/Berlin" + +export FIRST_USER_NAME="pi" +export FIRST_USER_PASS="pi" +export ENABLE_SSH=1 +export PUBKEY_SSH_FIRST_USER="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAm2qfo3uiWT9V7E/sH6unVO6XhGHeNnGUswxuADwFAKyflJq2yCALWIX7+DzEhBc7O9HxVztZAHLA+lfEpctQkA7KPgX98rjLHJlrm1lQXCPjwWjTZBrGNCmjWpYkc8jew/BzngmiwDlshYqzp0rWKNvQbkGJaVctqaraJAzE3F2wa+KkSBQuw2rAhiarbiO4MtO1AIw25EnSXHhP9EpeTKhAniKm73q977m5wpzaU+uwoGPCIyVl+BeaGLbPPIF35PJbg4tIqG6WLy3a8++Mf5Ml8lETcYYfjh4er3CvqFLhAYcaCLPNOwkK/YT4UnYZoZ4nt0Z+JWjxeNhIuJf64neysBdgB5E5FEYP2iYH+EUjcYp7YCrl/3/ag4Z2KAsF2qEa6/+s90Clm0r2mqRcQyLYQ6Co1YlYa1/jq7qsiuNgWvn5Mg8Pt4+L/C0KoycvUr4HhTS8EBJx+774p2uBa3mB65Vg2llKb8DdtQwR1bh0Ot9cjKTJY0pDyPiFbemZh2q7qD958bsOZCly43WYRd6E0Df68Q2MTz6ZC1y+z103gsEiK8bXmZp42ghDa96Ik2JO6pWCEUjBJ/9+rdudRHcfDlBqoS6+wg/z+WvtRtEyvVO4LSTrsX5xHWzVloSZeAGowmLbxGWHGWfl5oCcNfUzXo0lXDP0bzyy5NxWkpE= sven@phalanx" +export PUBKEY2_SSH_FIRST_USER="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC+pMJr432NOaDKnVN9+KDARU3XPDCMcwlsDdFHAEuVIGiNE2yxsC+UVKqu2+ZWKIlNET0zW8b87WsWVwiTa58lkxVre3g9DYAXpV7HPsf0bpTmzKqfPUC2z52aISluH/+Mf5FlytqFgpzx1VxREjvAw2H0GFE2K7+GsVcDFxjd5hv81FVAO9KISFnVVP9i+mSR7P4QOUYmXMw7Zq1z6hjXAGxXupEx8p/6KCqgo1tdVQBefJNOJpCABDI0yHgRsXnm7CUv1a/vM7QfCsn1hugcEGilacBLBcQp6EhXvleavX3ixffNV9RmOO0X06/EVwBtgal9aH375XABWihUi3EkRvfRqo07eieWzTIj6gO+AhZmuu4X/o53W5BG+cgMRV/+VGsLijH6jdvVv9W+motjX16TSHbSBHFaiwFyreAFi/A7WiUqdcbe12nnUsHlumhJSAIynCHKy6hgFEuGQFdENcudCgNMF7SDQEB52TwiO6BZuP6VHw4nNqxm+sbmKjgKi5vTrzIe7JkuRX+eIZLFZifFS7kfIRfQY67sCerTYsnC0Y0muX+VixKG3FIL6iSlF3KLOd41LPVNmBbpZK7oC62qrXBhvgA2d9D92o5rzqFCA6obEYiEDgyN6liASJD6VFNey366FyZzsf2U2dUeHFkyUxY0EEEFNeoOPhF5SQ== [email protected]" +export PUBKEY_ONLY_SSH=1 + +export STAGE_LIST="stage0 stage1 stage2 stage3a stage3a_dev" +#export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a stage3a_dev" + +#export SKIP_IMAGES_LIST="stage2 stage3a stage3a_dev" +export SKIP_IMAGES_LIST="stage2 stage3a" + diff --git a/scripts/01-build-rw-lightx.sh b/scripts/01-build-raspi-rw-lightxdev.cfg index 161d267..1c8269c 100755..100644 --- a/scripts/01-build-rw-lightx.sh +++ b/scripts/01-build-raspi-rw-lightxdev.cfg @@ -1,24 +1,22 @@ -#! /bin/sh +#! /bin/bash -sdir=`dirname $(readlink -f $0)` -rootdir=`dirname $sdir` - -export CUSTOM_NAME="MyMachine" -export CUSTOM_VERSION="1.1-rw" - -export PI_GEN="pi-gen (custom branch)" +export TARGET_RASPI="1" +export TARGET_ARCH="arm64" export RELEASE=bullseye # export RELEASE=buster -export TARGET_ARCH="arm64" - -# export APT_PROXY=http://jordan:3142 - # Produce a read-only rootfs # export ROOTFS_RO=1 # export REDUCED_FOOTPRINT=1 +# export APT_PROXY=http://jordan:3142 + +export CUSTOM_NAME="RaspiArm64LightDev" +export CUSTOM_VERSION="1.1-rw" + +export PI_GEN="pi-gen (custom branch)" + export IMG_NAME="${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}" export WORK_DIR="/data/${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}-work" export IMG_FILENAME=${IMG_NAME} @@ -41,13 +39,9 @@ export ENABLE_SSH=1 # export PUBKEY_SSH_FIRST_USER="ssh-rsa long-number my@machine" # export PUBKEY_ONLY_SSH=1 -# export STAGE_LIST="stage0 stage1 stage2 stage3a stage3b stage4 stage5" export STAGE_LIST="stage0 stage1 stage2 stage3a stage3a_dev" +#export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a stage3a_dev" -touch ${rootdir}/stage2/SKIP_IMAGES -touch ${rootdir}/stage3a/SKIP_IMAGES -# touch ${rootdir}/stage3a_dev/SKIP_IMAGES -# touch ${rootdir}/stage3b/SKIP_IMAGES -# touch ${rootdir}/stage4/SKIP_IMAGES +#export SKIP_IMAGES_LIST="stage2 stage3a stage3a_dev" +export SKIP_IMAGES_LIST="stage2 stage3a" -./build.sh diff --git a/scripts/02-build-raspi-ro-smalldesk-jau.cfg b/scripts/02-build-raspi-ro-smalldesk-jau.cfg new file mode 100644 index 0000000..4989669 --- /dev/null +++ b/scripts/02-build-raspi-ro-smalldesk-jau.cfg @@ -0,0 +1,50 @@ +#! /bin/bash + +export TARGET_RASPI="1" +export TARGET_ARCH="arm64" + +export RELEASE=bullseye +# export RELEASE=buster + +# Produce a read-only rootfs +export ROOTFS_RO=1 +export REDUCED_FOOTPRINT=1 + +export APT_PROXY=http://jordan:3142 + +export CUSTOM_NAME="RaspiArm64SmallDeskJau" +export CUSTOM_VERSION="1.1-ro" + +export PI_GEN="pi-gen (jau branch)" + +export IMG_NAME="${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}" +export WORK_DIR="/data/${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}-work" +export IMG_FILENAME=${IMG_NAME} + +export DEPLOY_DIR=/data/diskimages +export DEPLOY_ZIP=0 + +#export USE_QEMU=1 + +export TARGET_HOSTNAME=raspi04 + +export LOCALE_DEFAULT=en_US.UTF-8 +export KEYBOARD_KEYMAP=us +export KEYBOARD_LAYOUT="English (US)" +export TIMEZONE_DEFAULT="Europe/Berlin" + +export FIRST_USER_NAME="pi" +export FIRST_USER_PASS="pi" + +export ENABLE_SSH=1 +export PUBKEY_SSH_FIRST_USER="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAm2qfo3uiWT9V7E/sH6unVO6XhGHeNnGUswxuADwFAKyflJq2yCALWIX7+DzEhBc7O9HxVztZAHLA+lfEpctQkA7KPgX98rjLHJlrm1lQXCPjwWjTZBrGNCmjWpYkc8jew/BzngmiwDlshYqzp0rWKNvQbkGJaVctqaraJAzE3F2wa+KkSBQuw2rAhiarbiO4MtO1AIw25EnSXHhP9EpeTKhAniKm73q977m5wpzaU+uwoGPCIyVl+BeaGLbPPIF35PJbg4tIqG6WLy3a8++Mf5Ml8lETcYYfjh4er3CvqFLhAYcaCLPNOwkK/YT4UnYZoZ4nt0Z+JWjxeNhIuJf64neysBdgB5E5FEYP2iYH+EUjcYp7YCrl/3/ag4Z2KAsF2qEa6/+s90Clm0r2mqRcQyLYQ6Co1YlYa1/jq7qsiuNgWvn5Mg8Pt4+L/C0KoycvUr4HhTS8EBJx+774p2uBa3mB65Vg2llKb8DdtQwR1bh0Ot9cjKTJY0pDyPiFbemZh2q7qD958bsOZCly43WYRd6E0Df68Q2MTz6ZC1y+z103gsEiK8bXmZp42ghDa96Ik2JO6pWCEUjBJ/9+rdudRHcfDlBqoS6+wg/z+WvtRtEyvVO4LSTrsX5xHWzVloSZeAGowmLbxGWHGWfl5oCcNfUzXo0lXDP0bzyy5NxWkpE= sven@phalanx" +export PUBKEY2_SSH_FIRST_USER="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC+pMJr432NOaDKnVN9+KDARU3XPDCMcwlsDdFHAEuVIGiNE2yxsC+UVKqu2+ZWKIlNET0zW8b87WsWVwiTa58lkxVre3g9DYAXpV7HPsf0bpTmzKqfPUC2z52aISluH/+Mf5FlytqFgpzx1VxREjvAw2H0GFE2K7+GsVcDFxjd5hv81FVAO9KISFnVVP9i+mSR7P4QOUYmXMw7Zq1z6hjXAGxXupEx8p/6KCqgo1tdVQBefJNOJpCABDI0yHgRsXnm7CUv1a/vM7QfCsn1hugcEGilacBLBcQp6EhXvleavX3ixffNV9RmOO0X06/EVwBtgal9aH375XABWihUi3EkRvfRqo07eieWzTIj6gO+AhZmuu4X/o53W5BG+cgMRV/+VGsLijH6jdvVv9W+motjX16TSHbSBHFaiwFyreAFi/A7WiUqdcbe12nnUsHlumhJSAIynCHKy6hgFEuGQFdENcudCgNMF7SDQEB52TwiO6BZuP6VHw4nNqxm+sbmKjgKi5vTrzIe7JkuRX+eIZLFZifFS7kfIRfQY67sCerTYsnC0Y0muX+VixKG3FIL6iSlF3KLOd41LPVNmBbpZK7oC62qrXBhvgA2d9D92o5rzqFCA6obEYiEDgyN6liASJD6VFNey366FyZzsf2U2dUeHFkyUxY0EEEFNeoOPhF5SQ== [email protected]" +export PUBKEY_ONLY_SSH=1 + +export STAGE_LIST="stage0 stage1 stage2 stage3a stage3b" +#export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a stage3b" +export SKIP_STAGE_LIST="stage3a stage3b" + +#export SKIP_IMAGES_LIST="stage2 stage3a stage3b" +export SKIP_IMAGES_LIST="stage3a stage3b" + diff --git a/scripts/02-build-ro-smalldesk.sh b/scripts/02-build-raspi-ro-smalldesk.cfg index 1006590..8b87d3c 100755..100644 --- a/scripts/02-build-ro-smalldesk.sh +++ b/scripts/02-build-raspi-ro-smalldesk.cfg @@ -1,24 +1,22 @@ -#! /bin/sh +#! /bin/bash -sdir=`dirname $(readlink -f $0)` -rootdir=`dirname $sdir` - -export CUSTOM_NAME="MyMachine" -export CUSTOM_VERSION="1.1-ro" - -export PI_GEN="pi-gen (custom branch)" +export TARGET_RASPI="1" +export TARGET_ARCH="arm64" export RELEASE=bullseye # export RELEASE=buster -export TARGET_ARCH="arm64" - -# export APT_PROXY=http://jordan:3142 - # Produce a read-only rootfs export ROOTFS_RO=1 export REDUCED_FOOTPRINT=1 +# export APT_PROXY=http://jordan:3142 + +export CUSTOM_NAME="RaspiArm64SmallDesk" +export CUSTOM_VERSION="1.1-ro" + +export PI_GEN="pi-gen (custom branch)" + export IMG_NAME="${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}" export WORK_DIR="/data/${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}-work" export IMG_FILENAME=${IMG_NAME} @@ -41,12 +39,13 @@ export ENABLE_SSH=1 # export PUBKEY_SSH_FIRST_USER="ssh-rsa long-number my@machine" # export PUBKEY_ONLY_SSH=1 -# export STAGE_LIST="stage0 stage1 stage2 stage3a stage3b stage4 stage5" +# export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a" +export SKIP_IMAGES_LIST="stage2 stage3a" +# export SKIP_IMAGES_LIST="stage2 stage3a stage3a_dev stage3b stage4" + export STAGE_LIST="stage0 stage1 stage2 stage3a stage3b" +#export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a stage3b" -touch ${rootdir}/stage2/SKIP_IMAGES -touch ${rootdir}/stage3a/SKIP_IMAGES -# touch ${rootdir}/stage3b/SKIP_IMAGES -# touch ${rootdir}/stage4/SKIP_IMAGES +#export SKIP_IMAGES_LIST="stage2 stage3a stage3b" +export SKIP_IMAGES_LIST="stage2 stage3a" -./build.sh diff --git a/scripts/03-build-debian_amd64-ro-rescue-jau.cfg b/scripts/03-build-debian_amd64-ro-rescue-jau.cfg new file mode 100644 index 0000000..bfe108f --- /dev/null +++ b/scripts/03-build-debian_amd64-ro-rescue-jau.cfg @@ -0,0 +1,50 @@ +#! /bin/bash + +export TARGET_RASPI="0" +export TARGET_ARCH="amd64" + +export RELEASE=bullseye +# export RELEASE=buster + +# Produce a read-only rootfs +export ROOTFS_RO=1 +# export REDUCED_FOOTPRINT=1 + +export APT_PROXY=http://jordan:3142 + +export CUSTOM_NAME="DebAmd64RescueJau" +export CUSTOM_VERSION="1.1-ro" + +export PI_GEN="pi-gen (jau branch)" + +export IMG_NAME="${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}" +export WORK_DIR="/data/${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}-work" +export IMG_FILENAME=${IMG_NAME} + +export DEPLOY_DIR=/data/diskimages +export DEPLOY_ZIP=0 + +#export USE_QEMU=1 + +export TARGET_HOSTNAME=raspi04 + +export LOCALE_DEFAULT=en_US.UTF-8 +export KEYBOARD_KEYMAP=us +export KEYBOARD_LAYOUT="English (US)" +export TIMEZONE_DEFAULT="Europe/Berlin" + +export FIRST_USER_NAME="pi" +export FIRST_USER_PASS="pi" + +export ENABLE_SSH=1 +export PUBKEY_SSH_FIRST_USER="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAm2qfo3uiWT9V7E/sH6unVO6XhGHeNnGUswxuADwFAKyflJq2yCALWIX7+DzEhBc7O9HxVztZAHLA+lfEpctQkA7KPgX98rjLHJlrm1lQXCPjwWjTZBrGNCmjWpYkc8jew/BzngmiwDlshYqzp0rWKNvQbkGJaVctqaraJAzE3F2wa+KkSBQuw2rAhiarbiO4MtO1AIw25EnSXHhP9EpeTKhAniKm73q977m5wpzaU+uwoGPCIyVl+BeaGLbPPIF35PJbg4tIqG6WLy3a8++Mf5Ml8lETcYYfjh4er3CvqFLhAYcaCLPNOwkK/YT4UnYZoZ4nt0Z+JWjxeNhIuJf64neysBdgB5E5FEYP2iYH+EUjcYp7YCrl/3/ag4Z2KAsF2qEa6/+s90Clm0r2mqRcQyLYQ6Co1YlYa1/jq7qsiuNgWvn5Mg8Pt4+L/C0KoycvUr4HhTS8EBJx+774p2uBa3mB65Vg2llKb8DdtQwR1bh0Ot9cjKTJY0pDyPiFbemZh2q7qD958bsOZCly43WYRd6E0Df68Q2MTz6ZC1y+z103gsEiK8bXmZp42ghDa96Ik2JO6pWCEUjBJ/9+rdudRHcfDlBqoS6+wg/z+WvtRtEyvVO4LSTrsX5xHWzVloSZeAGowmLbxGWHGWfl5oCcNfUzXo0lXDP0bzyy5NxWkpE= sven@phalanx" +export PUBKEY2_SSH_FIRST_USER="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC+pMJr432NOaDKnVN9+KDARU3XPDCMcwlsDdFHAEuVIGiNE2yxsC+UVKqu2+ZWKIlNET0zW8b87WsWVwiTa58lkxVre3g9DYAXpV7HPsf0bpTmzKqfPUC2z52aISluH/+Mf5FlytqFgpzx1VxREjvAw2H0GFE2K7+GsVcDFxjd5hv81FVAO9KISFnVVP9i+mSR7P4QOUYmXMw7Zq1z6hjXAGxXupEx8p/6KCqgo1tdVQBefJNOJpCABDI0yHgRsXnm7CUv1a/vM7QfCsn1hugcEGilacBLBcQp6EhXvleavX3ixffNV9RmOO0X06/EVwBtgal9aH375XABWihUi3EkRvfRqo07eieWzTIj6gO+AhZmuu4X/o53W5BG+cgMRV/+VGsLijH6jdvVv9W+motjX16TSHbSBHFaiwFyreAFi/A7WiUqdcbe12nnUsHlumhJSAIynCHKy6hgFEuGQFdENcudCgNMF7SDQEB52TwiO6BZuP6VHw4nNqxm+sbmKjgKi5vTrzIe7JkuRX+eIZLFZifFS7kfIRfQY67sCerTYsnC0Y0muX+VixKG3FIL6iSlF3KLOd41LPVNmBbpZK7oC62qrXBhvgA2d9D92o5rzqFCA6obEYiEDgyN6liASJD6VFNey366FyZzsf2U2dUeHFkyUxY0EEEFNeoOPhF5SQ== [email protected]" +export PUBKEY_ONLY_SSH=1 + +export STAGE_LIST="stage0 stage1 stage2 stage3a stage3b stage_rescue" +#export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a stage3b stage_rescue" +export SKIP_STAGE_LIST="stage0 stage1 stage3a stage3b stage_rescue" + +#export SKIP_IMAGES_LIST="stage2 stage3a stage3b stage_rescue" +export SKIP_IMAGES_LIST="stage3a stage3b stage_rescue stage4" + diff --git a/scripts/03-build-debian_amd64-ro-rescue.cfg b/scripts/03-build-debian_amd64-ro-rescue.cfg new file mode 100644 index 0000000..a5a4d1f --- /dev/null +++ b/scripts/03-build-debian_amd64-ro-rescue.cfg @@ -0,0 +1,47 @@ +#! /bin/bash + +export TARGET_RASPI="0" +export TARGET_ARCH="amd64" + +export RELEASE=bullseye +# export RELEASE=buster + +# Produce a read-only rootfs +export ROOTFS_RO=1 +# export REDUCED_FOOTPRINT=1 + +# export APT_PROXY=http://jordan:3142 + +export CUSTOM_NAME="DebAmd64Rescue" +export CUSTOM_VERSION="1.1-ro" + +export PI_GEN="pi-gen (custom branch)" + +export IMG_NAME="${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}" +export WORK_DIR="/data/${CUSTOM_NAME}-${CUSTOM_VERSION}-${TARGET_ARCH}-work" +export IMG_FILENAME=${IMG_NAME} + +export DEPLOY_DIR=/data/diskimages +export DEPLOY_ZIP=0 + +#export USE_QEMU=1 + +export TARGET_HOSTNAME=raspi04 + +export LOCALE_DEFAULT=en_US.UTF-8 +export KEYBOARD_KEYMAP=us +export KEYBOARD_LAYOUT="English (US)" +export TIMEZONE_DEFAULT="Europe/Berlin" + +export FIRST_USER_NAME="pi" +export FIRST_USER_PASS="pi" +export ENABLE_SSH=1 +# export PUBKEY_SSH_FIRST_USER="ssh-rsa long-number my@machine" +# export PUBKEY_ONLY_SSH=1 + +export STAGE_LIST="stage0 stage1 stage2 stage3a stage3b stage_rescue" +#export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a stage3b stage_rescue" + +#export SKIP_IMAGES_LIST="stage2 stage3a stage3b stage_rescue" +export SKIP_IMAGES_LIST="stage2 stage3a stage3b" + diff --git a/scripts/apt-check.sh b/scripts/apt-check.sh new file mode 100755 index 0000000..fe7cd90 --- /dev/null +++ b/scripts/apt-check.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +#set -x + +sdir=`dirname $(readlink -f $0)` +rootdir=`dirname $sdir` + +packfile=$1 + +echo "Testing packages in ${packfile}" +PACKAGES=$(sed -f "${sdir}/remove-comments.sed" < "${packfile}") + +for i in ${PACKAGES} ; do + if ! apt-cache show ${i} > /dev/null 2>&1 ; then + echo missing ${i} + else + echo exists ${i} + fi +done diff --git a/scripts/common b/scripts/common index 614774c..75eb2af 100644 --- a/scripts/common +++ b/scripts/common @@ -15,7 +15,7 @@ bootstrap(){ # BOOTSTRAP_CMD=qemu-debootstrap # fi - BOOTSTRAP_ARGS+=(--arch arm64) + BOOTSTRAP_ARGS+=(--arch ${TARGET_ARCH}) BOOTSTRAP_ARGS+=(--include gnupg) BOOTSTRAP_ARGS+=(--components "main,contrib,non-free") #BOOTSTRAP_ARGS+=(--keyring "${STAGE_DIR}/files/raspberrypi.gpg") @@ -106,7 +106,7 @@ on_chroot() { export -f on_chroot print_issue() { - echo "Raspberry Pi (Zafena) ${IMG_DATE} UTC" + echo "GNU/Linux ${IMG_DATE} UTC" if [ -n "${CUSTOM_NAME}" -a -n "${CUSTOM_VERSION}" ]; then echo "${CUSTOM_NAME} version ${CUSTOM_VERSION}" fi diff --git a/scripts/find_1st_vfat.sh b/scripts/find_1st_vfat.sh new file mode 100644 index 0000000..677cc13 --- /dev/null +++ b/scripts/find_1st_vfat.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +find_blkpart() { + local fstype_exp="$1" + local res="" + local blkparts=$(lsblk -l | grep part | cut -d" " -f1) + if [ -z "${blkparts}" ]; then + # May take some time on PC's after loading device modules (usb, ..) + local blkpartwait=180 + while [ "$(time_elapsed)" -lt "$blkpartwait" ]; do + blkparts=$(lsblk -l | grep part | cut -d" " -f1) + if [ -n "${blkparts}" ]; then + break + fi + sleep 1 + done + if [ -z "${blkparts}" ]; then + panic "loop_rootfs: Block devices did not appear in time" + exit 1 + fi + fi + for i in ${blkparts} ; do + local FSTYPE=$(blkid -o value -s TYPE /dev/$i) + if [ "${FSTYPE}" = "${fstype_exp}" ]; then + res="/dev/$i" + break + fi + done + echo -n "${res}" +} + +BLKDEV=$(find_blkpart vfat) +echo "BLKDEV ${BLKDEV}" diff --git a/scripts/qcow2_handling b/scripts/qcow2_handling index bf9acb5..af763cf 100644 --- a/scripts/qcow2_handling +++ b/scripts/qcow2_handling @@ -356,7 +356,7 @@ function make_bootable_image() { echo "Get PARTUUIDs from image" IMGID="$(blkid -o value -s PTUUID "${EXPORT_IMAGE}")" - echo "Mount image" + echo "Mount image ${EXPORT_IMAGE}" MOUNTROOT=${WORK_DIR}/tmpimage mkdir -p $MOUNTROOT mount_rawimage "${EXPORT_IMAGE}" $MOUNTROOT @@ -377,7 +377,9 @@ function make_bootable_image() { echo "Set UUIDs to make it bootable" sed -i "s/BOOTDEV/PARTUUID=${BOOT_PARTUUID}/" "${MOUNTROOT}/etc/fstab" sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${MOUNTROOT}/etc/fstab" - sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${MOUNTROOT}/boot/sys_arm64_000/cmdline.txt" + if [ "${TARGET_RASPI}" = "1" ]; then + sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${MOUNTROOT}/boot/sys_${TARGET_ARCH}_000/cmdline.txt" + fi fi else echo "Setup hard devicenames" @@ -389,10 +391,12 @@ function make_bootable_image() { echo "Set hard device names to make it bootable" sed -i "s/BOOTDEV/${BOOT_DEV_NAME}/" "${MOUNTROOT}/etc/fstab" sed -i "s/ROOTDEV/${ROOT_DEV_NAME}/" "${MOUNTROOT}/etc/fstab" - sed -i "s/ROOTDEV/${ROOT_DEV_NAME}/" "${MOUNTROOT}/boot/sys_arm64_000/cmdline.txt" + if [ "${TARGET_RASPI}" = "1" ]; then + sed -i "s/ROOTDEV/${ROOT_DEV_NAME}/" "${MOUNTROOT}/boot/sys_${TARGET_ARCH}_000/cmdline.txt" + fi fi - echo "Umount image" + echo "Umount image ${EXPORT_IMAGE}" sync umount_image $MOUNTROOT diff --git a/stage0/00-configure-apt/00-run.sh b/stage0/00-configure-apt/00-run.sh index 07fd76e..904c1ef 100755 --- a/stage0/00-configure-apt/00-run.sh +++ b/stage0/00-configure-apt/00-run.sh @@ -1,13 +1,16 @@ #!/bin/bash -e if [ "${IS_TESTING}" = "1" ]; then - install -m 644 files/sources-testing.list "${ROOTFS_DIR}/etc/apt/" + install -m 644 files/sources-testing.list "${ROOTFS_DIR}/etc/apt/sources.list" else - install -m 644 files/sources-stable.list "${ROOTFS_DIR}/etc/apt/" + install -m 644 files/sources-stable.list "${ROOTFS_DIR}/etc/apt/sources.list" fi -install -m 644 files/raspi.list "${ROOTFS_DIR}/etc/apt/sources.list.d/" sed -i "s/RELEASE/${RELEASE}/g" "${ROOTFS_DIR}/etc/apt/sources.list" -sed -i "s/RELEASE/${RELEASE}/g" "${ROOTFS_DIR}/etc/apt/sources.list.d/raspi.list" + +if [ "${TARGET_RASPI}" = "1" ]; then + install -m 644 files/raspi.list "${ROOTFS_DIR}/etc/apt/sources.list.d/" + sed -i "s/RELEASE/${RELEASE}/g" "${ROOTFS_DIR}/etc/apt/sources.list.d/raspi.list" +fi if [ -n "$APT_PROXY" ]; then install -m 644 files/51cache "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache" @@ -28,9 +31,13 @@ if [ "${REDUCED_FOOTPRINT}" = "1" ]; then install -m 644 files/01_nodoc "${ROOTFS_DIR}/etc/dpkg/dpkg.cfg.d/01_nodoc" fi -on_chroot apt-key add - < files/raspberrypi.gpg.key +if [ "${TARGET_RASPI}" = "1" ]; then + on_chroot apt-key add - < files/raspberrypi.gpg.key +fi +if [ "${TARGET_ARCH}" = "arm64" ]; then + on_chroot dpkg --add-architecture armhf +fi on_chroot << EOF -dpkg --add-architecture armhf apt-get update apt-get dist-upgrade -y EOF diff --git a/stage0/02-firmware/00-run.sh b/stage0/02-firmware/00-run.sh new file mode 100755 index 0000000..4a8bbb5 --- /dev/null +++ b/stage0/02-firmware/00-run.sh @@ -0,0 +1,10 @@ +#!/bin/bash -e + +if [ "${TARGET_RASPI}" != "1" ]; then + on_chroot << EOF + if [ "${TARGET_ARCH}" = "amd64" -o "${TARGET_ARCH}" = "i386" ]; then + apt-get -o APT::Acquire::Retries=3 install --no-install-recommends -y amd64-microcode intel-microcode + fi + apt-get -o APT::Acquire::Retries=3 install --no-install-recommends -y linux-image-${TARGET_ARCH} +EOF +fi diff --git a/stage0/02-firmware/01-packages-sys-debian b/stage0/02-firmware/01-packages-sys-debian new file mode 100644 index 0000000..c96ce0f --- /dev/null +++ b/stage0/02-firmware/01-packages-sys-debian @@ -0,0 +1,6 @@ +atmel-firmware firmware-amd-graphics firmware-bnx2 firmware-bnx2x +firmware-brcm80211 firmware-intelwimax +#firmware-ipw2x00 +firmware-iwlwifi firmware-libertas firmware-linux firmware-linux-free firmware-linux-nonfree +firmware-misc-nonfree firmware-myricom firmware-netxen firmware-qlogic firmware-realtek +bluez-firmware diff --git a/stage0/02-firmware/01-packages b/stage0/02-firmware/01-packages-sys-raspi index b166aa8..b166aa8 100644 --- a/stage0/02-firmware/01-packages +++ b/stage0/02-firmware/01-packages-sys-raspi diff --git a/stage1/00-boot-files/00-run.sh b/stage1/00-boot-files/00-run.sh index bc61397..802f6bc 100755 --- a/stage1/00-boot-files/00-run.sh +++ b/stage1/00-boot-files/00-run.sh @@ -1,4 +1,6 @@ #!/bin/bash -e -install -m 644 files/cmdline.txt "${ROOTFS_DIR}/boot/" -install -m 644 files/config.txt "${ROOTFS_DIR}/boot/" +if [ "${TARGET_RASPI}" = "1" ]; then + install -m 644 files/cmdline.txt "${ROOTFS_DIR}/boot/" + install -m 644 files/config.txt "${ROOTFS_DIR}/boot/" +fi diff --git a/stage1/01-sys-tweaks/files/fstab b/stage1/01-sys-tweaks/files/fstab index f16e3fb..3238758 100644 --- a/stage1/01-sys-tweaks/files/fstab +++ b/stage1/01-sys-tweaks/files/fstab @@ -1,3 +1,3 @@ proc /proc proc defaults 0 0 -BOOTDEV /boot vfat defaults 0 2 +# BOOTDEV /boot vfat defaults 0 2 ROOTDEV / ext4 defaults,noatime 0 1 diff --git a/stage1/03-install-packages/00-packages b/stage1/03-install-packages/00-packages-sys-raspi index e8c148c..e8c148c 100644 --- a/stage1/03-install-packages/00-packages +++ b/stage1/03-install-packages/00-packages-sys-raspi diff --git a/stage2/01-sys-tweaks/00-packages-buster b/stage2/01-sys-tweaks/00-packages index 7cd345f..7e2ddc0 100644 --- a/stage2/01-sys-tweaks/00-packages-buster +++ b/stage2/01-sys-tweaks/00-packages @@ -3,32 +3,26 @@ ssh less fbset sudo psmisc strace console-setup keyboard-configuration debconf-utils parted unzip #build-essential manpages-dev python3 bash-completion gdb pkg-config libstdc++6 -#python3 python3-rpi.gpio python3-gpiozero -python-minimal python-rpi.gpio python-gpiozero +#python3 python3-gpiozero +python-minimal python-gpiozero bash-completion pkg-config v4l-utils avahi-daemon lua5.1 luajit hardlink ca-certificates curl -fake-hwclock nfs-common autofs usbutils -#libraspberrypi-dev libraspberrypi-doc libfreetype6-dev -libraspberrypi-dev libfreetype6-dev +libfreetype6-dev dosfstools squashfs-tools fatattr #dphys-swapfile bluez -raspberrypi-sys-mods -pi-bluetooth rfkill apt-listchanges usb-modeswitch -libpam-chksshpwd -rpi-update libmtp-runtime rsync htop iotop powertop iftop @@ -40,8 +34,6 @@ ethtool vl805fw #ntfs-3g pciutils -rpi-eeprom -raspinfo busybox initramfs-tools-core initramfs-tools diff --git a/stage2/01-sys-tweaks/00-packages-bullseye b/stage2/01-sys-tweaks/00-packages-bullseye index c5d2dc3..1e079d8 100644 --- a/stage2/01-sys-tweaks/00-packages-bullseye +++ b/stage2/01-sys-tweaks/00-packages-bullseye @@ -3,32 +3,26 @@ ssh less fbset sudo psmisc strace console-setup keyboard-configuration debconf-utils parted unzip #build-essential manpages-dev python3 bash-completion gdb pkg-config libstdc++6 -python3-minimal python3-rpi.gpio python3-gpiozero -#python-minimal python-rpi.gpio python-gpiozero +python3-minimal python3-gpiozero +#python-minimal python-gpiozero bash-completion pkg-config v4l-utils avahi-daemon lua5.1 luajit hardlink ca-certificates curl -fake-hwclock nfs-common autofs usbutils -#libraspberrypi-dev libraspberrypi-doc libfreetype6-dev -libraspberrypi-dev libfreetype6-dev +libfreetype6-dev dosfstools squashfs-tools fatattr #dphys-swapfile bluez -raspberrypi-sys-mods -pi-bluetooth rfkill apt-listchanges usb-modeswitch -libpam-chksshpwd -rpi-update libmtp-runtime rsync htop iotop powertop iftop @@ -40,8 +34,6 @@ ethtool #vl805fw #ntfs-3g pciutils -rpi-eeprom -raspinfo busybox initramfs-tools-core initramfs-tools diff --git a/stage2/01-sys-tweaks/00-packages-sys-debian b/stage2/01-sys-tweaks/00-packages-sys-debian new file mode 100644 index 0000000..b70f274 --- /dev/null +++ b/stage2/01-sys-tweaks/00-packages-sys-debian @@ -0,0 +1,2 @@ +sysfsutils +grub-pc diff --git a/stage2/01-sys-tweaks/00-packages-sys-raspi b/stage2/01-sys-tweaks/00-packages-sys-raspi new file mode 100644 index 0000000..d355fc8 --- /dev/null +++ b/stage2/01-sys-tweaks/00-packages-sys-raspi @@ -0,0 +1,11 @@ +#libraspberrypi-dev libraspberrypi-doc +libraspberrypi-dev +raspberrypi-sys-mods +pi-bluetooth +raspinfo +rpi-update +rpi-eeprom +libpam-chksshpwd +#python3 python3-rpi.gpio python3-gpiozero +python-minimal python-rpi.gpio python-gpiozero +fake-hwclock diff --git a/stage2/01-sys-tweaks/00-packages-sys-raspi-bullseye b/stage2/01-sys-tweaks/00-packages-sys-raspi-bullseye new file mode 100644 index 0000000..29261f8 --- /dev/null +++ b/stage2/01-sys-tweaks/00-packages-sys-raspi-bullseye @@ -0,0 +1,11 @@ +#libraspberrypi-dev libraspberrypi-doc +libraspberrypi-dev +raspberrypi-sys-mods +pi-bluetooth +raspinfo +rpi-update +rpi-eeprom +libpam-chksshpwd +python3-minimal python3-rpi.gpio python3-gpiozero +#python-minimal python-rpi.gpio python-gpiozero +fake-hwclock diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh index 81bc5a1..c200ae2 100755 --- a/stage2/01-sys-tweaks/01-run.sh +++ b/stage2/01-sys-tweaks/01-run.sh @@ -3,15 +3,20 @@ if [ "${ROOTFS_RO}" = "1" ] ; then install -v -m 644 files/fstab-rootfs_ro "${ROOTFS_DIR}/etc/fstab" fi -install -m 644 files/overlay_mount.service "${ROOTFS_DIR}/lib/systemd/system/" -install -m 755 files/overlay_mount "${ROOTFS_DIR}/etc/init.d/" +install -m 644 files/overlay_mount.service "${ROOTFS_DIR}/lib/systemd/system/" +install -m 755 files/overlay_mount "${ROOTFS_DIR}/etc/init.d/" + +install -m 644 files/rotatelog_init_rootfs.service "${ROOTFS_DIR}/lib/systemd/system/" +install -m 755 files/rotatelog_init_rootfs "${ROOTFS_DIR}/etc/init.d/" install -m 755 files/resize2fs_once "${ROOTFS_DIR}/etc/init.d/" install -d "${ROOTFS_DIR}/etc/systemd/system/rc-local.service.d" install -m 644 files/ttyoutput.conf "${ROOTFS_DIR}/etc/systemd/system/rc-local.service.d/" -install -m 644 files/50raspi "${ROOTFS_DIR}/etc/apt/apt.conf.d/" +if [ "${TARGET_RASPI}" = "1" ]; then + install -m 644 files/50raspi "${ROOTFS_DIR}/etc/apt/apt.conf.d/" +fi install -m 644 files/console-setup "${ROOTFS_DIR}/etc/default/" @@ -20,6 +25,9 @@ install -m 755 files/rc.local "${ROOTFS_DIR}/etc/" if [ -n "${PUBKEY_SSH_FIRST_USER}" ]; then install -v -m 0700 -o 1000 -g 1000 -d "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh echo "${PUBKEY_SSH_FIRST_USER}" >"${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys + if [ -n "${PUBKEY2_SSH_FIRST_USER}" ]; then + echo "${PUBKEY2_SSH_FIRST_USER}" >>"${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys + fi chown 1000:1000 "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys chmod 0600 "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys fi @@ -30,7 +38,9 @@ s/^#?[[:blank:]]*PasswordAuthentication[[:blank:]]*yes[[:blank:]]*$/PasswordAuth fi on_chroot << EOF - systemctl disable hwclock.sh + if [ "${TARGET_RASPI}" = "1" ]; then + systemctl disable hwclock.sh + fi systemctl disable rsync systemctl mask rsync @@ -39,7 +49,12 @@ on_chroot << EOF systemctl disable rpcbind systemctl mask rpcbind - if [ "\${ENABLE_SSH}" == "1" ]; then + if [ "${TARGET_RASPI}" != "1" ]; then + # ensure sysfsutils is enabled at boot + systemctl is-enabled sysfsutils + fi + + if [ "${ENABLE_SSH}" == "1" ]; then systemctl enable ssh else systemctl disable ssh @@ -56,32 +71,38 @@ on_chroot << EOF systemctl unmask overlay_mount systemctl enable overlay_mount + + systemctl unmask rotatelog_init_rootfs + systemctl enable rotatelog_init_rootfs else systemctl disable overlay_mount - systemctl mask overlay_mount + systemctl mask overlay_mount + + systemctl disable rotatelog_init_rootfs + systemctl mask rotatelog_init_rootfs fi # Setup unique system folder /boot/sys_arm64_000 - mkdir -p /boot/sys_arm64_000 + mkdir -p /boot/sys_${TARGET_ARCH}_000 - find /boot -maxdepth 1 -name \*.dtb -exec mv \{\} /boot/sys_arm64_000/ \; + find /boot -maxdepth 1 -name \*.dtb -exec mv \{\} /boot/sys_${TARGET_ARCH}_000/ \; - find /boot -maxdepth 1 -name kernel\*.img -exec mv \{\} /boot/sys_arm64_000/ \; + find /boot -maxdepth 1 -name kernel\*.img -exec mv \{\} /boot/sys_${TARGET_ARCH}_000/ \; for i in /boot/COPYING.linux /boot/LICENCE.broadcom \ /boot/issue.txt /boot/rootfs.img ; do if [ -f "\${i}" ]; then - mv "\${i}" /boot/sys_arm64_000/ + mv "\${i}" /boot/sys_${TARGET_ARCH}_000/ fi done if [ -d /boot/overlays ] ; then - mv /boot/overlays /boot/sys_arm64_000/ + mv /boot/overlays /boot/sys_${TARGET_ARCH}_000/ fi for i in /boot/config.txt /boot/cmdline.txt /boot/initrd.img ; do if [ -f "\${i}" ]; then - mv "\${i}" /boot/sys_arm64_000/\`basename \${i}\`.orig + mv "\${i}" /boot/sys_${TARGET_ARCH}_000/\`basename \${i}\`.orig fi done @@ -101,29 +122,55 @@ on_chroot << EOF systemctl disable man-db.timer systemctl mask man-db.timer - sed -i -e 's/#Storage=auto/Storage=volatile/g;s/#Compress=yes/Compress=yes/g;s/#RuntimeMaxUse=/RuntimeMaxUse=1M/g;s/#ForwardToSyslog=yes/ForwardToSyslog=no/g;s/#ForwardToWall=yes/ForwardToWall=no/g' /etc/systemd/journald.conf + sed -i -e 's/#Storage=auto/Storage=volatile/g;s/#Compress=yes/Compress=yes/g;s/#RuntimeMaxUse=/RuntimeMaxUse=1M/g;s/#ForwardToSyslog=yes/ForwardToSyslog=no/g;s/#ForwardToKMsg=no/ForwardToKMsg=no/g;s/#ForwardToConsole=no/ForwardToConsole=no/g;s/#ForwardToWall=yes/ForwardToWall=no/g;s/#TTYPath=\/dev\/console/TTYPath=\/dev\/tty3/g' /etc/systemd/journald.conf - sed -i -e 's/MODULES=most/MODULES=dep/g;s/BUSYBOX=auto/BUSYBOX=y/g;s/COMPRESS=gzip/COMPRESS=lzop/g' /etc/initramfs-tools/initramfs.conf + if [ "${TARGET_RASPI}" = "1" ]; then + sed -i -e 's/MODULES=most/MODULES=dep/g;s/BUSYBOX=auto/BUSYBOX=y/g;s/COMPRESS=gzip/COMPRESS=lzop/g' /etc/initramfs-tools/initramfs.conf + else + sed -i -e 's/BUSYBOX=auto/BUSYBOX=y/g;s/COMPRESS=gzip/COMPRESS=lzop/g' /etc/initramfs-tools/initramfs.conf + fi - echo "squashfs" >> /etc/modules - echo "squashfs" >> /etc/initramfs-tools/modules + if [ "${TARGET_RASPI}" = "1" ]; then + KMODULES="squashfs" + else + KMODULES="nls_cp437 nls_ascii fat vfat squashfs loop usb-common usbcore libahci ahci libata scsi_mod sd_mod usb-storage" + fi + for i in \${KMODULES} ; do + echo "\$i" >> /etc/modules + echo "\$i" >> /etc/initramfs-tools/modules + done else systemctl enable resize2fs_once fi EOF if [ "${ROOTFS_RO}" = "1" ] ; then - install -m 644 files/boot/config-rootfs_ro.txt "${ROOTFS_DIR}/boot/config.txt" - install -m 644 files/boot/config-rootfs_ro.txt "${ROOTFS_DIR}/boot/sys_arm64_000/config.txt" - install -m 644 files/boot/sys_arm64_000/cmdline-rootfs_ro.txt "${ROOTFS_DIR}/boot/sys_arm64_000/cmdline.txt" + if [ "${TARGET_RASPI}" = "1" ]; then + install -m 644 files/boot/config-rootfs_ro.txt "${ROOTFS_DIR}/boot/config.txt" + install -m 644 files/boot/config-rootfs_ro.txt "${ROOTFS_DIR}/boot/sys_arm64_000/config.txt" + install -m 644 files/boot/sys_arm64_000/cmdline-rootfs_ro.txt "${ROOTFS_DIR}/boot/sys_arm64_000/cmdline.txt" + else + install -m 644 files/grub/custom.cfg "${ROOTFS_DIR}/boot/grub/custom.cfg" + sed -i 's/sys_arm64_000/sys_${TARGET_ARCH}_000/g' "${ROOTFS_DIR}/boot/grub/custom.cfg" + cp "${ROOTFS_DIR}/boot/grub/custom.cfg" "${ROOTFS_DIR}/boot/sys_${TARGET_ARCH}_000/" + sed -i 's/GRUB_DEFAULT=0/GRUB_DEFAULT=loop_rootfs/g' "${ROOTFS_DIR}/etc/default/grub" + #sed -i 's/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=0/g' "${ROOTFS_DIR}/etc/default/grub" + fi - install -m 755 files/initramfs/loop_rootfs "${ROOTFS_DIR}/etc/initramfs-tools/scripts/init-premount/" + install -m 755 files/initramfs/loop_rootfs-premount "${ROOTFS_DIR}/etc/initramfs-tools/scripts/init-premount/loop_rootfs" + sed -i 's/sys_arm64_000/sys_${TARGET_ARCH}_000/g' "${ROOTFS_DIR}/etc/initramfs-tools/scripts/init-premount/loop_rootfs" + if [ "${TARGET_RASPI}" != "1" ]; then + sed -i 's/USES_RASPI_CONFIG=1/USES_RASPI_CONFIG=0/g' "${ROOTFS_DIR}/etc/initramfs-tools/scripts/init-premount/loop_rootfs" + fi + install -m 755 files/initramfs/loop_rootfs-bottom "${ROOTFS_DIR}/etc/initramfs-tools/scripts/init-bottom/loop_rootfs" install -m 755 files/initramfs/fsck_custom "${ROOTFS_DIR}/etc/initramfs-tools/hooks/" install -m 755 files/initramfs/extra_execs "${ROOTFS_DIR}/etc/initramfs-tools/hooks/" else - install -m 644 files/boot/config-rootfs_rw.txt "${ROOTFS_DIR}/boot/config.txt" - install -m 644 files/boot/config-rootfs_rw.txt "${ROOTFS_DIR}/boot/sys_arm64_000/config.txt" - install -m 644 files/boot/sys_arm64_000/cmdline-rootfs_rw.txt "${ROOTFS_DIR}/boot/sys_arm64_000/cmdline.txt" + if [ "${TARGET_RASPI}" = "1" ]; then + install -m 644 files/boot/config-rootfs_rw.txt "${ROOTFS_DIR}/boot/config.txt" + install -m 644 files/boot/config-rootfs_rw.txt "${ROOTFS_DIR}/boot/sys_arm64_000/config.txt" + install -m 644 files/boot/sys_arm64_000/cmdline-rootfs_rw.txt "${ROOTFS_DIR}/boot/sys_arm64_000/cmdline.txt" + fi fi if [ "${USE_QEMU}" = "1" ]; then @@ -143,15 +190,35 @@ on_chroot <<EOF setupcon --force --save-only -v usermod --pass='*' root - if [ "${ROOTFS_RO}" = "1" ] ; then + if [ "${ROOTFS_RO}" = "1" ]; then KVERSION=\$(ls /lib/modules/ | tail -n 1) - echo "mkinitramfs for kernel version: \${KVERSION}" - /usr/sbin/mkinitramfs -o /boot/sys_arm64_000/initrd.img \${KVERSION} + if [ "${TARGET_RASPI}" = "1" ]; then + echo "mkinitramfs for kernel version: \${KVERSION}" + /usr/sbin/mkinitramfs -o /boot/sys_${TARGET_ARCH}_000/initrd.img \${KVERSION} + else + update-initramfs -u -k \${KVERSION} + if [ -f "/boot/vmlinuz-\${KVERSION}" ] ; then + mv -f "/boot/vmlinuz-\${KVERSION}" /boot/sys_${TARGET_ARCH}_000/vmlinuz + fi + if [ -f "/boot/initrd.img-\${KVERSION}" ] ; then + mv -f "/boot/initrd.img-\${KVERSION}" /boot/sys_${TARGET_ARCH}_000/initrd.img + fi + if [ -f "/boot/config-\${KVERSION}" ] ; then + mv -f "/boot/config-\${KVERSION}" /boot/sys_${TARGET_ARCH}_000/config + fi + if [ -f "/boot/System.map-\${KVERSION}" ] ; then + mv -f "/boot/System.map-\${KVERSION}" /boot/sys_${TARGET_ARCH}_000/System.map + fi + fi mkdir -p /data/sdcard find /boot/ -maxdepth 1 -type f \ -exec cp -d --preserve=all \{\} /data/sdcard/ \; - cp -a /boot/sys_arm64_000 /data/sdcard/ + cp -a /boot/sys_${TARGET_ARCH}_000 /data/sdcard/ + fi + if [ "${TARGET_RASPI}" != "1" ]; then + update-grub + grub-install ${NBD_DEV} fi EOF diff --git a/stage2/01-sys-tweaks/files/fstab-rootfs_ro b/stage2/01-sys-tweaks/files/fstab-rootfs_ro index 9ea3a56..ad040ea 100644 --- a/stage2/01-sys-tweaks/files/fstab-rootfs_ro +++ b/stage2/01-sys-tweaks/files/fstab-rootfs_ro @@ -1,3 +1,3 @@ proc /proc proc defaults 0 0 -BOOTDEV /boot vfat defaults 0 2 +# BOOTDEV /boot vfat defaults 0 2 ROOTDEV / ext4 defaults,noatime,ro,errors=remount-ro 0 0 diff --git a/stage2/01-sys-tweaks/files/grub/custom.cfg b/stage2/01-sys-tweaks/files/grub/custom.cfg new file mode 100644 index 0000000..ac5c899 --- /dev/null +++ b/stage2/01-sys-tweaks/files/grub/custom.cfg @@ -0,0 +1,11 @@ +menuentry 'Debian GNU/Linux loop_rootfs' --id loop_rootfs { + load_video + insmod gzio + insmod part_msdos + insmod fat + echo 'Loading Linux ...' + linux /sys_amd64_000/vmlinuz root=file ro debug + echo 'Loading initial ramdisk ...' + initrd /sys_amd64_000/initrd.img +} + diff --git a/stage2/01-sys-tweaks/files/initramfs/extra_execs b/stage2/01-sys-tweaks/files/initramfs/extra_execs index 9f4c6c5..0c668c2 100755 --- a/stage2/01-sys-tweaks/files/initramfs/extra_execs +++ b/stage2/01-sys-tweaks/files/initramfs/extra_execs @@ -14,7 +14,7 @@ prereqs) ;; esac -if [ ! -x /usr/bin/unsquashfs ]; then +if [ ! -x /usr/bin/unsquashfs -o ! -x /bin/lsblk -o ! -x /sbin/blkid -o ! -x /bin/date ]; then exit 1 fi @@ -22,4 +22,6 @@ fi . /usr/share/initramfs-tools/hook-functions copy_exec /usr/bin/unsquashfs - +copy_exec /bin/lsblk +copy_exec /sbin/blkid +copy_exec /bin/date diff --git a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs deleted file mode 100755 index dc8fe97..0000000 --- a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs +++ /dev/null @@ -1,308 +0,0 @@ -#!/bin/sh - -PREREQ="udev" - -prereqs() -{ - echo "${PREREQ}" -} - -case ${1} in - prereqs) - prereqs - exit 0 - ;; -esac - -# -# If 'debug' has been passed via the boot cmdline, -# logoutput will be made available to '/run/initramfs/initramfs.debug'. -# - -. /scripts/functions - -readonly BOOT_PART="/dev/mmcblk0p1" -readonly BOOT_DIR="/mnt/boot" - -# Current config.txt with current OS_PREFIX -readonly CONFIG_FILE="${BOOT_DIR}/config.txt" -readonly CONFIG_FILE_OLD="${BOOT_DIR}/config.bak" - -# Optional fallback OS_PREFIX -readonly OS_PREFIX_FILE_LAST="${BOOT_DIR}/sys_last" -# Optional boot counter. -readonly BOOT_COUNTER_FILE="${BOOT_DIR}/sys_cntr" - -# -# To guarantee factory default fallback, have immutable: -# - Folder '/boot/sys_arm64_000/' folder (OS_PREFIX_DEFAULT), which includes -# - File '/boot/sys_arm64_000/config.txt' (CONFIG_FILE_DEFAULT). -# -# Notable: Every system folder contains its own immutable config.txt copy! -# - -# Default OS_PREFIX -> ${BOOT_DIR}/${OS_PREFIX_DEFAULT} -readonly OS_PREFIX_DEFAULT="sys_arm64_000" - -# Default config.txt with factory default OS_PREFIX_DEFAULT -readonly CONFIG_FILE_DEFAULT="${BOOT_DIR}/${OS_PREFIX_DEFAULT}/config.txt" - -OS_PREFIX="" -OS_PREFIX_LAST="" -BOOT_COUNTER="" - -IMAGE_FILE="" -FILE_FSTYPE="" - -check_fsfile() { - local fsfile=$1 - - if [ ! -f "${fsfile}" ]; then - log_failure_msg "loop_rootfs image file ${fsfile} doesn't exist." - return 1 - fi - log_success_msg "loop_rootfs image file ${fsfile} exists." - - FILE_FSTYPE=$(get_fstype "${fsfile}") - if [ -z "${FILE_FSTYPE}" -o "${FILE_FSTYPE}" = "unknown" ]; then - log_failure_msg "loop_rootfs image file ${fsfile} unknown fstype." - return 1 - fi - log_success_msg "loop_rootfs image file ${fsfile} of type ${FILE_FSTYPE}." - - if ! fsck -n -V -t "${FILE_FSTYPE}" "${fsfile}"; then - log_failure_msg "loop_rootfs image file ${fsfile} fsck failed." - return 1 - fi - log_success_msg "loop_rootfs image file ${fsfile} fsck OK." - - if [ "${FILE_FSTYPE}" = "squashfs" ]; then - if ! unsquashfs -l "${fsfile}" > /dev/null ; then - log_failure_msg "loop_rootfs image file ${fsfile} unsquashfs -l failed." - return 1 - fi - log_success_msg "loop_rootfs image file ${fsfile} unsquashfs -l OK." - fi - - return 0; -} - -attach_rootfs() { - local fsfile=$1 - - if ! check_fsfile "${fsfile}"; then - return 1 - fi - - # Using losetup from initrd - local rootdev="/dev/loop0" - if ! losetup ${rootdev} ${fsfile}; then - log_failure_msg "loop_rootfs could not attached ${fsfile} to loop-device ${rootdev}." - return 1 - fi - - # Latest losetup - #local rootdev=$(losetup --find --show ${fsfile}) - #if [ -z "${rootdev}" ]; then - # panic "loop_rootfs could not attached ${fsfile} to loop-device." - # return 1 - #fi - - # Propagate new local ROOT device and its ROOTFSTYPE - ROOTFSTYPE="${FILE_FSTYPE}" - ROOT="${rootdev}" - echo "ROOT=${ROOT}" >> /conf/param.conf - echo "ROOTFSTYPE=${ROOTFSTYPE}" >> /conf/param.conf - return 0; -} - -# 1 old file, 2 new file, 3 expected old_prefix, 4 expected new prefix -compare_files() { - local change=$(diff $1 $2) - #echo "change ${change}" - local old_prefix=$(echo "${change}" | sed -e '1d;3,4d' | awk -F = ' { print substr($2,0, length($2)-1) }') - local new_prefix=$(echo "${change}" | sed -e '1,3d' | awk -F = ' { print substr($2,0, length($2)-1) }') - #echo "old_prefix has '${old_prefix}', expected '${3}'" - #echo "new_prefix has '${new_prefix}', expected '${4}'" - [ "${3}" = "${old_prefix}" -a "${4}" = "${new_prefix}" ] - return $? -} - - -fallback_rootfs() { - local os_prefix_current="$1" - local os_prefix_fallback="$2" - # Cleanup - rm -f "${OS_PREFIX_FILE_LAST}" - rm -f "${BOOT_COUNTER_FILE}" - if [ "${os_prefix_fallback}" = "${OS_PREFIX_DEFAULT}" ]; then - # Factory reset fast path - log_success_msg "loop_rootfs fallback to factory default: ${OS_PREFIX} -> ${os_prefix_fallback}." - mv "${CONFIG_FILE}" "${CONFIG_FILE_OLD}" - cp "${CONFIG_FILE_DEFAULT}" "${CONFIG_FILE}" - else - # Setup config.txt - - #sed "s/os_prefix=${os_prefix_current}/os_prefix=${os_prefix_fallback}/g" "${CONFIG_FILE}" > "${CONFIG_FILE}.new" - #if ! compare_files "${CONFIG_FILE}" "${CONFIG_FILE}.new" "${os_prefix_current}" "${os_prefix_fallback}"; then - # log_failure_msg "loop_rootfs failed fallback setting in new ${CONFIG_FILE}, fallback to factory reset ${CONFIG_FILE_DEFAULT}." - # mv "${CONFIG_FILE}" "${CONFIG_FILE_OLD}" - # cp "${CONFIG_FILE_DEFAULT}" "${CONFIG_FILE}" - #else - # mv "${CONFIG_FILE}" "${CONFIG_FILE_OLD}" - # mv "${CONFIG_FILE}.new" "${CONFIG_FILE}" - #fi - - log_success_msg "loop_rootfs fallback to previous: ${OS_PREFIX} -> ${os_prefix_fallback}." - mv "${CONFIG_FILE}" "${CONFIG_FILE_OLD}" - cp "${BOOT_DIR}/${os_prefix_fallback}/config.txt" "${CONFIG_FILE}" - fi - sync - umount ${BOOT_DIR} - - # /usr/sbin/reboot --help - # BusyBox v1.30.1 (Debian 1:1.30.1-4) multi-call binary. - # Usage: reboot [-d DELAY] [-n] [-f] - # Reboot the system - # -d SEC Delay interval - # -n Do not sync - # -f Force (don't go through init) - # /usr/sbin/reboot -f - # - # /usr/bin/reboot --help - # Usage: {halt|reboot|poweroff} [-n] [reboot-arg] - # - /usr/bin/reboot reboot - exit 1 -} - -tee_date() { - ( while IFS= read -p -r line; do - printf '%s %s\n' "$(date -u +"%Y-%m-%d %H:%M:%S")" "$line" - done ) | tee -a $1 -} - -add_date() { - ( while IFS= read -r line; do - printf '%s %s\n' "$(date -u +"%Y-%m-%d %H:%M:%S")" "$line" - done ) >> $1 -} - -if [ "${ROOT}" != "file" ]; then - log_begin_msg "loop_rootfs skip non file ROOT ${ROOT}" - log_end_msg - exit 0 -fi - -log_begin_msg "loop_rootfs" -mkdir -p ${BOOT_DIR} - -# force fix verbose fseek, using undocumented options '-f', '-y' -if ! fsck -f -y -V -t vfat "${BOOT_PART}"; then - log_failure_msg "The vfat filesystem on ${BOOT_PART} seems to require a manual fsck, continuing" -fi - -if ! mount ${BOOT_PART} ${BOOT_DIR}; then - panic "loop_rootfs could not mount /boot." - exit 1 -fi - -# Make the 'debug' output file persistent, append -if [ -f /run/initramfs/initramfs.debug ]; then - add_date ${BOOT_DIR}/init_debug.log < /run/initramfs/initramfs.debug & -fi - -quiet_orig="${quiet}" -quiet=n - -# Bash Process Substitution to redir stdout/err to tee process, -# copying to file and console: -# exec &> >(tee -a ${BOOT_DIR}/initrd.log) -# -# But we ain't no bash, do a manual pipe instead -FIFO_OUT="/run/initramfs/out.fifo" -mkfifo "${FIFO_OUT}" -trap 'rm "${FIFO_OUT}"' EXIT - -if [ "${quiet_orig}" = "y" -o -n "${log_output}" ]; then - # Originally quiet was explicitly requested, only redir to file - # and leave console quiet. - # Same for debug log_output, as it redirects output already to tmpfs file. - add_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_OUT}" & - # add_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_ERR}" >&2 & -else - tee_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_OUT}" & - # tee_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_ERR}" >&2 & -fi -exec >${FIFO_OUT} 2>&1 - -if [ ! -f "${CONFIG_FILE}" ]; then - panic "loop_rootfs could not find ${CONFIG_FILE}." - exit 1 -fi - -OS_PREFIX=$(grep os_prefix ${CONFIG_FILE} | awk -F = ' { print substr($2,0, length($2)-1) }') -if [ -z "${OS_PREFIX}" ]; then - panic "loop_rootfs no os_prefix defined in ${CONFIG_FILE}." - exit 1 -fi - -if [ -f "${OS_PREFIX_FILE_LAST}" ]; then - BOOT_COUNTER=$(cat "${BOOT_COUNTER_FILE}") - if [ -n "$BOOT_COUNTER" -a $BOOT_COUNTER -eq $BOOT_COUNTER 2> /dev/null ]; then - # BOOT_COUNTER is a number - if [ $BOOT_COUNTER -gt 0 ]; then - # Fallback to OS_PREFIX_LAST, booted once already without being cleared! - OS_PREFIX_LAST=$(cat "${OS_PREFIX_FILE_LAST}") - IMAGE_FILE="${BOOT_DIR}/${OS_PREFIX_LAST}/rootfs.img" - if ! check_fsfile "${IMAGE_FILE}"; then - # IMAGE_FILE not existing for OS_PREFIX_FILE_LAST, corrupt or its fstype unknown - # Next: factory default OS_PREFIX_DEFAULT - log_failure_msg "loop_rootfs fallback ${OS_PREFIX_LAST} image file ${IMAGE_FILE} non existent or corrupt. Next factory default ${OS_PREFIX_DEFAULT}. Reboot..." - fallback_rootfs "${OS_PREFIX}" "${OS_PREFIX_DEFAULT}" - else - # Next: factory default OS_PREFIX_LAST - log_success_msg "loop_rootfs fallback ${OS_PREFIX} -> previous ${OS_PREFIX_LAST}, counter ${BOOT_COUNTER}. Reboot..." - fallback_rootfs "${OS_PREFIX}" "${OS_PREFIX_LAST}" - fi - exit 1 - else - # Testing new OS_PREFIX 1st boot: BOOT_COUNTER -> 1 - let BOOT_COUNTER=${BOOT_COUNTER} + 1 - echo ${BOOT_COUNTER} > "${BOOT_COUNTER_FILE}" - log_success_msg "loop_rootfs testing new ${OS_PREFIX} (counter -> ${BOOT_COUNTER} (1))." - fi - else - # Create BOOT_COUNTER, 1st boot: BOOT_COUNTER -> 1 - BOOT_COUNTER=1 - echo ${BOOT_COUNTER} > "${BOOT_COUNTER_FILE}" - log_success_msg "loop_rootfs testing new ${OS_PREFIX} (counter -> ${BOOT_COUNTER} (2))." - fi -elif [ -f "${BOOT_COUNTER_FILE}" ]; then - # cleanup BOOT_COUNTER_FILE, no OS_PREFIX_FILE_LAST - rm -f "${BOOT_COUNTER_FILE}" -fi - -IMAGE_FILE="${BOOT_DIR}/${OS_PREFIX}/rootfs.img" - -if ! attach_rootfs "${IMAGE_FILE}"; then - log_failure_msg "loop_rootfs could not attach to ${OS_PREFIX}, file ${IMAGE_FILE}." - if [ -n "${OS_PREFIX_LAST}" -a "${OS_PREFIX}" != "${OS_PREFIX_LAST}" ]; then - log_success_msg "loop_rootfs fallback ${OS_PREFIX} -> previous ${OS_PREFIX_LAST}. Reboot..." - fallback_rootfs "${OS_PREFIX}" "${OS_PREFIX_LAST}" - elif [ "${OS_PREFIX}" != "${OS_PREFIX_DEFAULT}" ]; then - log_success_msg "loop_rootfs fallback ${OS_PREFIX} -> factory default ${OS_PREFIX_DEFAULT}. Reboot..." - fallback_rootfs "${OS_PREFIX}" "${OS_PREFIX_DEFAULT}" - else - panic "loop_rootfs could not attach to factory default ${OS_PREFIX}, file ${IMAGE_FILE}. No fallback!" - fi - exit 1 -fi - -log_success_msg "loop_rootfs attached ${OS_PREFIX}, ${ROOTFSTYPE} file ${IMAGE_FILE} to loop-device ${ROOT}." - -log_end_msg - -quiet="${quiet_orig}" -exit 0 - diff --git a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-bottom b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-bottom new file mode 100755 index 0000000..e852b57 --- /dev/null +++ b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-bottom @@ -0,0 +1,24 @@ +#!/bin/sh -e + +PREREQ="udev" + +prereqs() +{ + echo "${PREREQ}" +} + +case ${1} in + prereqs) + prereqs + exit 0 + ;; +esac + +. /scripts/functions + +readonly BOOT_DIR="/mnt/boot" + +# move BOOT_DIR to the rootfs; fall back to util-linux mount that does +# not understand -o move +mount -n -o move ${BOOT_DIR} "${rootmnt:?}/boot" || mount -n --move ${BOOT_DIR} "${rootmnt}/boot" + diff --git a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-premount b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-premount new file mode 100755 index 0000000..02ad5b6 --- /dev/null +++ b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-premount @@ -0,0 +1,409 @@ +#!/bin/sh + +PREREQ="udev" + +prereqs() +{ + echo "${PREREQ}" +} + +case ${1} in + prereqs) + prereqs + exit 0 + ;; +esac + +# +# If 'debug' has been passed via the boot cmdline, +# logoutput will be made available to '/run/initramfs/initramfs.debug'. +# + +. /scripts/functions + +readonly BOOT_FSTYPE="vfat" +readonly BOOT_DIR="/mnt/boot" + +readonly USES_RASPI_CONFIG=1 + +# Current raspi config.txt with current OS_PREFIX +readonly RPI_CONFIG_FILE="${BOOT_DIR}/config.txt" +readonly RPI_CONFIG_FILE_OLD="${BOOT_DIR}/config.bak" + +# Current grub custom.cfg with current OS_PREFIX +readonly GRUB_CONFIG_FILE="${BOOT_DIR}/grub/custom.cfg" +readonly GRUB_CONFIG_FILE_OLD="${BOOT_DIR}/grub/custom.bak" + +# Optional fallback OS_PREFIX +readonly OS_PREFIX_FILE_LAST="${BOOT_DIR}/sys_last" +# Optional boot counter. +readonly BOOT_COUNTER_FILE="${BOOT_DIR}/sys_cntr" + +# +# To guarantee factory default fallback, have immutable: +# - Folder '/boot/sys_arm64_000/' folder (OS_PREFIX_DEFAULT), which includes +# - File '/boot/sys_arm64_000/config.txt' (RPI_CONFIG_FILE_DEFAULT). +# +# Notable: Every system folder contains its own immutable config.txt copy! +# + +# Default OS_PREFIX -> ${BOOT_DIR}/${OS_PREFIX_DEFAULT} +readonly OS_PREFIX_DEFAULT="sys_arm64_000" + +# Default raspi config.txt with factory default OS_PREFIX_DEFAULT +readonly RPI_CONFIG_FILE_DEFAULT="${BOOT_DIR}/${OS_PREFIX_DEFAULT}/config.txt" + +# Default grub custom.cfg with factory default OS_PREFIX_DEFAULT +readonly GRUB_CONFIG_FILE_DEFAULT="${BOOT_DIR}/${OS_PREFIX_DEFAULT}/custom.cfg" + +OS_PREFIX="" +OS_PREFIX_LAST="" +BOOT_COUNTER="" + +IMAGE_FILE="" +FILE_FSTYPE="" + +find_blkpart() { + local fstype_exp="$1" + local res="" + local blkparts=$(lsblk -l | grep part | cut -d" " -f1) + if [ -z "${blkparts}" ]; then + # May take some time on PC's after loading device modules (usb, ..) + local blkpartwait=180 + while [ "$(time_elapsed)" -lt "$blkpartwait" ]; do + blkparts=$(lsblk -l | grep part | cut -d" " -f1) + if [ -n "${blkparts}" ]; then + break + fi + sleep 1 + done + if [ -z "${blkparts}" ]; then + sync + panic "Block devices did not appear in time" + exit 1 + fi + fi + for i in ${blkparts} ; do + local FSTYPE=$(blkid -o value -s TYPE /dev/$i) + if [ "${FSTYPE}" = "${fstype_exp}" ]; then + res="/dev/$i" + break + fi + done + echo -n "${res}" +} + +check_fsfile() { + local fsfile=$1 + + if [ ! -f "${fsfile}" ]; then + log_failure_msg "Image file ${fsfile} doesn't exist." + return 1 + fi + log_success_msg "Image file ${fsfile} exists." + + FILE_FSTYPE=$(get_fstype "${fsfile}") + if [ -z "${FILE_FSTYPE}" -o "${FILE_FSTYPE}" = "unknown" ]; then + log_failure_msg "Image file ${fsfile} unknown fstype." + return 1 + fi + log_success_msg "Image file ${fsfile} of type ${FILE_FSTYPE}." + + if ! fsck -n -V -t "${FILE_FSTYPE}" "${fsfile}"; then + log_failure_msg "Image file ${fsfile} fsck failed." + return 1 + fi + log_success_msg "Image file ${fsfile} fsck OK." + + if [ "${FILE_FSTYPE}" = "squashfs" ]; then + if ! unsquashfs -l "${fsfile}" > /dev/null ; then + log_failure_msg "Image file ${fsfile} unsquashfs -l failed." + return 1 + fi + log_success_msg "Image file ${fsfile} unsquashfs -l OK." + fi + + return 0; +} + +attach_rootfs() { + local fsfile=$1 + + if ! check_fsfile "${fsfile}"; then + return 1 + fi + + # Using losetup from initrd + local rootdev="/dev/loop0" + if ! losetup ${rootdev} ${fsfile}; then + log_failure_msg "Could not attach ${fsfile} to loop-device ${rootdev}." + return 1 + fi + + # Latest losetup + #local rootdev=$(losetup --find --show ${fsfile}) + #if [ -z "${rootdev}" ]; then + # log_failure_msg "Could not attach ${fsfile} to loop-device." + # return 1 + #fi + + # Propagate new local ROOT device and its ROOTFSTYPE + ROOTFSTYPE="${FILE_FSTYPE}" + ROOT="${rootdev}" + echo "ROOT=${ROOT}" >> /conf/param.conf + echo "ROOTFSTYPE=${ROOTFSTYPE}" >> /conf/param.conf + return 0; +} + +# 1 old file, 2 new file, 3 expected old_prefix, 4 expected new prefix +compare_files() { + local change=$(diff $1 $2) + #echo "change ${change}" + local old_prefix=$(echo "${change}" | sed -e '1d;3,4d' | awk -F = ' { print substr($2,0, length($2)-1) }') + local new_prefix=$(echo "${change}" | sed -e '1,3d' | awk -F = ' { print substr($2,0, length($2)-1) }') + #echo "old_prefix has '${old_prefix}', expected '${3}'" + #echo "new_prefix has '${new_prefix}', expected '${4}'" + [ "${3}" = "${old_prefix}" -a "${4}" = "${new_prefix}" ] + return $? +} + + +fallback_rootfs() { + local os_prefix_current="$1" + local os_prefix_fallback="$2" + # Cleanup + rm -f "${OS_PREFIX_FILE_LAST}" + rm -f "${BOOT_COUNTER_FILE}" + if [ "${os_prefix_fallback}" = "${OS_PREFIX_DEFAULT}" ]; then + # Factory reset fast path + log_success_msg "Fallback to factory default: ${OS_PREFIX} -> ${os_prefix_fallback}." + if [ "${USES_RASPI_CONFIG}" = "1" ]; then + mv "${RPI_CONFIG_FILE}" "${RPI_CONFIG_FILE_OLD}" + cp "${RPI_CONFIG_FILE_DEFAULT}" "${RPI_CONFIG_FILE}" + else + mv "${GRUB_CONFIG_FILE}" "${GRUB_CONFIG_FILE_OLD}" + cp "${GRUB_CONFIG_FILE_DEFAULT}" "${GRUB_CONFIG_FILE}" + fi + else + # Setup config.txt + + #sed "s/os_prefix=${os_prefix_current}/os_prefix=${os_prefix_fallback}/g" "${RPI_CONFIG_FILE}" > "${RPI_CONFIG_FILE}.new" + #if ! compare_files "${RPI_CONFIG_FILE}" "${RPI_CONFIG_FILE}.new" "${os_prefix_current}" "${os_prefix_fallback}"; then + # log_failure_msg "Failed fallback setting in new ${RPI_CONFIG_FILE}, fallback to factory reset ${RPI_CONFIG_FILE_DEFAULT}." + # mv "${RPI_CONFIG_FILE}" "${RPI_CONFIG_FILE_OLD}" + # cp "${RPI_CONFIG_FILE_DEFAULT}" "${RPI_CONFIG_FILE}" + #else + # mv "${RPI_CONFIG_FILE}" "${RPI_CONFIG_FILE_OLD}" + # mv "${RPI_CONFIG_FILE}.new" "${RPI_CONFIG_FILE}" + #fi + + log_success_msg "Fallback to previous: ${OS_PREFIX} -> ${os_prefix_fallback}." + if [ "${USES_RASPI_CONFIG}" = "1" ]; then + mv "${RPI_CONFIG_FILE}" "${RPI_CONFIG_FILE_OLD}" + cp "${BOOT_DIR}/${os_prefix_fallback}/config.txt" "${RPI_CONFIG_FILE}" + else + mv "${GRUB_CONFIG_FILE}" "${GRUB_CONFIG_FILE_OLD}" + cp "${BOOT_DIR}/${os_prefix_fallback}/custom.cfg" "${GRUB_CONFIG_FILE}" + fi + fi + sync + umount ${BOOT_DIR} + + # /usr/sbin/reboot --help + # BusyBox v1.30.1 (Debian 1:1.30.1-4) multi-call binary. + # Usage: reboot [-d DELAY] [-n] [-f] + # Reboot the system + # -d SEC Delay interval + # -n Do not sync + # -f Force (don't go through init) + # panic "Reboot ... skipped" + /usr/sbin/reboot -d 0 -f + + # + # /usr/bin/reboot --help + # Usage: {halt|reboot|poweroff} [-n] [reboot-arg] + # + # /usr/bin/reboot reboot + exit 1 +} + +tee_date() { + ( while IFS= read -p -r line; do + printf '%s %s\n' "$(date -u +"%Y-%m-%d %H:%M:%S")" "$line" + done ) | tee -a $1 +} + +add_date() { + ( while IFS= read -r line; do + printf '%s %s\n' "$(date -u +"%Y-%m-%d %H:%M:%S")" "$line" + done ) >> $1 +} + +log_begin_msg "loop_rootfs" + +BOOT_PART=$(find_blkpart ${BOOT_FSTYPE}) + +if [ "${ROOT}" != "file" ]; then + log_success_msg "Skip loop for non file ROOT ${ROOT}" + if [ -n "${BOOT_PART}" ]; then + log_success_msg "(0) Trying first ${BOOT_FSTYPE} block device partition ${BOOT_PART}." + # force fix verbose fseek, using undocumented options '-f', '-y' + if ! fsck -f -y -V -t ${BOOT_FSTYPE} "${BOOT_PART}"; then + log_failure_msg "(0) The ${BOOT_FSTYPE} filesystem on ${BOOT_PART} seems to require a manual fsck, continuing" + fi + + mkdir -p ${BOOT_DIR} + + if ! mount -t ${BOOT_FSTYPE} ${BOOT_PART} ${BOOT_DIR} ; then + sync + log_failure_msg "(0) Could not mount ${BOOT_PART} on ${BOOT_DIR}." + exit 1 + fi + log_success_msg "(0) Mounted ${BOOT_PART} on ${BOOT_DIR}." + fi + log_end_msg + exit 0 +fi + +if [ -z "${BOOT_PART}" ]; then + sync + panic "Could not find first ${BOOT_FSTYPE} block device partition." + exit 1 +fi +log_success_msg "Using first ${BOOT_FSTYPE} block device partition ${BOOT_PART}." + +# force fix verbose fseek, using undocumented options '-f', '-y' +if ! fsck -f -y -V -t ${BOOT_FSTYPE} "${BOOT_PART}"; then + log_failure_msg "The ${BOOT_FSTYPE} filesystem on ${BOOT_PART} seems to require a manual fsck, continuing" +fi + +mkdir -p ${BOOT_DIR} + +if ! mount -t ${BOOT_FSTYPE} ${BOOT_PART} ${BOOT_DIR} ; then + sync + panic "Could not mount ${BOOT_PART} on ${BOOT_DIR}." + exit 1 +fi +log_success_msg "Mounted ${BOOT_PART} on ${BOOT_DIR}." + +# Make the 'debug' output file persistent (flush old) +if [ -f ${BOOT_DIR}/init_debug.log ]; then + rm -f ${BOOT_DIR}/init_debug.log +fi +if [ -f /run/initramfs/initramfs.debug ]; then + add_date ${BOOT_DIR}/init_debug.log < /run/initramfs/initramfs.debug & +fi + +quiet_orig="${quiet}" +quiet=n + +# Bash Process Substitution to redir stdout/err to tee process, +# copying to file and console: +# exec &> >(tee -a ${BOOT_DIR}/initrd.log) +# +# But we ain't no bash, do a manual pipe instead +FIFO_OUT="/run/initramfs/out.fifo" +mkfifo "${FIFO_OUT}" +trap 'rm "${FIFO_OUT}"' EXIT + +if [ "${quiet_orig}" = "y" -o -n "${log_output}" ]; then + # Originally quiet was explicitly requested, only redir to file + # and leave console quiet. + # Same for debug log_output, as it redirects output already to tmpfs file. + add_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_OUT}" & + # add_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_ERR}" >&2 & +else + tee_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_OUT}" & + # tee_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_ERR}" >&2 & +fi +exec >${FIFO_OUT} 2>&1 + +if [ "${USES_RASPI_CONFIG}" = "1" ]; then + if [ ! -f "${RPI_CONFIG_FILE}" ]; then + sync + panic "Could not find ${RPI_CONFIG_FILE}." + exit 1 + fi +else + if [ ! -f "${GRUB_CONFIG_FILE}" ]; then + sync + panic "Could not find ${GRUB_CONFIG_FILE}." + exit 1 + fi +fi + +if [ "${USES_RASPI_CONFIG}" = "1" ]; then + OS_PREFIX=$(grep os_prefix ${RPI_CONFIG_FILE} | awk -F = ' { print substr($2,0, length($2)-1) }') + if [ -z "${OS_PREFIX}" ]; then + sync + panic "No os_prefix defined in ${RPI_CONFIG_FILE}." + exit 1 + fi +else + OS_PREFIX=$(grep initrd ${GRUB_CONFIG_FILE} | awk -F / ' { print $2 }') + if [ -z "${OS_PREFIX}" ]; then + sync + panic "No os_prefix defined in ${GRUB_CONFIG_FILE}." + exit 1 + fi +fi + +if [ -f "${OS_PREFIX_FILE_LAST}" ]; then + BOOT_COUNTER=$(cat "${BOOT_COUNTER_FILE}") + if [ -n "${BOOT_COUNTER}" -a ${BOOT_COUNTER} -eq ${BOOT_COUNTER} 2> /dev/null ]; then + # BOOT_COUNTER is a number + if [ ${BOOT_COUNTER} -gt 0 ]; then + # Fallback to OS_PREFIX_LAST, booted once already without being cleared! + OS_PREFIX_LAST=$(cat "${OS_PREFIX_FILE_LAST}") + IMAGE_FILE="${BOOT_DIR}/${OS_PREFIX_LAST}/rootfs.img" + if ! check_fsfile "${IMAGE_FILE}"; then + # IMAGE_FILE not existing for OS_PREFIX_FILE_LAST, corrupt or its fstype unknown + # Next: factory default OS_PREFIX_DEFAULT + log_failure_msg "Fallback ${OS_PREFIX_LAST} image file ${IMAGE_FILE} non existent or corrupt. Next factory default ${OS_PREFIX_DEFAULT}. Reboot..." + fallback_rootfs "${OS_PREFIX}" "${OS_PREFIX_DEFAULT}" + else + # Next: factory default OS_PREFIX_LAST + log_success_msg "Fallback ${OS_PREFIX} -> previous ${OS_PREFIX_LAST}, counter ${BOOT_COUNTER}. Reboot..." + fallback_rootfs "${OS_PREFIX}" "${OS_PREFIX_LAST}" + fi + exit 1 + else + # Testing new OS_PREFIX 1st boot: BOOT_COUNTER -> 1 + let BOOT_COUNTER=${BOOT_COUNTER} + 1 + echo ${BOOT_COUNTER} > "${BOOT_COUNTER_FILE}" + log_success_msg "Testing new ${OS_PREFIX} (counter -> ${BOOT_COUNTER} (1))." + fi + else + # Create BOOT_COUNTER, 1st boot: BOOT_COUNTER -> 1 + BOOT_COUNTER=1 + echo ${BOOT_COUNTER} > "${BOOT_COUNTER_FILE}" + log_success_msg "Testing new ${OS_PREFIX} (counter -> ${BOOT_COUNTER} (2))." + fi +elif [ -f "${BOOT_COUNTER_FILE}" ]; then + # cleanup BOOT_COUNTER_FILE, no OS_PREFIX_FILE_LAST + rm -f "${BOOT_COUNTER_FILE}" +fi + +IMAGE_FILE="${BOOT_DIR}/${OS_PREFIX}/rootfs.img" + +if ! attach_rootfs "${IMAGE_FILE}"; then + log_failure_msg "Could not attach to ${OS_PREFIX}, file ${IMAGE_FILE}." + if [ -n "${OS_PREFIX_LAST}" -a "${OS_PREFIX}" != "${OS_PREFIX_LAST}" ]; then + log_success_msg "Fallback ${OS_PREFIX} -> previous ${OS_PREFIX_LAST}. Reboot..." + fallback_rootfs "${OS_PREFIX}" "${OS_PREFIX_LAST}" + elif [ "${OS_PREFIX}" != "${OS_PREFIX_DEFAULT}" ]; then + log_success_msg "Fallback ${OS_PREFIX} -> factory default ${OS_PREFIX_DEFAULT}. Reboot..." + fallback_rootfs "${OS_PREFIX}" "${OS_PREFIX_DEFAULT}" + else + sync + panic "Could not attach to factory default ${OS_PREFIX}, file ${IMAGE_FILE}. No fallback!" + fi + exit 1 +fi + +log_success_msg "Attached ${OS_PREFIX}, ${ROOTFSTYPE} file ${IMAGE_FILE} to loop-device ${ROOT}." + +log_end_msg + +quiet="${quiet_orig}" + diff --git a/stage2/01-sys-tweaks/files/resize2fs_once b/stage2/01-sys-tweaks/files/resize2fs_once index f1506a6..0754f2c 100644 --- a/stage2/01-sys-tweaks/files/resize2fs_once +++ b/stage2/01-sys-tweaks/files/resize2fs_once @@ -15,8 +15,8 @@ case "$1" in ROOT_PART=$(findmnt / -o source -n) ROOT_DEV_BASE=`lsblk -asr ${ROOT_PART} | tail -1 | awk ' { print $1 }'` ROOT_DEV="/dev/${ROOT_DEV_BASE}" - # Test ROOT_DEV deduction: (1) substring - if [ -n "${ROOT_PART} -a -n "${ROOT_DEV} -a -z "${ROOT_PART##*"${ROOT_DEV}"*}" ]; then + # Test ROOT_DEV deduction: (1) ROOT_DEV substring of ROOT_PART starting equal + if [ -n "${ROOT_PART} -a -n "${ROOT_DEV} -a -z "${ROOT_PART##"${ROOT_DEV}"*}" ]; then PARTED_OUT=`parted -s -m $ROOT_DEV unit B print` PART_NO=`echo "$PARTED_OUT" | grep ext4 | awk -F: ' { print $1 } '` # Test ROOT_DEV deduction: (2) identified partition number diff --git a/stage2/01-sys-tweaks/files/rotatelog_init_rootfs b/stage2/01-sys-tweaks/files/rotatelog_init_rootfs new file mode 100755 index 0000000..7d70dd2 --- /dev/null +++ b/stage2/01-sys-tweaks/files/rotatelog_init_rootfs @@ -0,0 +1,32 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: rotatelog_init_rootfs +# Required-Start: mountkernfs +# Required-Stop: umountroot +# Default-Start: S +# Default-Stop: 0 6 +# Short-Description: Rotates the /boot/init_rootfs.log if having more than 500 lines +### END INIT INFO +. /lib/lsb/init-functions +case "$1" in + start) + log_daemon_msg "Starting rotatelog_init_rootfs" + if [ -f /boot/init_rootfs.log ]; then + line_count=$(wc -l /boot/init_rootfs.log | awk ' { print $1 } ') + if [ -n "${line_count}" -a ${line_count} -eq ${line_count} 2> /dev/null ]; then + # line_count is a number + if [ ${line_count} -gt 500 ]; then + mv /boot/init_rootfs.log /boot/init_rootfs.bak + tail -n 50 /boot/init_rootfs.bak > /boot/init_rootfs.log + rm /boot/init_rootfs.bak + fi + fi + fi + log_end_msg $? + ;; + *) + echo "Usage: $0 start" >&2 + exit 3 + ;; +esac + diff --git a/stage2/01-sys-tweaks/files/rotatelog_init_rootfs.service b/stage2/01-sys-tweaks/files/rotatelog_init_rootfs.service new file mode 100644 index 0000000..26efdf6 --- /dev/null +++ b/stage2/01-sys-tweaks/files/rotatelog_init_rootfs.service @@ -0,0 +1,15 @@ +[Unit] +Description=Rotates init_rootfs.log if required +DefaultDependencies=no +After=systemd-remount-fs.service systemd-udevd.service +Before=local-fs-pre.target sysinit.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/etc/init.d/rotatelog_init_rootfs start + +[Install] +WantedBy=local-fs-pre.target +Alias=rotatelog_init_rootfs.service + diff --git a/stage2/02-net-tweaks/00-packages b/stage2/02-net-tweaks/00-packages index cc4a68e..ad08304 100644 --- a/stage2/02-net-tweaks/00-packages +++ b/stage2/02-net-tweaks/00-packages @@ -1,4 +1,2 @@ wpasupplicant wireless-tools firmware-atheros firmware-brcm80211 firmware-libertas firmware-misc-nonfree firmware-realtek -raspberrypi-net-mods -dhcpcd5 -net-tools +net-tools ifupdown iftop resolvconf diff --git a/stage2/02-net-tweaks/00-packages-sys-debian b/stage2/02-net-tweaks/00-packages-sys-debian new file mode 100644 index 0000000..1cc3c36 --- /dev/null +++ b/stage2/02-net-tweaks/00-packages-sys-debian @@ -0,0 +1 @@ +isc-dhcp-client diff --git a/stage2/02-net-tweaks/00-packages-sys-raspi b/stage2/02-net-tweaks/00-packages-sys-raspi new file mode 100644 index 0000000..fe25e27 --- /dev/null +++ b/stage2/02-net-tweaks/00-packages-sys-raspi @@ -0,0 +1,2 @@ +raspberrypi-net-mods +dhcpcd5 diff --git a/stage2/02-net-tweaks/01-run.sh b/stage2/02-net-tweaks/01-run.sh index d82381b..fae4ed0 100755 --- a/stage2/02-net-tweaks/01-run.sh +++ b/stage2/02-net-tweaks/01-run.sh @@ -1,7 +1,12 @@ #!/bin/bash -e -install -v -d "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d" -install -v -m 644 files/wait.conf "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/" +if [ "${TARGET_RASPI}" = "1" ]; then + install -v -d "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d" + install -v -m 644 files/wait.conf "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/" +fi + +install -m 644 files/network/ethN "${ROOTFS_DIR}/etc/network/interfaces.d/" +install -m 644 files/network/enN "${ROOTFS_DIR}/etc/network/interfaces.d/" install -v -d "${ROOTFS_DIR}/etc/wpa_supplicant" install -v -m 600 files/wpa_supplicant.conf "${ROOTFS_DIR}/etc/wpa_supplicant/" diff --git a/stage2/02-net-tweaks/files/network/enN b/stage2/02-net-tweaks/files/network/enN new file mode 100644 index 0000000..69e55d0 --- /dev/null +++ b/stage2/02-net-tweaks/files/network/enN @@ -0,0 +1,3 @@ +auto /en*=enp +allow-hotplug enp +iface enp inet dhcp diff --git a/stage2/02-net-tweaks/files/network/ethN b/stage2/02-net-tweaks/files/network/ethN new file mode 100644 index 0000000..cd4946c --- /dev/null +++ b/stage2/02-net-tweaks/files/network/ethN @@ -0,0 +1,3 @@ +auto /eth*=eth +allow-hotplug eth +iface eth inet dhcp diff --git a/stage2/04-console-autologin/00-packages b/stage2/04-console-autologin/00-packages-sys-raspi index 9e91ea1..9e91ea1 100644 --- a/stage2/04-console-autologin/00-packages +++ b/stage2/04-console-autologin/00-packages-sys-raspi diff --git a/stage2/04-console-autologin/01-run.sh b/stage2/04-console-autologin/01-run.sh index 26a0a1f..7d402ad 100755 --- a/stage2/04-console-autologin/01-run.sh +++ b/stage2/04-console-autologin/01-run.sh @@ -1,8 +1,10 @@ #!/bin/bash -e -# B2 Console Autologin -# B4 Desktop Autologin +if [ "${TARGET_RASPI}" = "1" ]; then + # B2 Console Autologin + # B4 Desktop Autologin -on_chroot << EOF - SUDO_USER="${FIRST_USER_NAME}" raspi-config nonint do_boot_behaviour B2 + on_chroot << EOF + SUDO_USER="${FIRST_USER_NAME}" raspi-config nonint do_boot_behaviour B2 EOF +fi diff --git a/stage3a/00-install-packages/00-packages b/stage3a/00-install-packages/00-packages index df13779..86891e2 100644 --- a/stage3a/00-install-packages/00-packages +++ b/stage3a/00-install-packages/00-packages @@ -2,12 +2,9 @@ alsa-utils librsvg2-common fonts-quicksand policykit-1 -gldriver-test fonts-droid-fallback fonts-liberation2 arandr -raspberrypi-net-mods tree libgl1-mesa-dri libgles1 libgles2-mesa mesa-utils -rp-prefapps diff --git a/stage3a/00-install-packages/00-packages-sys-raspi b/stage3a/00-install-packages/00-packages-sys-raspi new file mode 100644 index 0000000..ee7c786 --- /dev/null +++ b/stage3a/00-install-packages/00-packages-sys-raspi @@ -0,0 +1,2 @@ +gldriver-test +rp-prefapps diff --git a/stage3a_dev/00-install-packages/00-packages b/stage3a_dev/00-install-packages/00-packages index 0a4b100..9bf98d5 100644 --- a/stage3a_dev/00-install-packages/00-packages +++ b/stage3a_dev/00-install-packages/00-packages @@ -1,5 +1,5 @@ git git-all -build-essential autoconf automake libtool gawk alien fakeroot raspberrypi-kernel-headers +build-essential autoconf automake libtool gawk alien fakeroot python3 python3-dev python3-setuptools g++ gcc libc-dev libpthread-stubs0-dev g++ clang clang-tools diff --git a/stage3a_dev/00-install-packages/00-packages-sys-raspi b/stage3a_dev/00-install-packages/00-packages-sys-raspi new file mode 100644 index 0000000..18bb25d --- /dev/null +++ b/stage3a_dev/00-install-packages/00-packages-sys-raspi @@ -0,0 +1 @@ +raspberrypi-kernel-headers diff --git a/stage3a_dev/00-install-packages/00-run.sh b/stage3a_dev/00-install-packages/00-run.sh new file mode 100755 index 0000000..b1ef740 --- /dev/null +++ b/stage3a_dev/00-install-packages/00-run.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +if [ "${TARGET_RASPI}" != "1" ]; then + on_chroot << EOF + apt-get -o APT::Acquire::Retries=3 install --no-install-recommends -y linux-headers-${TARGET_ARCH} +EOF +fi diff --git a/stage3b/00-install-packages/00-packages b/stage3b/00-install-packages/00-packages index 9339cb6..ee7a72a 100644 --- a/stage3b/00-install-packages/00-packages +++ b/stage3b/00-install-packages/00-packages @@ -5,7 +5,6 @@ git ffmpeg mpv # omxplayer -raspberrypi-artwork gvfs -chromium rpi-chromium-mods +firefox-esr obconf diff --git a/stage3b/00-install-packages/00-packages-sys-raspi b/stage3b/00-install-packages/00-packages-sys-raspi new file mode 100644 index 0000000..44e1bc4 --- /dev/null +++ b/stage3b/00-install-packages/00-packages-sys-raspi @@ -0,0 +1 @@ +raspberrypi-artwork diff --git a/stage3b/04-console-autologin/00-packages b/stage3b/04-console-autologin/00-packages-sys-raspi index 9e91ea1..9e91ea1 100644 --- a/stage3b/04-console-autologin/00-packages +++ b/stage3b/04-console-autologin/00-packages-sys-raspi diff --git a/stage3b/04-console-autologin/01-run.sh b/stage3b/04-console-autologin/01-run.sh index 9a006f4..d5a4d68 100755 --- a/stage3b/04-console-autologin/01-run.sh +++ b/stage3b/04-console-autologin/01-run.sh @@ -1,8 +1,10 @@ #!/bin/bash -e -# B2 Console Autologin -# B4 Desktop Autologin +if [ "${TARGET_RASPI}" = "1" ]; then + # B2 Console Autologin + # B4 Desktop Autologin -on_chroot << EOF - SUDO_USER="${FIRST_USER_NAME}" raspi-config nonint do_boot_behaviour B4 + on_chroot << EOF + SUDO_USER="${FIRST_USER_NAME}" raspi-config nonint do_boot_behaviour B4 EOF +fi diff --git a/stage4/00-install-packages/00-packages-buster b/stage4/00-install-packages/00-packages index d03d850..9a30477 100644 --- a/stage4/00-install-packages/00-packages-buster +++ b/stage4/00-install-packages/00-packages @@ -2,24 +2,17 @@ python python3-pygame python-pygame python-tk python3 python3-tk thonny python3-pgzero python-serial python3-serial -#python-picamera python3-picamera debian-reference-en dillo -raspberrypi-net-mods raspberrypi-ui-mods python-pip python3-pip python3-numpy +pigpio python-pigpio python3-pigpio pypy -alacarte rc-gui sense-hat +alacarte tree libgl1-mesa-dri libgles1 libgles2-mesa xcompmgr geany -piclone -wiringpi pigpio python-pigpio python3-pigpio raspi-gpio python3-rpi.gpio -python-spidev python3-spidev python-twython python3-twython python-smbus python3-smbus python-flask python3-flask -pprompt -piwiz -rp-prefapps ffmpeg vlc diff --git a/stage4/00-install-packages/00-packages-bullseye b/stage4/00-install-packages/00-packages-bullseye index 28322dc..1a186dc 100644 --- a/stage4/00-install-packages/00-packages-bullseye +++ b/stage4/00-install-packages/00-packages-bullseye @@ -4,22 +4,16 @@ python3-pgzero python3-serial #python3-picamera debian-reference-en dillo -raspberrypi-net-mods raspberrypi-ui-mods +pigpio python3-pigpio python3-pip python3-numpy pypy -alacarte rc-gui sense-hat +alacarte tree libgl1-mesa-dri libgles1 libgles2-mesa xcompmgr geany -piclone -wiringpi pigpio python3-pigpio raspi-gpio python3-rpi.gpio -python3-spidev python3-twython python3-smbus python3-flask -pprompt -piwiz -rp-prefapps ffmpeg vlc diff --git a/stage4/00-install-packages/00-packages-sys-raspi b/stage4/00-install-packages/00-packages-sys-raspi new file mode 100644 index 0000000..03657ee --- /dev/null +++ b/stage4/00-install-packages/00-packages-sys-raspi @@ -0,0 +1,9 @@ +raspberrypi-net-mods raspberrypi-ui-mods +#python-picamera python3-picamera +piclone +wiringpi raspi-gpio python3-rpi.gpio +python-spidev python3-spidev +alacarte rc-gui sense-hat +pprompt +piwiz +rp-prefapps diff --git a/stage4/00-install-packages/00-packages-sys-raspi-bullseye b/stage4/00-install-packages/00-packages-sys-raspi-bullseye new file mode 100644 index 0000000..167f269 --- /dev/null +++ b/stage4/00-install-packages/00-packages-sys-raspi-bullseye @@ -0,0 +1,9 @@ +raspberrypi-net-mods raspberrypi-ui-mods +#python-picamera python3-picamera +piclone +wiringpi raspi-gpio python3-rpi.gpio +python3-spidev +alacarte rc-gui sense-hat +pprompt +piwiz +rp-prefapps diff --git a/stage4/00-install-packages/01-packages b/stage4/00-install-packages/01-packages new file mode 100644 index 0000000..fdf5e73 --- /dev/null +++ b/stage4/00-install-packages/01-packages @@ -0,0 +1,22 @@ +python-automationhat python3-automationhat +python-blinkt python3-blinkt +python-cap1xxx python3-cap1xxx +python-drumhat python3-drumhat +python-envirophat python3-envirophat +python-explorerhat python3-explorerhat +python-fourletterphat python3-fourletterphat +python-microdotphat python3-microdotphat +python-mote python3-mote +python-motephat python3-motephat +python-phatbeat python3-phatbeat +python-pianohat python3-pianohat +python-piglow python3-piglow +python-rainbowhat python3-rainbowhat +python-scrollphat python3-scrollphat +python-scrollphathd python3-scrollphathd +python-sn3218 python3-sn3218 +python-skywriter python3-skywriter +python-touchphat python3-touchphat +python-buttonshim python3-buttonshim +python-unicornhathd python3-unicornhathd +python-pantilthat python3-pantilthat diff --git a/stage4/00-install-packages/01-packages-bullseye b/stage4/00-install-packages/01-packages-bullseye index fdf5e73..5441d9d 100644 --- a/stage4/00-install-packages/01-packages-bullseye +++ b/stage4/00-install-packages/01-packages-bullseye @@ -1,22 +1,22 @@ -python-automationhat python3-automationhat -python-blinkt python3-blinkt -python-cap1xxx python3-cap1xxx -python-drumhat python3-drumhat -python-envirophat python3-envirophat -python-explorerhat python3-explorerhat -python-fourletterphat python3-fourletterphat -python-microdotphat python3-microdotphat -python-mote python3-mote -python-motephat python3-motephat -python-phatbeat python3-phatbeat -python-pianohat python3-pianohat -python-piglow python3-piglow -python-rainbowhat python3-rainbowhat -python-scrollphat python3-scrollphat -python-scrollphathd python3-scrollphathd -python-sn3218 python3-sn3218 -python-skywriter python3-skywriter -python-touchphat python3-touchphat -python-buttonshim python3-buttonshim -python-unicornhathd python3-unicornhathd -python-pantilthat python3-pantilthat +python3-automationhat +python3-blinkt +python3-cap1xxx +python3-drumhat +python3-envirophat +python3-explorerhat +python3-fourletterphat +python3-microdotphat +python3-mote +python3-motephat +python3-phatbeat +python3-pianohat +python3-piglow +python3-rainbowhat +python3-scrollphat +python3-scrollphathd +python3-sn3218 +python3-skywriter +python3-touchphat +python3-buttonshim +python3-unicornhathd +python3-pantilthat diff --git a/stage4/00-install-packages/01-packages-buster b/stage4/00-install-packages/01-packages-buster deleted file mode 100644 index 5441d9d..0000000 --- a/stage4/00-install-packages/01-packages-buster +++ /dev/null @@ -1,22 +0,0 @@ -python3-automationhat -python3-blinkt -python3-cap1xxx -python3-drumhat -python3-envirophat -python3-explorerhat -python3-fourletterphat -python3-microdotphat -python3-mote -python3-motephat -python3-phatbeat -python3-pianohat -python3-piglow -python3-rainbowhat -python3-scrollphat -python3-scrollphathd -python3-sn3218 -python3-skywriter -python3-touchphat -python3-buttonshim -python3-unicornhathd -python3-pantilthat diff --git a/stage4/03-bookshelf/00-run.sh b/stage4/03-bookshelf/00-run.sh index 8244568..8f485f5 100755 --- a/stage4/03-bookshelf/00-run.sh +++ b/stage4/03-bookshelf/00-run.sh @@ -1,15 +1,17 @@ #!/bin/sh -e -BOOKSHELF_URL="https://magpi.raspberrypi.org/bookshelf.xml" -GUIDE_URL="$(curl -s "$BOOKSHELF_URL" | awk -F '[<>]' "/<TITLE>Raspberry Pi Beginner's Guide 4th Edition<\/TITLE>/ {f=1; next} f==1 && /PDF/ {print \$3; exit}")" -OUTPUT="$(basename "$GUIDE_URL" | cut -f1 -d'?')" +if [ "${TARGET_RASPI}" = "1" ]; then + BOOKSHELF_URL="https://magpi.raspberrypi.org/bookshelf.xml" + GUIDE_URL="$(curl -s "$BOOKSHELF_URL" | awk -F '[<>]' "/<TITLE>Raspberry Pi Beginner's Guide 4th Edition<\/TITLE>/ {f=1; next} f==1 && /PDF/ {print \$3; exit}")" + OUTPUT="$(basename "$GUIDE_URL" | cut -f1 -d'?')" -if [ ! -f "files/$OUTPUT" ]; then - rm files/*.pdf -f - curl -s "$GUIDE_URL" -o "files/$OUTPUT" -fi + if [ ! -f "files/$OUTPUT" ]; then + rm files/*.pdf -f + curl -s "$GUIDE_URL" -o "files/$OUTPUT" + fi -file "files/$OUTPUT" | grep -q "PDF document" + file "files/$OUTPUT" | grep -q "PDF document" -install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/Bookshelf" -install -v -o 1000 -g 1000 -m 644 "files/$OUTPUT" "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/Bookshelf/" + install -v -o 1000 -g 1000 -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/Bookshelf" + install -v -o 1000 -g 1000 -m 644 "files/$OUTPUT" "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/Bookshelf/" +fi diff --git a/stage4/04-enable-xcompmgr/00-run.sh b/stage4/04-enable-xcompmgr/00-run.sh index 6a56a82..74b912c 100755 --- a/stage4/04-enable-xcompmgr/00-run.sh +++ b/stage4/04-enable-xcompmgr/00-run.sh @@ -1,5 +1,7 @@ #!/bin/bash -e -on_chroot << EOF - raspi-config nonint do_xcompmgr 0 +if [ "${TARGET_RASPI}" = "1" ]; then + on_chroot << EOF + raspi-config nonint do_xcompmgr 0 EOF +fi diff --git a/stage5/00-install-extras/00-packages b/stage5/00-install-extras/00-packages new file mode 100644 index 0000000..a6aca43 --- /dev/null +++ b/stage5/00-install-extras/00-packages @@ -0,0 +1,2 @@ +mu-editor +claws-mail diff --git a/stage5/00-install-extras/00-packages-bullseye b/stage5/00-install-extras/00-packages-bullseye index 7e678e4..a6aca43 100644 --- a/stage5/00-install-extras/00-packages-bullseye +++ b/stage5/00-install-extras/00-packages-bullseye @@ -1,16 +1,2 @@ mu-editor -#sonic-pi -#scratch nuscratch scratch3 -smartsim - -#minecraft-pi python-minecraftpi python-picraft python3-picraft -python3-sense-emu sense-emu-tools python3-sense-emu-doc - -#wolfram-engine claws-mail -greenfoot-unbundled bluej -#nodered -realvnc-vnc-viewer - -python3-games -code-the-classics diff --git a/stage5/00-install-extras/00-packages-buster b/stage5/00-install-extras/00-packages-sys-raspi index edf7b2e..9848de3 100644 --- a/stage5/00-install-extras/00-packages-buster +++ b/stage5/00-install-extras/00-packages-sys-raspi @@ -1,4 +1,3 @@ -mu-editor #sonic-pi #scratch nuscratch scratch3 smartsim @@ -7,7 +6,6 @@ smartsim python-sense-emu sense-emu-tools python-sense-emu-doc #wolfram-engine -claws-mail greenfoot-unbundled bluej #nodered realvnc-vnc-viewer diff --git a/stage5/00-install-extras/00-packages-sys-raspi-bullseye b/stage5/00-install-extras/00-packages-sys-raspi-bullseye new file mode 100644 index 0000000..2d0c598 --- /dev/null +++ b/stage5/00-install-extras/00-packages-sys-raspi-bullseye @@ -0,0 +1,14 @@ +#sonic-pi +#scratch nuscratch scratch3 +smartsim + +#minecraft-pi python-minecraftpi python-picraft python3-picraft +python3-sense-emu sense-emu-tools python3-sense-emu-doc + +#wolfram-engine +greenfoot-unbundled bluej +#nodered +realvnc-vnc-viewer + +python3-games +code-the-classics diff --git a/stage5/00-install-libreoffice/00-packages b/stage5/00-install-libreoffice/00-packages index 148e7b9..c3912d7 100644 --- a/stage5/00-install-libreoffice/00-packages +++ b/stage5/00-install-libreoffice/00-packages @@ -1,3 +1,2 @@ -libreoffice-pi -libreoffice-help-en-gb -libreoffice-l10n-en-gb +libreoffice-help-en-us +libreoffice-l10n-en-us diff --git a/stage5/00-install-libreoffice/00-packages-sys-debian b/stage5/00-install-libreoffice/00-packages-sys-debian new file mode 100644 index 0000000..63a39a7 --- /dev/null +++ b/stage5/00-install-libreoffice/00-packages-sys-debian @@ -0,0 +1 @@ +libreoffice diff --git a/stage5/00-install-libreoffice/00-packages-sys-raspi b/stage5/00-install-libreoffice/00-packages-sys-raspi new file mode 100644 index 0000000..0249e8e --- /dev/null +++ b/stage5/00-install-libreoffice/00-packages-sys-raspi @@ -0,0 +1 @@ +libreoffice-pi |