Score:0

How do I reschedule mdadm resyncs? Where is /etc/cron.d/mdadm?

cn flag

I've got a software RAID setup using mdadm on a fully updated Ubuntu 20.04. I experience monthly ~31h array resyncs. I suspect this comes from /etc/default/mdadm, which includes:

# AUTOCHECK:
#   should mdadm run periodic redundancy checks over your arrays? See
#   /etc/cron.d/mdadm.
AUTOCHECK=true

I'd like to change when this is scheduled, but I don't seem to have /etc/cron.d/mdadm:

# apt policy mdadm
mdadm:
  Installed: 4.1-5ubuntu1.2
  Candidate: 4.1-5ubuntu1.2
  Version table:
 *** 4.1-5ubuntu1.2 500
        500 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     4.1-5ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages

# find /etc -name '*mdadm*' -or -name '*checkarray*'
/etc/default/mdadm
/etc/monit/conf-available/mdadm
/etc/logcheck/violations.d/mdadm
/etc/logcheck/ignore.d.server/mdadm
/etc/modprobe.d/mdadm.conf
/etc/mdadm
/etc/mdadm/mdadm.conf

# dpkg -S /etc/cron.d/mdadm
dpkg-query: no path found matching pattern /etc/cron.d/mdadm

# grep -REi 'mdadm|raid|/dev/md|autocheck|checkarray' /etc/*cron*

#

So I'm guessing the Debian/Ubuntu documentation is outdated and that this check trigger has moved (to /usr/share/mdadm/checkarray perhaps, though I still don't know what triggers it). The first dialog in dpkg-reconfigure mdadm notes that this check triggers on the first Sunday of the month at 01:06 (see screenshot below), but I can't find the source of that trigger.

first dialog of dpkg-reconfigure mdadm

The best I can find is checkarray. My search:

# dpkg -L mdadm |xargs -d '\n' grep -Fswn AUTOCHECK
/usr/share/mdadm/checkarray: -c|--cron  honour AUTOCHECK setting in /etc/default/mdadm.
/usr/share/mdadm/checkarray:if [ $cron = 1 ] && ! is_true ${AUTOCHECK:-false}; then

I'm guessing the solution is to set AUTOCHECK=false, find the checkarray command it would have run, then manually add my own cron job that replicates it. To do that, I'm looking to confirm this is the best option and to find the ideal arguments to pass it.

I'm also curious about what happened to the old method and where I might find updated documentation.

Bonus question: since resyncing takes so long, is there a way to break it up so I can do it incrementally over multiple nights?

muru avatar
us flag
I'd guess that these have moved over to using systemd timers, like a lot of other system administration tasks. There are a few timers listed in https://packages.ubuntu.com/focal/amd64/mdadm/filelist
Score:0
br flag

It's handled by systemd. The resync script used is /usr/share/mdadm/mdcheck, the trigger is in /lib/systemd/system/mdcheck_start.timer and the action is defined in /lib/systemd/system/mdcheck_start.service (or possibly /etc/systemd/system/..., which is where you should copy the above if you need to modify them).

You can specify a time limit to the process in the service file, it should continue where it left off at next boot (with timeout specified in the timer file). Or you can interrupt the check when you want - take a look at the end of the mdcheck script.

Adrian Zaugg avatar
in flag
There used to be a tool '/usr/share/mdadm/checkarray' that did the job.
cn flag
Hm, that's a good start. Continuing at the next boot isn't great for a system that only reboots a few times a year, but I also see a `/lib/systemd/system/mdcheck_continue.timer` in there. How do I use that? I figure my solution will involve `TimeoutStopSec` but I'm not experienced with systemd: do I edit that file, or replace the symlinks in `/etc/systemd/system/mdmonitor.service.wants/` with my altered file(s)?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.