-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_raid_array
executable file
·58 lines (52 loc) · 1.57 KB
/
create_raid_array
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -e
err_report() {
echo "Error at $BASH_SOURCE on line $1!"
if [[ -n "$MADE_EF1" && -n "$EFI1" ]]; then
losetup -d "$EFI1"
fi
if [[ -n "$MADE_EF2" && -n "$EFI2" ]]; then
losetup -d "$EFI2"
fi
}
trap 'err_report $LINENO' ERR
if [[ "$EUID" != "0" ]]; then
echo "Must be run as root!"
exit 1
fi
if [[ -e /dev/md0 ]]; then
echo "Error: Called $0, but /dev/md0 already exists!"
exit 1
fi
if [[ ! -f efi1 ]]; then
echo "Error: Called $0, but $(cwd)/efi1 doesn't exist!"
exit 1
fi
if [[ ! -f efi2 ]]; then
echo "Error: Called $0, but $(cwd)/efi2 doesn't exist!"
exit 1
fi
# Get the loops associated to that EFI block
EFI1="$(losetup -a | sed -En "s/(\/dev\/loop[0-9]+):.*\/efi1\)/\1/p")"
EFI2="$(losetup -a | sed -En "s/(\/dev\/loop[0-9]+):.*\/efi2\)/\1/p")"
if [[ -n "$EFI1" || -n "$EFI1" ]]; then
echo "EFI1 or EFI2 found: ($EFI1) ($EFI2)"
exit 1
fi
# Setup EFIs as loops
losetup -f efi1
losetup -f efi2
# Get the loops associated to that EFI block
EFI1="$(losetup -a | sed -En "s/(\/dev\/loop[0-9]+):.*\/efi1\)/\1/p")"
MADE_EF1=true
EFI2="$(losetup -a | sed -En "s/(\/dev\/loop[0-9]+):.*\/efi2\)/\1/p")"
MADE_EF2=true
# Get windows partition name
WIN_PARTITION="$(fdisk -l | grep "Microsoft basic data" | awk '{print $1}')"
if [[ "$(echo "$WIN_PARTITION" | wc -l)" != "1" ]]; then
echo "Could not find a single unique windows partition, found: "
echo "$WIN_PARTITION"
exit 1
fi
# Build a RAID array out of EFI1 / windows partition / EFI2
mdadm --build --verbose /dev/md0 --chunk=512 --level=linear --raid-devices=3 "$EFI1" "$WIN_PARTITION" "$EFI2"