From 1ef72dc481a2e350983d12b4b14e7ec374d38a0b Mon Sep 17 00:00:00 2001 From: /rootzoll Date: Wed, 13 Dec 2023 22:14:45 +0100 Subject: [PATCH] Repair Fresh HDD/SSD Setup (#4317) --- home.admin/_background.sh | 8 +-- home.admin/_bootstrap.sh | 18 ++--- home.admin/config.scripts/blitz.datadrive.sh | 71 +++++++++++++------- home.admin/config.scripts/blitz.fatpack.sh | 2 +- 4 files changed, 60 insertions(+), 39 deletions(-) diff --git a/home.admin/_background.sh b/home.admin/_background.sh index 79a47095..d8be81c9 100755 --- a/home.admin/_background.sh +++ b/home.admin/_background.sh @@ -485,8 +485,8 @@ do mkdir -p /home/admin/backups/scb/ 2>/dev/null cp $scbPath $localBackupPath cp $scbPath $localTimestampedPath - cp $scbPath /boot/channel.backup - echo "OK channel.backup copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/channel.backup'" + cp $scbPath /boot/firmware/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 # see ./config.scripts/blitz.backupdevice.sh @@ -591,8 +591,8 @@ do mkdir -p /home/admin/backups/er/ 2>/dev/null cp $erPath $localBackupPath cp $erPath $localTimestampedPath - cp $erPath /boot/${netprefix}emergency.recover - echo "OK emergency.recover copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/${netprefix}emergency.recover'" + cp $erPath /boot/firmware/${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 # see ./config.scripts/blitz.backupdevice.sh diff --git a/home.admin/_bootstrap.sh b/home.admin/_bootstrap.sh index ba69bd36..2645feeb 100755 --- a/home.admin/_bootstrap.sh +++ b/home.admin/_bootstrap.sh @@ -127,11 +127,11 @@ source ${configFile} 2>/dev/null ###################################### # CHECK SD CARD STATE -# when a file 'stop' is on the sd card boot partition - stop for manual provision -flagExists=$(sudo ls /boot/stop | grep -c 'stop') +# when a file 'stop' is on the sd card bootfs partition root - stop for manual provision +flagExists=$(sudo ls /boot/firmware/stop | grep -c 'stop') if [ "${flagExists}" == "1" ]; then # remove flag - sudo rm /boot/stop + sudo rm /boot/firmware/stop # set state info /home/admin/_cache.sh set state "stop" /home/admin/_cache.sh set message "stopped for manual provision" @@ -230,11 +230,11 @@ systemInitReboot=0 ################################ # FORCED SWITCH TO HDMI # if a file called 'hdmi' gets -# placed onto the boot part of +# placed onto the bootfs part of # 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 # delete that file (to prevent loop) sudo rm /boot/hdmi* @@ -310,10 +310,10 @@ fi # 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 # delete that file (to prevent loop) - rm /boot/ssh.reset* >> $logFile + rm /boot/firmware/ssh.reset* >> $logFile # delete ssh certs echo "SSHRESET switch found ... stopping SSH and deleting old certs" >> $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) 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 echo "Found BTRFS flag ---> formatting with experimental BTRFS filesystem" >> ${logFile} filesystem="btrfs" @@ -985,7 +985,7 @@ fi # FORCE UASP FLAG #################### # 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" echo "DONE forceUasp=on recorded in raspiblitz.conf" >> $logFile fi diff --git a/home.admin/config.scripts/blitz.datadrive.sh b/home.admin/config.scripts/blitz.datadrive.sh index 2db632bd..52d7e265 100755 --- a/home.admin/config.scripts/blitz.datadrive.sh +++ b/home.admin/config.scripts/blitz.datadrive.sh @@ -109,10 +109,10 @@ if [ "$1" = "status" ]; then testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g') if [ $(echo $line | grep -c "nvme") = 0 ]; then 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 - testdevice=$(echo $testname | sed 's/\([^p]*\).*/\1/') - testpartition=$(echo $testname | grep -P '[p]{1}') + testdevice=$(echo $testname | sed 's/\([^p]*\).*/\1/') + testpartition=$(echo $testname | grep -P '[p]{1}') fi if [ ${#testpartition} -gt 0 ]; then @@ -121,8 +121,8 @@ if [ "$1" = "status" ]; then testsize=0 fi - #echo "# line($line)" - #echo "# testname(${testname}) testdevice(${testdevice}) testpartition(${testpartition}) testsize(${testsize})" + # echo "# line($line)" + # echo "# testname(${testname}) testdevice(${testdevice}) testpartition(${testpartition}) testsize(${testsize})" # count partitions testpartitioncount=0 @@ -132,36 +132,37 @@ if [ "$1" = "status" ]; then testpartitioncount=$((testpartitioncount-1)) fi - #echo "# testpartitioncount($testpartitioncount)" - #echo "# testpartitioncount(${testpartitioncount})" - #echo "# OSPartition(${OSPartition})" - #echo "# bootPartition(${bootPartition})" - #echo "# hdd(${hdd})" - 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') - else + else testParentDisk=$(echo "$testpartition" | sed 's/\([^p]*\).*/\1/') - fi - if [ $(echo "$OSPartition" | grep -c "nvme") = 0 ]; then + fi + + if [ $(echo "$OSPartition" | grep -c "nvme") = 0 ]; then OSParentDisk=$(echo "$OSPartition" | sed 's/[^a-z]*//g') - else + else OSParentDisk=$(echo "$OSPartition" | sed 's/\([^p]*\).*/\1/') fi + if [ $(echo "$bootPartition" | grep -c "nvme") = 0 ]; then bootParentDisk=$(echo "$bootPartition" | sed 's/[^a-z]*//g') - else - bootParentDisk=$(echo "$bootPartition" | sed 's/\([^p]*\).*/\1/') - fi + else + bootParentDisk=$(echo "$bootPartition" | sed 's/\([^p]*\).*/\1/') + fi if [ "$testdevice" != "$OSParentDisk" ] && [ "$testdevice" != "$bootParentDisk" ];then sizeDataPartition=${testsize} hddDataPartition="${testpartition}" hdd="${testdevice}" fi + elif [ $testpartitioncount -gt 0 ]; then # if a partition was found - make sure to skip the OS and boot partitions + # echo "# testpartitioncount > 0" if [ "${testpartition}" != "${OSPartition}" ] && [ "${testpartition}" != "${bootPartition}" ]; then # make sure to use the biggest if [ ${testsize} -gt ${sizeDataPartition} ]; then @@ -170,19 +171,34 @@ if [ "$1" = "status" ]; then hdd="${testdevice}" fi fi + else # 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}" fi - # make sure to use the biggest + + # make sure to use the biggest 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) hddDataPartition="${testdevice}1" hdd="${testdevice}" - fi + fi + fi + + # echo "# testpartitioncount($testpartitioncount)" + # echo "# OSPartition(${OSPartition})" + # echo "# bootPartition(${bootPartition})" + # echo "# hdd(${hdd})" + done < .lsblk.tmp rm -f .lsblk.tmp 1>/dev/null 2>/dev/null @@ -520,7 +536,7 @@ if [ "$1" = "status" ]; then hddAdapterUSAP=0 # 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 fi # or UASP is set by config file @@ -695,10 +711,13 @@ if [ "$1" = "format" ]; then if [ $wipePartitions -eq 1 ]; then # wipe all partitions and write fresh GPT >&2 echo "# Wiping all partitions (sfdisk/wipefs)" + >&2 echo "# sfdisk" sfdisk --delete /dev/${hdd} sleep 4 + >&2 echo "# wipefs" wipefs -a /dev/${hdd} sleep 4 + >&2 echo "# lsblk" partitions=$(lsblk | grep -c "─${hdd}") if [ ${partitions} -gt 0 ]; then >&2 echo "# WARNING: partitions are still not clean - try Quick & Dirty" @@ -710,6 +729,7 @@ if [ "$1" = "format" ]; then echo "error='partition cleaning failed'" exit 1 fi + >&2 echo "# parted" parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2 sleep 2 sync @@ -726,9 +746,10 @@ if [ "$1" = "format" ]; then mkdir -p /tmp/ext4 1>/dev/null if [ $ext4IsPartition -eq 0 ]; then # 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 sleep 6 + >&2 echo "# sync" sync # loop until the partition gets available loopdone=0 diff --git a/home.admin/config.scripts/blitz.fatpack.sh b/home.admin/config.scripts/blitz.fatpack.sh index 3d0e8e3e..c41bcc5a 100755 --- a/home.admin/config.scripts/blitz.fatpack.sh +++ b/home.admin/config.scripts/blitz.fatpack.sh @@ -24,7 +24,7 @@ if [ "${needsExpansion}" == "1" ]; then # write a stop file to prevent full bootstrap # after fsexpand reboot - touch /boot/stop + touch /boot/firmware/stop # trigger fsexpand /home/admin/config.scripts/blitz.bootdrive.sh fsexpand