test new part

This commit is contained in:
2025-04-26 16:20:06 -07:00
parent f9327e82ae
commit 23114d61e2

View File

@@ -12,11 +12,9 @@ mkdir -p "${ROOTFS_DIR}"
BOOT_SIZE="$((512 * 1024 * 1024))" BOOT_SIZE="$((512 * 1024 * 1024))"
ROOT_SIZE=$(du -x --apparent-size -s "${EXPORT_ROOTFS_DIR}" --exclude var/cache/apt/archives --exclude boot/firmware --block-size=1 | cut -f 1) ROOT_SIZE=$(du -x --apparent-size -s "${EXPORT_ROOTFS_DIR}" --exclude var/cache/apt/archives --exclude boot/firmware --block-size=1 | cut -f 1)
# All partition sizes and starts will be aligned to this size
ALIGN="$((4 * 1024 * 1024))" ALIGN="$((4 * 1024 * 1024))"
ROOT_MARGIN="$(echo "($ROOT_SIZE * 0.2 + 400 * 1024 * 1024) / 1" | bc)" ROOT_MARGIN="$(echo "($ROOT_SIZE * 0.2 + 400 * 1024 * 1024) / 1" | bc)"
# Recovery partition fixed size: 256MB
RECOVERY_SIZE="$((256 * 1024 * 1024))" RECOVERY_SIZE="$((256 * 1024 * 1024))"
BOOT_PART_START=$((ALIGN)) BOOT_PART_START=$((ALIGN))
@@ -37,14 +35,14 @@ parted --script "${IMG_FILE}" unit B mkpart primary ext4 "${ROOT_PART_START}" "$
echo "Creating loop device..." echo "Creating loop device..."
cnt=0 cnt=0
until ensure_next_loopdev && LOOP_DEV="$(losetup --show --find --partscan "$IMG_FILE")"; do until ensure_next_loopdev && LOOP_DEV="$(losetup --show --find --partscan "$IMG_FILE")"; do
if [ $cnt -lt 5 ]; then if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1)) cnt=$((cnt + 1))
echo "Error in losetup. Retrying..." echo "Error in losetup. Retrying..."
sleep 5 sleep 5
else else
echo "ERROR: losetup failed; exiting" echo "ERROR: losetup failed; exiting"
exit 1 exit 1
fi fi
done done
ensure_loopdev_partitions "$LOOP_DEV" ensure_loopdev_partitions "$LOOP_DEV"
@@ -54,29 +52,37 @@ ROOT_DEV="${LOOP_DEV}p3"
ROOT_FEATURES="^huge_file" ROOT_FEATURES="^huge_file"
for FEATURE in 64bit; do for FEATURE in 64bit; do
if grep -q "$FEATURE" /etc/mke2fs.conf; then if grep -q "$FEATURE" /etc/mke2fs.conf; then
ROOT_FEATURES="^$FEATURE,$ROOT_FEATURES" ROOT_FEATURES="^$FEATURE,$ROOT_FEATURES"
fi fi
done done
if [ "$BOOT_SIZE" -lt 134742016 ]; then if [ "$BOOT_SIZE" -lt 134742016 ]; then
FAT_SIZE=16 FAT_SIZE=16
else else
FAT_SIZE=32 FAT_SIZE=32
fi fi
mkdosfs -n bootfs -F "$FAT_SIZE" -s 4 -v "$BOOT_DEV" > /dev/null mkdosfs -n bootfs -F "$FAT_SIZE" -s 4 -v "$BOOT_DEV" > /dev/null
mkdosfs -n recovery -F "16" -s 4 -v "$RECOVERY_DEV" > /dev/null mkdosfs -n recovery -F "16" -s 4 -v "$RECOVERY_DEV" > /dev/null
mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null
mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4 # Create new layout
mkdir -p "${ROOTFS_DIR}/boot/firmware" mkdir -p "${ROOTFS_DIR}/part1"
mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot/firmware" -t vfat mkdir -p "${ROOTFS_DIR}/part2"
mkdir -p "${ROOTFS_DIR}/recovery"
mount -v "$RECOVERY_DEV" "${ROOTFS_DIR}/recovery" -t ext4
rsync -aHAXx --exclude /var/cache/apt/archives --exclude /boot/firmware "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/" mount -v "$BOOT_DEV" "${ROOTFS_DIR}/part1" -t vfat
rsync -rtx "${EXPORT_ROOTFS_DIR}/boot/firmware/" "${ROOTFS_DIR}/boot/firmware/" mount -v "$RECOVERY_DEV" "${ROOTFS_DIR}/part2" -t ext4
#rsync -aHAXx "${EXPORT_ROOTFS_DIR}/recovery/" "${ROOTFS_DIR}/recovery/"
echo "Image created with boot, rootfs, and 256MB recovery partition." mkdir -p "${ROOTFS_DIR}/part1/bootfs"
mkdir -p "${ROOTFS_DIR}/part1/rootfs"
mkdir -p "${ROOTFS_DIR}/part2/recovery"
mount -v "$ROOT_DEV" "${ROOTFS_DIR}/part1/rootfs" -t ext4
# Copy files
rsync -aHAXx --exclude /var/cache/apt/archives --exclude /boot/firmware "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/part1/rootfs/"
rsync -rtx "${EXPORT_ROOTFS_DIR}/boot/firmware/" "${ROOTFS_DIR}/part1/bootfs/"
# If you have recovery files to copy, uncomment:
# rsync -aHAXx "${EXPORT_ROOTFS_DIR}/recovery/" "${ROOTFS_DIR}/part2/recovery/"