From 98135fc9c07aadf6fb2c8d043b85655e25d599b3 Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Fri, 7 Aug 2026 12:21:00 +0200 Subject: [PATCH 1/2] fix(ns-storage): drop the ns_data label when releasing the storage The storage is auto-mounted by filesystem label, but remove-storage only released the partition when it lived on the OS disk. A storage removed from a secondary drive kept its ns_data label, so once a new storage was created two partitions matched and block mount stacked both of them onto /mnt/data at boot; ns.storage get-configuration reported the wrong device for the same reason. Clear the label with tune2fs when the partition is on a secondary drive, keeping the partition itself so that its logs remain available for later inspection. Also read the partition number from sysfs instead of assuming the OS disk partition is number 3. Assisted-by: Claude Code:claude-opus-5[1m] --- packages/ns-storage/files/remove-storage | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/ns-storage/files/remove-storage b/packages/ns-storage/files/remove-storage index 201bdc137..8cda445d0 100644 --- a/packages/ns-storage/files/remove-storage +++ b/packages/ns-storage/files/remove-storage @@ -37,9 +37,16 @@ sync && sleep 5 umount -f /mnt/data rm -rf /mnt/data -# Removing parition +# Release the partition being removed. Only one partition may carry the +# ns_data label, otherwise a storage created later would be mounted over +# /mnt/data alongside this one. if [ "$rom_disk" == "$data_disk" ]; then - parted "/dev/${data_disk}" rm 3 + # Partition carved out of the OS disk: give the space back + parted -s "/dev/${data_disk}" rm "$(cat "/sys/class/block/${data_part}/partition")" +else + # Secondary drive: keep the partition so its logs can still be + # inspected, just drop the label + tune2fs -L "" "/dev/${data_part}" >/dev/null fi # Restore dnsmasq to /tmp before the storage disappears. From 8899a4bce939ee752f9deb8b37f59c09c681895f Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Fri, 7 Aug 2026 12:25:05 +0200 Subject: [PATCH 2/2] fix(ns-storage): do not abort remove-storage when no storage is mounted With no storage configured, looking up the parent disk of an empty device name made lsblk exit 32 and, under set -e, remove-storage bailed out before doing anything. ns.factoryreset runs the script unconditionally, so a factory reset silently skipped the storage teardown. Guard the lookup, the umount and the partition release on an actually mounted storage, and tolerate the missing uci sections and crontab. Assisted-by: Claude Code:claude-opus-5[1m] --- packages/ns-storage/files/remove-storage | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/ns-storage/files/remove-storage b/packages/ns-storage/files/remove-storage index 8cda445d0..36f6015e7 100644 --- a/packages/ns-storage/files/remove-storage +++ b/packages/ns-storage/files/remove-storage @@ -10,20 +10,22 @@ set -e rom_part=$(lsblk -l --json | jq -r '.blockdevices[] | select(any(.mountpoints[]; . == "/boot")) | .name') rom_disk=$(lsblk -lno pkname /dev/$rom_part) +# Both stay empty when no storage is mounted, e.g. on factory reset data_part=$(lsblk -l --json | jq -r '.blockdevices[] | select(any(.mountpoints[]; . == "/mnt/data")) | .name') -data_disk=$(lsblk -lno pkname /dev/$data_part) +data_disk='' +[ -n "$data_part" ] && data_disk=$(lsblk -lno pkname "/dev/$data_part") # Removing auto-mount -uci delete fstab.ns_data +uci -q delete fstab.ns_data || : uci commit fstab # Configuring rsyslog -uci delete rsyslog.ns_data +uci -q delete rsyslog.ns_data || : uci commit rsyslog /etc/init.d/rsyslog restart # Removing sync-data cron job -crontab -l | grep -v "/usr/sbin/sync-data" | sort | uniq | crontab - +(crontab -l 2>/dev/null || :) | grep -v "/usr/sbin/sync-data" | sort | uniq | crontab - /etc/init.d/cron restart # Stop process that will prevent umount @@ -34,13 +36,17 @@ crontab -l | grep -v "/usr/sbin/sync-data" | sort | uniq | crontab - sync && sleep 5 # Umounting data device -umount -f /mnt/data +if grep -q " /mnt/data " /proc/mounts; then + umount -f /mnt/data +fi rm -rf /mnt/data # Release the partition being removed. Only one partition may carry the # ns_data label, otherwise a storage created later would be mounted over # /mnt/data alongside this one. -if [ "$rom_disk" == "$data_disk" ]; then +if [ -z "$data_part" ]; then + : # no storage was mounted, nothing to release +elif [ "$rom_disk" == "$data_disk" ]; then # Partition carved out of the OS disk: give the space back parted -s "/dev/${data_disk}" rm "$(cat "/sys/class/block/${data_part}/partition")" else