Repair Fresh HDD/SSD Setup (#4317)

This commit is contained in:
/rootzoll 2023-12-13 22:14:45 +01:00 committed by GitHub
parent 07cdde07c0
commit 1ef72dc481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 39 deletions

View File

@ -485,8 +485,8 @@ do
mkdir -p /home/admin/backups/scb/ 2>/dev/null mkdir -p /home/admin/backups/scb/ 2>/dev/null
cp $scbPath $localBackupPath cp $scbPath $localBackupPath
cp $scbPath $localTimestampedPath cp $scbPath $localTimestampedPath
cp $scbPath /boot/channel.backup cp $scbPath /boot/firmware/channel.backup
echo "OK channel.backup copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/channel.backup'" echo "OK channel.backup copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/firmware/channel.backup'"
# check if a additional local backup target is set # check if a additional local backup target is set
# see ./config.scripts/blitz.backupdevice.sh # see ./config.scripts/blitz.backupdevice.sh
@ -591,8 +591,8 @@ do
mkdir -p /home/admin/backups/er/ 2>/dev/null mkdir -p /home/admin/backups/er/ 2>/dev/null
cp $erPath $localBackupPath cp $erPath $localBackupPath
cp $erPath $localTimestampedPath cp $erPath $localTimestampedPath
cp $erPath /boot/${netprefix}emergency.recover cp $erPath /boot/firmware/${netprefix}emergency.recover
echo "OK emergency.recover copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/${netprefix}emergency.recover'" echo "OK emergency.recover copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/firmware/${netprefix}emergency.recover'"
# check if a additional local backup target is set # check if a additional local backup target is set
# see ./config.scripts/blitz.backupdevice.sh # see ./config.scripts/blitz.backupdevice.sh

View File

@ -127,11 +127,11 @@ source ${configFile} 2>/dev/null
###################################### ######################################
# CHECK SD CARD STATE # CHECK SD CARD STATE
# when a file 'stop' is on the sd card boot partition - stop for manual provision # when a file 'stop' is on the sd card bootfs partition root - stop for manual provision
flagExists=$(sudo ls /boot/stop | grep -c 'stop') flagExists=$(sudo ls /boot/firmware/stop | grep -c 'stop')
if [ "${flagExists}" == "1" ]; then if [ "${flagExists}" == "1" ]; then
# remove flag # remove flag
sudo rm /boot/stop sudo rm /boot/firmware/stop
# set state info # set state info
/home/admin/_cache.sh set state "stop" /home/admin/_cache.sh set state "stop"
/home/admin/_cache.sh set message "stopped for manual provision" /home/admin/_cache.sh set message "stopped for manual provision"
@ -230,11 +230,11 @@ systemInitReboot=0
################################ ################################
# FORCED SWITCH TO HDMI # FORCED SWITCH TO HDMI
# if a file called 'hdmi' gets # if a file called 'hdmi' gets
# placed onto the boot part of # placed onto the bootfs part of
# the sd card - switch to hdmi # the sd card - switch to hdmi
################################ ################################
forceHDMIoutput=$(sudo ls /boot/hdmi* 2>/dev/null | grep -c hdmi) forceHDMIoutput=$(sudo ls /boot/firmware/hdmi* 2>/dev/null | grep -c hdmi)
if [ ${forceHDMIoutput} -eq 1 ]; then if [ ${forceHDMIoutput} -eq 1 ]; then
# delete that file (to prevent loop) # delete that file (to prevent loop)
sudo rm /boot/hdmi* sudo rm /boot/hdmi*
@ -310,10 +310,10 @@ fi
# the sd card - delete old ssh data # the sd card - delete old ssh data
################################ ################################
sshReset=$(sudo ls /boot/ssh.reset* 2>/dev/null | grep -c reset) sshReset=$(sudo ls /boot/firmware/ssh.reset* 2>/dev/null | grep -c reset)
if [ ${sshReset} -eq 1 ]; then if [ ${sshReset} -eq 1 ]; then
# delete that file (to prevent loop) # delete that file (to prevent loop)
rm /boot/ssh.reset* >> $logFile rm /boot/firmware/ssh.reset* >> $logFile
# delete ssh certs # delete ssh certs
echo "SSHRESET switch found ... stopping SSH and deleting old certs" >> $logFile echo "SSHRESET switch found ... stopping SSH and deleting old certs" >> $logFile
/home/admin/config.scripts/blitz.ssh.sh renew >> $logFile /home/admin/config.scripts/blitz.ssh.sh renew >> $logFile
@ -557,7 +557,7 @@ if [ ${isMounted} -eq 0 ]; then
# check if there is a flag set on sd card boot section to format as btrfs (experimental) # check if there is a flag set on sd card boot section to format as btrfs (experimental)
filesystem="ext4" filesystem="ext4"
flagBTRFS=$(sudo ls /boot/btrfs* 2>/dev/null | grep -c btrfs) flagBTRFS=$(sudo ls /boot/firmware/btrfs* 2>/dev/null | grep -c btrfs)
if [ "${flagBTRFS}" != "0" ]; then if [ "${flagBTRFS}" != "0" ]; then
echo "Found BTRFS flag ---> formatting with experimental BTRFS filesystem" >> ${logFile} echo "Found BTRFS flag ---> formatting with experimental BTRFS filesystem" >> ${logFile}
filesystem="btrfs" filesystem="btrfs"
@ -985,7 +985,7 @@ fi
# FORCE UASP FLAG # FORCE UASP FLAG
#################### ####################
# if uasp.force flag was set on sd card - now move into raspiblitz.conf # if uasp.force flag was set on sd card - now move into raspiblitz.conf
if [ -f "/boot/uasp.force" ]; then if [ -f "/boot/firmware/uasp.force" ]; then
/home/admin/config.scripts/blitz.conf.sh set forceUasp "on" /home/admin/config.scripts/blitz.conf.sh set forceUasp "on"
echo "DONE forceUasp=on recorded in raspiblitz.conf" >> $logFile echo "DONE forceUasp=on recorded in raspiblitz.conf" >> $logFile
fi fi

View File

@ -109,10 +109,10 @@ if [ "$1" = "status" ]; then
testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g') testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g')
if [ $(echo $line | grep -c "nvme") = 0 ]; then if [ $(echo $line | grep -c "nvme") = 0 ]; then
testdevice=$(echo $testname | sed 's/[^a-z]*//g') testdevice=$(echo $testname | sed 's/[^a-z]*//g')
testpartition=$(echo $testname | grep -P '[a-z]{3,5}[0-9]{1}') testpartition=$(echo $testname | grep -P '[a-z]{3,5}[0-9]{1}')
else else
testdevice=$(echo $testname | sed 's/\([^p]*\).*/\1/') testdevice=$(echo $testname | sed 's/\([^p]*\).*/\1/')
testpartition=$(echo $testname | grep -P '[p]{1}') testpartition=$(echo $testname | grep -P '[p]{1}')
fi fi
if [ ${#testpartition} -gt 0 ]; then if [ ${#testpartition} -gt 0 ]; then
@ -121,8 +121,8 @@ if [ "$1" = "status" ]; then
testsize=0 testsize=0
fi fi
#echo "# line($line)" # echo "# line($line)"
#echo "# testname(${testname}) testdevice(${testdevice}) testpartition(${testpartition}) testsize(${testsize})" # echo "# testname(${testname}) testdevice(${testdevice}) testpartition(${testpartition}) testsize(${testsize})"
# count partitions # count partitions
testpartitioncount=0 testpartitioncount=0
@ -132,36 +132,37 @@ if [ "$1" = "status" ]; then
testpartitioncount=$((testpartitioncount-1)) testpartitioncount=$((testpartitioncount-1))
fi fi
#echo "# testpartitioncount($testpartitioncount)"
#echo "# testpartitioncount(${testpartitioncount})"
#echo "# OSPartition(${OSPartition})"
#echo "# bootPartition(${bootPartition})"
#echo "# hdd(${hdd})"
if [ "$(uname -m)" = "x86_64" ]; then if [ "$(uname -m)" = "x86_64" ]; then
if [ $(echo "$testpartition" | grep -c "nvme") = 0 ]; then
# For PC systems
if [ $(echo "$testpartition" | grep -c "nvme") = 0 ]; then
testParentDisk=$(echo "$testpartition" | sed 's/[^a-z]*//g') testParentDisk=$(echo "$testpartition" | sed 's/[^a-z]*//g')
else else
testParentDisk=$(echo "$testpartition" | sed 's/\([^p]*\).*/\1/') testParentDisk=$(echo "$testpartition" | sed 's/\([^p]*\).*/\1/')
fi fi
if [ $(echo "$OSPartition" | grep -c "nvme") = 0 ]; then
if [ $(echo "$OSPartition" | grep -c "nvme") = 0 ]; then
OSParentDisk=$(echo "$OSPartition" | sed 's/[^a-z]*//g') OSParentDisk=$(echo "$OSPartition" | sed 's/[^a-z]*//g')
else else
OSParentDisk=$(echo "$OSPartition" | sed 's/\([^p]*\).*/\1/') OSParentDisk=$(echo "$OSPartition" | sed 's/\([^p]*\).*/\1/')
fi fi
if [ $(echo "$bootPartition" | grep -c "nvme") = 0 ]; then if [ $(echo "$bootPartition" | grep -c "nvme") = 0 ]; then
bootParentDisk=$(echo "$bootPartition" | sed 's/[^a-z]*//g') bootParentDisk=$(echo "$bootPartition" | sed 's/[^a-z]*//g')
else else
bootParentDisk=$(echo "$bootPartition" | sed 's/\([^p]*\).*/\1/') bootParentDisk=$(echo "$bootPartition" | sed 's/\([^p]*\).*/\1/')
fi fi
if [ "$testdevice" != "$OSParentDisk" ] && [ "$testdevice" != "$bootParentDisk" ];then if [ "$testdevice" != "$OSParentDisk" ] && [ "$testdevice" != "$bootParentDisk" ];then
sizeDataPartition=${testsize} sizeDataPartition=${testsize}
hddDataPartition="${testpartition}" hddDataPartition="${testpartition}"
hdd="${testdevice}" hdd="${testdevice}"
fi fi
elif [ $testpartitioncount -gt 0 ]; then elif [ $testpartitioncount -gt 0 ]; then
# if a partition was found - make sure to skip the OS and boot partitions # if a partition was found - make sure to skip the OS and boot partitions
# echo "# testpartitioncount > 0"
if [ "${testpartition}" != "${OSPartition}" ] && [ "${testpartition}" != "${bootPartition}" ]; then if [ "${testpartition}" != "${OSPartition}" ] && [ "${testpartition}" != "${bootPartition}" ]; then
# make sure to use the biggest # make sure to use the biggest
if [ ${testsize} -gt ${sizeDataPartition} ]; then if [ ${testsize} -gt ${sizeDataPartition} ]; then
@ -170,19 +171,34 @@ if [ "$1" = "status" ]; then
hdd="${testdevice}" hdd="${testdevice}"
fi fi
fi fi
else else
# default hdd set, when there is no OSpartition and there might be no partitions at all # default hdd set, when there is no OSpartition and there might be no partitions at all
if [ "${OSPartition}" = "root" ] && [ "${hdd}" = "" ] && [ "${testdevice}" != "" ]; then # echo "# else"
# echo "# testsize(${testsize})"
# echo "# sizeDataPartition(${sizeDataPartition})"
if [ "${OSPartition}" = "mmcblk0p2" ] && [ "${hdd}" = "" ] && [ "${testdevice}" != "" ]; then
# echo "# OSPartition = mmcblk0p2"
hdd="${testdevice}" hdd="${testdevice}"
fi fi
# make sure to use the biggest
# make sure to use the biggest
if [ ${testsize} -gt ${sizeDataPartition} ]; then if [ ${testsize} -gt ${sizeDataPartition} ]; then
# Partition to be created is smaller than disk so this is not correct (but close) # Partition to be created is smaller than disk so this is not correct (but close)
# echo "# testsize > sizeDataPartition"
sizeDataPartition=$(fdisk -l /dev/$testdevice | grep GiB | cut -d " " -f 5) sizeDataPartition=$(fdisk -l /dev/$testdevice | grep GiB | cut -d " " -f 5)
hddDataPartition="${testdevice}1" hddDataPartition="${testdevice}1"
hdd="${testdevice}" hdd="${testdevice}"
fi fi
fi fi
# echo "# testpartitioncount($testpartitioncount)"
# echo "# OSPartition(${OSPartition})"
# echo "# bootPartition(${bootPartition})"
# echo "# hdd(${hdd})"
done < .lsblk.tmp done < .lsblk.tmp
rm -f .lsblk.tmp 1>/dev/null 2>/dev/null rm -f .lsblk.tmp 1>/dev/null 2>/dev/null
@ -520,7 +536,7 @@ if [ "$1" = "status" ]; then
hddAdapterUSAP=0 hddAdapterUSAP=0
# check if force UASP flag is set on sd card # check if force UASP flag is set on sd card
if [ -f "/boot/uasp.force" ]; then if [ -f "/boot/firmware/uasp.force" ]; then
hddAdapterUSAP=1 hddAdapterUSAP=1
fi fi
# or UASP is set by config file # or UASP is set by config file
@ -695,10 +711,13 @@ if [ "$1" = "format" ]; then
if [ $wipePartitions -eq 1 ]; then 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)"
>&2 echo "# sfdisk"
sfdisk --delete /dev/${hdd} sfdisk --delete /dev/${hdd}
sleep 4 sleep 4
>&2 echo "# wipefs"
wipefs -a /dev/${hdd} wipefs -a /dev/${hdd}
sleep 4 sleep 4
>&2 echo "# lsblk"
partitions=$(lsblk | grep -c "${hdd}") partitions=$(lsblk | grep -c "${hdd}")
if [ ${partitions} -gt 0 ]; then if [ ${partitions} -gt 0 ]; then
>&2 echo "# WARNING: partitions are still not clean - try Quick & Dirty" >&2 echo "# WARNING: partitions are still not clean - try Quick & Dirty"
@ -710,6 +729,7 @@ if [ "$1" = "format" ]; then
echo "error='partition cleaning failed'" echo "error='partition cleaning failed'"
exit 1 exit 1
fi fi
>&2 echo "# parted"
parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2 parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2
sleep 2 sleep 2
sync sync
@ -726,9 +746,10 @@ if [ "$1" = "format" ]; then
mkdir -p /tmp/ext4 1>/dev/null mkdir -p /tmp/ext4 1>/dev/null
if [ $ext4IsPartition -eq 0 ]; then 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 - hdd(${hdd})"
parted -s /dev/${hdd} mkpart primary ext4 1024KiB 100% 1>&2 parted -s /dev/${hdd} mkpart primary ext4 1024KiB 100% 1>&2
sleep 6 sleep 6
>&2 echo "# sync"
sync sync
# loop until the partition gets available # loop until the partition gets available
loopdone=0 loopdone=0

View File

@ -24,7 +24,7 @@ if [ "${needsExpansion}" == "1" ]; then
# write a stop file to prevent full bootstrap # write a stop file to prevent full bootstrap
# after fsexpand reboot # after fsexpand reboot
touch /boot/stop touch /boot/firmware/stop
# trigger fsexpand # trigger fsexpand
/home/admin/config.scripts/blitz.bootdrive.sh fsexpand /home/admin/config.scripts/blitz.bootdrive.sh fsexpand