diff -pruN 4.1-8/debian/changelog 4.1-8ubuntu1/debian/changelog
--- 4.1-8/debian/changelog	2020-10-13 18:15:45.000000000 +0000
+++ 4.1-8ubuntu1/debian/changelog	2020-10-26 12:15:40.000000000 +0000
@@ -1,3 +1,44 @@
+mdadm (4.1-8ubuntu1) hirsute; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - Ship finalrd hook.
+    - Do not install mdadm-shutdown.service on Ubuntu.
+    - Drop broken and unused init scripts in favor of native systemd units,
+      which can cause failure to reconfigure mdadm package under certain
+      confiment types.
+    - Drop /etc/cron.d/mdadm and migrate to systemd mdcheck_start|continue
+      timer units.
+    - Drop /etc/cron.daily/mdadm and migrate to system mdmonitor-oneshot
+      timer unit.
+    - mdcheck_start.timer configures the mdcheck on a first sunday of the
+      month, with a randomized start delay of up to 24h, and runs for at
+      most 6h. mdcheck_continue.timer kicks off daily, with a randomized
+      start delay of up to 12h, and continues mdcheck for at most 6h.
+    - mdmonitor-oneshot.timer runs daily, with a randomized start delay of
+      up to 24h.
+    - One can use systemd drop-ins to change .timer units timings, set
+      environmental variables to decrease/increase the length of checking,
+      or start the checks by hand. Previously used checkarray is still
+      available, albeit not used by timer units.
+    - Above ensures that previous daily / monthly checks are performed, but
+      are randomized, such that performance is not as impacted across a
+      cluster of machines.
+    - Honor the debconf daily autoscan setting in the systemd timer.
+    - d/p/mdcheck-fix-empty-spaces-in-timer-unit-files.patch:
+      - The spaces were causing a FTBFS situation, triggered by
+        dh_installsystemd not finding units.
+    - d/p/mdcheck-when-mdcheck-start-is-enabled-mdcheck-continue-too.patch:
+      - When mdcheck_start is enabled, enable mdcheck_continue too.
+    - d/p/mdcheck-log-when-done.patch:
+      - Make sure mdcheck logs the completion too, so that
+      it can be determined how long the raid check took.
+
+  * Also fix up whitespace in systemd/mdmonitor-oneshot.timer.
+  * Cherrypick upstream fix to allow assembling dirty degrated IMSM raid
+    arrays with --force flag. LP: #1894792
+
+ -- Dimitri John Ledkov <xnox@ubuntu.com>  Mon, 26 Oct 2020 12:15:40 +0000
+
 mdadm (4.1-8) unstable; urgency=medium
 
   * Comprehensive FAQ improvements and amendments.(Closes: #715387)
@@ -48,6 +89,69 @@ mdadm (4.1-6) unstable; urgency=medium
 
  -- Felix Lechner <felix.lechner@lease-up.com>  Sat, 12 Sep 2020 20:46:58 -0700
 
+mdadm (4.1-5ubuntu5) groovy; urgency=medium
+
+  * d/p/mdcheck-fix-empty-spaces-in-timer-unit-files.patch:
+    - The spaces were causing a FTBFS situation, triggered by
+      dh_installsystemd not finding units.
+
+ -- Eric Desrochers <eric.desrochers@canonical.com>  Mon, 28 Sep 2020 11:44:00 -0400
+
+mdadm (4.1-5ubuntu4) groovy; urgency=medium
+
+  * d/p/mdcheck-when-mdcheck-start-is-enabled-mdcheck-continue-too.patch:
+    - When mdcheck_start is enabled, enable mdcheck_continue too.
+
+ -- Eric Desrochers <eric.desrochers@canonical.com>  Fri, 25 Sep 2020 10:27:50 -0400
+
+mdadm (4.1-5ubuntu3) groovy; urgency=medium
+
+  * d/p/mdcheck-log-when-done.patch:
+    - Make sure mdcheck logs the completion too, so that
+     it can be determined how long the raid check took.
+
+ -- Eric Desrochers <eric.desrochers@canonical.com>  Thu, 24 Sep 2020 09:14:49 -0400
+
+mdadm (4.1-5ubuntu2) groovy; urgency=medium
+
+  * d/rules: Install misc/mdcheck (LP: #1852747)
+    - The absence of mdcheck utility is preventing
+      mdcheck_continue.service & mdcheck_start.service
+      to execute the command when the service start via
+      ExecStart. (Closes: #960132)
+
+ -- Eric Desrochers <eric.desrochers@canonical.com>  Wed, 23 Sep 2020 14:08:32 -0400
+
+mdadm (4.1-5ubuntu1) focal; urgency=medium
+
+  [ dann frazier ]
+  * Merge from Debian unstable.  Remaining changes:
+    - Ship finalrd hook.
+    - Do not install mdadm-shutdown.service on Ubuntu.
+    - Drop broken and unused init scripts in favor of native systemd units,
+      which can cause failure to reconfigure mdadm package under certain
+      confiment types.
+    - Drop /etc/cron.d/mdadm and migrate to systemd mdcheck_start|continue
+      timer units.
+    - Drop /etc/cron.daily/mdadm and migrate to system mdmonitor-oneshot
+      timer unit.
+    - mdcheck_start.timer configures the mdcheck on a first sunday of the
+      month, with a randomized start delay of up to 24h, and runs for at
+      most 6h. mdcheck_continue.timer kicks off daily, with a randomized
+      start delay of up to 12h, and continues mdcheck for at most 6h.
+    - mdmonitor-oneshot.timer runs daily, with a randomized start delay of
+      up to 24h.
+    - One can use systemd drop-ins to change .timer units timings, set
+      environmental variables to decrease/increase the length of checking,
+      or start the checks by hand. Previously used checkarray is still
+      available, albeit not used by timer units.
+    - Above ensures that previous daily / monthly checks are performed, but
+      are randomized, such that performance is not as impacted across a
+      cluster of machines.
+    - Honor the debconf daily autoscan setting in the systemd timer.
+
+ -- dann frazier <dannf@ubuntu.com>  Thu, 23 Jan 2020 11:41:55 -0700
+
 mdadm (4.1-5) unstable; urgency=medium
 
   * QA upload.
@@ -58,6 +162,39 @@ mdadm (4.1-5) unstable; urgency=medium
 
  -- dann frazier <dannf@debian.org>  Wed, 22 Jan 2020 09:56:25 -0700
 
+mdadm (4.1-4ubuntu1) focal; urgency=medium
+
+  [ dann frazier ]
+  * Merge from Debian unstable.  Remaining changes:
+    - Ship finalrd hook.
+    - Do not install mdadm-shutdown.service on Ubuntu.
+    - Drop broken and unused init scripts in favor of native systemd units,
+      which can cause failure to reconfigure mdadm package under certain
+      confiment types.
+    - Drop /etc/cron.d/mdadm and migrate to systemd mdcheck_start|continue
+      timer units.
+    - Drop /etc/cron.daily/mdadm and migrate to system mdmonitor-oneshot
+      timer unit.
+    - mdcheck_start.timer configures the mdcheck on a first sunday of the
+      month, with a randomized start delay of up to 24h, and runs for at
+      most 6h. mdcheck_continue.timer kicks off daily, with a randomized
+      start delay of up to 12h, and continues mdcheck for at most 6h.
+    - mdmonitor-oneshot.timer runs daily, with a randomized start delay of
+      up to 24h.
+    - One can use systemd drop-ins to change .timer units timings, set
+      environmental variables to decrease/increase the length of checking,
+      or start the checks by hand. Previously used checkarray is still
+      available, albeit not used by timer units.
+    - Above ensures that previous daily / monthly checks are performed, but
+      are randomized, such that performance is not as impacted across a
+      cluster of machines.
+  * Honor the debconf daily autoscan setting in the systemd timer.
+
+  [ Guilherme G. Piccoli ]
+  * Introduce "broken" state for RAID0/Linear in mdadm (LP: #1847924)
+
+ -- dann frazier <dannf@ubuntu.com>  Wed, 04 Dec 2019 07:05:07 -0700
+
 mdadm (4.1-4) unstable; urgency=medium
 
   * QA upload.
@@ -77,6 +214,44 @@ mdadm (4.1-3) unstable; urgency=medium
 
  -- Daniel Baumann <daniel.baumann@progress-linux.org>  Fri, 09 Aug 2019 17:19:20 +0000
 
+mdadm (4.1-2ubuntu3) eoan; urgency=medium
+
+  * Drop /etc/cron.d/mdadm and migrate to systemd mdcheck_start|continue
+    timer units.
+  * Drop /etc/cron.daily/mdadm and migrate to system mdmonitor-oneshot
+    timer unit.
+  * mdcheck_start.timer configures the mdcheck on a first sunday of the
+    month, with a randomized start delay of up to 24h, and runs for at
+    most 6h. mdcheck_continue.timer kicks off daily, with a randomized
+    start delay of up to 12h, and continues mdcheck for at most 6h.
+  * mdmonitor-oneshot.timer runs daily, with a randomized start delay of
+    up to 24h.
+  * One can use systemd drop-ins to change .timer units timings, set
+    environmental variables to decrease/increase the length of checking,
+    or start the checks by hand. Previously used checkarray is still
+    available, albeit not used by timer units.
+  * Above ensures that previous daily / monthly checks are performed, but
+    are randomized, such that performance is not as impacted across a
+    cluster of machines. LP: #1815201
+
+ -- Dimitri John Ledkov <xnox@ubuntu.com>  Tue, 18 Jun 2019 16:29:44 +0100
+
+mdadm (4.1-2ubuntu2) eoan; urgency=medium
+
+  * Drop broken and unused init scripts in favor of native systemd units,
+    which can cause failure to reconfigure mdadm package under certain
+    confiment types. LP: #1829325
+
+ -- Dimitri John Ledkov <xnox@ubuntu.com>  Mon, 20 May 2019 19:57:41 +0100
+
+mdadm (4.1-2ubuntu1) eoan; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - Ship finalrd hook.
+    - Do not install mdadm-shutdown.service on Ubuntu.
+
+ -- Steve Langasek <steve.langasek@ubuntu.com>  Sat, 04 May 2019 20:58:27 -0700
+
 mdadm (4.1-2) unstable; urgency=medium
 
   * QA upload.
@@ -84,6 +259,14 @@ mdadm (4.1-2) unstable; urgency=medium
 
  -- Dimitri John Ledkov <xnox@ubuntu.com>  Tue, 12 Mar 2019 03:58:03 +0000
 
+mdadm (4.1-1ubuntu1) disco; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - Ship finalrd hook.
+    - Do not install mdadm-shutdown.service on Ubuntu.
+
+ -- Dimitri John Ledkov <xnox@ubuntu.com>  Wed, 16 Jan 2019 11:29:22 +0000
+
 mdadm (4.1-1) unstable; urgency=medium
 
   * New upstream release.
@@ -94,6 +277,13 @@ mdadm (4.1-1) unstable; urgency=medium
 
  -- Dimitri John Ledkov <xnox@ubuntu.com>  Tue, 15 Jan 2019 18:23:53 +0000
 
+mdadm (4.1~rc1-4ubuntu1) cosmic; urgency=medium
+
+  * Ship finalrd hook.
+  * Do not install mdadm-shutdown.service on Ubuntu.
+
+ -- Dimitri John Ledkov <xnox@ubuntu.com>  Fri, 03 Aug 2018 14:53:18 +0100
+
 mdadm (4.1~rc1-4) unstable; urgency=medium
 
   * Cherrypick master patches up to 20th of July 2018. LP: #1781427
@@ -2074,3 +2264,4 @@ mdctl (0.5-1) unstable; urgency=low
     (closes: Bug#126610)
 
  -- Mario Joussen <mario@joussen.org>  Wed, 26 Dec 2001 17:07:09 +0100
+
diff -pruN 4.1-8/debian/control 4.1-8ubuntu1/debian/control
--- 4.1-8/debian/control	2020-09-13 23:12:12.000000000 +0000
+++ 4.1-8ubuntu1/debian/control	2020-10-26 12:15:40.000000000 +0000
@@ -1,7 +1,8 @@
 Source: mdadm
 Section: admin
 Priority: optional
-Maintainer: Felix Lechner <felix.lechner@lease-up.com>
+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
+XSBC-Original-Maintainer: Felix Lechner <felix.lechner@lease-up.com>
 Build-Depends:
  debhelper-compat (= 13),
  groff-base,
@@ -24,6 +25,7 @@ Depends:
  udev
 Recommends:
  ${mta:Recommends},
+ finalrd (>= 3~),
  kmod | module-init-tools
 Suggests:
  ${mta:Suggests},
diff -pruN 4.1-8/debian/mdadm.cron.d 4.1-8ubuntu1/debian/mdadm.cron.d
--- 4.1-8/debian/mdadm.cron.d	2020-09-13 23:12:12.000000000 +0000
+++ 4.1-8ubuntu1/debian/mdadm.cron.d	1970-01-01 00:00:00.000000000 +0000
@@ -1,12 +0,0 @@
-#
-# cron.d/mdadm -- schedules periodic redundancy checks of MD devices
-#
-# Copyright © martin f. krafft <madduck@madduck.net>
-# distributed under the terms of the Artistic Licence 2.0
-#
-
-# By default, run at 00:57 on every Sunday, but do nothing unless the day of
-# the month is less than or equal to 7. Thus, only run on the first Sunday of
-# each month. crontab(5) sucks, unfortunately, in this regard; therefore this
-# hack (see #380425).
-57 0 * * 0 root if [ -x /usr/share/mdadm/checkarray ] && [ $(date +\%d) -le 7 ]; then /usr/share/mdadm/checkarray --cron --all --idle --quiet; fi
diff -pruN 4.1-8/debian/mdadm.cron.daily 4.1-8ubuntu1/debian/mdadm.cron.daily
--- 4.1-8/debian/mdadm.cron.daily	2020-09-13 23:12:12.000000000 +0000
+++ 4.1-8ubuntu1/debian/mdadm.cron.daily	1970-01-01 00:00:00.000000000 +0000
@@ -1,21 +0,0 @@
-#!/bin/sh
-#
-# cron.daily/mdadm -- daily check that MD devices are functional
-#
-# Copyright © 2008 Paul Slootman <paul@debian.org>
-# distributed under the terms of the Artistic Licence 2.0
-
-# As recommended by the manpage, run
-#      mdadm --monitor --scan --oneshot
-# every day to ensure that any degraded MD devices don't go unnoticed.
-# Email will go to the address specified in /etc/mdadm/mdadm.conf .
-#
-set -eu
-
-MDADM=/sbin/mdadm
-[ -x $MDADM ] || exit 0 # package may be removed but not purged
-
-[ -e /etc/default/mdadm ] && . /etc/default/mdadm
-[ $AUTOSCAN = false ] && exit 0
-
-exec $MDADM --monitor --scan --oneshot
diff -pruN 4.1-8/debian/mdadm.finalrd 4.1-8ubuntu1/debian/mdadm.finalrd
--- 4.1-8/debian/mdadm.finalrd	1970-01-01 00:00:00.000000000 +0000
+++ 4.1-8ubuntu1/debian/mdadm.finalrd	2020-01-23 18:39:24.000000000 +0000
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-3.0-only
+set -e
+
+if [ "$1" = "setup" ]
+then
+    . /usr/share/initramfs-tools/hook-functions
+    copy_exec /sbin/mdadm
+    copy_exec /sbin/mdmon
+
+    exit 0
+fi
+
+mdmon --all --takeover
+mdadm -vv --wait-clean --scan
+mdadm -vv --stop --scan
diff -pruN 4.1-8/debian/mdadm.init 4.1-8ubuntu1/debian/mdadm.init
--- 4.1-8/debian/mdadm.init	2020-09-13 23:12:12.000000000 +0000
+++ 4.1-8ubuntu1/debian/mdadm.init	1970-01-01 00:00:00.000000000 +0000
@@ -1,100 +0,0 @@
-#!/bin/sh
-#
-# Start the MD monitor daemon for all active MD arrays if desired.
-# This script is not used under systemd.
-#
-# Copyright © 2001-2005 Mario Jou/3en <joussen@debian.org>
-# Copyright © 2005-2009 Martin F. Krafft <madduck@debian.org>
-# Distributable under the terms of the GNU GPL version 2.
-#
-### BEGIN INIT INFO
-# Provides:          mdadm
-# Required-Start:    $local_fs $syslog
-# Required-Stop:     $local_fs $syslog sendsigs 
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: MD monitoring daemon
-# Description:       mdadm provides a monitor mode, in which it will scan for
-#                    problems with the MD devices. If a problem is found, the
-#                    administrator is alerted via email, or a custom script is
-#                    run.
-### END INIT INFO
-#
-set -eu
-
-MDADM=/sbin/mdadm
-MDMON=/sbin/mdmon
-RUNDIR=/run/mdadm
-PIDFILE=$RUNDIR/monitor.pid
-DEBIANCONFIG=/etc/default/mdadm
-
-test -x "$MDADM" || exit 0
-
-test -f /proc/mdstat || exit 0
-
-START_DAEMON=true
-test -f $DEBIANCONFIG && . $DEBIANCONFIG
-
-. /lib/lsb/init-functions
-
-is_true()
-{
-  case "${1:-}" in
-    [Yy]es|[Yy]|1|[Tt]|[Tt]rue) return 0;;
-    *) return 1;
-  esac
-}
-
-case "${1:-}" in
-  start)
-    if [ -x /usr/bin/systemd-detect-virt ] && /usr/bin/systemd-detect-virt --quiet --container; then
-      log_daemon_msg "Not starting MD monitoring service in container"
-      log_end_msg 0
-      exit 0
-    fi
-
-    if is_true $START_DAEMON; then
-      log_daemon_msg "Starting MD monitoring service" "mdadm --monitor"
-      mkdir -p $RUNDIR
-      set +e
-      start-stop-daemon -S -p $PIDFILE -x $MDADM -- \
-        --monitor --pid-file $PIDFILE --daemonise --scan ${DAEMON_OPTIONS:-}
-      log_end_msg $?
-      set -e
-    fi
-    if [ "$(echo $RUNDIR/md[0-9]*.pid)" != "$RUNDIR/md[0-9]*.pid" ]; then
-      log_daemon_msg "Restarting MD external metadata monitor" "mdmon --takeover --all"
-      set +e
-      $MDMON --takeover --all
-      log_end_msg $?
-      set -e
-    fi
-    ;;
-  stop)
-    if [ -f $PIDFILE ] ; then
-      log_daemon_msg "Stopping MD monitoring service" "mdadm --monitor"
-      set +e
-      start-stop-daemon -K -p $PIDFILE -x $MDADM
-      rm -f $PIDFILE
-      log_end_msg $?
-      set -e
-    fi
-    for file in $RUNDIR/md[0-9]*.pid ; do
-      [ ! -f "$file" ] && continue
-      ln -sf $file /run/sendsigs.omit.d/mdmon-${file##*/}
-    done
-    ;;
-  status)
-    status_of_proc -p $PIDFILE "$MDADM" "mdadm" && exit 0 || exit $?
-    ;;
-  restart|reload|force-reload)
-    ${0:-} stop
-    ${0:-} start
-    ;;
-  *)
-    echo "Usage: ${0:-} {start|stop|status|restart|reload|force-reload}" >&2
-    exit 1
-    ;;
-esac
-
-exit 0
diff -pruN 4.1-8/debian/mdadm.maintscript 4.1-8ubuntu1/debian/mdadm.maintscript
--- 4.1-8/debian/mdadm.maintscript	2020-09-13 23:12:12.000000000 +0000
+++ 4.1-8ubuntu1/debian/mdadm.maintscript	2020-10-13 21:44:01.000000000 +0000
@@ -1 +1,5 @@
 rm_conffile /etc/init.d/mdadm-raid 3.4-2~
+rm_conffile /etc/init.d/mdadm 4.1-2ubuntu2~
+rm_conffile /etc/init.d/mdadm-waitidle 4.1-2ubuntu2~
+rm_conffile /etc/cron.d/mdadm 4.1-2ubuntu3~
+rm_conffile /etc/cron.daily/mdadm 4.1-2ubuntu3~
diff -pruN 4.1-8/debian/patches/7b99edab2834d5d08ef774b4cff784caaa1a186f.patch 4.1-8ubuntu1/debian/patches/7b99edab2834d5d08ef774b4cff784caaa1a186f.patch
--- 4.1-8/debian/patches/7b99edab2834d5d08ef774b4cff784caaa1a186f.patch	1970-01-01 00:00:00.000000000 +0000
+++ 4.1-8ubuntu1/debian/patches/7b99edab2834d5d08ef774b4cff784caaa1a186f.patch	2020-10-26 12:15:40.000000000 +0000
@@ -0,0 +1,98 @@
+From 7b99edab2834d5d08ef774b4cff784caaa1a186f Mon Sep 17 00:00:00 2001
+From: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
+Date: Tue, 5 May 2020 12:17:17 +0200
+Subject: Assemble.c: respect force flag.
+
+If the array is dirty handler will set resync_start to 0 to inform kernel
+that resync is needed. RWH affects only raid456 module, for other
+levels array will be started even array is degraded and resync cannot be
+performed.
+
+Force is really meaningful for raid456. If array is degraded and resync
+is requested, kernel will reject an attempt to start the array. To
+respect force, it has to be marked as clean (this will be done for each
+array without PPL) and remove the resync request (only for raid 456).
+Data corruption may occur so proper warning is added.
+
+Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
+Signed-off-by: Jes Sorensen <jsorensen@fb.com>
+
+Bug-Ubuntu: https://launchpad.net/bugs/1894792
+
+---
+ Assemble.c | 51 ++++++++++++++++++++++++++++++++++++++-------------
+ 1 file changed, 38 insertions(+), 13 deletions(-)
+
+diff --git a/Assemble.c b/Assemble.c
+index 2ed5884..3e5d4e6 100644
+--- a/Assemble.c
++++ b/Assemble.c
+@@ -2030,6 +2030,15 @@ int assemble_container_content(struct supertype *st, int mdfd,
+ 			free(avail);
+ 			return err;
+ 		}
++	} else if (c->force) {
++		/* Set the array as 'clean' so that we can proceed with starting
++		 * it even if we don't have all devices. Mdmon doesn't care
++		 * if the dirty flag is set in metadata, it will start managing
++		 * it anyway.
++		 * This is really important for raid456 (RWH case), other levels
++		 * are started anyway.
++		 */
++		content->array.state |= 1;
+ 	}
+ 
+ 	if (enough(content->array.level, content->array.raid_disks,
+@@ -2049,20 +2058,36 @@ int assemble_container_content(struct supertype *st, int mdfd,
+ 	}
+ 	free(avail);
+ 
+-	if (c->runstop <= 0 &&
+-	    (working + preexist + expansion) <
+-	    content->array.working_disks) {
+-		if (c->export && result)
+-			*result |= INCR_UNSAFE;
+-		else if (c->verbose >= 0) {
+-			pr_err("%s assembled with %d device%s",
+-			       chosen_name, preexist + working,
+-			       preexist + working == 1 ? "":"s");
+-			if (preexist)
+-				fprintf(stderr, " (%d new)", working);
+-			fprintf(stderr, " but not safe to start\n");
++	if ((working + preexist + expansion) < content->array.working_disks) {
++		if (c->runstop <= 0) {
++			if (c->export && result)
++				*result |= INCR_UNSAFE;
++			else if (c->verbose >= 0) {
++				pr_err("%s assembled with %d device%s",
++					chosen_name, preexist + working,
++					preexist + working == 1 ? "":"s");
++				if (preexist)
++					fprintf(stderr, " (%d new)", working);
++				fprintf(stderr, " but not safe to start\n");
++				if (c->force)
++					pr_err("Consider --run to start array as degraded.\n");
++			}
++			return 1;
++		} else if (content->array.level >= 4 &&
++			   content->array.level <= 6 &&
++			   content->resync_start != MaxSector &&
++			   c->force) {
++			/* Don't inform the kernel that the array is not
++			 * clean and requires resync.
++			 */
++			content->resync_start = MaxSector;
++			err = sysfs_set_num(content, NULL, "resync_start",
++					    MaxSector);
++			if (err)
++				return 1;
++			pr_err("%s array state forced to clean. It may cause data corruption.\n",
++				chosen_name);
+ 		}
+-		return 1;
+ 	}
+ 
+ 
+-- 
+cgit 1.2.3-1.el7
+
diff -pruN 4.1-8/debian/patches/mdcheck-fix-empty-spaces-in-timer-unit-files.patch 4.1-8ubuntu1/debian/patches/mdcheck-fix-empty-spaces-in-timer-unit-files.patch
--- 4.1-8/debian/patches/mdcheck-fix-empty-spaces-in-timer-unit-files.patch	1970-01-01 00:00:00.000000000 +0000
+++ 4.1-8ubuntu1/debian/patches/mdcheck-fix-empty-spaces-in-timer-unit-files.patch	2020-10-26 12:15:40.000000000 +0000
@@ -0,0 +1,37 @@
+Description: mdcheck fix empty spaces in timer unit files
+ dh_installsystemd is failling thus FBTFS because of the spaces
+ in the systemd unit timer files directive.
+Author: Eric Desrochers <eric.desrochers@canonical.com>
+Bug-Ubuntu: https://launchpad.net/bugs/1852747
+Index: mdadm-4.1-8ubuntu1/systemd/mdcheck_continue.timer
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdcheck_continue.timer
++++ mdadm-4.1-8ubuntu1/systemd/mdcheck_continue.timer
+@@ -15,4 +15,4 @@ Persistent=true
+ 
+ 
+ [Install]
+-WantedBy= mdmonitor.service
++WantedBy=mdmonitor.service
+Index: mdadm-4.1-8ubuntu1/systemd/mdcheck_start.timer
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdcheck_start.timer
++++ mdadm-4.1-8ubuntu1/systemd/mdcheck_start.timer
+@@ -14,5 +14,5 @@ RandomizedDelaySec=24h
+ Persistent=true
+ 
+ [Install]
+-WantedBy= mdmonitor.service
+-Also= mdcheck_continue.timer
++WantedBy=mdmonitor.service
++Also=mdcheck_continue.timer
+Index: mdadm-4.1-8ubuntu1/systemd/mdmonitor-oneshot.timer
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdmonitor-oneshot.timer
++++ mdadm-4.1-8ubuntu1/systemd/mdmonitor-oneshot.timer
+@@ -14,4 +14,4 @@ RandomizedDelaySec=24h
+ Persistent=true
+ 
+ [Install]
+-WantedBy= mdmonitor.service
++WantedBy=mdmonitor.service
diff -pruN 4.1-8/debian/patches/mdcheck-log-when-done.patch 4.1-8ubuntu1/debian/patches/mdcheck-log-when-done.patch
--- 4.1-8/debian/patches/mdcheck-log-when-done.patch	1970-01-01 00:00:00.000000000 +0000
+++ 4.1-8ubuntu1/debian/patches/mdcheck-log-when-done.patch	2020-09-24 13:14:49.000000000 +0000
@@ -0,0 +1,32 @@
+Description: mdcheck: Log when done
+ Currently mdcheck (when called with `--duration`) logs only the
+ beginning of the check, the pausing and the continuation but not the
+ completion.
+
+ So, log the completion, too, so that it can be determined how long the
+ raid check took.
+
+ 2020-05-08T18:00:02+02:00 deadpool root: mdcheck start checking /dev/md0
+ 2020-05-08T18:00:02+02:00 deadpool root: mdcheck start checking /dev/md1
+ 2020-05-09T15:32:04+02:00 deadpool root: mdcheck finished checking /dev/md1
+ 2020-05-09T17:38:04+02:00 deadpool root: mdcheck finished checking /dev/md0
+
+Author: Donald Buczek <buczek@molgen.mpg.de>
+Origin: upstream, https://git.kernel.org/pub/scm/utils/mdadm/mdadm.git/commit/?id=3b7aae927bdb6e150d1aaf3aaf0d183a06abda0b
+Bug-Ubuntu: https://launchpad.net/bugs/1852747
+--- a/misc/mdcheck
++++ b/misc/mdcheck
+@@ -125,11 +125,13 @@
+ 	do
+ 		eval fl=\$MD_${i}_fl
+ 		eval sys=\$MD_${i}_sys
++		eval dev=\$MD_${i}_dev
+ 
+ 		if [ -z "$fl" ]; then continue; fi
+ 
+ 		if [ "`cat $sys/md/sync_action`" != 'check' ]
+ 		then
++			logger -p daemon.info mdcheck finished checking $dev
+ 			eval MD_${i}_fl=
+ 			rm -f $fl
+ 			continue;
diff -pruN 4.1-8/debian/patches/mdcheck-when-mdcheck-start-is-enabled-mdcheck-continue-too.patch 4.1-8ubuntu1/debian/patches/mdcheck-when-mdcheck-start-is-enabled-mdcheck-continue-too.patch
--- 4.1-8/debian/patches/mdcheck-when-mdcheck-start-is-enabled-mdcheck-continue-too.patch	1970-01-01 00:00:00.000000000 +0000
+++ 4.1-8ubuntu1/debian/patches/mdcheck-when-mdcheck-start-is-enabled-mdcheck-continue-too.patch	2020-09-25 14:27:37.000000000 +0000
@@ -0,0 +1,31 @@
+Description: mdcheck: when mdcheck_start is enabled, enable mdcheck_continue too.
+ mdcheck_continue continues a regular array scan that was started by
+ mdcheck_start.
+ mdcheck_start will ensure that mdcheck_continue is active.
+ Howver if you reboot after a check has started, but before it finishes,
+ then mdcheck_continue won't cause it to continue, because nothing
+ starts it on boot.
+
+ So add an install option for mdcheck_contine, and make sure it
+ gets enabled when mdcheck_start is enabled.
+
+Author: NeilBrown <neilb@suse.de>
+Origin: upstream, https://git.kernel.org/pub/scm/utils/mdadm/mdadm.git/commit/?id=6636788aaf4ec0cacaefb6e77592e4a68e70a957
+Bug-Ubuntu: https://launchpad.net/bugs/1852747
+--- a/systemd/mdcheck_continue.timer
++++ b/systemd/mdcheck_continue.timer
+@@ -12,3 +12,7 @@
+ OnCalendar=daily
+ RandomizedDelaySec=12h
+ Persistent=true
++
++
++[Install]
++WantedBy= mdmonitor.service
+--- a/systemd/mdcheck_start.timer
++++ b/systemd/mdcheck_start.timer
+@@ -15,3 +15,4 @@
+ 
+ [Install]
+ WantedBy= mdmonitor.service
++Also= mdcheck_continue.timer
diff -pruN 4.1-8/debian/patches/randomize-timers.patch 4.1-8ubuntu1/debian/patches/randomize-timers.patch
--- 4.1-8/debian/patches/randomize-timers.patch	1970-01-01 00:00:00.000000000 +0000
+++ 4.1-8ubuntu1/debian/patches/randomize-timers.patch	2020-10-26 12:12:31.000000000 +0000
@@ -0,0 +1,81 @@
+Description: Randomize md array check timers
+Author: Dimitri John Ledkov <xnox@ubuntu.com>
+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1815201
+
+Index: mdadm-4.1-8ubuntu1/systemd/mdcheck_continue.timer
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdcheck_continue.timer
++++ mdadm-4.1-8ubuntu1/systemd/mdcheck_continue.timer
+@@ -9,5 +9,6 @@
+ Description=MD array scrubbing - continuation
+ 
+ [Timer]
+-OnCalendar= 1:05:00
+-
++OnCalendar=daily
++RandomizedDelaySec=12h
++Persistent=true
+Index: mdadm-4.1-8ubuntu1/systemd/mdcheck_start.service
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdcheck_start.service
++++ mdadm-4.1-8ubuntu1/systemd/mdcheck_start.service
+@@ -13,6 +13,4 @@ Documentation=man:mdadm(8)
+ [Service]
+ Type=oneshot
+ Environment=MDADM_CHECK_DURATION='"6 hours"'
+-EnvironmentFile=-/run/sysconfig/mdadm
+-ExecStartPre=-/usr/lib/mdadm/mdadm_env.sh
+ ExecStart=/usr/share/mdadm/mdcheck --duration $MDADM_CHECK_DURATION
+Index: mdadm-4.1-8ubuntu1/systemd/mdcheck_start.timer
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdcheck_start.timer
++++ mdadm-4.1-8ubuntu1/systemd/mdcheck_start.timer
+@@ -10,6 +10,8 @@ Description=MD array scrubbing
+ 
+ [Timer]
+ OnCalendar=Sun *-*-1..7 1:00:00
++RandomizedDelaySec=24h
++Persistent=true
+ 
+ [Install]
+ WantedBy= mdmonitor.service
+Index: mdadm-4.1-8ubuntu1/systemd/mdmonitor-oneshot.service
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdmonitor-oneshot.service
++++ mdadm-4.1-8ubuntu1/systemd/mdmonitor-oneshot.service
+@@ -10,7 +10,4 @@ Description=Reminder for degraded MD arr
+ Documentation=man:mdadm(8)
+ 
+ [Service]
+-Environment=MDADM_MONITOR_ARGS=--scan
+-EnvironmentFile=-/run/sysconfig/mdadm
+-ExecStartPre=-/usr/lib/mdadm/mdadm_env.sh
+-ExecStart=BINDIR/mdadm --monitor --oneshot $MDADM_MONITOR_ARGS
++ExecStart=BINDIR/mdadm --monitor --oneshot --scan
+Index: mdadm-4.1-8ubuntu1/systemd/mdmonitor-oneshot.timer
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdmonitor-oneshot.timer
++++ mdadm-4.1-8ubuntu1/systemd/mdmonitor-oneshot.timer
+@@ -9,7 +9,9 @@
+ Description=Reminder for degraded MD arrays
+ 
+ [Timer]
+-OnCalendar= 2:00:00
++OnCalendar=daily
++RandomizedDelaySec=24h
++Persistent=true
+ 
+ [Install]
+ WantedBy= mdmonitor.service
+Index: mdadm-4.1-8ubuntu1/systemd/mdcheck_continue.service
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdcheck_continue.service
++++ mdadm-4.1-8ubuntu1/systemd/mdcheck_continue.service
+@@ -13,7 +13,5 @@ Documentation=man:mdadm(8)
+ [Service]
+ Type=oneshot
+ Environment=MDADM_CHECK_DURATION='"6 hours"'
+-EnvironmentFile=-/run/sysconfig/mdadm
+-ExecStartPre=-/usr/lib/mdadm/mdadm_env.sh
+ ExecStart=/usr/share/mdadm/mdcheck --continue --duration $MDADM_CHECK_DURATION
+ 
diff -pruN 4.1-8/debian/patches/series 4.1-8ubuntu1/debian/patches/series
--- 4.1-8/debian/patches/series	2020-09-16 10:14:45.000000000 +0000
+++ 4.1-8ubuntu1/debian/patches/series	2020-10-26 12:15:40.000000000 +0000
@@ -25,3 +25,9 @@ strcat-look-for-md-device-in-dev-md.patc
 exit-gracefully-when-md-device-not-found.patch
 lp-1847924-introduce-new-array-state-broken.patch
 test-installed.patch
+randomize-timers.patch
+systemd-honor-debconf-daily-scan.patch
+mdcheck-log-when-done.patch
+mdcheck-when-mdcheck-start-is-enabled-mdcheck-continue-too.patch
+mdcheck-fix-empty-spaces-in-timer-unit-files.patch
+7b99edab2834d5d08ef774b4cff784caaa1a186f.patch
diff -pruN 4.1-8/debian/patches/systemd-honor-debconf-daily-scan.patch 4.1-8ubuntu1/debian/patches/systemd-honor-debconf-daily-scan.patch
--- 4.1-8/debian/patches/systemd-honor-debconf-daily-scan.patch	1970-01-01 00:00:00.000000000 +0000
+++ 4.1-8ubuntu1/debian/patches/systemd-honor-debconf-daily-scan.patch	2020-10-26 12:12:36.000000000 +0000
@@ -0,0 +1,18 @@
+Description: Honor the debconf mdadm/autoscan setting in the systemd timer
+ Debian added an mdadm/autoscan template to allow users to disable this
+ feature via debconf. This is exposed as a variable in /etc/default/mdadm,
+ which is processed by a cronjob in Debian. Ubuntu has dropped the cronjob
+ and moved to a systemd timer, so we need to add our own processing.
+Author: dann frazier <dannf@ubuntu.com>
+
+Index: mdadm-4.1-8ubuntu1/systemd/mdmonitor-oneshot.service
+===================================================================
+--- mdadm-4.1-8ubuntu1.orig/systemd/mdmonitor-oneshot.service
++++ mdadm-4.1-8ubuntu1/systemd/mdmonitor-oneshot.service
+@@ -10,4 +10,5 @@ Description=Reminder for degraded MD arr
+ Documentation=man:mdadm(8)
+ 
+ [Service]
+-ExecStart=BINDIR/mdadm --monitor --oneshot --scan
++EnvironmentFile=-/etc/default/mdadm
++ExecStart=sh -c '[ "$AUTOSCAN" != "true" ] || BINDIR/mdadm --monitor --oneshot --scan'
diff -pruN 4.1-8/debian/rules 4.1-8ubuntu1/debian/rules
--- 4.1-8/debian/rules	2020-09-13 23:12:12.000000000 +0000
+++ 4.1-8ubuntu1/debian/rules	2020-10-13 21:44:00.000000000 +0000
@@ -60,6 +60,8 @@ install-arch: build-arch
 		$(DESTDIR)/usr/share/initramfs-tools/scripts/local-bottom/mdadm
 	install -Dm0644 debian/mdadm.modules \
 		$(DESTDIR)/etc/modprobe.d/mdadm.conf
+	install -Dm0755 debian/mdadm.finalrd \
+		$(DESTDIR)/usr/share/finalrd/mdadm.finalrd
 
 	install -Dm0755 debian/mkconf $(DESTDIR)/usr/share/mdadm/mkconf
 	install -Dm0755 debian/checkarray $(DESTDIR)/usr/share/mdadm/checkarray
@@ -68,10 +70,11 @@ install-arch: build-arch
 	install -Dm0755 udeb/mdadm $(DESTDIR_UDEB)/sbin/mdadm
 	install -Dm0755 udeb/mdmon $(DESTDIR_UDEB)/sbin/mdmon
 	install -Dm0644 $(DESTDIR)/lib/udev/rules.d/63-md-raid-arrays.rules $(DESTDIR_UDEB)/lib/udev/rules.d/63-md-raid-arrays.rules
-	install -Dm0644 debian/mdadm-shutdown.service $(DESTDIR)/lib/systemd/system/mdadm-shutdown.service
 ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes), yes)
 	install -Dm0644 $(DESTDIR)/lib/udev/rules.d/64-md-raid-assembly.rules $(DESTDIR_UDEB)/lib/udev/rules.d/64-md-raid-assembly.rules
 	install -Dm0644 debian/source_mdadm.py $(DESTDIR)/usr/share/apport/package-hooks/source_mdadm.py
+else
+	install -Dm0644 debian/mdadm-shutdown.service $(DESTDIR)/lib/systemd/system/mdadm-shutdown.service
 endif
 
 binary-arch: install-arch
@@ -80,12 +83,9 @@ binary-arch: install-arch
 	dh_installdebconf
 	dh_installdocs
 	dh_installexamples -pmdadm mdadm.conf-example misc/syslog-events
-	dh_installinit --init-script=mdadm-waitidle --no-start -- stop 98 0 6 .
-	dh_link -pmdadm /dev/null /lib/systemd/system/mdadm-waitidle.service
-	dh_installinit -- defaults 25
-	dh_link -pmdadm /dev/null /lib/systemd/system/mdadm.service
 	dh_installman
 	dh_installcron
+	dh_installsystemd -pmdadm mdcheck_continue.timer mdcheck_start.timer mdmonitor-oneshot.timer
 	dh_installchangelogs ChangeLog
 	dh_installlogcheck
 	dh_link
