mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-10-10 04:43:10 +02:00
blitz.datadrive.sh format option both ext4 and btrfs (#1711)
This commit is contained in:
@@ -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)
|
||||||
isValid=$(lsblk -o NAME,TYPE | grep disk | grep -c "${hdd}")
|
if [ "$2" = "btrfs" ]; then
|
||||||
|
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,55 +417,74 @@ if [ "$1" = "format" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# wipe all partitions and write fresh GPT
|
if [[ $hdd =~ [0-9] ]]; then
|
||||||
>&2 echo "# Wiping all partitions (sfdisk/wipefs)"
|
ext4IsPartition=1
|
||||||
sudo sfdisk --delete /dev/${hdd}
|
else
|
||||||
sleep 4
|
ext4IsPartition=0
|
||||||
sudo wipefs -a /dev/${hdd}
|
|
||||||
sleep 4
|
|
||||||
partitions=$(lsblk | grep -c "─${hdd}")
|
|
||||||
if [ ${partitions} -gt 0 ]; then
|
|
||||||
>&2 echo "# WARNING: partitions are still not clean - try Quick & Dirty"
|
|
||||||
sudo dd if=/dev/zero of=/dev/${hdd} bs=512 count=1
|
|
||||||
fi
|
fi
|
||||||
partitions=$(lsblk | grep -c "─${hdd}")
|
|
||||||
if [ ${partitions} -gt 0 ]; then
|
wipePartitions=0
|
||||||
>&2 echo "# ERROR: partition cleaning failed"
|
if [ "$2" = "btrfs" ]; then
|
||||||
echo "error='partition cleaning failed'"
|
wipePartitions=1
|
||||||
exit 1
|
fi
|
||||||
|
if [ "$2" = "ext4" ] && [ $ext4IsPartition -eq 0 ]; then
|
||||||
|
wipePartitions=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $wipePartitions -eq 1 ]; then
|
||||||
|
# wipe all partitions and write fresh GPT
|
||||||
|
>&2 echo "# Wiping all partitions (sfdisk/wipefs)"
|
||||||
|
sudo sfdisk --delete /dev/${hdd}
|
||||||
|
sleep 4
|
||||||
|
sudo wipefs -a /dev/${hdd}
|
||||||
|
sleep 4
|
||||||
|
partitions=$(lsblk | grep -c "─${hdd}")
|
||||||
|
if [ ${partitions} -gt 0 ]; then
|
||||||
|
>&2 echo "# WARNING: partitions are still not clean - try Quick & Dirty"
|
||||||
|
sudo dd if=/dev/zero of=/dev/${hdd} bs=512 count=1
|
||||||
|
fi
|
||||||
|
partitions=$(lsblk | grep -c "─${hdd}")
|
||||||
|
if [ ${partitions} -gt 0 ]; then
|
||||||
|
>&2 echo "# ERROR: partition cleaning failed"
|
||||||
|
echo "error='partition cleaning failed'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sudo parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2
|
||||||
|
sleep 2
|
||||||
|
sync
|
||||||
fi
|
fi
|
||||||
sudo parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2
|
|
||||||
sleep 2
|
|
||||||
sync
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
# write new EXT4 partition
|
if [ $ext4IsPartition -eq 0 ]; then
|
||||||
>&2 echo "# Creating the one big partition"
|
# write new EXT4 partition
|
||||||
sudo parted /dev/${hdd} mkpart primary ext4 0% 100% 1>&2
|
>&2 echo "# Creating the one big partition"
|
||||||
sleep 6
|
sudo parted /dev/${hdd} mkpart primary ext4 0% 100% 1>&2
|
||||||
sync
|
sleep 6
|
||||||
# loop until the partion gets available
|
sync
|
||||||
loopdone=0
|
# loop until the partion gets available
|
||||||
loopcount=0
|
loopdone=0
|
||||||
while [ ${loopdone} -eq 0 ]
|
loopcount=0
|
||||||
do
|
while [ ${loopdone} -eq 0 ]
|
||||||
>&2 echo "# waiting until the partion gets available"
|
do
|
||||||
sleep 2
|
>&2 echo "# waiting until the partion gets available"
|
||||||
sync
|
sleep 2
|
||||||
loopdone=$(lsblk -o NAME | grep -c ${hdd}1)
|
sync
|
||||||
loopcount=$(($loopcount +1))
|
loopdone=$(lsblk -o NAME | grep -c ${hdd}1)
|
||||||
if [ ${loopcount} -gt 10 ]; then
|
loopcount=$(($loopcount +1))
|
||||||
>&2 echo "# partion failed"
|
if [ ${loopcount} -gt 10 ]; then
|
||||||
echo "error='partition failed'"
|
>&2 echo "# partion failed"
|
||||||
exit 1
|
echo "error='partition failed'"
|
||||||
fi
|
exit 1
|
||||||
done
|
fi
|
||||||
>&2 echo "# partion available"
|
done
|
||||||
|
>&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"
|
||||||
sudo mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null
|
if [ $ext4IsPartition -eq 0 ]; then
|
||||||
|
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
|
||||||
sudo tune2fs -c 1 /dev/${hdd}1
|
if [ $ext4IsPartition -eq 0 ]; then
|
||||||
|
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
|
||||||
|
Reference in New Issue
Block a user