-
Notifications
You must be signed in to change notification settings - Fork 4
/
raid_startup.sh
31 lines (25 loc) · 1.04 KB
/
raid_startup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# runs on startup after reboot
# -> restarts the raid /dev/mdX (inactive)
# --> decrypts the RAID to /dev/mapper/mdX
# ---> mounts it to /mnt/mdX
# ----> using LUKS key /root/luks.key
raidName="mdX" # mdX
keyfile="/root/luks.key" # /root/luks.key
devPath="/dev/$raidName" # /dev/mdX
mapperPath="/dev/mapper/$raidName" # /dev/mapper/mdX
mntPath="/mnt/$raidName" # /mnt/mdX
# reassemble mdadm array
while [ ! -b /dev/md0 ]; do /sbin/mdadm --assemble --scan --verbose &> /dev/kmsg; sleep 30; done
# luksOpen (decrypt) using /root/luks.key from /dev/mdX (mdadm raid) to /dev/mapper/mdX (decrypted lukspart)
cryptsetup luksOpen "$devPath" --key-file "$keyfile" "$raidName" &> /dev/kmsg
if [ ! -b "$mapperPath" ]; then
echo "[-] ERROR: can't find $mapperPath ... ABORTING raid startup" &> /dev/kmsg;
exit;
fi
# creating /mnt/mdX if not existing
if [ ! -d "$mntPath" ]; then
mkdir "$mntPath"
fi
# mount /dev/mapper/mdX (decrypted LUKS) -> /mnt/mdX
mount -t btrfs "$mapperPath" "$mntPath" &> /dev/kmsg