aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Luis Duran <jlduran@FreeBSD.org>2026-01-17 18:09:14 +0000
committerJose Luis Duran <jlduran@FreeBSD.org>2026-01-17 18:09:14 +0000
commit61ac7309c3669bdadd3983f0bb03440a7c147820 (patch)
treeaa43c9e4e199a99c74f0c5a6f3747fc2eaec7def
parent5ba2a74e3a208ec5641832ffcb9674c0e4b06950 (diff)
nanobsd: Add a provisional populate_part function
Add a _populate_part(ition) function that mimics the current populate_slice. Note however, that this function is not backward-compatible with populate_slice, hence the different name. A "_" is prepended to signal that it still experimental. It can be used to populate the /cfg and /data partition using makefs(8). Initially not wired. Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D48790
-rwxr-xr-xtools/tools/nanobsd/defaults.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/tools/nanobsd/defaults.sh b/tools/tools/nanobsd/defaults.sh
index 9827095b334c..7775dd572fb5 100755
--- a/tools/tools/nanobsd/defaults.sh
+++ b/tools/tools/nanobsd/defaults.sh
@@ -724,6 +724,50 @@ populate_slice() {
nano_umount ${mnt}
}
+_populate_part() (
+ local dir fs lbl metalog size type
+ type=$1
+ fs=$2
+ dir=$3
+ lbl=$4
+ size=$5
+ metalog=$6
+
+ echo "Creating ${fs}"
+
+ # Use the directory provided, otherwise create an empty one temporarily.
+ if [ -n "${dir}" ] && [ -d "${dir}" ]; then
+ echo "Populating ${lbl} from ${dir}"
+ else
+ if [ "${type}" = "cfg" ]; then
+ dir=$(mktemp -d -p "${NANO_OBJ}" -t "${type}")
+ trap "rm -f ${dir}" 1 2 15 EXIT
+ fi
+ fi
+
+ if [ -d "${dir}" ]; then
+ # If there is no metalog, create one using the default
+ # NANO_DEF_UNAME and NANO_DEF_GNAME for all entries in the spec.
+ if [ -z "${metalog}" ]; then
+ metalog=$(mktemp -p "${NANO_OBJ}" -t "${type}")
+ trap "rm -f ${metalog}" 1 2 15 EXIT
+ echo "/set type=dir uname=${NANO_DEF_UNAME}" \
+ "gname=${NANO_DEF_GNAME} mode=0755" > "${metalog}"
+ echo ". type=dir uname=${NANO_DEF_UNAME}" \
+ "gname=${NANO_DEF_GNAME} mode=0755" >> "${metalog}"
+ (
+ cd "${dir}"
+ mtree -bc -k flags,gid,gname,link,mode,uid,uname |
+ mtree -C | tail -n +2 |
+ sed 's/uid=[[:digit:]]*/uname=root/g' |
+ sed 's/gid=[[:digit:]]*/gname=wheel/g' >> "${metalog}"
+ )
+ fi
+
+ nano_makefs "-DxZ ${NANO_MAKEFS}" "${metalog}" "${size}" "${fs}" "${dir}"
+ fi
+)
+
populate_cfg_slice() {
populate_slice "$1" "$2" "$3" "$4"
}