140 lines
2.8 KiB
Bash

#!/bin/bash
# sudo mdadm -S /dev/md0
function print(){
#izpisemo diske z lsblk
lsblk
}
function create(){
if [ ! "$2" ] || [ ! "$3" ]; then
echo "Use: $1 <disk> <file-system-type>"
exit 1
fi
#dodamo label gpt drivu
parted -s $2 mklabel gpt
#ustvarimo particijo 50% velikosti
parted -s "$2" mkpart primary 1 50%
#ustvarimo particijo 50% velikosti
parted -s "$2" mkpart primary 50% -- -1
#ustvarimo datotecni sistem
echo -e "y\n" | mkfs.$3 ${2}1
#ustvarimo datotecni sistem
echo -e "y\n" | mkfs.$3 ${2}2
}
function fs(){
if [ ! "$2" ] || [ ! "$3" ]; then
echo "Use: $1 <disk> <file-system-type>"
exit 1
fi
#dodamo filesistem
echo -e "y\n" | mkfs.$3 "$2"
}
function attach(){
if [ ! "$2" ] || [ ! "$3" ]; then
echo "Use: $1 <partition> <mount point>"
exit 1
fi
#priklopimo $2 particijo v $3 mount point
mount $2 $3
}
function update(){
if [ ! "$2" ]; then
echo "Use: $1 <partiton>"
exit 1
fi
#dodamo razsiritve ext4
tune2fs -O extents,uninit_bg,huge_file $2
#preverimo zbircni sistem
e2fsck -f $2
#dodamo recicle bin
tune2fs -j $2
}
function createRaid(){
if [ ! "$2" ] || [ ! "$3" ]; then
echo "Use: $1 <partition 1> <partition 2>"
exit 1
fi
#ustvari particjo z labelo msdos in dovolimo raid
parted -s $2 mklabel msdos
parted -s $2 mkpart primary 1 -- -1
parted -s $2 set 1 raid on
parted -s $3 mklabel msdos
parted -s $3 mkpart primary 1 -- -1
parted -s $3 set 1 raid on
#ustvarimo radi z imenom md0 in dodamo 2 diska v raid
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 ${2}1 ${3}1
}
function hotSpare(){
if [ ! "$2" ]; then
echo "Use: $1 <partiton>"
exit 1
fi
parted -s $2 mklabel msdos
parted -s $2 mkpart primary 1 -- -1
parted -s $2 set 1 raid on
#dodamo spare disk v raid
mdadm --manage /dev/md0 --add-spare ${2}1
}
function printRaid(){
#izpisemo detaile o raidu md0
mdadm --detail /dev/md0
}
function failure(){
if [ ! "$2" ]; then
echo "Use: $1 <partiton>"
exit 1
fi
#failamo particijo v raidu
mdadm --manage /dev/md0 --fail $2
}
function remove(){
if [ ! "$2" ]; then
echo "Use: $1 <partiton>"
exit 1
fi
#odstranimo disk iz raida
mdadm --manage /dev/md0 --remove $2
}
if [[ $EUID -ne 0 ]]; then
echo "Must be root"
exit 1
fi
case $1 in
-izpis) print ;;
-ustvari) create "$@" ;;
-filesistem) fs "$@" ;;
-priklopi) attach "$@" ;;
-posodobi) update "$@" ;;
-ustvariraid) createRaid "$@" ;;
-hotspare) hotSpare "$@" ;;
-izpisraid) printRaid "$@" ;;
-izpad) failure "$@" ;;
-odstrani) remove "$@" ;;
esac