Page MenuHomeFreeBSD

D58968.id184334.diff
No OneTemporary

D58968.id184334.diff

diff --git a/tools/tools/nanobsd/Files/root/updatep1 b/tools/tools/nanobsd/Files/root/updatep1
--- a/tools/tools/nanobsd/Files/root/updatep1
+++ b/tools/tools/nanobsd/Files/root/updatep1
@@ -44,7 +44,7 @@
fi
# Blow away old system
-dd if=/dev/zero of="/dev/${NANO_DRIVE}s1" bs=1m count=1 > /dev/null 2>&1
+dd if=/dev/zero of="/dev/${NANO_DRIVE}s1" bs=1m count=1 status=none
# Copy in new system
dd of="/dev/${NANO_DRIVE}s1" obs=64k
diff --git a/tools/tools/nanobsd/Files/root/updatep2 b/tools/tools/nanobsd/Files/root/updatep2
--- a/tools/tools/nanobsd/Files/root/updatep2
+++ b/tools/tools/nanobsd/Files/root/updatep2
@@ -44,7 +44,7 @@
fi
# Blow away old system.
-dd if=/dev/zero of="/dev/${NANO_DRIVE}s2" bs=1m count=1 > /dev/null 2>&1
+dd if=/dev/zero of="/dev/${NANO_DRIVE}s2" bs=1m count=1 status=none
# Copy in new system
dd of="/dev/${NANO_DRIVE}s2" obs=64k
@@ -58,5 +58,6 @@
sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/conf/base/etc/fstab
sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/etc/fstab
umount /mnt
-trap 1 2 15 EXIT
+trap - 1 2 15 EXIT
+
gpart set -a active -i 2 "${NANO_DRIVE}"
diff --git a/tools/tools/nanobsd/defaults.sh b/tools/tools/nanobsd/defaults.sh
--- a/tools/tools/nanobsd/defaults.sh
+++ b/tools/tools/nanobsd/defaults.sh
@@ -1364,11 +1364,15 @@
err "Regular expression pattern not found"
fi
[ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf
- if $do_precompiled && [ -z "$NANO_NOPKGBASE" ]; then
+ if [ -z "$NANO_NOPKGBASE" ]; then
tgt_pkg_update_file_sha256 etc/defaults/rc.conf
tgt_pkg_update_config_files_content etc/defaults/rc.conf
fi
+ if [ "$NANO_PLAN" = "default" ]; then
+ tgt_patch_gptboot
+ fi
+
tgt_write_fstab
tgt_dir cfg
diff --git a/tools/tools/nanobsd/dhcpd/common b/tools/tools/nanobsd/dhcpd/common
--- a/tools/tools/nanobsd/dhcpd/common
+++ b/tools/tools/nanobsd/dhcpd/common
@@ -34,6 +34,8 @@
# NB: You want the other file
+legacy
+
NANO_PMAKE="make -j $(sysctl -n hw.ncpu)"
NANO_CFG_BASE=$(pwd)
diff --git a/tools/tools/nanobsd/gpt.sh b/tools/tools/nanobsd/gpt.sh
--- a/tools/tools/nanobsd/gpt.sh
+++ b/tools/tools/nanobsd/gpt.sh
@@ -487,3 +487,37 @@
sed -i "" "s=/dev/gpt/${NANO_LABEL}${current}=/dev/gpt/${NANO_LABEL}${new}=g" "${f}"
done
}
+
+# Patch gptboot rc script to understand ping-ponging between partitions
+tgt_patch_gptboot() {
+ (
+ cd "$NANO_WORLDDIR"
+
+ [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/rc.d/gptboot
+ if ! patch -s -V none etc/rc.d/gptboot <<\EOF
+--- etc/rc.d/gptboot
++++ etc/rc.d/gptboot
+@@ -58,6 +58,12 @@
+ # We want to log success after all failures.
+ echo -n "Boot from ${part} succeeded."
+ gpart unset -a bootonce -i ${pos} ${disk} >/dev/null
++ old_bootme=$(gpart show "${disk}" |
++ egrep 'freebsd-ufs.*(\[|,)bootme(,|\])' | awk '{print $3}')
++ if [ -n "${old_bootme}" ]; then
++ gpart unset -a bootme -i "${old_bootme}" "${disk}" >/dev/null
++ fi
++ gpart set -a bootme -i ${pos} ${disk} >/dev/null
+ fi
+ fi
+ ;;
+EOF
+ then
+ err "Patching /etc/rc.d/gptboot failed!"
+ fi
+ [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 555 etc/rc.d/gptboot
+ if [ -z "$NANO_NOPKGBASE" ]; then
+ tgt_pkg_update_file_sha256 etc/rc.d/gptboot
+ tgt_pkg_update_config_files_content etc/rc.d/gptboot
+ fi
+ )
+}
diff --git a/tools/tools/nanobsd/gpt/Files.mtree b/tools/tools/nanobsd/gpt/Files.mtree
--- a/tools/tools/nanobsd/gpt/Files.mtree
+++ b/tools/tools/nanobsd/gpt/Files.mtree
@@ -1,8 +1,15 @@
+#
+# To generate this mtree file:
+# cd tools/tools/nanobsd
+# mtree -c -p gpt/Files | mtree -C -k type,uname,gname,mode > gpt/Files.mtree
+# and update the desired ownerships and permissions
+#
. type=dir uname=root gname=wheel mode=0755
./usr type=dir uname=root gname=wheel mode=0755
./usr/local type=dir uname=root gname=wheel mode=0755
./usr/local/sbin type=dir uname=root gname=wheel mode=0755
./usr/local/sbin/change_password type=file uname=root gname=wheel mode=0555
+./usr/local/sbin/rollback type=file uname=root gname=wheel mode=0555
./usr/local/sbin/save_cfg type=file uname=root gname=wheel mode=0555
./usr/local/sbin/save_sshkeys type=file uname=root gname=wheel mode=0555
./usr/local/sbin/update type=file uname=root gname=wheel mode=0555
diff --git a/tools/tools/nanobsd/gpt/Files/usr/local/sbin/rollback b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/rollback
new file mode 100644
--- /dev/null
+++ b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/rollback
@@ -0,0 +1,53 @@
+#!/bin/sh
+#
+# Copyright (c) 2026 [XXX]
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+set -e
+
+. /etc/nanobsd.conf
+
+: "${NANO_ROOT:?NANO_ROOT not set in /etc/nanobsd.conf}"
+: "${NANO_ALTROOT:?NANO_ALTROOT not set in /etc/nanobsd.conf}"
+
+root_mountfrom=$(kenv vfs.root.mountfrom)
+root_mountfrom=${root_mountfrom#*:}
+
+case "$root_mountfrom" in
+"/dev/gpt/${NANO_ALTROOT}")
+ curr_label="${NANO_ALTROOT}"
+ prev_label="${NANO_ROOT}"
+ ;;
+"/dev/gpt/${NANO_ROOT}")
+ curr_label="${NANO_ROOT}"
+ prev_label="${NANO_ALTROOT}"
+ ;;
+*)
+ echo "Invalid root device '${root_mountfrom}'." >&2
+ exit 1
+ ;;
+esac
+
+component=$(glabel status | awk -v label="gpt/${prev_label}" '$1 == label {print $3}')
+if [ -z "$component" ]; then
+ echo "Could not find provider for '${prev_label}'." >&2
+ exit 1
+fi
+index="${component##*p}"
+geom="${component%p*}"
+
+printf "You are currently running on '%s'.\n" "$curr_label" > /dev/tty
+printf "Are you sure you want to roll back to '%s' (y/N)? " "$prev_label" > /dev/tty
+read -r key < /dev/tty
+case "$key" in
+[yY]) ;;
+*) exit 0 ;;
+esac
+
+echo "Rolling back to '${prev_label}' (${geom}p${index})..."
+
+gpart set -a bootonce -i "$index" "$geom"
+
+echo "Done!"
diff --git a/tools/tools/nanobsd/gpt/Files/usr/local/sbin/save_cfg b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/save_cfg
--- a/tools/tools/nanobsd/gpt/Files/usr/local/sbin/save_cfg
+++ b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/save_cfg
@@ -27,41 +27,62 @@
file_path="${filename%/*}"
if [ "$file_path" != "$filename" ]; then
if [ ! -d "/etc/${file_path}" ]; then
- echo "Error: Path /etc/${file_path} is not a directory." >&2
+ printf "Error: Path /etc/%s is not a directory.\n" \
+ "$file_path" >&2
exit 1;
fi
fi
#
# Ask user - how should we handle this file.
- # Add to cfg (y/n/i)?
+ # Add to cfg (y/N/i/?)?
# y) -> save this file in /cfg
# n) -> do not save this file in /cfg for current
- # script invocation ONLY
+ # script invocation ONLY (default)
# i) -> add file to ignore list (/cfg/.ignore hierarchy)
- # and never try to add this file to /cfg.
+ # and never try to add this file to /cfg
+ # ?) -> print help
#
# touch is used to add files to /cfg to keep the script
# flow straight and easy
#
- read -rp "New file /etc/${filename} found. Add to /cfg (y/n/i)? " key < /dev/tty
- case "$key" in
- [yY])
- if [ "$file_path" != "$filename" ]; then
- mkdir -vp "/cfg/${file_path}"
- fi
- touch "/cfg/${filename}" &&
- echo "File /etc/${filename} added to /cfg."
- ;;
- [iI])
- mkdir -vp /cfg/.ignore
- if [ "$file_path" != "$filename" ]; then
- mkdir -vp "/cfg/.ignore/${file_path}"
- fi
- touch "/cfg/.ignore/${filename}" &&
- echo "File /etc/${filename} added to ignore list."
- ;;
- esac
+ while true; do
+ printf "New file /etc/%s found. Add to /cfg (y/N/i/?)? " \
+ "$filename" > /dev/tty
+ read -r key < /dev/tty
+ case "$key" in
+ [yY])
+ if [ "$file_path" != "$filename" ]; then
+ mkdir -p "/cfg/${file_path}" &&
+ printf "Directory /etc/%s added to /cfg.\n" \
+ "$file_path"
+ fi
+ touch "/cfg/${filename}" &&
+ printf "File /etc/%s added to /cfg.\n" \
+ "$filename"
+ break
+ ;;
+ [iI])
+ mkdir -p /cfg/.ignore
+ if [ "$file_path" != "$filename" ]; then
+ mkdir -p "/cfg/.ignore/${file_path}"
+ fi
+ touch "/cfg/.ignore/${filename}" &&
+ printf "File /etc/%s added to ignore list.\n" \
+ "$filename"
+ break
+ ;;
+ \?)
+ echo " y - save this file in /cfg" > /dev/tty
+ echo " n - do not save this file in /cfg for current" > /dev/tty
+ echo " script invocation ONLY (default)" > /dev/tty
+ echo " i - add file to ignore list (/cfg/.ignore hierarchy)" > /dev/tty
+ echo " and never try to add this file to /cfg" > /dev/tty
+ echo " ? - print help" > /dev/tty
+ ;;
+ *) break ;;
+ esac
+ done
fi
fi
done || exit 1
@@ -85,11 +106,13 @@
# Give user an option to remove file from /cfg if this file is
# removed from /etc
#
- read -rp "File /cfg/${filename} not found in /etc. Remove from /cfg (y/n)? " key < /dev/tty
+ printf "File /cfg/%s not found in /etc. Remove from /cfg (y/N)? " \
+ "$filename" > /dev/tty
+ read -r key < /dev/tty
case "$key" in
[yY])
rm "/cfg/${filename}" &&
- echo "File /cfg/${filename} removed"
+ printf "File /cfg/%s removed.\n" "$filename"
;;
esac
fi
diff --git a/tools/tools/nanobsd/gpt/Files/usr/local/sbin/update b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/update
--- a/tools/tools/nanobsd/gpt/Files/usr/local/sbin/update
+++ b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/update
@@ -1,6 +1,7 @@
#!/bin/sh
#
-# Copyright (c) 2026 [XXX]
+# Copyright (c) 2011 iXsystems, Inc.
+# All rights reserved.
#
# SPDX-License-Identifier: BSD-2-Clause
#
@@ -12,17 +13,20 @@
: "${NANO_ROOT:?NANO_ROOT not set in /etc/nanobsd.conf}"
: "${NANO_ALTROOT:?NANO_ALTROOT not set in /etc/nanobsd.conf}"
-current_root=$(df -n / | awk 'END {print $1}')
+root_mountfrom=$(kenv vfs.root.mountfrom)
+root_mountfrom=${root_mountfrom#*:}
-case "$current_root" in
+case "$root_mountfrom" in
"/dev/gpt/${NANO_ALTROOT}")
+ echo "Updating '${NANO_ROOT}'..."
exec sh /usr/local/sbin/updatep1
;;
"/dev/gpt/${NANO_ROOT}")
+ echo "Updating '${NANO_ALTROOT}'..."
exec sh /usr/local/sbin/updatep2
;;
*)
- echo "Invalid root device '${current_root}'." >&2
+ echo "Invalid root device '${root_mountfrom}'." >&2
exit 1
;;
esac
diff --git a/tools/tools/nanobsd/gpt/Files/usr/local/sbin/updatep1 b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/updatep1
new file mode 100644
--- /dev/null
+++ b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/updatep1
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# Copyright (c) 2004-2005 Poul-Henning Kamp.
+# All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+#
+# Script to update partition 1 on a NanoBSD system.
+#
+# usage:
+# ssh somewhere cat image.s1 | sh updatep1
+#
+
+set -e
+
+. /etc/nanobsd.conf
+
+: "${NANO_ROOT:?NANO_ROOT not set in /etc/nanobsd.conf}"
+
+root_mountfrom=$(kenv vfs.root.mountfrom)
+root_mountfrom=${root_mountfrom#*:}
+
+if [ "$root_mountfrom" = "/dev/gpt/${NANO_ROOT}" ]; then
+ echo "You are running partition 1 already." >&2
+ echo "You probably want to use 'updatep2' instead." >&2
+ exit 1
+fi
+
+component=$(glabel status | awk -v label="gpt/${NANO_ROOT}" '$1 == label {print $3}')
+if [ -z "$component" ]; then
+ echo "Could not find provider for 'gpt/${NANO_ROOT}'." >&2
+ exit 1
+fi
+index="${component##*p}"
+geom="${component%p*}"
+
+# Blow away old system
+dd if=/dev/zero of="/dev/gpt/${NANO_ROOT}" bs=1m count=1 status=none
+
+# Copy in new system
+dd of="/dev/gpt/${NANO_ROOT}" bs=1m iflag=fullblock status=progress
+
+# Check that it worked
+fsck_ufs -n "/dev/gpt/${NANO_ROOT}"
+
+gpart set -a bootonce -i "$index" "$geom"
+
+echo "Done!"
diff --git a/tools/tools/nanobsd/gpt/Files/usr/local/sbin/updatep2 b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/updatep2
new file mode 100644
--- /dev/null
+++ b/tools/tools/nanobsd/gpt/Files/usr/local/sbin/updatep2
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# Copyright (c) 2004-2005 Poul-Henning Kamp.
+# All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+#
+# Script to update partition 2 on a NanoBSD system.
+#
+# usage:
+# ssh somewhere cat image.s1 | sh updatep2
+#
+
+set -e
+
+. /etc/nanobsd.conf
+
+: "${NANO_ALTROOT:?NANO_ALTROOT not set in /etc/nanobsd.conf}"
+: "${NANO_ROOT:?NANO_ROOT not set in /etc/nanobsd.conf}"
+
+root_mountfrom=$(kenv vfs.root.mountfrom)
+root_mountfrom=${root_mountfrom#*:}
+
+if [ "$root_mountfrom" = "/dev/gpt/${NANO_ALTROOT}" ]; then
+ echo "You are running partition 2 already." >&2
+ echo "You probably want to use 'updatep1' instead." >&2
+ exit 1
+fi
+
+component=$(glabel status | awk -v label="gpt/${NANO_ALTROOT}" '$1 == label {print $3}')
+if [ -z "$component" ]; then
+ echo "Could not find provider for 'gpt/${NANO_ALTROOT}'." >&2
+ exit 1
+fi
+index="${component##*p}"
+geom="${component%p*}"
+
+# Blow away old system
+dd if=/dev/zero of="/dev/gpt/${NANO_ALTROOT}" bs=1m count=1 status=none
+
+# Copy in new system
+dd of="/dev/gpt/${NANO_ALTROOT}" bs=1m iflag=fullblock status=progress
+
+# Check that it worked
+fsck_ufs -n "/dev/gpt/${NANO_ALTROOT}"
+
+# Update the /etc/fstab
+trap "umount /mnt" 1 2 15 EXIT
+mount "/dev/gpt/${NANO_ALTROOT}" /mnt
+sed -i "" "s/${NANO_ROOT}/${NANO_ALTROOT}/" /mnt/conf/base/etc/fstab
+sed -i "" "s/${NANO_ROOT}/${NANO_ALTROOT}/" /mnt/etc/fstab
+umount /mnt
+trap - 1 2 15 EXIT
+
+gpart set -a bootonce -i "$index" "$geom"
+
+echo "Done!"
diff --git a/tools/tools/nanobsd/legacy.sh b/tools/tools/nanobsd/legacy.sh
--- a/tools/tools/nanobsd/legacy.sh
+++ b/tools/tools/nanobsd/legacy.sh
@@ -27,6 +27,8 @@
#
#
+NANO_PLAN=legacy
+
# Media geometry, only relevant if bios doesn't understand LBA
[ -n "$NANO_SECTS" ] || NANO_SECTS=63
[ -n "$NANO_HEADS" ] || NANO_HEADS=16
@@ -203,7 +205,7 @@
# Calculate MBR partition layout (start offset, size, index)
# from media/image/code/conf/data sizes
#
-calculate_partitioning() {
+is_defined calculate_partitioning || calculate_partitioning() {
echo $NANO_MEDIASIZE $NANO_IMAGES \
$NANO_SECTS $NANO_HEADS \
$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
@@ -364,7 +366,7 @@
# Assemble a full MBR disk image using mdconfig and gpart,
# write all partitions (root, altroot, cfg, data) via live mounts
#
-create_diskimage() {
+is_defined create_diskimage || create_diskimage() {
pprint 2 "build diskimage"
pprint 3 "log: ${NANO_OBJ}/_.di"
diff --git a/tools/tools/nanobsd/nanobsd.sh b/tools/tools/nanobsd/nanobsd.sh
--- a/tools/tools/nanobsd/nanobsd.sh
+++ b/tools/tools/nanobsd/nanobsd.sh
@@ -66,9 +66,6 @@
do_precompiled=false
do_prep_image=true
-# Pull in legacy stuff for now automatically
-. "${topdir}/legacy.sh"
-
set +e
args=$(getopt BKXWbc:fhiIknPpqUvw $*)
if [ $? -ne 0 ]; then
@@ -181,6 +178,10 @@
usage
fi
+# Transition hack -- If you get this warning, add 'legacy' to your nano config file
+[ -n "$NANO_PLAN" ] || echo "Warning: no plan defined, assuming legacy config."
+[ -n "$NANO_PLAN" ] || legacy
+
#######################################################################
# And then it is as simple as that...
diff --git a/tools/tools/nanobsd/pcengines/common.conf b/tools/tools/nanobsd/pcengines/common.conf
--- a/tools/tools/nanobsd/pcengines/common.conf
+++ b/tools/tools/nanobsd/pcengines/common.conf
@@ -1,6 +1,8 @@
#
#
+legacy
+
NANO_SRC=$(pwd)
NANO_SRC=${NANO_SRC%/tools/tools/nanobsd/pcengines}
NANO_OBJ=${NANO_SRC}/../nanobsd-builds/${NANO_NAME}/obj
diff --git a/tools/tools/nanobsd/rescue/common b/tools/tools/nanobsd/rescue/common
--- a/tools/tools/nanobsd/rescue/common
+++ b/tools/tools/nanobsd/rescue/common
@@ -1,5 +1,7 @@
#!/bin/sh
+legacy
+
#NANO_SRC=$(pwd)
#NANO_SRC=${NANO_SRC%/tools/tools/nanobsd/rescue}
#NANO_OBJ=${NANO_SRC}/../nanobsd-builds/${NANO_NAME}/obj

File Metadata

Mime Type
text/plain
Expires
Thu, Aug 20, 11:50 AM (8 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36991491
Default Alt Text
D58968.id184334.diff (15 KB)

Event Timeline