nextcloud / nextcloud/nextcloudpi

ncp-diag: Falsely reporting data in SD = yes, if root and data directories are BTRFS

Open
#1,509 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug good first issue
Dominant language
Shell
Stars
2.9k
Forks
318
PR merge metrics
No merged PRs in 30d

Description

My Nextcloud is installed on a small x86-server with Debian using the curl-version of NCP. The root directory / is installed on a BTRFS partition.

I have used nc-datadir to move my data to a plugged in USB drive. Nevertheless, the system info in the NCP Panel, and, of course, ncp-diag still reports that my data are in the SD! Accordingly, system info complains that I should use nc-datadir to move your files to your plugged in USB drive.

Result from ncp-diag:

>>> You should use nc-datadir to move your files to your plugged in USB drive <<<

NextCloudPi version|v1.48.2
OS|Debian GNU/Linux 11. 5.10.0-16-amd64 (x86_64)
automount|yes
USB devices|sda sdb
>>> datadir|/media/USB*** <<<
>>> data in SD|yes <<<
data filesystem|btrfs
data disk usage|213G/932G
rootfs usage|19G/25G
swapfile|/dev/mmcblk1p3
dbdir|/media/USB***
Nextcloud check|ok
Nextcloud version|23.0.7.2
HTTPD service|up
PHP service|up
MariaDB service|up
Redis service|up
HPB service|up
Postfix service|up
internet check|ok
port check 80|open
port check 443|open
IP|192.168.***
gateway|192.168.***
interface|enp1s0
certificates|***
NAT loopback|no
uptime|1:11

I took a look at ncp-diag. In line 33 the location of the data directory is tested:
echo "data in SD|$( [[ $( stat -fc%d / ) == $( stat -fc%d "$DATADIR" ) ]] && echo yes || echo no )"

If I understand it correctly, the stat command is used to compare the file system at the root directory / against the $DATADIR directory, where the Nextcloud data are stored. It compares the number of free inodes in each filesystem: If the numbers are identical data in SD = yes. Otherwise the result is no.

In my case, both directories, the root directory and the $DATADIR directory, reside on a BTRFS partition. BTRFS does not use inodes for its meta data. Accordingly, it will always report 0 as the number of free inodes!

Wouldn't it be better to test directly, if both directories are on the same device? This could be done via findmnt:

echo "data in SD|$( [[ $( findmnt -n -o SOURCE --target / ) == $( findmnt -n -o SOURCE --target "$DATADIR" ) ]] && echo yes || echo no )"

findmnt is part of the package util-linux, which, according to my knowledge, is automatically installed in Debian as well as in Raspbian/Raspberry PI OS.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at line 33 of ncp-diag, where stat compares the root and data-directory filesystems and incorrectly reports data in SD for BTRFS. Review the proposed findmnt-based comparison, then verify that the diagnostic reports no when the directories are on different devices and yes when they share one.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, shell
Domain
operating-systems, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.