Created
January 31, 2024 11:57
-
-
Save JonasGao/e41c45470c23b40ae656dbe14c289c23 to your computer and use it in GitHub Desktop.
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 | |
[ -z "$1" ] && echo "Please provide DEV" && exit 1 | |
[ -z "$2" ] && echo "Please provide MTN" && exit 2 | |
DEV=$1 | |
MNT=$2 | |
PAR="${DEV}1" | |
printf """Partition~ | |
Will: | |
Init disk: \"$DEV\" | |
Create partition: \"$PAR\" | |
Mount it to: \"$MNT\" | |
Format: \"ext4\" | |
""" | |
read -p "Continue? " -n 1 -r | |
echo | |
if [ "$REPLY" != "y" ] | |
then | |
echo "Abort~" | |
exit 0 | |
fi | |
echo "Partition..." | |
( | |
echo n # Add a new partition | |
echo p # Primary partition | |
echo 1 # Partition number | |
echo # First sector (Accept default: 1) | |
echo # Last sector (Accept default: varies) | |
echo w # Write changes | |
) | fdisk "$DEV" | |
echo "Formating..." | |
mkfs.ext4 "$PAR" | |
echo "Mounting..." | |
mkdir -p "$MNT" | |
mount "$PAR" "$MNT" | |
echo "Finish" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment