ThisCalculator

Everyday

Synology SHR Btrfs UFS Scan Different Partition Offset?

Updated · Standard formula, shown below

Synology SHR Btrfs UFS Scan Different Partition Offset?

Yes, when you run a filesystem check (scan) on a Synology NAS that uses SHR (Synology Hybrid RAID) with Btrfs, the scan is performed on the Btrfs volume that sits on top of the SHR array, and the partition offset used by the scan is the offset of that Btrfs partition within the SHR device, not the raw disk offset. This means that if you try to run a scan directly on a physical disk or on a different partition, you will get errors or an incorrect result because the filesystem metadata is located at a specific offset that only the SHR layer knows about.

Background: SHR and Btrfs on Synology

Synology Hybrid RAID (SHR) is a proprietary RAID implementation that combines multiple disks into a single storage pool, allowing for flexible disk sizes and easy expansion. On top of this pool, Synology creates one or more volumes, and the default filesystem for these volumes is Btrfs (since DSM 6.0). Btrfs is a modern copy-on-write filesystem that provides snapshotting, checksumming, and self-healing capabilities.

When you create a Btrfs volume on an SHR pool, the volume occupies a contiguous range of logical blocks on the pool. The pool itself is composed of one or more RAID groups, and each RAID group is striped across the physical disks. The partition offset that matters for a scan is the offset of the Btrfs volume within the logical pool, not the physical disk offset.

How the Scan Works on SHR Btrfs

When you run a filesystem check (e.g., btrfs check or btrfs scrub) on a Synology NAS, the system mounts the Btrfs volume and performs the scan on the logical device that represents the volume. This logical device is a mapping over the SHR pool, and the kernel knows the correct offset because it reads the partition table of the pool device.

If you were to manually run a scan on a raw physical disk, you would be scanning the wrong area because the Btrfs superblock is not at the start of the disk; it is at the start of the volume partition, which is offset by the RAID metadata and any other partitions. The same applies if you try to scan a different partition on the same disk—the filesystem is not there.

Why the Offset Matters

Btrfs stores its superblock at a fixed offset from the start of the partition (usually 64 KiB). If you scan the wrong offset, the tool will not find the superblock and will report that no Btrfs filesystem exists, or it may find a corrupted superblock and attempt to repair it, potentially causing data loss. Synology’s own tools (like syno_btrfs_check) are designed to work with the correct offset automatically because they query the kernel’s device mapper for the mapping.

For a home user, this means you should never try to run a filesystem check on a disk that is part of an SHR pool by directly accessing /dev/sda or similar. Instead, you should use the Synology DSM interface or the command-line tools that are aware of the SHR layout.

How to Run a Scan Correctly

To run a Btrfs scan on a Synology NAS with SHR, you have two main options:

  • Via DSM: Go to Storage Manager > Storage Pool > Volume > File System Check. This will run a check on the Btrfs volume using the correct offset.
  • Via SSH: Log in as admin, then run sudo btrfs check /dev/md2 (replace md2 with the correct md device for your volume). The md device is the logical device that represents the SHR pool, and it already has the correct partition offset.

If you need to find the correct md device, run cat /proc/mdstat to list all md devices and their roles. The volume devices are usually named md2, md3, etc., depending on the number of volumes.

Common Problems and Misconceptions

A common mistake is to think that because SHR uses mdadm (Linux software RAID), you can scan each disk individually. But SHR is not a simple RAID1 or RAID5; it uses a custom layout that includes a hidden partition for the RAID metadata. Scanning a single disk will not see the Btrfs filesystem because the filesystem is spread across multiple disks in a striped fashion.

Another misconception is that you can use btrfs restore to recover files from a disk that was part of an SHR pool. This will not work unless you have the entire pool assembled, because the data is interleaved across disks. You need to assemble the SHR pool first, which requires all disks to be present and healthy.

Comparing SHR to Other RAID and Filesystem Combinations

If you were using a traditional RAID (e.g., RAID1 or RAID5) with ext4, the scan offset would be simpler because the filesystem starts at a predictable offset on the md device. But with Btrfs on SHR, the added complexity of the SHR metadata means that the offset is not obvious without the kernel’s help.

On a non-Synology system, if you use mdadm to create a RAID array and then format it with Btrfs, the partition offset is usually zero because the md device is the whole array. But SHR adds an extra layer: the SHR pool is itself a md device, and the Btrfs volume is a partition on that md device. So the offset is the partition start within the md device.

Costs and Safety Considerations

Running a filesystem scan on a large Btrfs volume can take hours and may temporarily reduce performance. It is safe to run a read-only check, but a repair (with --repair) should only be done with a backup, because it can cause data loss if the filesystem is badly corrupted. Always ensure you have a current backup before attempting any repair.

If you are unsure about the offset or the health of your pool, the safest approach is to contact Synology support or consult the official documentation. Never attempt to bypass the SHR layer by scanning raw disks, as this can lead to irreversible data loss.

Frequently Asked Questions

Can I run btrfs check on a single disk from my SHR array?

No, because the Btrfs filesystem is striped across all disks in the SHR pool. A single disk contains only fragments of the filesystem, and the superblock is not present on every disk. You must assemble the entire pool first.

What is the partition offset for Btrfs on SHR?

The offset is the start of the Btrfs partition within the md device that represents the SHR pool. It is not a fixed number; it depends on the pool layout and the size of the partition. The kernel calculates it automatically when you access the volume.

Why does my scan fail when I use /dev/sda?

Because /dev/sda is the raw disk, and the Btrfs filesystem is not stored at the start of the disk. The SHR metadata and RAID stripes occupy the beginning, so the Btrfs superblock is at a different offset. Scanning /dev/sda will not find the filesystem.

Can I use btrfs restore to recover files from a failed disk?

Only if you have the entire SHR pool assembled and accessible. If a disk has failed, you need to replace it and let the pool rebuild before you can mount the volume. btrfs restore works on a mounted or unmounted volume, but it needs the full logical device.

Is it safe to run a Btrfs scrub on an SHR pool?

Yes, a scrub is a read-only operation that checks checksums and repairs silent corruption. It is safe and recommended to run regularly. It does not modify the filesystem metadata, only data blocks that are damaged.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.