Red Hat/CentOS hard disk partitioning,formatting & updating fstab with UUID
I came to a situation where I need to partitioning, formatting & updating fstab with UUID of 25 servers each having 26 disks in total. If i am doing it manually, it will take ages to complete.
Here is a script which has FOR loop, ARRAY, COUNTER…etc below are the major tasks
- read disk names
- create mount points
- creating the partition using fdisk (noninteractive way)
- formatting with XFS
- getting UUID and update in fstab
- setting block reservation to 0
#!/bin/bash echo “________HDD__________” IFS=$’\n’ read -d ” -ra DiskName < <(fdisk -l | grep 800 | egrep -v “GPT|WARNING” | awk ‘{print $2}’ | sed ‘s/://g’) for i in “${!DiskName[@]}”;do COUNTER=$(expr $COUNTER + 1) doneIFS=$’\n’ read -d ” -ra ForDiskName < <(fdisk -l | grep 4000 | egrep -v “GPT|WARNING” | awk ‘{print $2}’ | sed ‘s/://g’) ForCOUNTER=$(expr $ForCOUNTER + 1) done |
NOTE: copy-paste may add some extra Characters, I Am Not an expert in scripting 🙂