3 # Copyright (C) 2018 Oracle. All Rights Reserved.
5 # Author: Darrick J. Wong <darrick.wong@oracle.com>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
12 # This program is distributed in the hope that it would be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write the Free Software Foundation,
19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
22 conffile="@root_sysconfdir@/e2scrub.conf"
24 test -f "${conffile}" && . "${conffile}"
29 echo "Usage: $0 [OPTIONS]"
30 echo " -A: Scrub all ext[234] filesystems even if not mounted."
31 echo " -r: Remove e2scrub snapshots."
32 echo " -V: Print version information and exit."
36 echo "e2scrub_all @E2FSPROGS_VERSION@ (@E2FSPROGS_DATE@)"
39 while getopts "ArV" opt; do
42 "r") scrub_args="${scrub_args} -r";;
43 "V") print_version; exit 0;;
44 *) print_help; exit 2;;
47 shift "$((OPTIND - 1))"
49 # Find scrub targets, make sure we only do this once.
51 lsblk -o NAME,FSTYPE,MOUNTPOINT -p -P -n | while read vars; do
60 # Skip unmounted filesystems unless -A
61 if [ "${scrub_all}" -eq 0 ] && [ -z "${MOUNTPOINT}" ]; then
65 # Skip non-lvm devices and lvm snapshots
66 lvm_vars="$(lvs --nameprefixes -o vg_name,lv_name,lv_role --noheadings "${NAME}" 2> /dev/null)"
67 test $? -ne 0 && continue
69 echo "${LVM2_LV_ROLE}" | grep -q "snapshot" && continue
71 if [ -n "${MOUNTPOINT}" ]; then
79 # Scrub any mounted fs on lvm by creating a snapshot and fscking that.
80 stdin="$(realpath /dev/stdin)"
81 ls_scrub_targets | while read tgt; do
82 ${DBG} "@root_sbindir@/e2scrub" ${scrub_args} "${tgt}" < "${stdin}"