I'm sure the reason I'm having a brain fart is because it's late, but how can I go about performing a btrfs check on the root partition?
The device needs to be unmounted, which can't happen because it's the root partition...
Thanks
If you're using systemd
, you can pass the kernel parameter fsck.mode=force
to check all filesystems.
This will repair all "safe" errors.
If you still have issues (check your logs), pass fsck.repair=yes
in addition to the above, which will attempt to repair everything.
For the source of this and other options (eg shutdown -F
) for upstart
and sysvinit
init, see here.
Boot from a livecd and perform the check from there.
The only way to check BTRFS system is to use its own tool btrfs check
, you must have the root volume unmounted therefore the only option is to really boot from a livecd.
Any advice that ultimately leads to calling fsck.btrfs
is wrong, this is just a stub that prints out a message and does nothing. This includes answers with fsck.mode
kernel command line options or .forcefsck
files as well.
[root@nuc ~]# cat /usr/sbin/fsck.btrfs
#!/usr/bin/sh -f
AUTO=false
while getopts ":aApy" c
do
case $c in
a|A|p|y) AUTO=true;;
esac
done
shift $(($OPTIND - 1))
eval DEV=\${$#}
if [ ! -e $DEV ]; then
echo "$0: $DEV does not exist"
exit 8
fi
if ! $AUTO; then
echo "If you wish to check the consistency of a BTRFS filesystem or"
echo "repair a damaged filesystem, see btrfs(8) subcommand 'check'."
fi
exit 0
However if you are just unsure if everything is okay after poweroutage or something like that, btrfs check
can perform a readonly check on a mounted filesystem:
[root@nuc ~]# btrfs check --readonly --force /dev/sda5
Opening filesystem to check...
WARNING: filesystem mounted, continuing because of --force
Checking filesystem on /dev/sda5
UUID: 8c44de9c-c91b-4ac4-857b-da191dc62274
[1/7] checking root items
[2/7] checking extents
[3/7] checking free space cache
[4/7] checking fs roots
[5/7] checking only csums items (without verifying data)
[6/7] checking root refs
[7/7] checking quota groups skipped (not enabled on this FS)
found 3628683264 bytes used, no error found
total csum bytes: 3093864
total tree bytes: 136937472
total fs tree bytes: 126074880
total extent tree bytes: 6455296
btree space waste bytes: 23047273
file data blocks allocated: 5676253184
referenced 4705763328