diff --git a/Dockerfile b/Dockerfile index cf03b06..bf2e3d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apt-get -y update && \ git vim parted \ quilt coreutils qemu-user-static debootstrap zerofree zip dosfstools \ libarchive-tools libcap2-bin rsync grep udev xz-utils curl xxd file kmod bc \ - binfmt-support ca-certificates fdisk gpg pigz arch-test \ + binfmt-support ca-certificates fdisk gpg pigz arch-test f2fs-tools\ && rm -rf /var/lib/apt/lists/* COPY . /pi-gen/ diff --git a/README_AURACAST_SYSTEM.md b/README_AURACAST_SYSTEM.md index e5fe7b1..8ca9365 100644 --- a/README_AURACAST_SYSTEM.md +++ b/README_AURACAST_SYSTEM.md @@ -9,3 +9,6 @@ - install docker - install poetry - install wireguard +- install openocd + +TODO: migrate to https://github.com/raspberrypi/rpi-image-gen \ No newline at end of file diff --git a/export-image/05-finalise/01-run.sh b/export-image/05-finalise/01-run.sh index c59c23b..aae179b 100755 --- a/export-image/05-finalise/01-run.sh +++ b/export-image/05-finalise/01-run.sh @@ -96,7 +96,12 @@ fi ROOT_DEV="$(awk "\$2 == \"${ROOTFS_DIR}\" {print \$1}" /etc/mtab)" unmount "${ROOTFS_DIR}" -zerofree "${ROOT_DEV}" +ROOTFS_TYPE=$(lsblk -no FSTYPE "${ROOT_DEV}") +if [ "$ROOTFS_TYPE" = "ext4" ] || [ "$ROOTFS_TYPE" = "ext3" ] || [ "$ROOTFS_TYPE" = "ext2" ]; then + zerofree "${ROOT_DEV}" +else + echo "Skipping zerofree: rootfs is not ext2/3/4 (detected: $ROOTFS_TYPE)" +fi unmount_image "${IMG_FILE}" diff --git a/export-image/prerun.sh b/export-image/prerun.sh index 6a5309a..9394538 100755 --- a/export-image/prerun.sh +++ b/export-image/prerun.sh @@ -30,7 +30,10 @@ truncate -s "${IMG_SIZE}" "${IMG_FILE}" parted --script "${IMG_FILE}" mklabel msdos parted --script "${IMG_FILE}" unit B mkpart primary fat32 "${BOOT_PART_START}" "$((BOOT_PART_START + BOOT_PART_SIZE - 1))" -parted --script "${IMG_FILE}" unit B mkpart primary ext4 "${ROOT_PART_START}" "$((ROOT_PART_START + ROOT_PART_SIZE - 1))" +# Default ext4 root partition (commented out for F2FS) +# parted --script "${IMG_FILE}" unit B mkpart primary ext4 "${ROOT_PART_START}" "$((ROOT_PART_START + ROOT_PART_SIZE - 1))" +# F2FS root partition +parted --script "${IMG_FILE}" unit B mkpart primary f2fs "${ROOT_PART_START}" "$((ROOT_PART_START + ROOT_PART_SIZE - 1))" echo "Creating loop device..." cnt=0 @@ -63,9 +66,14 @@ else fi mkdosfs -n bootfs -F "$FAT_SIZE" -s 4 -v "$BOOT_DEV" > /dev/null -mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null +# Default ext4 root filesystem creation (commented out for F2FS) +# mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null +# mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4 + +# F2FS root filesystem creation +mkfs.f2fs -l rootfs "$ROOT_DEV" +mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t f2fs -mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4 mkdir -p "${ROOTFS_DIR}/boot/firmware" mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot/firmware" -t vfat diff --git a/stage0/00-packages b/stage0/00-packages new file mode 100644 index 0000000..063c7f9 --- /dev/null +++ b/stage0/00-packages @@ -0,0 +1 @@ +f2fs-tools diff --git a/stage1/00-boot-files/files/cmdline.txt b/stage1/00-boot-files/files/cmdline.txt index 03cde68..16ba53b 100644 --- a/stage1/00-boot-files/files/cmdline.txt +++ b/stage1/00-boot-files/files/cmdline.txt @@ -1 +1 @@ -console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 fsck.repair=yes rootwait +console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=f2fs rootflags=noatime,fsync_mode=strict fsck.repair=yes rootwait diff --git a/stage1/00-boot-files/files/config.txt b/stage1/00-boot-files/files/config.txt index 1145582..15087ae 100644 --- a/stage1/00-boot-files/files/config.txt +++ b/stage1/00-boot-files/files/config.txt @@ -49,7 +49,6 @@ otg_mode=1 dtoverlay=dwc2,dr_mode=host [all] - # uart debug enable on GPIO14/15 enable_uart=1 uart_2ndstage=1 @@ -59,5 +58,5 @@ dtdebug=1 # for auracaster project dtoverlay=disable-bt dtoverlay=disable-wifi -dtoverlay=uart1-pi5 -dtoverlay=uart2-pi5 \ No newline at end of file +dtoverlay=uart2,ctsrts +dtoverlay=uart3,ctsrts \ No newline at end of file diff --git a/stage1/01-sys-tweaks/files/fstab b/stage1/01-sys-tweaks/files/fstab index 525c3bc..0a4d38c 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/firmware vfat defaults 0 2 -ROOTDEV / ext4 defaults,noatime 0 1 +ROOTDEV / f2fs defaults,noatime,fsync_mode=strict 0 1 diff --git a/stage2/01-sys-tweaks/00-patches/07-resize-init.diff b/stage2/01-sys-tweaks/00-patches/07-resize-init.diff index e508a9f..7557cbe 100644 --- a/stage2/01-sys-tweaks/00-patches/07-resize-init.diff +++ b/stage2/01-sys-tweaks/00-patches/07-resize-init.diff @@ -1,5 +1,5 @@ --- stage2.orig/rootfs/boot/firmware/cmdline.txt +++ stage2/rootfs/boot/firmware/cmdline.txt @@ -1 +1 @@ --console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 fsck.repair=yes rootwait -+console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot +-console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=f2fs rootflags=noatime,fsync_mode=strict fsck.repair=yes rootwait ++console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=f2fs rootflags=noatime,fsync_mode=strict fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot diff --git a/stage2/04-auracaster_customization/00-run-chroot.sh b/stage2/04-auracaster_customization/00-run-chroot.sh index a2c5118..15fbd8f 100755 --- a/stage2/04-auracaster_customization/00-run-chroot.sh +++ b/stage2/04-auracaster_customization/00-run-chroot.sh @@ -9,45 +9,6 @@ which python3 || echo "python3 not found" echo "DEBUG: Checking user 'caster'" id caster || echo "user caster not found" - -# Add Docker's official GPG key: -apt-get update -apt-get install -y ca-certificates curl -install -m 0755 -d /etc/apt/keyrings -curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc -chmod a+r /etc/apt/keyrings/docker.asc - -# Add the repository to Apt sources: -echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ - bookworm stable" | \ - tee /etc/apt/sources.list.d/docker.list > /dev/null -apt-get update -apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin - -# Ensure docker group exists and add main user to it -DOCKER_GROUP=docker -if ! getent group "$DOCKER_GROUP" > /dev/null; then - groupadd "$DOCKER_GROUP" -fi -# Use FIRST_USER_NAME if set, else default to 'pi' -USER_TO_ADD="${FIRST_USER_NAME:-pi}" -usermod -aG "$DOCKER_GROUP" "$USER_TO_ADD" || true -docker compose version - -# Install Python Poetry for caster user (official installer) -su - caster -c "curl -sSL https://install.python-poetry.org | python3 -" - -# Add Poetry to PATH for caster user -CASTER_BASHRC="/home/caster/.bashrc" -if ! grep -q 'export PATH="/home/caster/.local/bin:$PATH"' "$CASTER_BASHRC" 2>/dev/null; then - echo 'export PATH="/home/caster/.local/bin:$PATH"' >> "$CASTER_BASHRC" - chown caster: "$CASTER_BASHRC" -fi - -# Install WireGuard -apt-get install -y wireguard wireguard-tools - # Disable WiFi # Option 1: Mask wpa_supplicant (prevents WiFi client connections) systemctl mask wpa_supplicant.service || true @@ -61,4 +22,61 @@ apt-get install -y rfkill && rfkill block wifi || true systemctl mask bluetooth.service || true systemctl disable hciuart.service || true + +# install Docker +# Add Docker's official GPG key: +# apt-get update +# apt-get install -y ca-certificates curl +# install -m 0755 -d /etc/apt/keyrings +# curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc +# chmod a+r /etc/apt/keyrings/docker.asc + +# # Add the repository to Apt sources: +# echo \ +# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ +# bookworm stable" | \ +# tee /etc/apt/sources.list.d/docker.list > /dev/null +# apt-get update +# apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin + +# # Ensure docker group exists and add main user to it +# DOCKER_GROUP=docker +# if ! getent group "$DOCKER_GROUP" > /dev/null; then +# groupadd "$DOCKER_GROUP" +# fi +# # Use FIRST_USER_NAME if set, else default to 'pi' +# USER_TO_ADD="${FIRST_USER_NAME:-pi}" +# usermod -aG "$DOCKER_GROUP" "$USER_TO_ADD" || true +# docker compose version + + +# Install Python Poetry for caster user (official installer) +su - caster -c "curl -sSL https://install.python-poetry.org | python3 -" + +# Add Poetry to PATH for caster user +CASTER_BASHRC="/home/caster/.bashrc" +if ! grep -q 'export PATH="/home/caster/.local/bin:$PATH"' "$CASTER_BASHRC" 2>/dev/null; then + echo 'export PATH="/home/caster/.local/bin:$PATH"' >> "$CASTER_BASHRC" + chown caster: "$CASTER_BASHRC" +fi +# enable in project venv install +/home/caster/.local/bin/poetry config virtualenvs.in-project true + +# # install openocd +# apt install git build-essential libtool autoconf texinfo libusb-1.0-0-dev libftdi1-dev libhidapi-dev pkg-config -y +# apt-get install pkg-config libjim-dev -y +# if [ ! -d openocd ]; then +# git clone --recurse-submodules https://github.com/raspberrypi/openocd.git +# fi +# cd openocd +# git fetch --all +# git checkout 8b8c9731a514d3e4dd367d4e77826711201b81b3 +# ./bootstrap +# ./configure --enable-bcm2835gpio --enable-sysfsgpio +# make +# make install +# cd .. + +apt install f2fs-tools + touch /root/CUSTOM_STAGE_WORKED diff --git a/stage2/04-auracaster_customization/01-run.sh b/stage2/04-auracaster_customization/01-run.sh new file mode 100644 index 0000000..5b6891d --- /dev/null +++ b/stage2/04-auracaster_customization/01-run.sh @@ -0,0 +1 @@ +apt install f2fs-tools \ No newline at end of file