Last active
September 10, 2020 15:40
-
-
Save guangbochen/63c7053d5819b1946c70d5d475d2dc4a 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 | |
set -e | |
function prepare(){ | |
#precheck | |
echo "Pre-checking..." | |
command -v fdisk >/dev/null 2>&1 || { echo >&2 "fdisk is required but it's not installed. Please install it first."; exit 1; } | |
command -v mkfs.ext4 >/dev/null 2>&1 || { echo >&2 "mkfs.ext4 is required but it's not installed. Please install it first."; exit 1; } | |
command -v mount >/dev/null 2>&1 || { echo >&2 "mount is required but it's not installed. Please install it first."; exit 1; } | |
echo "Pre-checking done" | |
sudo fdisk -l | |
DEFAULT_DATA_PATH=/mydata | |
echo "Please provide new disk name:(e.g. /dev/vdb)" | |
read DISK_NAME | |
echo "Please provide new data volume path to mount:($DEFAULT_DATA_PATH)" | |
read DATA_PATH | |
if [[ -z "$DISK_NAME" ]];then | |
echo "Disk name is required!" | |
exit 1 | |
fi | |
if [[ -z "$DATA_PATH" ]];then | |
DATA_PATH=$DEFAULT_DATA_PATH | |
fi | |
} | |
function mountdisk(){ | |
echo "Mount disk $DISK_NAME to path $DATA_PATH" | |
if [ -d "${DATA_PATH}" ];then | |
echo "${DATA_PATH} already exist, continue.." | |
else | |
echo "Createing new path ${DATA_PATH}" | |
sudo mkdir $DATA_PATH | |
fi | |
sudo fdisk ${DISK_NAME} | |
sudo mkfs.ext4 ${DISK_NAME}1 | |
sudo mount ${DISK_NAME}1 ${DATA_PATH} | |
df -h | |
} | |
prepare | |
mountdisk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment