Created
May 10, 2025 17:11
-
-
Save h0ffy/8cb96cf92d59fc5b23587972cc7824ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# by h0ffy//JennyLab VX! | |
function print_status() { | |
if [[ "${1}" == "1" ]]; then | |
echo -e "[\033[0;32mOK\033[0m]" | |
else | |
echo -e "[\033[0;31mERROR\033[0m]" | |
exit | |
fi | |
} | |
if [[ "$((UID))" != "0" ]]; then | |
echo "[ERROR] Require root privileges" | |
exit 0 | |
fi | |
if [[ "${#}" != "4" ]]; then | |
echo ${#} | |
echo "${0} <dev or partition> <dev or partition> <mount_point>" | |
echo "${0} /dev/sdb /dev/sdc /jenny" | |
echo "${0} /dev/sda4 /dev/sdb /jenny" | |
exit 0 | |
fi | |
if [ ! -d "${4}" ]; then | |
echo "Directory ${4} no exists." | |
printf "Make directory ${4}\t\t\t" | |
mkdir $4 && print_status 1 || print_status 0 | |
fi | |
printf "Create RAID0 in /dev/md0\t\t\t" | |
mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 $1 $2 && print_status 1 || print_status 0 | |
printf "Format RAID0 with optimized XFS\t\t\t" | |
mkfs.xfs -f \ | |
-d su=512k,sw=2 \ | |
-l size=256m,lazy-count=1 \ | |
-i size=512,maxpct=5 \ | |
-n size=4096 \ | |
/dev/md0 && print_status 1 || print_status 0 | |
printf "Save raid to persistence\t\t\t" | |
mdadm --detail --scan >> /etc/mdadm/mdadm.conf && print_status 1 || print_status 0 | |
printf "Upate initram fs\t\t\t" | |
update-initramfs -u && print_status 1 || print_status 0 | |
printf "Test mount ${4}\t\t\t" | |
mount -t xfs -o noatime,nodiratime,logbufs=8,logbsize=256k,allocsize=1m,logbsize=256k,noalign /dev/md0 $4 && print_status 1 || print_status 0 | |
printf "Umount ${4}\t\t\t" | |
umount $4 && print_status 1 || print_status 0 | |
printf "Make fstab...\t\t\t" | |
UUID=`blkid | grep md0 | awk '{print $2}' | awk -F"=" '{print $2}' | sed 's/"//g'` | |
echo "UUID=${UUID} ${4} xfs noatime,nodiratime,logbufs=8,logbsize=256k,allocsize=1m,logbsize=256k,noalign 0 0" | tee -a /etc/fstab 2>&1 1>/dev/null && print_status 1 || print_status 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment