#!/bin/bash HDD="/dev/sda" DATA="${HDD}2" SWAP="${HDD}1" DATAMOUNT="/data" PART_TABLE="/root/ClusterPartitions.sfdisk" HDD_WHIPE_KEYWORD="KillHDD" # First, we check the kernel command line to make sure we want to mangle the HDDs: dmesg | grep -q "^Kernel command line.*${HDD_WHIPE_KEYWORD}" if [ $? != 0 ] then echo "Quitting HDD whipe procedure since ${HDD_WHIPE_KEYWORD} is not in kernel command line" exit 2 fi # check to see if the disk exists if [ -b $HDD ] then mount ${DATA} ${DATAMOUNT} if [ ! -e /data/$(echo $HOSTNAME) ] then # The HDD is not tagged therefore: # 0- We unmount, just in case there was another FS umount ${DATAMOUNT} # 1- We partition it: sfdisk --force /dev/sda < ${PART_TABLE} # 2- We format the partition we want to use as data mkreiserfs -f -f --label "DATA" -q ${DATA} # 3- We also kept some spare space for eventual use of swap mkswap ${SWAP} # 4- Now we mount the disk mount ${DATA} ${DATAMOUNT} # 5- We tag the disk with the hostname touch /data/$(echo $HOSTNAME) else echo "Found the file tag /data/$(echo $HOSTNAME), not formatting the drive!" fi else echo "The data disk (${HDD}) is missing!" echo "Removing ${DATAMOUNT} so no one fills up the ram (unionfs here)" rmdir ${DATAMOUNT} exit 1 fi #swapon ${SWAP}