Don't pack rootfs dir into tar archives anymore, use them directly when creating...
authorDaniel Abrecht <public@danielabrecht.ch>
Tue, 16 Mar 2021 22:06:11 +0000 (23:06 +0100)
committerDaniel Abrecht <public@danielabrecht.ch>
Tue, 16 Mar 2021 22:06:11 +0000 (23:06 +0100)
chroot-build-helper/real-makefile
config/default/config
config/default/rootfs/etc/default/flash-kernel
config/default/rootfs/etc/fstab
makefile
script/assemble_image.sh
script/debootstrap.sh

index bfaaff8a1b4c6bd0defd23f34093285f4adb4661..8ff4e0aa3e8ec8518278050f429092f1dc22b258 100644 (file)
@@ -104,7 +104,7 @@ bin/$(DISTRO)/$(RELEASE)/%/.build: build-env/$(DISTRO)/$(RELEASE)/rootfs/root/%/
            ); \
          then echo 'Not building package, this version is already in the repo, and DONT_BUILD_IF_IN_REPO is set to yes'; \
          else \
-           dch -b -D \"\$$DISTRO-\$$RELEASE\" --force-distribution -v \"\$$version\" \"Version suffix automatically added by librem5-image-builder. Git commit \$$commit.\"; \
+           dch -b -D \"\$$DISTRO-\$$RELEASE\" --force-distribution -v \"\$$version\" \"Version suffix automatically added by librem5-image-builder. Git commit \$$commit.\" <&-; \
            sed -i 's/\(libsystemd-dev\)[^,]*/\1 | libelogind-dev/g' debian/control; \
            apt-get -y build-dep .; \
            if [ \"$(DO_BUILD_SOURCE_PACKAGES)\" = yes ]; \
index d5006f8a46f1e9548940eb39c05cf9fb7e03d2c5..516eefeb6807743defe9ca6a700476fa209662e4 100644 (file)
@@ -4,6 +4,7 @@ IMGSIZE = auto
 DISTRO = devuan
 VARIANT = base
 CHROOT_REPO = $(REPO)
+# Can be changed to f2fs once sload.f2fs supports preserving the file owner: https://sourceforge.net/p/linux-f2fs/mailman/linux-f2fs-devel/thread/685cd73aea4daa72236ec53aa9c3a7fe%40abrecht.li/#msg37240606
 FSTYPE = ext4
 
 BUILD_PACKAGES = no
index 5d71cab926058eee0665b33a8b383cfe268a997c..47c1ebfb695436b65a80c014fe76249e64fa7b9d 100644 (file)
@@ -1,2 +1,2 @@
-LINUX_KERNEL_CMDLINE="console=tty1"
+LINUX_KERNEL_CMDLINE="console=tty1 ro"
 LINUX_KERNEL_CMDLINE_DEFAULTS=""
index 3b889f371e141e5a46cc4d458f619f19796dc666..0f496dd00f1a129c7f2e85b60fb53370ccd93bbe 100644 (file)
@@ -1,6 +1,6 @@
 # <file system>                <mount point>   <type>  <options>                               <dump>  <pass>
 
 proc                   /proc           proc    nosuid,noexec,nodev,hidepid=2           0       0
-/dev/mmcblk0p3         /               ext4    discard,relatime,errors=remount-ro      0       1
-/dev/mmcblk0p2         /boot           ext2    ro,relatime                             0       1
+/dev/mmcblk0p3         /               auto    defaults,discard,relatime               0       1
+/dev/mmcblk0p2         /boot           ext2    defaults,ro,relatime                    0       1
 tmpfs                  /tmp            tmpfs   defaults,noexec,nosuid,nodev            0       0
index 2e5f7107ea89987f44d7f3f6fc0f1ba1afa184b8..8f12b0dc6279a2518940c6de16f41ef3b45e7a46 100644 (file)
--- a/makefile
+++ b/makefile
@@ -51,9 +51,11 @@ build/bin/usernsexec: repo/.usernsexec.repo build/bin/.dir
        cp repo/usernsexec/bin/usernsexec build/bin/
        cp repo/usernsexec/script/uexec build/bin/
 
-build/bin/writeTar2Ext: repo/.tar2ext.repo build/bin/.dir
+build/bin/tar2ext: repo/.tar2ext.repo build/bin/.dir
        $(MAKE) -C repo/tar2ext/
-       cp repo/tar2ext/bin/writeTar2Ext build/bin/
+       cp repo/tar2ext/scripts/sload.ext4 build/bin/
+       ( cd build/bin/; ln -sf sload.ext4 sload.ext3; ln -sf sload.ext4 sload.ext2; )
+       cp repo/tar2ext/bin/tar2ext build/bin/
 
 build/$(IMAGE_NAME)/deb/%.deb: build/$(IMAGE_NAME)/deb/.dir
        getdeb.sh "$@"
@@ -68,7 +70,7 @@ $(DEBOOTSTRAP_SCRIPT): build/$(IMAGE_NAME)/deb/debootstrap.deb
        [ -e "$@" ]
        touch "$@"
 
-build/$(IMAGE_NAME)/rootfs.tar: \
+build/$(IMAGE_NAME)/root.fs/: \
   kernel/bin/linux-image.deb \
   uboot/bin/uboot_firmware_and_dtb.bin \
   build/bin/usernsexec \
@@ -79,8 +81,8 @@ build/$(IMAGE_NAME)/rootfs.tar: \
 
 bin/$(IMAGE_NAME): \
   build/bin/fuseloop \
-  build/bin/writeTar2Ext \
-  build/$(IMAGE_NAME)/rootfs.tar \
+  build/bin/tar2ext \
+  build/$(IMAGE_NAME)/root.fs/ \
   uboot/bin/uboot_firmware_and_dtb.bin \
   kernel/bin/linux-image.deb
        ./script/assemble_image.sh
index aa2248e30d36d210ae3a344954175c48c253a06f..3f90a58b3c9988c027d61e74e893ddd02025a432 100755 (executable)
@@ -5,17 +5,26 @@ if [ -z "$project_root" ]; then
   exit 1
 fi
 
-set -xe
+set -ex
+
+# Make sure the current working directory is correct
+cd "$(dirname "$0")/.."
+base="$PWD"
+
+asroot=""
+if [ $(id -u) != 0 ]
+  then asroot=uexec
+fi
+
+# Make sure sbin is in path, tools like sload.f2fs are in there
+PATH="/sbin:/usr/sbin:$PATH"
 
 if [ -z "$IMGSIZE" ] || [ "$IMGSIZE" = auto ]; then
-  rootfs_size="$(stat -c '%s' "build/$IMAGE_NAME/rootfs.tar")"
+  rootfs_size="$($asroot du --block-size=1 -s "$base/build/$IMAGE_NAME/root.fs" | grep -o '^[0-9]*')"
   IMGSIZE="$(expr "$(expr "$(expr "$rootfs_size" \* 120 / 100 + 268435456 + 2048 + 1023)" / 1024 + 1023)" / 1024 + 1024)"MiB
 fi
 
-cd "$(dirname "$0")/.."
-base="$PWD"
-
-tmp="$(mktemp -d -p build)"
+tmp="$(mktemp -d -p "$base/build")"
 
 # if there is an old temporary image, remove it
 rm -f "$tmp/$IMAGE_NAME"
@@ -38,10 +47,7 @@ type=83, name=root
 EOF
 
 # Get partition offsets
-IFSOLD="$IFS"
-IFS=
 partitions="$(sfdisk -J "$tmp/$IMAGE_NAME" | jq -r '.partitiontable.partitions[] | "start=\(.start) size=\(.size) type=\(.type) bootable=\(.bootable)"')"
-IFS="$OLDIFS"
 
 # Unmount & remove fuse loop devices
 umount_wait(){
@@ -51,10 +57,6 @@ umount_wait(){
     # Unmount partitions. Using -z because we may get EBUSY otherwise. Unfortunately, we don't know when it's done this way
     mountpoint -q "$part" && fusermount -zu "$part"
   done
-  # Wait until nothing is accessing the file anymore
-  while lsof "$tmp/$IMAGE_NAME" >/dev/null
-    do sleep 0.1
-  done
   # remove fuse loop devices
   rm -f "$tmp"/part*
 }
@@ -65,7 +67,7 @@ cleanup(){
   umount_wait
   rm -rf "$tmp"
 }
-trap cleanup EXIT
+trap cleanup EXIT INT TERM
 
 # This is the default for most tools. Don't change this, the other commands in this script haven't been adjusted to use this instead of the default.
 blocksize=512
@@ -96,16 +98,22 @@ dd conv=notrunc,sync if=uboot/firmware/m4.bin of="$bootloaderdev" bs=1024
 # Copy uboot bootloader to image
 dd conv=notrunc,sync if=uboot/bin/uboot_firmware_and_dtb.bin of="$bootloaderdev" bs=1024 seek=31
 
+mkfsoptions=
+case "$FSTYPE" in
+  ext?) mkfsoptions="$mkfsoptions -L root -E discard -O encrypt" ;;
+  f2fs) mkfsoptions="$mkfsoptions -l root -O extra_attr,inode_checksum,compression,inode_crtime,lost_found,encrypt" ;; # Can't enable "quota", sload.f2fs doesn't handle it properly...
+esac
+
 # Format partitions
 mkfs.ext2 -L boot "$bootdev"
-mkfs.ext4 -L root -E discard "$rootdev"
+"mkfs.$FSTYPE" $mkfsoptions "$rootdev"
 
-# Write rootfs to partitions
-writeTar2Ext "$bootdev" < "build/$IMAGE_NAME/bootfs.tar"
-writeTar2Ext "$rootdev" < "build/$IMAGE_NAME/rootfs.tar"
+# Write data to partitions
+$asroot sload.ext2 -P -f "$base/build/$IMAGE_NAME/boot.fs" "$bootdev"
+$asroot "sload.$FSTYPE" -P -f "$base/build/$IMAGE_NAME/root.fs" "$rootdev"
 
 # Unmount & remove fuse loop devices
 umount_wait
 
 # Copy finished image
-cp "$tmp/$IMAGE_NAME" "bin/$IMAGE_NAME"
+mv "$tmp/$IMAGE_NAME" "bin/$IMAGE_NAME"
index 86f55858b23fd88b7d8840af436606138a34f01f..52ff0150b190b71ad1f1c7f182ac1e32ff195c3c 100755 (executable)
@@ -27,7 +27,6 @@ trap cleanup EXIT
 
 # Remove old files from previous runs
 rm -rf "$tmp/rootfs" "$tmp/bootfs"
-rm -f "$tmp/rootfs.tar" "$tmp/bootfs.tar" "$tmp/device_nodes"
 
 # Create temporary directories
 mkdir -p "$tmp/rootfs"
@@ -136,9 +135,8 @@ rm -rf "$tmp/rootfs/root/helper"
 rm -f "$tmp/rootfs/dev/null"
 rm -f "$tmp/rootfs/dev/urandom"
 
-# Create tar archives and remove tared directories
-cd "$tmp/rootfs"
-tar cf "$tmp/rootfs.tar" .
-cd "$tmp/bootfs"
-tar cf "$tmp/bootfs.tar" .
-cd "$base"
+# Move rootfs and bootfs to signal they're done
+rm -rf "$tmp/root.fs" "$tmp/boot.fs"
+touch -c "$tmp/rootfs" "$tmp/bootfs"
+mv "$tmp/rootfs" "$tmp/root.fs"
+mv "$tmp/bootfs" "$tmp/boot.fs"