Last active
March 27, 2019 05:33
-
-
Save mhatreabhay/11dab660e987c57fd0b20f9874afe351 to your computer and use it in GitHub Desktop.
linux managed disk setup
This file contains 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 | |
set -e | |
drive=/dev/sdc1 | |
if [ $(cat /proc/mounts | grep /dev/sdc1 | wc | awk '{print $1}') == 0 ]; then | |
(echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk /dev/sdc | |
sleep 5 | |
mkfs -t ext4 /dev/sdc1 | |
elif [ $(blkid $drive -p -o value -s TYPE) != 'ext4' ]; then | |
(echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk /dev/sdc | |
sleep 5 | |
mkfs -t ext4 /dev/sdc1 | |
fi | |
if [ -d '/datadrive' ]; then | |
echo "/datadrive exists" | |
else | |
mkdir /datadrive | |
fi | |
if [ $(df -h | grep "datadrive"| awk '{print $1}')=='/dev/sdc1' ]; then | |
echo "device is mounted" | |
x1=$(df -h | grep "datadrive"| awk '{print $1}') | |
if [ -z $x1 ]; then | |
mount /dev/sdc1 /datadrive | |
fi | |
else | |
echo "device is not mounted" | |
mount /dev/sdc1 /datadrive | |
fi | |
x1=$(df -h | grep "datadrive"| awk '{print $1}') | |
x2=$(blkid | grep $x1 | awk '{print $2}') | |
if [ $(cat /etc/fstab | grep "${x2//\"}" | wc | awk '{print $1}') -gt 0 ]; then | |
echo "/etc/fstab is already updated" | |
else | |
echo "updating /etc/fstab" | |
printf "%s /datadrive ext4 defaults,nofail 1 2" "${x2//\"}" | tee -a /etc/fstab | |
fi | |
set +e | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment