title: systemd: unlock LUKS encrypted mdadm raid on boot
body: <p>I set up a RAID using this guide: <a href="https://wiki.debian.org/SoftwareRAID" rel="nofollow noreferrer">https://wiki.debian.org/SoftwareRAID</a> on a minimal Stretch install.
  After that, I <code>cryptsetup luksFormat</code>'ed <code>/dev/md0</code> (without using LVM).</p>
  
  <p>The problem is that the encrypted partition isn't unlocked automatically.</p>
  
  <p>My <code>/etc/crypttab</code> looks like this:</p>
  
  <pre><code>sda2_crypt UUID=ROOTUUID /dev/disk/by-label/USBLABEL:/root.key luks,keyscript=/lib/cryptsetup/scripts/passdev
  raid       UUID=RAIDUUID /dev/disk/by-label/USBLABEL:/raid.key luks,keyscript=/lib/cryptsetup/scripts/passdev
  </code></pre>
  
  <p>This loads the key from a USB drive during boot and unlocks the LUKS partition.
  It works fine for <code>sda2_crypt</code> (the rootfs), but not for the raid.</p>
  
  <p>My guess is that mdadm isn't loaded at this point and thus the RAID device doesn't exist. When the machine is booted <code>cryptdisks_start raid</code> works just fine.
  I think the relevant part of the logs is this:</p>
  
  <pre><code>/var/log/syslog:Aug 22 15:09:54 nas systemd[1]: Dependency failed for Cryptography Setup for raid.
  /var/log/syslog:Aug 22 15:09:54 nas systemd[1]: Dependency failed for dev-mapper-raid.device.
  /var/log/syslog:Aug 22 15:09:54 nas systemd[1]: dev-mapper-raid.device: Job dev-mapper-raid.device/start failed with result 'dependency'.
  /var/log/syslog:Aug 22 15:09:54 nas systemd[1]: systemd-cryptsetup@raid.service: Job systemd-cryptsetup@raid.service/start failed with result 'dependency'.
  /var/log/syslog:Aug 22 15:13:31 nas systemd[1]: Dependency failed for Cryptography Setup for raid.
  /var/log/syslog:Aug 22 15:13:31 nas systemd[1]: systemd-cryptsetup@raid.service: Job systemd-cryptsetup@raid.service/start failed with result 'dependency'.
  </code></pre>
  
  <p>I've tried to force <code>cryptsetup.target</code> to wait for <code>systemd-cryptsetup@raid.service</code> but that didn't work.</p>
  
  <p>This is my first time with systemd and I could really use some help :) Thanks!</p>