-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraid1-raid0-install.sh
117 lines (92 loc) · 4.19 KB
/
raid1-raid0-install.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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
##########################################################
# # #
# Organization: Edgevana #
# #
# Purpose: Migrate RAID1 installations to RAID0 #
# for Solana validator nodes. #
# #
# DISCLAIMER: #
# This script is provided "AS IS" without warranty of #
# any kind. Use at your own risk. The author or #
# Edgevana are not responsible for any data loss or #
# damage that may occur through the use of this script. #
# Users are advised to understand and verify the #
# commands being executed. #
# #
# INSTRUCTIONS: #
# This script is intended to be run in recovery mode #
# on Vultr servers. Before running, ensure that your #
# data is backed up and the server is in recovery mode. #
# Follow the steps provided by Vultr to enter recovery #
# mode, then execute this script. #
# #
# For support or queries, contact: #
# #
##########################################################
# Speed up all raid operations within the recovery ISO so things dont take as long
echo 5000000 > /proc/sys/dev/raid/speed_limit_max
# Checks if there is any raid syncing,recoverying, or reshaping
hold_until_raid_in_sync() {
echo "Checking if raid is in sync..."
# Loop indefinitely until the RAID is in sync
while true; do
# Extract the current status of the RAID
local status=$(cat /proc/mdstat)
# Check for the presence of 'recovery' or 'resync'
if echo "$status" | grep -E 'recovery|resync|reshape'; then
# If the RAID is resyncing, print the status and sleep for a bit
echo "$status"
echo "RAID is resyncing. Waiting..."
sleep 5 # wait for 30 seconds before checking again
else
# If there's no 'recovery' or 'resync', the RAID should be in sync
if echo "$status" | grep -q 'active\|clean'; then
echo "RAID is in sync. Proceeding..."
break # exit the loop
else
echo "RAID status is unknown. Please check manually."
exit 2 # exit with an error code
fi
fi
done
# Notify that the RAID is now in sync
echo "The RAID is now in sync. You can continue with other operations."
}
# Checking to make sure in sync before we start
hold_until_raid_in_sync
# We stop it here because its in read-only mode
mdadm --stop /dev/md127
# Putting it back together now to get out of read only mode
mdadm -A -s
# Making sure its still in sync
hold_until_raid_in_sync
# Going to fail a disk and then remove it in prep to turn into raid0
mdadm --manage /dev/md127 --fail /dev/sdb2
mdadm --manage /dev/md127 --remove /dev/sdb2
# We check the filesystem to make sure its good to go
e2fsck -fy /dev/md127
# Resize filesystem to make sure we can fit it all on a new disk with a dd command, also makes this a quicker process
resize2fs /dev/md127 50G
# Wipes the second disk for a raid0
wipefs -a /dev/sdb2
# Create the raid0
mdadm --create --verbose /dev/md0 --level=0 --raid-devices=1 /dev/sdb2 --force
# We copy over the existing installation.
dd if=/dev/md127 of=/dev/md0 bs=1G count=55 status=progress
# Stopping the raid1, no longer needed
mdadm --stop /dev/md127
# Wipe it
wipefs -a /dev/sda2
# Add it to the raid0, this will take a while. It will also turn into a raid4 which is normal for this expansion process
mdadm --grow /dev/md0 --level=0 --raid-devices=2 --add /dev/sda2
# Wait untill this raid0 creation is fully done
hold_until_raid_in_sync
# We check the filesystem to make sure its good to go
e2fsck -fy /dev/md0
# Make the filesystem max size
resize2fs /dev/md0
# Reboot
echo "System is ready for a reboot. RAID-0 has been created."
echo "Run 'reboot'"