How to run btrfs check?

How do I run btrfs check on i) the root FS, ii) USB-attached NAS/srv disk on boot? What I get is it has to be run before mounting the disks, so I tried adding the check commands to various places in /lib/preinit (definitely before 80_mount_root). I store the script’s output to /tmp to be able to see what was going on, but it seems it never actually runs successfully.

The script I’m running:

btrfs check --repair /dev/mmcblk0p1 2>&1 1>/tmp/fsck.root
echo $? >>/tmp/fsck.root
if [[ ! -f /dev/sda1 ]]; then sleep 5; fi
btrfs check --repair /dev/sda1 2>&1 1>/tmp/fsck.nas
echo $? >>/tmp/fsck.nas

The content of both files is just this:

enabling repair mode
Opening filesystem to check...
1

Sources:

To make it clear - I’m seeking for an automated solution - i.e. without a serial console…

Side note: my understanding is that it’s not generally good to run btrfs check --repair blindly/automatically. You shouldn’t need it at all when recovering after power loss and similar conditions – those actions are automatic when you mount btrfs.

I meant it as an enable-on-demand script. The main reason was that yesterday I saw some BTRFS errors in syslog, so I wanted to run the checks and repair these errors sooner rather than later.

My experience of flash drive errors and his unexpected unplugging is that - this occurred only when the flash drive was inserted in the rear port under the antenna. There are newer errors in the front USB port. I have not observed any improvement if I changed the kind of file system (Btrfs, EXT4, …)

017-12-06T14:38:02+01:00 err kernel[]: [536599.252025] Buffer I/O error on dev sda1, logical block 3899392, lost sync page write

image

@JardaB The NAS disk is an external-powered RAID box, and I don’t unplug it at any time. But thanks for the info. I have it connected to the rear USB. However, although wifi is running on the router, I usually don’t have any clients connected to it.

What I describe assumes is that the flash drive is affected by the radiation of the nearby antenna. On the external RAID field of the influence I don’t suppose - you’ll see

I think I’ve seen somewhere that the USB (cable) and the adjacent WiFi antenna on Omnia might have some slight interference, but it’s a rather vague memory and I’m not a HW person.


That is USB radiation poisoning the WLAN signal but I would not reckon that in reverse the WLAN signal is interfering with the data stream on the external drive, at least never heard of such case.

1 Like