diff options
20 files changed, 211 insertions, 66 deletions
@@ -119,6 +119,18 @@ The following environment variables are supported: If using `ROOTFS_RO`, this variable specifies the shared `tmpfs` size for the overlays - see above. + * `BOOT_FSTYPE` (Default: `vfat`) + + Allows user to define the `/boot` filesystem type. For Raspberry this **must** be `vfat`, the default. + However, as we support other target system, this may be one of: `vfat`, `ext2`, `ext4` or `xfs`. + + * `BOOT_FSOPTIONS` (Default: `rw,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro`) + + Allows user to define the mount options for the `/boot` filesystem, see `BOOT_FSTYPE`. + For `vfat`, only the `codepage 437` is being hardcoded in the `initrd` `loop_rootfs` and scripts, as it is the default for GNU/Linux. + + Further more, producing the image failed with `codepage 850` on `vfat` operations on the `overlay` diversions within `pi-gen`. + * `REDUCED_FOOTPRINT` (Default: unset) If set to one, i.e. `REDUCED_FOOTPRINT=1`, @@ -1,11 +1,12 @@ #!/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 APT_GET_INSTALL_OPTS='-o APT::Acquire::Retries=3 -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"' + local packfile; local PACKAGES; log "Begin ${SUB_STAGE_DIR}" @@ -339,6 +340,14 @@ export BASE_QCOW2_SIZE=${BASE_QCOW2_SIZE:-15200M} source "${SCRIPT_DIR}/qcow2_handling" export ROOTFS_RO_OVERLAY_TMPFS_SIZE=${ROOTFS_RO_OVERLAY_TMPFS_SIZE:-128M} +# vfat, ext2, ext4 or xfs +export BOOT_FSTYPE=${BOOT_FSTYPE:-vfat} +# codepage is hardcoded in 'loop_rootfs' and scripts, as well as required by pi-gen build +if [ -z ${FAT_CODEPAGE+x} ]; then + readonly FAT_CODEPAGE="437" + export FAT_CODEPAGE +fi +export BOOT_FSOPTIONS=${BOOT_FSOPTIONS:-rw,noatime,fmask=0022,dmask=0022,codepage=${FAT_CODEPAGE},iocharset=ascii,shortname=mixed,errors=remount-ro} dependencies_check "${BASE_DIR}/depends" diff --git a/scripts/02-build-raspi-ro-smalldesk-jau.cfg b/scripts/02-build-raspi-ro-smalldesk-jau.cfg index 1ffbcf7..52f8ddc 100644 --- a/scripts/02-build-raspi-ro-smalldesk-jau.cfg +++ b/scripts/02-build-raspi-ro-smalldesk-jau.cfg @@ -43,9 +43,7 @@ export PUBKEY_ONLY_SSH=1 export STAGE_LIST="stage0 stage1 stage2 stage3a stage3b_lxde" #export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a stage3b_lxde" -#export SKIP_STAGE_LIST="stage0 stage1 stage2 stage3a" #export SKIP_IMAGES_LIST="stage2 stage3a stage3b_lxde" -#export SKIP_IMAGES_LIST="stage3a stage3b_lxde" export SKIP_IMAGES_LIST="stage2 stage3a" diff --git a/scripts/make_dualboot_image.sh b/scripts/make_dualboot_image.sh index b4f55ea..3b29718 100755 --- a/scripts/make_dualboot_image.sh +++ b/scripts/make_dualboot_image.sh @@ -21,12 +21,15 @@ if [ -z "${1}" -o -z "${2}" -o -z "${3}" -o -z "${4}" ]; then fi readonly grub_image="data/grub-i386-image01.bin" +# codepage is hardcoded in 'loop_rootfs' and scripts, as well as required by pi-gen build +readonly FAT_CODEPAGE="437" IMG_FILE="${1}" IMG_FILE_SIZE="${2}" MNT_DIR="${3}" SRC_DIR="${4}" +rm -f ${IMG_FILE} dd if=/dev/zero of=${IMG_FILE} bs=4M count=${IMG_FILE_SIZE} conv=notrunc iflag=count_bytes,skip_bytes oflag=seek_bytes,dsync status=progress sfdisk ${IMG_FILE} << EOF @@ -41,13 +44,13 @@ if [ -z "${nbd_dev}" ]; then fi p1dev="/dev/mapper/${nbd_dev}p1" -mkfs.fat -n BOOT -F 32 -v ${p1dev} +mkfs.fat -n BOOT -F 32 --codepage=${FAT_CODEPAGE} -v ${p1dev} sync ${sdir}/grubimg_to_blockdevice.sh "${grub_image}" "/dev/${nbd_dev}" mount ${p1dev} ${MNT_DIR} -cp -a ${SRC_DIR}/* ${MNT_DIR}/ +cp -dR --preserve=mode,timestamps ${SRC_DIR}/* ${MNT_DIR}/ sync umount ${MNT_DIR} sync diff --git a/scripts/qcow2_handling b/scripts/qcow2_handling index d757e65..770d074 100644 --- a/scripts/qcow2_handling +++ b/scripts/qcow2_handling @@ -3,6 +3,12 @@ sdir=`dirname $(readlink -f "${BASH_SOURCE[0]}")` rootdir=`dirname $sdir` +# codepage is hardcoded in 'loop_rootfs' and scripts, as well as required by pi-gen build +if [ -z ${FAT_CODEPAGE+x} ]; then + readonly FAT_CODEPAGE="437" + export FAT_CODEPAGE +fi + # QCOW2 Routines export CURRENT_IMAGE @@ -104,7 +110,7 @@ mount_qimage() { fi mount -v -t ext4 $MAP_ROOT_DEV "$2" mkdir -p "$2/boot" - mount -v -t vfat $MAP_BOOT_DEV "$2/boot" + mount -v -t ${BOOT_FSTYPE} $MAP_BOOT_DEV "$2/boot" CURRENT_MOUNTPOINT="$2" } export -f mount_qimage @@ -132,7 +138,7 @@ mount_rawimage() { fi mount -v -t ext4 $MAP_ROOT_DEV "$2" mkdir -p "$2/boot" - mount -v -t vfat $MAP_BOOT_DEV "$2/boot" + mount -v -t ${BOOT_FSTYPE} $MAP_BOOT_DEV "$2/boot" CURRENT_MOUNTPOINT="$2" } export -f mount_rawimage @@ -198,7 +204,25 @@ EOF sync kpartx -a /dev/${NBD_DEV} - mkfs.fat -n BOOT -F 32 -v $MAP_BOOT_DEV + case ${BOOT_FSTYPE} in + xfs) + mkfs.xfs -L BOOT $MAP_BOOT_DEV + ;; + ext4) + mkfs.ext4 -L BOOT -O "^huge_file,^metadata_csum,^64bit" $MAP_BOOT_DEV + ;; + ext2) + mkfs.ext2 -L BOOT -O "^has_journal,^huge_file,^metadata_csum,^64bit" $MAP_BOOT_DEV + ;; + vfat) + mkfs.fat -n BOOT -F 32 --codepage=${FAT_CODEPAGE} -v $MAP_BOOT_DEV + ;; + *) + echo "BOOT_FSTYPE not one of[xfs,ext4,ext2,vfat] but '${BOOT_FSTYPE}'. Exit." + exit 1; + ;; + esac + if [ "${ROOTFS_RO}" = "1" ] ; then # Set reserved-blocks-percentage for root to zero, no journaling mkfs.ext4 -L ROOTFS -m 0 -O "^has_journal,^huge_file,^metadata_csum,^64bit" $MAP_ROOT_DEV @@ -222,7 +246,7 @@ EOF mount -v -t ext4 $MAP_ROOT_DEV "${ROOTFS_DIR}" mkdir -p "${ROOTFS_DIR}/boot" - mount -v -t vfat $MAP_BOOT_DEV "${ROOTFS_DIR}/boot" + mount -v -t ${BOOT_FSTYPE} $MAP_BOOT_DEV "${ROOTFS_DIR}/boot" CURRENT_IMAGE=${WORK_DIR}/image-${STAGE}.qcow2 CURRENT_MOUNTPOINT=${ROOTFS_DIR} popd > /dev/null diff --git a/stage2/01-sys-tweaks/00-packages-nr b/stage2/01-sys-tweaks/00-packages-nr index fe2145c..5919d70 100644 --- a/stage2/01-sys-tweaks/00-packages-nr +++ b/stage2/01-sys-tweaks/00-packages-nr @@ -1,2 +1,2 @@ #cifs-utils - +lsof diff --git a/stage2/01-sys-tweaks/00-packages-sys-debian b/stage2/01-sys-tweaks/00-packages-sys-debian index b70f274..d8cdf6f 100644 --- a/stage2/01-sys-tweaks/00-packages-sys-debian +++ b/stage2/01-sys-tweaks/00-packages-sys-debian @@ -1,2 +1,3 @@ sysfsutils +xfsprogs grub-pc diff --git a/stage2/01-sys-tweaks/00-packages-sys-raspi b/stage2/01-sys-tweaks/00-packages-sys-raspi index d355fc8..4352d73 100644 --- a/stage2/01-sys-tweaks/00-packages-sys-raspi +++ b/stage2/01-sys-tweaks/00-packages-sys-raspi @@ -9,3 +9,7 @@ libpam-chksshpwd #python3 python3-rpi.gpio python3-gpiozero python-minimal python-rpi.gpio python-gpiozero fake-hwclock +plymouth +plymouth-label +plymouth-themes +rpd-plym-splash diff --git a/stage2/01-sys-tweaks/00-packages-sys-raspi-bullseye b/stage2/01-sys-tweaks/00-packages-sys-raspi-bullseye index 29261f8..e1e0b92 100644 --- a/stage2/01-sys-tweaks/00-packages-sys-raspi-bullseye +++ b/stage2/01-sys-tweaks/00-packages-sys-raspi-bullseye @@ -9,3 +9,7 @@ libpam-chksshpwd python3-minimal python3-rpi.gpio python3-gpiozero #python-minimal python-rpi.gpio python-gpiozero fake-hwclock +plymouth +plymouth-label +plymouth-themes +rpd-plym-splash diff --git a/stage2/01-sys-tweaks/00-patches/07-resize-init.diff b/stage2/01-sys-tweaks/00-patches/07-resize-init.diff deleted file mode 100644 index 8c41357..0000000 --- a/stage2/01-sys-tweaks/00-patches/07-resize-init.diff +++ /dev/null @@ -1,5 +0,0 @@ ---- stage2.orig/rootfs/boot/cmdline.txt -+++ stage2/rootfs/boot/cmdline.txt -@@ -1 +1 @@ --console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait -+console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh index 98b900d..34cee22 100755 --- a/stage2/01-sys-tweaks/01-run.sh +++ b/stage2/01-sys-tweaks/01-run.sh @@ -10,7 +10,8 @@ sed -i "s/OVERLAY_TMPFS_SIZE/${ROOTFS_RO_OVERLAY_TMPFS_SIZE}/g" "${ROOTFS_DIR}/e 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 -m 644 files/resize2fs_once.service "${ROOTFS_DIR}/lib/systemd/system/" +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/" @@ -41,12 +42,19 @@ fi on_chroot << EOF if [ "${TARGET_RASPI}" = "1" ]; then systemctl disable hwclock.sh + plymouth-set-default-theme pix + else + # No packages, still make sure + systemctl disable plymouth + systemctl mask plymouth fi - # /boot and ROOT are mounted via our 'loop_rootfs' script - # without having a live mapping in /etc/fstab. - systemctl disable systemd-remount-fs - systemctl mask systemd-remount-fs + if [ "${ROOTFS_RO}" = "1" ] ; then + # /boot and ROOT are mounted via our 'loop_rootfs' script + # without having a live mapping in /etc/fstab. + systemctl disable systemd-remount-fs + systemctl mask systemd-remount-fs + fi systemctl disable rsync systemctl mask rsync @@ -115,10 +123,10 @@ on_chroot << EOF fi done - # Allow this partition to be found by loop_rootfs - touch /boot/loop_rootfs.id - if [ "${ROOTFS_RO}" = "1" ] ; then + # Allow this partition to be found by loop_rootfs + touch /boot/loop_rootfs.id + systemctl disable resize2fs_once systemctl mask resize2fs_once @@ -142,16 +150,18 @@ on_chroot << EOF sed -i -e 's/BUSYBOX=auto/BUSYBOX=y/g;s/COMPRESS=gzip/COMPRESS=lzop/g' /etc/initramfs-tools/initramfs.conf fi + # Adding both codepage 437 (FAT_CODEPAGE) and 850 to be safe, as fsck.vfat may misbehave if [ "${TARGET_RASPI}" = "1" ]; then - KMODULES="squashfs" + KMODULES="nls_cp437 nls_cp850 nls_ascii squashfs fat vfat drm vc4" else - KMODULES="nls_cp437 nls_ascii fat vfat squashfs loop usb-common usbcore libahci ahci libata scsi_mod sd_mod usb-storage" + KMODULES="nls_cp437 nls_cp850 nls_ascii fat vfat squashfs loop usb-common usbcore libahci ahci libata scsi_mod sd_mod usb-storage drm" fi for i in \${KMODULES} ; do echo "\$i" >> /etc/modules echo "\$i" >> /etc/initramfs-tools/modules done else + systemctl unmask resize2fs_once systemctl enable resize2fs_once fi EOF @@ -159,10 +169,12 @@ EOF if [ "${ROOTFS_RO}" = "1" ] ; then 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" + install -m 644 files/boot/config-rootfs_ro.txt "${ROOTFS_DIR}/boot/sys_${TARGET_ARCH}_000/config.txt" + install -m 644 files/boot/sys_arm64_000/cmdline-rootfs_ro.txt "${ROOTFS_DIR}/boot/sys_${TARGET_ARCH}_000/cmdline.txt" + sed -i "s/sys_arm64_000/sys_${TARGET_ARCH}_000/g" "${ROOTFS_DIR}/boot/config.txt" + sed -i "s/sys_arm64_000/sys_${TARGET_ARCH}_000/g" "${ROOTFS_DIR}/boot/sys_${TARGET_ARCH}_000/config.txt" else - install -m 644 files/grub/custom.cfg "${ROOTFS_DIR}/boot/grub/custom.cfg" + install -m 644 files/grub/custom-rootfs_ro.cfg "${ROOTFS_DIR}/boot/grub/custom.cfg" sed -i "s/sys_amd64_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=.*$/GRUB_DEFAULT=loop_rootfs/g;s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=0/g;s/#GRUB_TERMINAL=.*$/GRUB_TERMINAL=console/g;s/#GRUB_DISABLE_LINUX_UUID=.*$/GRUB_DISABLE_LINUX_UUID=true/g' "${ROOTFS_DIR}/etc/default/grub" @@ -178,7 +190,9 @@ if [ "${ROOTFS_RO}" = "1" ] ; then fi 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" + sed -i "s/sys_arm64_000/sys_${TARGET_ARCH}_000/g" "${ROOTFS_DIR}/etc/initramfs-tools/scripts/init-premount/loop_rootfs" + sed -i "s/BOOT_FSTYPE=.*$/BOOT_FSTYPE=${BOOT_FSTYPE}/g" "${ROOTFS_DIR}/etc/initramfs-tools/scripts/init-premount/loop_rootfs" + sed -i "s/BOOT_FSOPTIONS=.*$/BOOT_FSOPTIONS=${BOOT_FSOPTIONS}/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 @@ -188,8 +202,8 @@ if [ "${ROOTFS_RO}" = "1" ] ; then else 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" + install -m 644 files/boot/config-rootfs_rw.txt "${ROOTFS_DIR}/boot/sys_${TARGET_ARCH}_000/config.txt" + install -m 644 files/boot/sys_arm64_000/cmdline-rootfs_rw.txt "${ROOTFS_DIR}/boot/sys_${TARGET_ARCH}_000/cmdline.txt" fi fi @@ -210,8 +224,10 @@ on_chroot <<EOF setupcon --force --save-only -v usermod --pass='*' root + KVERSION=\$(ls /lib/modules/ | tail -n 1) if [ "${ROOTFS_RO}" = "1" ]; then - KVERSION=\$(ls /lib/modules/ | tail -n 1) + rm -f /boot/sys_${TARGET_ARCH}_000/initrd.img + if [ "${TARGET_RASPI}" = "1" ]; then echo "mkinitramfs for kernel version: \${KVERSION}" /usr/sbin/mkinitramfs -o /boot/sys_${TARGET_ARCH}_000/initrd.img \${KVERSION} @@ -235,10 +251,18 @@ on_chroot <<EOF find /boot/ -maxdepth 1 -type f \ -exec cp -d --preserve=all \{\} /data/sdcard/ \; cp -a /boot/sys_${TARGET_ARCH}_000 /data/sdcard/ + else + if [ "${TARGET_RASPI}" != "1" ]; then + update-initramfs -u -k \${KVERSION} + fi fi if [ "${TARGET_RASPI}" != "1" ]; then update-grub - grub-install --force-file-id --modules="gzio part_msdos fat" /dev/${NBD_DEV} + if [ "${ROOTFS_RO}" = "1" ] ; then + grub-install --force-file-id --modules="gzio part_msdos fat" /dev/${NBD_DEV} + else + grub-install --force-file-id --modules="gzio part_msdos fat ext2" /dev/${NBD_DEV} + fi # Remove storage device related 'search.fs_uuid' and allow multi homing rm -f /boot/grub/i386-pc/load.cfg diff --git a/stage2/01-sys-tweaks/files/boot/sys_arm64_000/cmdline-rootfs_ro.txt b/stage2/01-sys-tweaks/files/boot/sys_arm64_000/cmdline-rootfs_ro.txt index 015beb1..6218f03 100755 --- a/stage2/01-sys-tweaks/files/boot/sys_arm64_000/cmdline-rootfs_ro.txt +++ b/stage2/01-sys-tweaks/files/boot/sys_arm64_000/cmdline-rootfs_ro.txt @@ -1 +1 @@ -dwc_otg.lpm_enable=0 console=tty3 root=file elevator=deadline fsck.repair=no rootwait quiet +dwc_otg.lpm_enable=0 console=tty3 root=file ro elevator=deadline fsck.repair=no loglevel=3 logo.nologo splash quiet plymouth.ignore-serial-consoles vt.global_cursor_default=0 diff --git a/stage2/01-sys-tweaks/files/boot/sys_arm64_000/cmdline-rootfs_rw.txt b/stage2/01-sys-tweaks/files/boot/sys_arm64_000/cmdline-rootfs_rw.txt index c321838..42962cc 100755 --- a/stage2/01-sys-tweaks/files/boot/sys_arm64_000/cmdline-rootfs_rw.txt +++ b/stage2/01-sys-tweaks/files/boot/sys_arm64_000/cmdline-rootfs_rw.txt @@ -1 +1 @@ -dwc_otg.lpm_enable=0 console=tty3 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet +dwc_otg.lpm_enable=0 console=tty3 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait loglevel=3 logo.nologo splash quiet plymouth.ignore-serial-consoles vt.global_cursor_default=0 diff --git a/stage2/01-sys-tweaks/files/grub/custom.cfg b/stage2/01-sys-tweaks/files/grub/custom-rootfs_ro.cfg index 7ba9eea..16157f6 100644 --- a/stage2/01-sys-tweaks/files/grub/custom.cfg +++ b/stage2/01-sys-tweaks/files/grub/custom-rootfs_ro.cfg @@ -3,7 +3,7 @@ menuentry 'Debian GNU/Linux loop_rootfs' --id loop_rootfs { insmod part_msdos insmod fat echo 'Loading Linux ...' - linux /sys_amd64_000/vmlinuz root=file ro quiet + linux /sys_amd64_000/vmlinuz console=tty3 root=file ro elevator=none fsck.repair=no echo 'Loading initial ramdisk ...' initrd /sys_amd64_000/initrd.img } diff --git a/stage2/01-sys-tweaks/files/initramfs/fsck_custom b/stage2/01-sys-tweaks/files/initramfs/fsck_custom index 133d26e..4fbc1c4 100755 --- a/stage2/01-sys-tweaks/files/initramfs/fsck_custom +++ b/stage2/01-sys-tweaks/files/initramfs/fsck_custom @@ -21,7 +21,7 @@ fi . /usr/share/initramfs-tools/scripts/functions . /usr/share/initramfs-tools/hook-functions -fsck_types="ext4 squashfs vfat" +fsck_types="xfs ext4 ext2 vfat" copy_exec /sbin/fsck copy_exec /sbin/logsave diff --git a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-bottom b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-bottom index e852b57..73e1121 100755 --- a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-bottom +++ b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-bottom @@ -16,8 +16,20 @@ esac . /scripts/functions +. /conf/param.conf + readonly BOOT_DIR="/mnt/boot" +# cleanup logging jobs +if [ -n "${LOOP_ROOTFS_LOG_PIDS}" ]; then + for i in ${LOOP_ROOTFS_LOG_PIDS} ; do + if [ -d "/proc/${i}" ]; then + kill $i + fi + done +fi +echo "LOOP_ROOTFS_LOG_PIDS=\"\"" >> /conf/param.conf + # 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 index 7805e17..3b0b5bc 100755 --- a/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-premount +++ b/stage2/01-sys-tweaks/files/initramfs/loop_rootfs-premount @@ -21,7 +21,11 @@ esac . /scripts/functions -readonly BOOT_FSTYPE="vfat" +# codepage is hardcoded in 'loop_rootfs' and scripts, as well as required by pi-gen build +# Note: fsck.vfat '-c ${FAT_CODEPAGE}' leads to usage page despite being a valid argument, using 850 for fsck.vfat only. +readonly FAT_CODEPAGE="437" +readonly BOOT_FSTYPE=vfat +readonly BOOT_FSOPTIONS=rw,noatime,fmask=0022,dmask=0022,codepage=${FAT_CODEPAGE},iocharset=ascii,shortname=mixed,errors=remount-ro readonly BOOT_DIR="/mnt/boot" readonly USES_RASPI_CONFIG=1 @@ -85,6 +89,10 @@ mylog_warning_msg() { _mylog "Warning: %s\\n" "$*" } +mylog_info_msg() { + _mylog "Info: %s\\n" "$*" +} + mylog_begin_msg() { _mylog "Begin: %s ... " "$*" } @@ -95,16 +103,17 @@ mylog_end_msg() { find_partition_base() { local fstype_exp="$1" - local mnt_dir="$2" - local file_exp="$3" - local blkparts=$(lsblk -l | grep part | cut -d" " -f1) + local mnt_opts="$2" + local mnt_dir="$3" + local file_exp="$4" + local blkparts=$(lsblk -l | grep part | cut -d" " -f1 | tr '\n' ' ') local part_dev="" if [ -z "${blkparts}" ]; then # May take some time on PC's after loading device modules (usb, ..) local blkpartwait=180 - mylog_warning_msg "Waiting up to ${blkpartwait} seconds for block devices to become online ..." + mylog_info_msg "Waiting up to ${blkpartwait} seconds for block devices to become online ..." while [ "$(time_elapsed)" -lt "$blkpartwait" ]; do - blkparts=$(lsblk -l | grep part | cut -d" " -f1) + blkparts=$(lsblk -l | grep part | cut -d" " -f1 | tr '\n' ' ') if [ -n "${blkparts}" ]; then break fi @@ -122,15 +131,43 @@ find_partition_base() { if [ "${fs_type}" = "${fstype_exp}" ]; then part_dev="/dev/$i" # force fix verbose fseek, using undocumented options '-f', '-y' - if ! fsck -f -y -V -t ${fs_type} "${part_dev}" >&2 ; then - mylog_warning_msg "The ${fs_type} filesystem on ${part_dev} seems to require a manual fsck, continuing" + case ${fs_type} in + xfs) + # a NOP + mylog_info_msg "Running: fsck.xfs ${part_dev}" + fsck.xfs ${part_dev} >&2 + ;; + ext4) + mylog_info_msg "Running: fsck.ext4 -p ${part_dev}" + fsck.ext4 -p ${part_dev} >&2 + ;; + ext2) + mylog_info_msg "Running: fsck.ext2 -p ${part_dev}" + fsck.ext2 -p ${part_dev} >&2 + ;; + vfat) + # Note: fsck.vfat '-c ${FAT_CODEPAGE}' leads to usage page despite being a valid argument, using 850 for fsck.vfat only. + # mylog_info_msg "Running: fsck.vfat -a -w -c ${FAT_CODEPAGE} ${part_dev}" + # fsck.vfat -a -w -c ${FAT_CODEPAGE} ${part_dev} >&2 + mylog_info_msg "Running: fsck.vfat -a -w ${part_dev}" + fsck.vfat -a -w ${part_dev} >&2 + ;; + *) + mylog_info_msg "Running: fsck -f -y -t ${fs_type} ${part_dev}" + fsck -f -y -t ${fs_type} ${part_dev} >&2 + ;; + esac + if [ $? -ne 0 ]; then + mylog_warning_msg "fsck ${fs_type}: Filesystem on ${part_dev} seems to require a manual fsck, continuing" + else + mylog_success_msg "fsck ${fs_type}: Filesystem on ${part_dev} OK" fi - if ! mount -t ${fs_type} ${part_dev} ${mnt_dir} >&2 ; then - mylog_warning_msg "Could not mount ${fs_type} from ${part_dev} on ${mnt_dir}, continuing." + if ! mount -t ${fs_type} -o ${mnt_opts} ${part_dev} ${mnt_dir} >&2 ; then + mylog_warning_msg "Could not mount ${fs_type} with '${mnt_opts}' from ${part_dev} on ${mnt_dir}, continuing." part_dev="" continue fi - mylog_success_msg "Mounted ${fs_type} from ${part_dev} on ${mnt_dir} ..." + mylog_success_msg "Mounted ${fs_type} with '${mnt_opts}' from ${part_dev} on ${mnt_dir} ..." if [ -f "${mnt_dir}/${file_exp}" ] ; then mylog_success_msg "Found "${mnt_dir}/${file_exp}" on mounted ${fs_type} from ${part_dev}, done!" break @@ -145,13 +182,13 @@ find_partition_base() { } find_partition() { - local part_dev=$(find_partition_base "$1" "$2" "$3") + local part_dev=$(find_partition_base $*) if [ -z "${part_dev}" ]; then # May take some time on PC's after loading device modules (usb, ..) local blkpartwait=180 - mylog_warning_msg "Retrying up to ${blkpartwait} seconds finding ${BOOT_FSTYPE} partition for ${BOOT_DIR} ..." + mylog_info_msg "Retrying up to ${blkpartwait} seconds finding ${BOOT_FSTYPE} partition for ${BOOT_DIR} ..." while [ "$(time_elapsed)" -lt "$blkpartwait" ]; do - part_dev=$(find_partition_base "$1" "$2" "$3") + part_dev=$(find_partition_base $*) if [ -n "${part_dev}" ]; then break fi @@ -177,11 +214,12 @@ check_fsfile() { fi mylog_success_msg "Image file ${fsfile} of type ${FILE_FSTYPE}." - if ! fsck -n -V -t "${FILE_FSTYPE}" "${fsfile}"; then - mylog_failure_msg "Image file ${fsfile} fsck failed." + mylog_info_msg "Running: fsck -f -y -t ${FILE_FSTYPE} ${fsfile}" + if ! fsck -f -y -t ${FILE_FSTYPE} ${fsfile} >&2 ; then + mylog_failure_msg "fsck ${FILE_FSTYPE}: Image file ${fsfile} fsck failed." return 1 fi - mylog_success_msg "Image file ${fsfile} fsck OK." + mylog_success_msg "fsck ${fs_type}: Image file ${fsfile} OK" if [ "${FILE_FSTYPE}" = "squashfs" ]; then if ! unsquashfs -l "${fsfile}" > /dev/null ; then @@ -297,20 +335,21 @@ fallback_rootfs() { tee_date() { ( while IFS= read -p -r line; do - printf '%s %s\n' "$(date -u +"%Y-%m-%d %H:%M:%S")" "$line" + printf '%s %s\n' "$(/usr/bin/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" + printf '%s %s\n' "$(/usr/bin/date -u +"%Y-%m-%d %H:%M:%S")" "$line" done ) >> $1 } +LOOP_ROOTFS_LOG_PIDS="" mylog_begin_msg "loop_rootfs" mkdir -p ${BOOT_DIR} -BOOT_PART=$(find_partition ${BOOT_FSTYPE} ${BOOT_DIR} "loop_rootfs.id") +BOOT_PART=$(find_partition ${BOOT_FSTYPE} ${BOOT_FSOPTIONS} ${BOOT_DIR} "loop_rootfs.id") if [ "${ROOT}" != "file" ]; then mylog_success_msg "Skip loop for non file ROOT ${ROOT}" @@ -336,6 +375,7 @@ if [ -f ${BOOT_DIR}/init_debug.log ]; then fi if [ -f /run/initramfs/initramfs.debug ]; then add_date ${BOOT_DIR}/init_debug.log < /run/initramfs/initramfs.debug & + LOOP_ROOTFS_LOG_PIDS="${LOOP_ROOTFS_LOG_PIDS} $!" fi quiet_orig="${quiet}" @@ -360,6 +400,8 @@ else tee_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_OUT}" & # tee_date ${BOOT_DIR}/init_rootfs.log < "${FIFO_ERR}" >&2 & fi +LOOP_ROOTFS_LOG_PIDS="${LOOP_ROOTFS_LOG_PIDS} $!" + exec >${FIFO_OUT} 2>&1 if [ "${USES_RASPI_CONFIG}" = "1" ]; then @@ -445,6 +487,9 @@ if ! attach_rootfs "${IMAGE_FILE}"; then exit 1 fi +LOOP_ROOTFS_LOG_PIDS=${LOOP_ROOTFS_LOG_PIDS##*( )} +echo "LOOP_ROOTFS_LOG_PIDS=\"${LOOP_ROOTFS_LOG_PIDS}\"" >> /conf/param.conf + mylog_success_msg "Attached ${OS_PREFIX}, ${ROOTFSTYPE} file ${IMAGE_FILE} to loop-device ${ROOT}." mylog_end_msg diff --git a/stage2/01-sys-tweaks/files/initramfs/test/reset_initrd.sh b/stage2/01-sys-tweaks/files/initramfs/test/reset_initrd.sh index 77b2f0a..17fb1ca 100755 --- a/stage2/01-sys-tweaks/files/initramfs/test/reset_initrd.sh +++ b/stage2/01-sys-tweaks/files/initramfs/test/reset_initrd.sh @@ -1,10 +1,9 @@ #!/bin/sh -set -x +#dest="root@zaf502" +dest="root@virtl09" -cd /etc/initramfs-tools/ -cp /home/pi/loop_rootfs scripts/init-premount/loop_rootfs -mkinitramfs -o /home/pi/initrd.img 5.10.17-v8+ -cp /home/pi/initrd.img /boot/sys_arm64_000/initrd.img -cp /home/pi/initrd.img /boot/sys_arm64_001/initrd.img -sync +scp extra_execs ${dest}:/etc/initramfs-tools/hooks/ +scp loop_rootfs-bottom ${dest}:/etc/initramfs-tools/scripts/init-bottom/loop_rootfs +scp loop_rootfs-premount ${dest}:/etc/initramfs-tools/scripts/init-premount/loop_rootfs +echo mkinitramfs -o /boot/sys_arm64_000/initrd.img 5.10.17-v8+ diff --git a/stage2/01-sys-tweaks/files/resize2fs_once b/stage2/01-sys-tweaks/files/resize2fs_once index 0754f2c..f8e45a6 100644..100755 --- a/stage2/01-sys-tweaks/files/resize2fs_once +++ b/stage2/01-sys-tweaks/files/resize2fs_once @@ -1,9 +1,9 @@ #!/bin/sh ### BEGIN INIT INFO # Provides: resize2fs_once -# Required-Start: +# Required-Start: mountkernfs # Required-Stop: -# Default-Start: 3 +# Default-Start: S # Default-Stop: # Short-Description: Resize the root filesystem to fill partition # Description: diff --git a/stage2/01-sys-tweaks/files/resize2fs_once.service b/stage2/01-sys-tweaks/files/resize2fs_once.service new file mode 100644 index 0000000..0c755a8 --- /dev/null +++ b/stage2/01-sys-tweaks/files/resize2fs_once.service @@ -0,0 +1,15 @@ +[Unit] +Description=Resize the root filesystem to fill partition +DefaultDependencies=no +After=systemd-udevd.service +Before=systemd-remount-fs.service systemd-random-seed.service systemd-journald.service local-fs-pre.target sysinit.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/etc/init.d/resize2fs_once start + +[Install] +WantedBy=systemd-remount-fs.service +Alias=resize2fs_once.service + |