Skip to content

fix(ns-storage): drop the ns_data label when releasing the storage - #1874

Open
gsanchietti wants to merge 2 commits into
NethServer:mainfrom
gsanchietti:issue1862
Open

fix(ns-storage): drop the ns_data label when releasing the storage#1874
gsanchietti wants to merge 2 commits into
NethServer:mainfrom
gsanchietti:issue1862

Conversation

@gsanchietti

Copy link
Copy Markdown
Member

Summary

The persistent storage is auto-mounted by filesystem label (fstab.ns_data.label=ns_data), but remove-storage only released the old partition when it lived on the OS disk:

if [ "$rom_disk" == "$data_disk" ]; then
    parted "/dev/${data_disk}" rm 3
fi

A storage removed from a secondary drive therefore kept its ns_data label. Once a new storage was created, two partitions matched the label and block mount stacked both onto /mnt/data at boot. ns.storage get-configuration reported the wrong device for the same reason.

Two commits:

  1. Release the label. On a secondary drive, clear it with tune2fs -L "" and keep the partition, so its logs stay available for later inspection — the behaviour proposed in the issue. On the OS disk the partition is still deleted, but the partition number now comes from /sys/class/block/<part>/partition instead of the hardcoded 3.
  2. Don't abort when nothing is mounted. Pre-existing, found while testing: with no storage configured, lsblk -lno pkname /dev/ exits 32 and set -e killed the script before any teardown ran. ns.factoryreset invokes remove-storage unconditionally, so a factory reset silently skipped the storage teardown entirely.

No new dependencies — parted and tune2fs are already in DEPENDS.

Related issue

#1862

How to test

On a machine with the OS disk plus a second drive:

  1. Delete the storage if one exists, then create a new one on the secondary drive.
  2. Delete it. Check the label is gone but the partition is not:
    lsblk -lno KNAME,LABEL   # no ns_data
    lsblk /dev/<second-disk> # partition still there
    
  3. Create a storage on a partition of the primary drive, then reboot.
  4. Only one filesystem must be mounted:
    grep /mnt/data /proc/mounts   # a single line
    storage-status                # ok
    api-cli ns.storage get-configuration   # reports the primary drive partition
    

Reverse cycle (primary → delete → secondary) should leave partition 3 gone from the primary drive's GPT and the secondary partition as the only ns_data.

For the second commit, run /usr/sbin/remove-storage with no storage configured: it must exit 0 and leave dnsmasq, rsyslog, cron and victoria-metrics running.

Verified on a dev VM (OS on vda with a bios_grub partition 128, secondary nvme0n1): all of the above, before and after reboot.

Known limitation

Systems that are already double-mounted are not repaired automatically — data_part resolves to two devices there. They need one manual tune2fs -L "" /dev/<stale-partition>; afterwards this fix keeps them correct.

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]
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]
@gsanchietti gsanchietti self-assigned this Aug 7, 2026
@gsanchietti
gsanchietti marked this pull request as ready for review August 7, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants