blitz.datadrive.sh format option both ext4 and btrfs (#1711)

This commit is contained in:
arno
2020-11-01 11:46:31 +01:00
committed by rootzoll
parent d437545df1
commit 36401d8775

View File

@@ -357,7 +357,12 @@ if [ "$1" = "format" ]; then
fi fi
# check if device is existing and a disk (not a partition) # check if device is existing and a disk (not a partition)
if [ "$2" = "btrfs" ]; then
isValid=$(lsblk -o NAME,TYPE | grep disk | grep -c "${hdd}") isValid=$(lsblk -o NAME,TYPE | grep disk | grep -c "${hdd}")
else
#TODO: Validate ext4
isValid=1
fi
if [ ${isValid} -eq 0 ]; then if [ ${isValid} -eq 0 ]; then
>&2 echo "# either given device was not found" >&2 echo "# either given device was not found"
>&2 echo "# or is not of type disk - see 'lsblk'" >&2 echo "# or is not of type disk - see 'lsblk'"
@@ -412,6 +417,21 @@ if [ "$1" = "format" ]; then
fi fi
fi fi
if [[ $hdd =~ [0-9] ]]; then
ext4IsPartition=1
else
ext4IsPartition=0
fi
wipePartitions=0
if [ "$2" = "btrfs" ]; then
wipePartitions=1
fi
if [ "$2" = "ext4" ] && [ $ext4IsPartition -eq 0 ]; then
wipePartitions=1
fi
if [ $wipePartitions -eq 1 ]; then
# wipe all partitions and write fresh GPT # wipe all partitions and write fresh GPT
>&2 echo "# Wiping all partitions (sfdisk/wipefs)" >&2 echo "# Wiping all partitions (sfdisk/wipefs)"
sudo sfdisk --delete /dev/${hdd} sudo sfdisk --delete /dev/${hdd}
@@ -432,13 +452,16 @@ if [ "$1" = "format" ]; then
sudo parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2 sudo parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2
sleep 2 sleep 2
sync sync
fi
# formatting old: EXT4 # formatting old: EXT4
if [ "$2" = "ext4" ]; then if [ "$2" = "ext4" ]; then
# prepare temp mount point # prepare temp mount point
sudo mkdir -p /tmp/ext4 1>/dev/null sudo mkdir -p /tmp/ext4 1>/dev/null
if [ $ext4IsPartition -eq 0 ]; then
# write new EXT4 partition # write new EXT4 partition
>&2 echo "# Creating the one big partition" >&2 echo "# Creating the one big partition"
sudo parted /dev/${hdd} mkpart primary ext4 0% 100% 1>&2 sudo parted /dev/${hdd} mkpart primary ext4 0% 100% 1>&2
@@ -461,6 +484,7 @@ if [ "$1" = "format" ]; then
fi fi
done done
>&2 echo "# partion available" >&2 echo "# partion available"
fi
# make sure /mnt/hdd is unmounted before formatting # make sure /mnt/hdd is unmounted before formatting
sudo umount -f /tmp/ext4 2>/dev/null sudo umount -f /tmp/ext4 2>/dev/null
@@ -472,7 +496,11 @@ if [ "$1" = "format" ]; then
fi fi
>&2 echo "# Formatting" >&2 echo "# Formatting"
if [ $ext4IsPartition -eq 0 ]; then
sudo mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null sudo mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null
else
sudo mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd} 1>/dev/null
fi
loopdone=0 loopdone=0
loopcount=0 loopcount=0
while [ ${loopdone} -eq 0 ] while [ ${loopdone} -eq 0 ]
@@ -491,7 +519,11 @@ if [ "$1" = "format" ]; then
# setting fsk check intervall to 1 # setting fsk check intervall to 1
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467567572 # see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467567572
if [ $ext4IsPartition -eq 0 ]; then
sudo tune2fs -c 1 /dev/${hdd}1 sudo tune2fs -c 1 /dev/${hdd}1
else
sudo tune2fs -c 1 /dev/${hdd}
fi
>&2 echo "# OK EXT 4 format done" >&2 echo "# OK EXT 4 format done"
exit 0 exit 0