git: dadbbccd8049 - main - nanobsd: Account for metadata overhead in code slice
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 27 May 2026 00:37:02 UTC
The branch main has been updated by jlduran:
URL: https://cgit.FreeBSD.org/src/commit/?id=dadbbccd804980895a098b01f553b5f7193daa81
commit dadbbccd804980895a098b01f553b5f7193daa81
Author: Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2026-05-27 00:14:56 +0000
Commit: Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2026-05-27 00:14:56 +0000
nanobsd: Account for metadata overhead in code slice
The code slice size (CODE_SIZE) includes 16 sectors reserved for disk
metadata (see bsdlabel(8) offset). Subtract these 16 sectors from the
total size passed to nano_makefs.
This prevents the generated filesystem from consuming the entire slice
allocation, ensuring there is enough space for the metadata without
overflowing the partition boundary.
Reviewed by: imp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D57220
---
tools/tools/nanobsd/legacy.sh | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/tools/tools/nanobsd/legacy.sh b/tools/tools/nanobsd/legacy.sh
index 670a2f5ca968..8e57163c030d 100644
--- a/tools/tools/nanobsd/legacy.sh
+++ b/tools/tools/nanobsd/legacy.sh
@@ -31,6 +31,10 @@
[ -n "$NANO_SECTS" ] || NANO_SECTS=63
[ -n "$NANO_HEADS" ] || NANO_HEADS=16
+# The first partition should start at offset 16,
+# because the first 16 sectors are reserved for metadata.
+METADATA_SECTS=16
+
# Functions and variable definitions used by the legacy nanobsd
# image building system.
@@ -127,7 +131,7 @@ create_code_slice() {
trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
gpart create -s bsd "${MD}"
- gpart add -t freebsd-ufs -b 16 "${MD}"
+ gpart add -t freebsd-ufs -b "${METADATA_SECTS}" "${MD}"
if [ -f ${NANO_WORLDDIR}/boot/boot ]; then
echo "Making bootable partition"
gpart bootcode -b ${NANO_WORLDDIR}/boot/boot ${MD}
@@ -172,8 +176,8 @@ _create_code_slice() {
echo "Partition will not be bootable"
fi
nano_makefs "-DxZ ${NANO_MAKEFS} -o minfree=0,optimization=space" \
- "${NANO_METALOG}" "${CODE_SIZE}" "${NANO_OBJ}/_.disk.part" \
- "${NANO_WORLDDIR}"
+ "${NANO_METALOG}" "$(( CODE_SIZE - METADATA_SECTS ))" \
+ "${NANO_OBJ}/_.disk.part" "${NANO_WORLDDIR}"
mkimg -s bsd \
${bootcode} \
-p freebsd-ufs:="${NANO_OBJ}/_.disk.part" \
@@ -308,8 +312,8 @@ _create_diskimage() {
echo "Duplicating to second image..."
tgt_switch_root_fstab "${NANO_SLICE_ROOT}" "${NANO_SLICE_ALTROOT}"
nano_makefs "-DxZ ${NANO_MAKEFS} -o minfree=0,optimization=space" \
- "${NANO_METALOG}" "${CODE_SIZE}" "${NANO_OBJ}/_.altroot.part" \
- "${NANO_WORLDDIR}"
+ "${NANO_METALOG}" "$(( CODE_SIZE - METADATA_SECTS ))" \
+ "${NANO_OBJ}/_.altroot.part" "${NANO_WORLDDIR}"
tgt_switch_root_fstab "${NANO_SLICE_ALTROOT}" "${NANO_SLICE_ROOT}"
if [ -f "${NANO_WORLDDIR}/boot/boot" ]; then
bootcode="-b ${NANO_WORLDDIR}/boot/boot"