mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-27 12:06:36 +02:00
More options for datadrive (ext4) (#1297)
This commit is contained in:
@@ -15,7 +15,7 @@ if [ ${#error} -gt 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# temp mount
|
# temp mount
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddCandidate})
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddPartitionCandidate})
|
||||||
if [ ${#error} -gt 0 ]; then
|
if [ ${#error} -gt 0 ]; then
|
||||||
echo "FAIL blitz.datadrive.sh tempmount --> ${error}"
|
echo "FAIL blitz.datadrive.sh tempmount --> ${error}"
|
||||||
echo "Please report issue to the raspiblitz github."
|
echo "Please report issue to the raspiblitz github."
|
||||||
@@ -26,7 +26,8 @@ fi
|
|||||||
echo
|
echo
|
||||||
echo "# --> Linking drives/directories"
|
echo "# --> Linking drives/directories"
|
||||||
echo "# hddCandidate='${hddCandidate}'"
|
echo "# hddCandidate='${hddCandidate}'"
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh link ${hddCandidate})
|
echo "# hddPartitionCandidate='${hddPartitionCandidate}'"
|
||||||
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh link
|
||||||
if [ ${#error} -gt 0 ]; then
|
if [ ${#error} -gt 0 ]; then
|
||||||
echo "FAIL blitz.datadrive.sh link --> ${error}"
|
echo "FAIL blitz.datadrive.sh link --> ${error}"
|
||||||
echo "Please report issue to the raspiblitz github."
|
echo "Please report issue to the raspiblitz github."
|
||||||
@@ -37,7 +38,8 @@ fi
|
|||||||
echo
|
echo
|
||||||
echo "# --> Adding the data drive to OS ..."
|
echo "# --> Adding the data drive to OS ..."
|
||||||
echo "# hddCandidate='${hddCandidate}'"
|
echo "# hddCandidate='${hddCandidate}'"
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh fstab ${hddCandidate})
|
echo "# hddPartitionCandidate='${hddPartitionCandidate}'"
|
||||||
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh fstab ${hddPartitionCandidate})
|
||||||
if [ ${#error} -gt 0 ]; then
|
if [ ${#error} -gt 0 ]; then
|
||||||
echo "FAIL blitz.datadrive.sh fstab --> ${error}"
|
echo "FAIL blitz.datadrive.sh fstab --> ${error}"
|
||||||
echo "Please report issue to the raspiblitz github."
|
echo "Please report issue to the raspiblitz github."
|
||||||
@@ -162,4 +164,4 @@ else
|
|||||||
echo "# HDD empty --> follow further setup"
|
echo "# HDD empty --> follow further setup"
|
||||||
./10setupBlitz.sh
|
./10setupBlitz.sh
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@@ -213,7 +213,7 @@ do
|
|||||||
|
|
||||||
sleep 4
|
sleep 4
|
||||||
echo "" > ./.syncinfo.tmp
|
echo "" > ./.syncinfo.tmp
|
||||||
lsblk -o NAME | grep "^sd" | while read -r detectedDrive ; do
|
lsblk -o NAME | grep "^[s|v]d" | while read -r detectedDrive ; do
|
||||||
isSystemDrive=$(echo "${datadisk}" | grep -c "${detectedDrive}")
|
isSystemDrive=$(echo "${datadisk}" | grep -c "${detectedDrive}")
|
||||||
if [ ${isSystemDrive} -eq 0 ]; then
|
if [ ${isSystemDrive} -eq 0 ]; then
|
||||||
|
|
||||||
@@ -316,4 +316,4 @@ OK NO FORMAT - Please remove decive now.
|
|||||||
echo "starting new sync loop"
|
echo "starting new sync loop"
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
done
|
done
|
||||||
|
@@ -26,46 +26,60 @@ if [ ${configExists} -eq 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if file system was expanded to full capacity and sd card is bigger then 8GB
|
# check if file system was expanded to full capacity and sd card is bigger than 8GB
|
||||||
# see: https://github.com/rootzoll/raspiblitz/issues/936
|
# see: https://github.com/rootzoll/raspiblitz/issues/936
|
||||||
isRaspbian=$(cat /etc/os-release 2>/dev/null | grep -c 'Raspbian')
|
source ${infoFile}
|
||||||
isArmbian=$(cat /etc/os-release 2>/dev/null | grep -c 'Debian')
|
isRaspbian=$(echo $baseimage | grep -c 'raspbian')
|
||||||
if [ ${isRaspbian} -gt 0 ] || [ ${isArmbian} -gt 0 ]; then
|
isArmbian=$(echo $baseimage | grep -c 'armbian')
|
||||||
if [ ${isRaspbian} -gt 0 ]; then
|
resizeRaspbian="/usr/bin/raspi-config"
|
||||||
echo "### RASPBIAN: CHECKING SD CARD SIZE ###" >> ${logFile}
|
resizeArmbian="/usr/lib/armbian/armbian-resize-filesystem"
|
||||||
elif [ ${isArmbian} -gt 0 ]; then
|
|
||||||
echo "### ARMBIAN: CHECKING SD CARD SIZE ###" >> ${logFile}
|
minimumSize=8192000
|
||||||
fi
|
minimumSizeGB=$((minimumSize/1000/1000))
|
||||||
sudo sed -i "s/^message=.*/message='Checking SD Card'/g" ${infoFile}
|
|
||||||
byteSizeSdCard=$(df --output=size,source | grep "/dev/root" | tr -cd "[0-9]")
|
rootPartition=$(sudo mount|grep " / "|awk '{print $1}')
|
||||||
echo "Size in Bytes is: ${byteSizeSdCard}" >> ${logFile}
|
rootPartitionLength=${#rootPartition}
|
||||||
if [ ${byteSizeSdCard} -lt 8192000 ]; then
|
rootDisk=${rootPartition:5:rootPartitionLength-6}
|
||||||
echo "SD Card filesystem is smaller then 8GB." >> ${logFile}
|
rootDiskSize=$(sudo fdisk -l|grep "Disk"|grep $rootDisk|awk '{print $5}')
|
||||||
if [ ${fsexpanded} -eq 1 ]; then
|
|
||||||
echo "There was already an attempt to expand the fs, but still not bigger then 8GB." >> ${logFile}
|
if [ ${#rootDisk} -gt 0 ]; then
|
||||||
echo "SD card seems to small - at least a 16GB card is needed. Display on LCD to user." >> ${logFile}
|
echo "### CHECKING ROOT DISK SIZE ###" >> ${logFile}
|
||||||
sudo sed -i "s/^state=.*/state=sdtoosmall/g" ${infoFile}
|
sudo sed -i "s/^message=.*/message='Checking Disk size'/g" ${infoFile}
|
||||||
sudo sed -i "s/^message=.*/message='Min 16GB SD card needed'/g" ${infoFile}
|
echo "Size in Bytes is: ${rootDiskSize} ($rootDisk)" >> ${logFile}
|
||||||
exit 1
|
if [ $rootDiskSize -lt $minimumSize ]; then
|
||||||
else
|
echo "Disk filesystem is smaller than ${minimumSizeGB}GB." >> ${logFile}
|
||||||
echo "Try to expand SD card FS, display info and reboot." >> ${logFile}
|
if [ ${fsexpanded} -eq 1 ]; then
|
||||||
sudo sed -i "s/^state=.*/state=reboot/g" ${infoFile}
|
echo "There was already an attempt to expand the fs, but still not bigger than 8GB." >> ${logFile}
|
||||||
sudo sed -i "s/^message=.*/message='Expanding SD Card'/g" ${infoFile}
|
echo "SD card seems to small - at least a 16GB disk is needed. Display on LCD to user." >> ${logFile}
|
||||||
sudo sed -i "s/^fsexpanded=.*/fsexpanded=1/g" ${infoFile}
|
sudo sed -i "s/^state=.*/state=sdtoosmall/g" ${infoFile}
|
||||||
if [ ${isRaspbian} -gt 0 ]; then
|
sudo sed -i "s/^message=.*/message='Min 16GB SD card needed'/g" ${infoFile}
|
||||||
sudo raspi-config --expand-rootfs
|
exit 1
|
||||||
elif [ ${isArmbian} -gt 0 ]; then
|
else
|
||||||
sudo /usr/lib/armbian/armbian-resize-filesystem start
|
echo "Try to expand SD card FS, display info and reboot." >> ${logFile}
|
||||||
|
sudo sed -i "s/^state=.*/state=reboot/g" ${infoFile}
|
||||||
|
sudo sed -i "s/^message=.*/message='Expanding SD Card'/g" ${infoFile}
|
||||||
|
sudo sed -i "s/^fsexpanded=.*/fsexpanded=1/g" ${infoFile}
|
||||||
|
if [ "${cpu}" == "x86_64" ]; then
|
||||||
|
echo "Please expand disk size." >> ${logFile}
|
||||||
|
# TODO: Expand disk size on x86_64
|
||||||
|
elif [ ${isRaspbian} -gt 0 ]; then
|
||||||
|
if [ -x ${resizeRaspbian} ]; then
|
||||||
|
$(sudo $resizeRaspbian --expand-rootfs)
|
||||||
|
fi
|
||||||
|
elif [ ${isArmbian} -gt 0 ]; then
|
||||||
|
if [ -x ${resizeArmbian} ]; then
|
||||||
|
$(sudo $resizeArmbian start)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sleep 6
|
||||||
|
sudo shutdown -r now
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
sleep 6
|
else
|
||||||
sudo shutdown -r now
|
echo "Size looks good. Bigger than ${minimumSizeGB}GB disk is used." >> ${logFile}
|
||||||
exit 0
|
fi
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "Size looks good. Bigger than 8GB card is used." >> ${logFile}
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "Baseimage is not raspbian (${isRaspbian}), skipping the sd card size check." >> ${logFile}
|
echo "Disk of root partition ('$rootDisk') not detected, skipping the size check." >> ${logFile}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# import config values
|
# import config values
|
||||||
@@ -552,7 +566,8 @@ echo "Prepare fstab for permanent data drive mounting .." >> ${logFile}
|
|||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
||||||
# update /etc/fstab
|
# update /etc/fstab
|
||||||
echo "datadisk --> ${datadisk}" >> ${logFile}
|
echo "datadisk --> ${datadisk}" >> ${logFile}
|
||||||
sudo /home/admin/config.scripts/blitz.datadrive.sh fstab ${datadisk} >> ${logFile}
|
echo "datapartition --> ${datapartition}" >> ${logFile}
|
||||||
|
sudo /home/admin/config.scripts/blitz.datadrive.sh fstab ${datapartition} >> ${logFile}
|
||||||
|
|
||||||
echo "DONE - Give raspi some cool off time after hard building .... 5 secs sleep" >> ${logFile}
|
echo "DONE - Give raspi some cool off time after hard building .... 5 secs sleep" >> ${logFile}
|
||||||
sleep 5
|
sleep 5
|
||||||
|
@@ -242,6 +242,7 @@ if [ ${afterSetupScriptExists} -eq 1 ]; then
|
|||||||
sudo rm /home/admin/setup.sh
|
sudo rm /home/admin/setup.sh
|
||||||
# reboot again
|
# reboot again
|
||||||
echo "DONE wait 6 secs ... one more reboot needed ... "
|
echo "DONE wait 6 secs ... one more reboot needed ... "
|
||||||
|
|
||||||
sudo shutdown -r now
|
sudo shutdown -r now
|
||||||
sleep 100
|
sleep 100
|
||||||
fi
|
fi
|
||||||
@@ -296,13 +297,19 @@ fi
|
|||||||
# HDD CHECK & PRE-INIT
|
# HDD CHECK & PRE-INIT
|
||||||
################################
|
################################
|
||||||
|
|
||||||
|
# Without LCD message needs to be printed
|
||||||
# wait loop until HDD is connected
|
# wait loop until HDD is connected
|
||||||
|
echo ""
|
||||||
until [ ${isMounted} -eq 1 ] || [ ${#hddCandidate} -gt 0 ]
|
until [ ${isMounted} -eq 1 ] || [ ${#hddCandidate} -gt 0 ]
|
||||||
do
|
do
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
||||||
|
echo "isMounted: $isMounted" >> $logFile
|
||||||
|
echo "hddCandidate: $hddCandidate" >> $logFile
|
||||||
|
message="Connect the Hard Drive"
|
||||||
|
echo $message
|
||||||
if [ ${isMounted} -eq 0 ] && [ ${#hddCandidate} -eq 0 ]; then
|
if [ ${isMounted} -eq 0 ] && [ ${#hddCandidate} -eq 0 ]; then
|
||||||
sed -i "s/^state=.*/state=noHDD/g" ${infoFile}
|
sed -i "s/^state=.*/state=noHDD/g" ${infoFile}
|
||||||
sed -i "s/^message=.*/message='Connect the Hard Drive'/g" ${infoFile}
|
sed -i "s/^message=.*/message='$message'/g" ${infoFile}
|
||||||
fi
|
fi
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
@@ -313,6 +320,7 @@ sed -i "s/^message=.*/message='please wait'/g" ${infoFile}
|
|||||||
|
|
||||||
# get fresh info about data drive to continue
|
# get fresh info about data drive to continue
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
||||||
|
echo "isMounted: $isMounted" >> $logFile
|
||||||
|
|
||||||
# check if the HDD is auto-mounted ( auto-mounted = setup-done)
|
# check if the HDD is auto-mounted ( auto-mounted = setup-done)
|
||||||
if [ ${isMounted} -eq 0 ]; then
|
if [ ${isMounted} -eq 0 ]; then
|
||||||
@@ -336,8 +344,8 @@ if [ ${isMounted} -eq 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# temp mount the HDD
|
# temp mount the HDD
|
||||||
echo "Temp mounting data drive" >> $logFile
|
echo "Temp mounting data drive ($hddCandidate)" >> $logFile
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddCandidate})
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddPartitionCandidate})
|
||||||
if [ ${#error} -gt 0 ]; then
|
if [ ${#error} -gt 0 ]; then
|
||||||
echo "Failed to tempmount the HDD .. awaiting user setup." >> $logFile
|
echo "Failed to tempmount the HDD .. awaiting user setup." >> $logFile
|
||||||
sed -i "s/^state=.*/state=waitsetup/g" ${infoFile}
|
sed -i "s/^state=.*/state=waitsetup/g" ${infoFile}
|
||||||
@@ -413,6 +421,7 @@ if [ ${isMounted} -eq 0 ]; then
|
|||||||
cp $logFile /home/admin/raspiblitz.recover.log
|
cp $logFile /home/admin/raspiblitz.recover.log
|
||||||
echo "shutdown in 1min" >> $logFile
|
echo "shutdown in 1min" >> $logFile
|
||||||
sync
|
sync
|
||||||
|
|
||||||
sudo shutdown -r -F +1
|
sudo shutdown -r -F +1
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
|
@@ -49,7 +49,7 @@ fi
|
|||||||
isMounted=$(sudo df | grep -c /mnt/hdd)
|
isMounted=$(sudo df | grep -c /mnt/hdd)
|
||||||
isBTRFS=$(sudo btrfs filesystem show 2>/dev/null| grep -c 'BLITZSTORAGE')
|
isBTRFS=$(sudo btrfs filesystem show 2>/dev/null| grep -c 'BLITZSTORAGE')
|
||||||
isRaid=$(btrfs filesystem df /mnt/hdd 2>/dev/null | grep -c "Data, RAID1")
|
isRaid=$(btrfs filesystem df /mnt/hdd 2>/dev/null | grep -c "Data, RAID1")
|
||||||
isSSD=$(sudo cat /sys/block/sda/queue/rotational 2>/dev/null | grep -c 0)
|
isSSD="Unknown"
|
||||||
|
|
||||||
# determine if swap is external on or not
|
# determine if swap is external on or not
|
||||||
externalSwapPath="/mnt/hdd/swapfile"
|
externalSwapPath="/mnt/hdd/swapfile"
|
||||||
@@ -70,7 +70,6 @@ if [ "$1" = "status" ]; then
|
|||||||
echo "# BASICS"
|
echo "# BASICS"
|
||||||
echo "isMounted=${isMounted}"
|
echo "isMounted=${isMounted}"
|
||||||
echo "isBTRFS=${isBTRFS}"
|
echo "isBTRFS=${isBTRFS}"
|
||||||
echo "isSSD=${isSSD}"
|
|
||||||
|
|
||||||
# if HDD is not mounted system is in the pre-setup phase
|
# if HDD is not mounted system is in the pre-setup phase
|
||||||
# deliver all the detailes needed about the data drive
|
# deliver all the detailes needed about the data drive
|
||||||
@@ -79,33 +78,38 @@ if [ "$1" = "status" ]; then
|
|||||||
echo
|
echo
|
||||||
echo "# SETUP INFO"
|
echo "# SETUP INFO"
|
||||||
|
|
||||||
# find the HDD (biggest single device)
|
# find the HDD (biggest single partition)
|
||||||
size=0
|
sizeDataPartition=0
|
||||||
lsblk -o NAME | grep "^sd" | while read -r usbdevice ; do
|
lsblk -o NAME,SIZE -b | grep "[^|*][s|v]d[a-z][0-9]" > .lsblk.tmp
|
||||||
testsize=$(lsblk -o NAME,SIZE -b | grep "^${usbdevice}" | awk '$1=$1' | cut -d " " -f 2)
|
while read line; do
|
||||||
if [ ${testsize} -gt ${size} ]; then
|
testdevice=$(echo $line | cut -d " " -f 1)
|
||||||
size=${testsize}
|
testsize=$(echo $line | cut -d " " -f 2)
|
||||||
echo "${usbdevice}" > .hdd.tmp
|
if [ ${testsize} -gt ${sizeDataPartition} ]; then
|
||||||
|
sizeDataPartition=${testsize}
|
||||||
|
hddDataPartition="${testdevice:2:4}"
|
||||||
|
hdd="${hddDataPartition:0:3}"
|
||||||
fi
|
fi
|
||||||
done
|
done < .lsblk.tmp
|
||||||
hdd=$(cat .hdd.tmp 2>/dev/null)
|
rm -f .lsblk.tmp 1>/dev/null 2>/dev/null
|
||||||
rm -f .hdd.tmp 1>/dev/null 2>/dev/null
|
isSSD=$(sudo cat /sys/block/${hdd}/queue/rotational 2>/dev/null | grep -c 0)
|
||||||
|
|
||||||
echo "hddCandidate='${hdd}'"
|
echo "hddCandidate='${hdd}'"
|
||||||
|
echo "hddPartitionCandidate='${hddDataPartition}'"
|
||||||
|
echo "isSSD=${isSSD}"
|
||||||
|
|
||||||
if [ ${#hdd} -gt 0 ]; then
|
if [ ${#hddDataPartition} -gt 0 ]; then
|
||||||
|
|
||||||
# check size in bytes and GBs
|
# check partition size in bytes and GBs
|
||||||
size=$(lsblk -o NAME,SIZE -b | grep "^${hdd}" | awk '$1=$1' | cut -d " " -f 2)
|
echo "hddDataPartitionBytes=${sizeDataPartition}"
|
||||||
echo "hddBytes=${size}"
|
hddDataPartitionGigaBytes=$(echo "scale=0; ${sizeDataPartition}/1024/1024/1024" | bc -l)
|
||||||
hddGigaBytes=$(echo "scale=0; ${size}/1024/1024/1024" | bc -l)
|
echo "hddGigaBytes=${hddDataPartitionGigaBytes}"
|
||||||
echo "hddGigaBytes=${hddGigaBytes}"
|
|
||||||
|
|
||||||
# check if single drive with that size
|
# check if single drive with that size
|
||||||
hddCount=$(lsblk -o NAME,SIZE -b | grep "^sd" | grep -c ${size})
|
hddCount=$(lsblk -o NAME,SIZE -b | grep -c ${hddDataPartition})
|
||||||
echo "hddCount=${hddCount}"
|
echo "hddCount=${hddCount}"
|
||||||
|
|
||||||
# check format of devices first partition
|
# check format of devices partition
|
||||||
hddFormat=$(lsblk -o FSTYPE,NAME,TYPE | grep part | grep "${hdd}1" | cut -d " " -f 1)
|
hddFormat=$(lsblk -o FSTYPE,NAME,TYPE | grep part | grep "${hddDataPartition}" | cut -d " " -f 1)
|
||||||
echo "hddFormat='${hddFormat}'"
|
echo "hddFormat='${hddFormat}'"
|
||||||
|
|
||||||
# if 'ext4' or 'btrfs' then temp mount and investigate content
|
# if 'ext4' or 'btrfs' then temp mount and investigate content
|
||||||
@@ -121,19 +125,21 @@ if [ "$1" = "status" ]; then
|
|||||||
mountError=""
|
mountError=""
|
||||||
sudo mkdir -p /mnt/hdd
|
sudo mkdir -p /mnt/hdd
|
||||||
if [ "${hddFormat}" = "ext4" ]; then
|
if [ "${hddFormat}" = "ext4" ]; then
|
||||||
mountError=$(sudo mount /dev/${hdd}1 /mnt/hdd 2>&1)
|
hddDataPartitionExt4=$hddDataPartition
|
||||||
|
mountError=$(sudo mount /dev/${hddDataPartitionExt4} /mnt/hdd 2>&1)
|
||||||
|
isTempMounted=$(df | grep /mnt/hdd | grep -c ${hddDataPartitionExt4})
|
||||||
fi
|
fi
|
||||||
if [ "${hddFormat}" = "btrfs" ]; then
|
if [ "${hddFormat}" = "btrfs" ]; then
|
||||||
mountError=$(sudo mount -o degraded /dev/${hdd}1 /mnt/hdd 2>&1)
|
mountError=$(sudo mount -o degraded /dev/${hdd}1 /mnt/hdd 2>&1)
|
||||||
|
isTempMounted=$(df | grep /mnt/hdd | grep -c ${hdd})
|
||||||
fi
|
fi
|
||||||
isTempMounted=$(df | grep /mnt/hdd | grep -c ${hdd})
|
|
||||||
|
|
||||||
# check for mount error
|
# check for mount error
|
||||||
if [ ${#mountError} -gt 0 ] || [ ${isTempMounted} -eq 0 ]; then
|
if [ ${#mountError} -gt 0 ] || [ ${isTempMounted} -eq 0 ]; then
|
||||||
echo "hddError='data mount failed'"
|
echo "hddError='data mount failed'"
|
||||||
|
|
||||||
# check for recoverable RaspiBlitz data (if config file exists) and raid
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
# check for recoverable RaspiBlitz data (if config file exists) and raid
|
||||||
hddRaspiData=$(sudo ls -l /mnt/hdd${subVolumeDir} | grep -c raspiblitz.conf)
|
hddRaspiData=$(sudo ls -l /mnt/hdd${subVolumeDir} | grep -c raspiblitz.conf)
|
||||||
isRaid=$(btrfs filesystem df /mnt/hdd 2>/dev/null | grep -c "Data, RAID1")
|
isRaid=$(btrfs filesystem df /mnt/hdd 2>/dev/null | grep -c "Data, RAID1")
|
||||||
echo "hddRaspiData=${hddRaspiData}"
|
echo "hddRaspiData=${hddRaspiData}"
|
||||||
@@ -145,11 +151,12 @@ if [ "$1" = "status" ]; then
|
|||||||
if [ "${hddFormat}" = "btrfs" ]; then
|
if [ "${hddFormat}" = "btrfs" ]; then
|
||||||
# in btrfs setup the second partition is storage partition
|
# in btrfs setup the second partition is storage partition
|
||||||
sudo mount /dev/${hdd}2 /mnt/storage 2>/dev/null
|
sudo mount /dev/${hdd}2 /mnt/storage 2>/dev/null
|
||||||
|
isTempMounted=$(df | grep /mnt/storage | grep -c ${hdd})
|
||||||
else
|
else
|
||||||
# in ext4 setup the first partition is also the storage partition
|
# in ext4 setup the partition is also the storage partition
|
||||||
sudo mount /dev/${hdd}1 /mnt/storage 2>/dev/null
|
sudo mount /dev/${hddDataPartitionExt4} /mnt/storage 2>/dev/null
|
||||||
|
isTempMounted=$(df | grep /mnt/storage | grep -c ${hddDataPartitionExt4})
|
||||||
fi
|
fi
|
||||||
isTempMounted=$(df | grep /mnt/storage | grep -c ${hdd})
|
|
||||||
if [ ${isTempMounted} -eq 0 ]; then
|
if [ ${isTempMounted} -eq 0 ]; then
|
||||||
echo "hddError='storage mount failed'"
|
echo "hddError='storage mount failed'"
|
||||||
else
|
else
|
||||||
@@ -180,8 +187,17 @@ if [ "$1" = "status" ]; then
|
|||||||
# STATUS INFO WHEN MOUNTED
|
# STATUS INFO WHEN MOUNTED
|
||||||
|
|
||||||
# output data drive
|
# output data drive
|
||||||
hdd=$(df | grep "/mnt/hdd" | cut -d " " -f 1 | cut -d "/" -f 3 | sed 's/[0-9]*//g')
|
hddDataPartition=$(df | grep "/mnt/hdd" | cut -d " " -f 1 | cut -d "/" -f 3)
|
||||||
|
hdd=$(echo $hddDataPartition | sed 's/[0-9]*//g')
|
||||||
|
hddFormat=$(lsblk -o FSTYPE,NAME,TYPE | grep part | grep "${hddDataPartition}" | cut -d " " -f 1)
|
||||||
|
if [ "${hddFormat}" = "ext4" ]; then
|
||||||
|
hddDataPartitionExt4=$hddDataPartition
|
||||||
|
fi
|
||||||
|
isSSD=$(sudo cat /sys/block/${hdd}/queue/rotational 2>/dev/null | grep -c 0)
|
||||||
|
|
||||||
|
echo "isSSD=${isSSD}"
|
||||||
echo "datadisk='${hdd}'"
|
echo "datadisk='${hdd}'"
|
||||||
|
echo "datapartition='${hddDataPartition}'"
|
||||||
|
|
||||||
# check if blockchain data is available
|
# check if blockchain data is available
|
||||||
hddBlocksBitcoin=$(sudo ls /mnt/hdd/bitcoin/blocks/blk00000.dat 2>/dev/null | grep -c '.dat')
|
hddBlocksBitcoin=$(sudo ls /mnt/hdd/bitcoin/blocks/blk00000.dat 2>/dev/null | grep -c '.dat')
|
||||||
@@ -197,16 +213,16 @@ if [ "$1" = "status" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# check size in bytes and GBs
|
# check size in bytes and GBs
|
||||||
size=$(lsblk -o NAME,SIZE -b | grep "^${hdd}" | awk '$1=$1' | cut -d " " -f 2)
|
sizeDataPartition=$(lsblk -o NAME,SIZE -b | grep "${hddDataPartition}" | awk '$1=$1' | cut -d " " -f 2)
|
||||||
echo "hddBytes=${size}"
|
echo "hddBytes=${sizeDataPartition}"
|
||||||
hddGigaBytes=$(echo "scale=0; ${size}/1024/1024/1024" | bc -l)
|
hddGigaBytes=$(echo "scale=0; ${sizeDataPartition}/1024/1024/1024" | bc -l)
|
||||||
echo "hddGigaBytes=${hddGigaBytes}"
|
echo "hddGigaBytes=${hddGigaBytes}"
|
||||||
|
|
||||||
# used space - at the moment just string info to display
|
# used space - at the moment just string info to display
|
||||||
if [ ${isBTRFS} -eq 0 ]; then
|
if [ ${isBTRFS} -eq 0 ]; then
|
||||||
# EXT4 calculations
|
# EXT4 calculations
|
||||||
hdd_used_space=$(df -h | grep "/dev/${hdd}" | sed -e's/ */ /g' | cut -d" " -f 3 2>/dev/null)
|
hdd_used_space=$(df -h | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 3 2>/dev/null)
|
||||||
hdd_used_ratio=$(df -h | grep "/dev/${hdd}" | sed -e's/ */ /g' | cut -d" " -f 5 | tr -dc '0-9' 2>/dev/null)
|
hdd_used_ratio=$(df -h | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 5 | tr -dc '0-9' 2>/dev/null)
|
||||||
hddUsedInfo="${hdd_used_space} (${hdd_used_ratio}%)"
|
hddUsedInfo="${hdd_used_space} (${hdd_used_ratio}%)"
|
||||||
else
|
else
|
||||||
# BRTS calculations
|
# BRTS calculations
|
||||||
@@ -276,9 +292,9 @@ if [ "$1" = "format" ]; then
|
|||||||
|
|
||||||
# check valid format
|
# check valid format
|
||||||
if [ "$2" = "btrfs" ]; then
|
if [ "$2" = "btrfs" ]; then
|
||||||
>&2 echo "# DATA DRIVE - FORMATTING to new BTRFS layout (new)"
|
>&2 echo "# DATA DRIVE - FORMATTING to BTRFS layout (new)"
|
||||||
elif [ "$2" = "ext4" ]; then
|
elif [ "$2" = "ext4" ]; then
|
||||||
>&2 echo "# DATA DRIVE - FORMATTING to new EXT4 layout (old)"
|
>&2 echo "# DATA DRIVE - FORMATTING to EXT4 layout (old)"
|
||||||
else
|
else
|
||||||
>&2 echo "# missing valid second parameter: 'btrfs' or 'ext4'"
|
>&2 echo "# missing valid second parameter: 'btrfs' or 'ext4'"
|
||||||
echo "error='missing parameter'"
|
echo "error='missing parameter'"
|
||||||
@@ -303,7 +319,7 @@ if [ "$1" = "format" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get basic info on data drives
|
# get basic info on data drive
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
||||||
|
|
||||||
if [ ${isSwapExternal} -eq 1 ] && [ "${hdd}" == "${datadisk}" ]; then
|
if [ ${isSwapExternal} -eq 1 ] && [ "${hdd}" == "${datadisk}" ]; then
|
||||||
@@ -361,151 +377,149 @@ if [ "$1" = "format" ]; then
|
|||||||
sleep 2
|
sleep 2
|
||||||
sync
|
sync
|
||||||
|
|
||||||
fi
|
# formatting old: EXT4
|
||||||
|
if [ "$2" = "ext4" ]; then
|
||||||
|
|
||||||
# formatting old: EXT4
|
# prepare temp mount point
|
||||||
if [ "$1" = "format" ] && [ "$2" = "ext4" ]; then
|
sudo mkdir -p /tmp/ext4 1>/dev/null
|
||||||
|
|
||||||
# prepare temp mount point
|
# write new EXT4 partition
|
||||||
sudo mkdir -p /tmp/ext4 1>/dev/null
|
>&2 echo "# Creating the one big partition"
|
||||||
|
sudo parted /dev/${hdd} mkpart primary ext4 0% 100% 1>/dev/null 2>/dev/null
|
||||||
|
sleep 6
|
||||||
|
sync
|
||||||
|
# loop until the partion gets available
|
||||||
|
loopdone=0
|
||||||
|
loopcount=0
|
||||||
|
while [ ${loopdone} -eq 0 ]
|
||||||
|
do
|
||||||
|
>&2 echo "# waiting until the partion gets available"
|
||||||
|
sleep 2
|
||||||
|
sync
|
||||||
|
loopdone=$(lsblk -o NAME | grep -c ${hdd}1)
|
||||||
|
loopcount=$(($loopcount +1))
|
||||||
|
if [ ${loopcount} -gt 10 ]; then
|
||||||
|
echo "error='partition failed'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# write new EXT4 partition
|
# make sure /mnt/hdd is unmounted before formatting
|
||||||
>&2 echo "# Creating the one big partition"
|
sudo umount -f /tmp/ext4 2>/dev/null
|
||||||
sudo parted /dev/${hdd} mkpart primary ext4 0% 100% 1>/dev/null 2>/dev/null
|
unmounted=$(df | grep -c "/tmp/ext4")
|
||||||
sleep 6
|
if [ ${unmounted} -gt 0 ]; then
|
||||||
sync
|
echo "error='failed to unmount /tmp/ext4'"
|
||||||
# loop until the partion gets available
|
exit 1
|
||||||
loopdone=0
|
fi
|
||||||
loopcount=0
|
|
||||||
while [ ${loopdone} -eq 0 ]
|
|
||||||
do
|
|
||||||
>&2 echo "# waiting until the partion gets available"
|
|
||||||
sleep 2
|
|
||||||
sync
|
|
||||||
loopdone=$(lsblk -o NAME | grep -c ${hdd}1)
|
|
||||||
loopcount=$(($loopcount +1))
|
|
||||||
if [ ${loopcount} -gt 10 ]; then
|
|
||||||
echo "error='partition failed'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# make sure /mnt/hdd is unmounted before formatting
|
>&2 echo "# Formatting"
|
||||||
sudo umount -f /tmp/ext4 2>/dev/null
|
sudo mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null
|
||||||
unmounted=$(df | grep -c "/tmp/ext4")
|
loopdone=0
|
||||||
if [ ${unmounted} -gt 0 ]; then
|
loopcount=0
|
||||||
echo "error='failed to unmount /tmp/ext4'"
|
while [ ${loopdone} -eq 0 ]
|
||||||
exit 1
|
do
|
||||||
|
>&2 echo "# waiting until formatted drives gets available"
|
||||||
|
sleep 2
|
||||||
|
sync
|
||||||
|
loopdone=$(lsblk -o NAME,LABEL | grep -c BLOCKCHAIN)
|
||||||
|
loopcount=$(($loopcount +1))
|
||||||
|
if [ ${loopcount} -gt 10 ]; then
|
||||||
|
echo "error='formatting ext4 failed'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# setting fsk check intervall to 1
|
||||||
|
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467567572
|
||||||
|
sudo tune2fs -c 1 /dev/${hdd}1
|
||||||
|
|
||||||
|
>&2 echo "# OK EXT 4 format done"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
>&2 echo "# Formatting"
|
# formatting new: BTRFS layout - this consists of 3 volmunes:
|
||||||
sudo mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null
|
if [ "$2" = "btrfs" ]; then
|
||||||
loopdone=0
|
|
||||||
loopcount=0
|
|
||||||
while [ ${loopdone} -eq 0 ]
|
|
||||||
do
|
|
||||||
>&2 echo "# waiting until formatted drives gets available"
|
|
||||||
sleep 2
|
|
||||||
sync
|
|
||||||
loopdone=$(lsblk -o NAME,LABEL | grep -c BLOCKCHAIN)
|
|
||||||
loopcount=$(($loopcount +1))
|
|
||||||
if [ ${loopcount} -gt 10 ]; then
|
|
||||||
echo "error='formatting ext4 failed'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# setting fsk check intervall to 1
|
# prepare temo mount point
|
||||||
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467567572
|
sudo mkdir -p /tmp/btrfs 1>/dev/null
|
||||||
sudo tune2fs -c 1 /dev/${hdd}1
|
|
||||||
|
|
||||||
>&2 echo "# OK EXT 4 format done"
|
>&2 echo "# Creating BLITZDATA"
|
||||||
exit 0
|
sudo parted -s -a optimal -- /dev/${hdd} mkpart primary btrfs 0% 30GiB 1>/dev/null
|
||||||
|
sync && sleep 3
|
||||||
fi
|
win=$(lsblk -o NAME | grep -c ${hdd}1)
|
||||||
|
if [ ${win} -eq 0 ]; then
|
||||||
# formatting new: BTRFS layout - this consists of 3 volmunes:
|
echo "error='partition failed'"
|
||||||
if [ "$1" = "format" ] && [ "$2" = "btrfs" ]; then
|
exit 1
|
||||||
|
fi
|
||||||
# prepare temo mount point
|
sudo mkfs.btrfs -f -L BLITZDATA /dev/${hdd}1 1>/dev/null
|
||||||
sudo mkdir -p /tmp/btrfs 1>/dev/null
|
sync && sleep 3
|
||||||
|
win=$(lsblk -o NAME,LABEL | grep -c BLITZDATA)
|
||||||
>&2 echo "# Creating BLITZDATA"
|
if [ ${win} -eq 0 ]; then
|
||||||
sudo parted -s -a optimal -- /dev/${hdd} mkpart primary btrfs 0% 30GiB 1>/dev/null
|
echo "error='formatting failed'"
|
||||||
sync && sleep 3
|
exit 1
|
||||||
win=$(lsblk -o NAME | grep -c ${hdd}1)
|
fi
|
||||||
if [ ${win} -eq 0 ]; then
|
>&2 echo "# OK BLITZDATA exists now"
|
||||||
echo "error='partition failed'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sudo mkfs.btrfs -f -L BLITZDATA /dev/${hdd}1 1>/dev/null
|
|
||||||
sync && sleep 3
|
|
||||||
win=$(lsblk -o NAME,LABEL | grep -c BLITZDATA)
|
|
||||||
if [ ${win} -eq 0 ]; then
|
|
||||||
echo "error='formatting failed'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
>&2 echo "# OK BLITZDATA exists now"
|
|
||||||
|
|
||||||
>&2 echo "# Creating SubVolume for Snapshots"
|
>&2 echo "# Creating SubVolume for Snapshots"
|
||||||
sudo mount /dev/${hdd}1 /tmp/btrfs 1>/dev/null
|
sudo mount /dev/${hdd}1 /tmp/btrfs 1>/dev/null
|
||||||
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
|
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
|
||||||
echo "error='mount ${hdd}1 failed'"
|
echo "error='mount ${hdd}1 failed'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
cd /tmp/btrfs
|
cd /tmp/btrfs
|
||||||
sudo btrfs subvolume create WORKINGDIR
|
sudo btrfs subvolume create WORKINGDIR
|
||||||
subVolDATA=$(sudo btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
|
subVolDATA=$(sudo btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
|
||||||
cd && sudo umount /tmp/btrfs
|
cd && sudo umount /tmp/btrfs
|
||||||
|
|
||||||
>&2 echo "# Creating BLITZSTORAGE"
|
>&2 echo "# Creating BLITZSTORAGE"
|
||||||
sudo parted -s -a optimal -- /dev/${hdd} mkpart primary btrfs 30GiB -34GiB 1>/dev/null
|
sudo parted -s -a optimal -- /dev/${hdd} mkpart primary btrfs 30GiB -34GiB 1>/dev/null
|
||||||
sync && sleep 3
|
sync && sleep 3
|
||||||
win=$(lsblk -o NAME | grep -c ${hdd}2)
|
win=$(lsblk -o NAME | grep -c ${hdd}2)
|
||||||
if [ ${win} -eq 0 ]; then
|
if [ ${win} -eq 0 ]; then
|
||||||
echo "error='partition failed'"
|
echo "error='partition failed'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sudo mkfs.btrfs -f -L BLITZSTORAGE /dev/${hdd}2 1>/dev/null
|
sudo mkfs.btrfs -f -L BLITZSTORAGE /dev/${hdd}2 1>/dev/null
|
||||||
sync && sleep 3
|
sync && sleep 3
|
||||||
win=$(lsblk -o NAME,LABEL | grep -c BLITZSTORAGE)
|
win=$(lsblk -o NAME,LABEL | grep -c BLITZSTORAGE)
|
||||||
if [ ${win} -eq 0 ]; then
|
if [ ${win} -eq 0 ]; then
|
||||||
echo "error='formatting failed'"
|
echo "error='formatting failed'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
>&2 echo "# OK BLITZSTORAGE exists now"
|
>&2 echo "# OK BLITZSTORAGE exists now"
|
||||||
|
|
||||||
>&2 echo "# Creating SubVolume for Snapshots"
|
>&2 echo "# Creating SubVolume for Snapshots"
|
||||||
sudo mount /dev/${hdd}2 /tmp/btrfs 1>/dev/null
|
sudo mount /dev/${hdd}2 /tmp/btrfs 1>/dev/null
|
||||||
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
|
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
|
||||||
echo "error='mount ${hdd}2 failed'"
|
echo "error='mount ${hdd}2 failed'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
cd /tmp/btrfs
|
cd /tmp/btrfs
|
||||||
sudo btrfs subvolume create WORKINGDIR
|
sudo btrfs subvolume create WORKINGDIR
|
||||||
cd && sudo umount /tmp/btrfs
|
cd && sudo umount /tmp/btrfs
|
||||||
|
|
||||||
>&2 echo "# Creating the FAT32 partion"
|
>&2 echo "# Creating the FAT32 partion"
|
||||||
sudo parted -s -a optimal -- /dev/${hdd} mkpart primary fat32 -34GiB 100% 1>/dev/null
|
sudo parted -s -a optimal -- /dev/${hdd} mkpart primary fat32 -34GiB 100% 1>/dev/null
|
||||||
sync && sleep 3
|
sync && sleep 3
|
||||||
win=$(lsblk -o NAME | grep -c ${hdd}3)
|
win=$(lsblk -o NAME | grep -c ${hdd}3)
|
||||||
if [ ${win} -eq 0 ]; then
|
if [ ${win} -eq 0 ]; then
|
||||||
echo "error='partition failed'"
|
echo "error='partition failed'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
>&2 echo "# Creating Volume BLITZTEMP (format)"
|
>&2 echo "# Creating Volume BLITZTEMP (format)"
|
||||||
sudo mkfs -t vfat -n BLITZTEMP /dev/${hdd}3 1>/dev/null
|
sudo mkfs -t vfat -n BLITZTEMP /dev/${hdd}3 1>/dev/null
|
||||||
sync && sleep 3
|
sync && sleep 3
|
||||||
win=$(lsblk -o NAME,LABEL | grep -c BLITZTEMP)
|
win=$(lsblk -o NAME,LABEL | grep -c BLITZTEMP)
|
||||||
if [ ${win} -eq 0 ]; then
|
if [ ${win} -eq 0 ]; then
|
||||||
echo "error='formatting failed'"
|
echo "error='formatting failed'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
>&2 echo "# OK BLITZTEMP exists now"
|
>&2 echo "# OK BLITZTEMP exists now"
|
||||||
|
|
||||||
>&2 echo "# OK BTRFS format done"
|
>&2 echo "# OK BTRFS format done"
|
||||||
exit 0
|
exit 0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
@@ -517,41 +531,42 @@ if [ "$1" = "fstab" ]; then
|
|||||||
# get device to temp mount
|
# get device to temp mount
|
||||||
hdd=$2
|
hdd=$2
|
||||||
if [ ${#hdd} -eq 0 ]; then
|
if [ ${#hdd} -eq 0 ]; then
|
||||||
>&2 echo "# FAIL which device should be temp mounted (e.g. sda)"
|
echo "# FAIL which device/partition should be temp mounted (e.g. sda)"
|
||||||
>&2 echo "# run 'status' to see device candidates"
|
echo "# run 'status' to see device candidates"
|
||||||
echo "error='missing second parameter'"
|
echo "error='missing second parameter'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check is exist and which format
|
# check if exist and which format
|
||||||
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd}1 | cut -d ' ' -f 1)
|
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd} | cut -d ' ' -f 1)
|
||||||
if [ ${#hddFormat} -eq 0 ]; then
|
if [ ${#hddFormat} -eq 0 ]; then
|
||||||
>&2 echo "# FAIL given device not found"
|
echo "# FAIL given device/partition not found"
|
||||||
echo "error='device not found'"
|
echo "error='device not found'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# unmount
|
# unmount
|
||||||
if [ ${isMounted} -eq 1 ]; then
|
if [ ${isMounted} -eq 1 ]; then
|
||||||
>&2 echo "# unmounting all drives"
|
echo "# unmounting all drives"
|
||||||
sudo umount /mnt/hdd 2>/dev/null
|
sudo umount /mnt/hdd > /dev/null 2>&1
|
||||||
sudo umount /mnt/storage 2>/dev/null
|
sudo umount /mnt/storage > /dev/null 2>&1
|
||||||
sudo umount /mnt/temp 2>/dev/null
|
sudo umount /mnt/temp > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${hddFormat}" = "ext4" ]; then
|
if [ "${hddFormat}" = "ext4" ]; then
|
||||||
|
|
||||||
### EXT4 ###
|
### EXT4 ###
|
||||||
|
|
||||||
|
hddDataPartitionExt4=$hdd
|
||||||
# loop until the uuids are available
|
# loop until the uuids are available
|
||||||
uuid1=""
|
uuid1=""
|
||||||
loopcount=0
|
loopcount=0
|
||||||
while [ ${#uuid1} -eq 0 ]
|
while [ ${#uuid1} -eq 0 ]
|
||||||
do
|
do
|
||||||
>&2 echo "# waiting until uuid gets available"
|
echo "# waiting until uuid gets available"
|
||||||
sleep 2
|
sleep 2
|
||||||
sync
|
sync
|
||||||
uuid1=$(lsblk -o NAME,UUID | grep "${hdd}" | awk '$1=$1' | cut -d " " -f 2 | grep "-")
|
uuid1=$(lsblk -o NAME,UUID | grep "${hddDataPartitionExt4}" | awk '$1=$1' | cut -d " " -f 2 | grep "-")
|
||||||
loopcount=$(($loopcount +1))
|
loopcount=$(($loopcount +1))
|
||||||
if [ ${loopcount} -gt 10 ]; then
|
if [ ${loopcount} -gt 10 ]; then
|
||||||
echo "error='no uuid'"
|
echo "error='no uuid'"
|
||||||
@@ -560,9 +575,14 @@ if [ "$1" = "fstab" ]; then
|
|||||||
done
|
done
|
||||||
|
|
||||||
# write new /etc/fstab & mount
|
# write new /etc/fstab & mount
|
||||||
>&2 echo "# updating /etc/fstab & mount"
|
echo "# mount /mnt/hdd"
|
||||||
sudo mkdir -p /mnt/hdd 1>/dev/null
|
sudo mkdir -p /mnt/hdd 1>/dev/null
|
||||||
sudo sed "3 a UUID=${uuid1} /mnt/hdd ext4 noexec,defaults 0 2" -i /etc/fstab 1>/dev/null
|
updated=$(cat /etc/fstab | grep -c "/mnt/hdd")
|
||||||
|
if [ $updated -eq 0 ]; then
|
||||||
|
echo "# updating /etc/fstab"
|
||||||
|
sudo sed "/raspiblitz/ i UUID=${uuid1} /mnt/hdd ext4 noexec,defaults 0 2" -i /etc/fstab 1>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
sync
|
sync
|
||||||
sudo mount -a 1>/dev/null
|
sudo mount -a 1>/dev/null
|
||||||
|
|
||||||
@@ -571,19 +591,19 @@ if [ "$1" = "fstab" ]; then
|
|||||||
loopcount=0
|
loopcount=0
|
||||||
while [ ${mountactive1} -eq 0 ]
|
while [ ${mountactive1} -eq 0 ]
|
||||||
do
|
do
|
||||||
>&2 echo "# waiting until mounting is active"
|
echo "# waiting until mounting is active"
|
||||||
sleep 2
|
sleep 2
|
||||||
sync
|
sync
|
||||||
mountactive1=$(df | grep -c /mnt/hdd)
|
mountactive1=$(df | grep -c /mnt/hdd)
|
||||||
loopcount=$(($loopcount +1))
|
loopcount=$(($loopcount +1))
|
||||||
if [ ${loopcount} -gt 10 ]; then
|
if [ ${loopcount} -gt 10 ]; then
|
||||||
>&2 echo "# WARNING was not able freshly mount new devives - might need reboot or check /etc/fstab"
|
echo "# WARNING was not able freshly mount new devices - might need reboot or check /etc/fstab"
|
||||||
echo "needsReboot=1"
|
echo "needsReboot=1"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
>&2 echo "# OK - fstab updated for EXT4 layout"
|
echo "# OK - fstab updated for EXT4 layout"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
elif [ "${hddFormat}" = "btrfs" ]; then
|
elif [ "${hddFormat}" = "btrfs" ]; then
|
||||||
@@ -672,7 +692,7 @@ if [ "$1" = "fstab" ]; then
|
|||||||
mountactive3=$(df | grep -c /mnt/storage)
|
mountactive3=$(df | grep -c /mnt/storage)
|
||||||
loopcount=$(($loopcount +1))
|
loopcount=$(($loopcount +1))
|
||||||
if [ ${loopcount} -gt 10 ]; then
|
if [ ${loopcount} -gt 10 ]; then
|
||||||
>&2 echo "# WARNING was not able freshly mount new devives - might need reboot or check /etc/fstab"
|
>&2 echo "# WARNING was not able freshly mount new devices - might need reboot or check /etc/fstab"
|
||||||
echo "needsReboot=1"
|
echo "needsReboot=1"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -938,15 +958,15 @@ if [ "$1" = "tempmount" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# get device to temp mount
|
# get device to temp mount
|
||||||
hdd=$2
|
hddDataPartition=$2
|
||||||
if [ ${#hdd} -eq 0 ]; then
|
if [ ${#hddDataPartition} -eq 0 ]; then
|
||||||
>&2 echo "# FAIL which device should be temp mounted (e.g. sda)"
|
>&2 echo "# FAIL which device should be temp mounted (e.g. sda)"
|
||||||
>&2 echo "# run 'status' to see device candidates"
|
>&2 echo "# run 'status' to see device candidates"
|
||||||
echo "error='missing second parameter'"
|
echo "error='missing second parameter'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hdd}1 | cut -d ' ' -f 1)
|
hddFormat=$(lsblk -o FSTYPE,NAME | grep ${hddDataPartition} | cut -d ' ' -f 1)
|
||||||
if [ ${#hddFormat} -eq 0 ]; then
|
if [ ${#hddFormat} -eq 0 ]; then
|
||||||
>&2 echo "# FAIL given device not found"
|
>&2 echo "# FAIL given device not found"
|
||||||
echo "error='device not found'"
|
echo "error='device not found'"
|
||||||
@@ -954,10 +974,11 @@ if [ "$1" = "tempmount" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${hddFormat}" = "ext4" ]; then
|
if [ "${hddFormat}" = "ext4" ]; then
|
||||||
|
hddDataPartitionExt4=$hddDataPartition
|
||||||
|
|
||||||
# do EXT4 temp mount
|
# do EXT4 temp mount
|
||||||
sudo mkdir -p /mnt/hdd 1>/dev/null
|
sudo mkdir -p /mnt/hdd 1>/dev/null
|
||||||
sudo mount /dev/${hdd}1 /mnt/hdd
|
sudo mount /dev/${hddDataPartitionExt4} /mnt/hdd
|
||||||
|
|
||||||
# check result
|
# check result
|
||||||
isMounted=$(df | grep -c "/mnt/hdd")
|
isMounted=$(df | grep -c "/mnt/hdd")
|
||||||
@@ -970,6 +991,7 @@ if [ "$1" = "tempmount" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
elif [ "${hddFormat}" = "btrfs" ]; then
|
elif [ "${hddFormat}" = "btrfs" ]; then
|
||||||
|
hdd=$hddDataPartition
|
||||||
|
|
||||||
# get user and grouid if usr/group bitcoin
|
# get user and grouid if usr/group bitcoin
|
||||||
bitcoinUID=$(id -u bitcoin)
|
bitcoinUID=$(id -u bitcoin)
|
||||||
|
@@ -317,7 +317,7 @@ if [ "$1" = "import-gui" ]; then
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
# now temp mount the HDD/SSD
|
# now temp mount the HDD/SSD
|
||||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddCandidate})
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddPartitionCandidate})
|
||||||
if [ ${#error} -gt 0 ]; then
|
if [ ${#error} -gt 0 ]; then
|
||||||
echo "FAIL: Was not able to temp mount the HDD/SSD --> ${error}"
|
echo "FAIL: Was not able to temp mount the HDD/SSD --> ${error}"
|
||||||
exit 1
|
exit 1
|
||||||
|
Reference in New Issue
Block a user