-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlinux-prep-raid-on-azure.sh
62 lines (45 loc) · 1.91 KB
/
linux-prep-raid-on-azure.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
#!/bin/bash
# Set bash script options
set -o nounset
set -o errexit
# Install mdadm on Ubuntu
apt-get update -y
apt-get install mdadm -y --no-install-recommends
# Install mdadm on Centos
yum -y install mdadm
# Create backup copy of fstab
cp /etc/fstab /etc/fstab.original
# Enumerate data disks attached to VM
# Leverages udev rules for Azure storage devices located at https://github.com/Azure/WALinuxAgent/blob/2.0/config/66-azure-storage.rules
attached=`basename -a $(find /sys/class/block -name 'sd[a-z]')`
reserved=`basename -a $(readlink -f /dev/disk/azure/root /dev/disk/azure/resource)`
datadisks=(${attached[@]/$reserved})
# Set value to be used for filesystem mount point folder
mp='data1'
# Set value to be used for filesystem label - max length 16 chars
fslabel=$(hostname | cut -c1-10)-$mp
# Set value for filesystem barriers - 0 if using Premium Storage w/ ReadOnly Caching or NoCache; 1 otherwise
b=0
# Set value for initial RAID command string used to span multiple data disks
RAID_CMD="mdadm --create /dev/md1 --level 0 --raid-devices ${#datadisks[@]} "
# Loop through each data disk, fdisk and add to RAID command string
for d in "${datadisks[@]}"; do
disk="/dev/${d}"
(echo n; echo p; echo 1; echo ; echo ; echo t; echo fd; echo p; echo w;) | fdisk ${disk}
RAID_CMD+="${disk}1 "
done
# Build RAID device
eval "$RAID_CMD"
# Format and label filesystem
mkfs.ext4 /dev/md1 -L ${fslabel}
# Set value of UUID for new filesystem
uuid=$(blkid -p /dev/md1 | grep -oP '[-a-z0-9]{36}')
# Create mount point folder
mkdir -p /media/${mp}
# Add new filesystem to working copy of fstab
echo "UUID=${uuid} /media/${mp} ext4 defaults,noatime,barrier=${b} 0 0" >> /etc/fstab
# Mount all unmounted filesystems
mount -a
# After initial provisioning, use these commands to obtain disk device or UUID of filesystem based on label
# disk=$(blkid -L ${fslabel})
# uuid=$(blkid | grep "LABEL=\"${fslabel}\"" | grep -oP '[-a-z0-9]{36}')