From bf9dbc0321676426e1bc25b6d54c5856578f10ea Mon Sep 17 00:00:00 2001 From: openoms <43343391+openoms@users.noreply.github.com> Date: Fri, 17 May 2024 09:55:01 +0200 Subject: [PATCH] add GPT integrity check for amd64 (#4576) --- home.admin/_bootstrap.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/home.admin/_bootstrap.sh b/home.admin/_bootstrap.sh index f848d471e..eecea58ad 100755 --- a/home.admin/_bootstrap.sh +++ b/home.admin/_bootstrap.sh @@ -337,6 +337,34 @@ else echo "No HDMI switch found. " >> $logFile fi +################################ +# GPT integrity check +################################ + +check_and_fix_gpt() { + local device=$1 + output=$(sudo gdisk -l $device 2>&1) + if echo "$output" | grep -q "PMBR size mismatch"; then + echo "GPT PMBR size mismatch detected on $device. Fixing..." >> $logFile + sgdisk -e $device + echo "Fixed GPT PMBR size mismatch on $device." >> $logFile + elif echo "$output" | grep -q "The backup GPT table is not on the end of the device"; then + echo "Backup GPT table is not at the end of $device. Fixing..." >> $logFile + sgdisk -e $device + echo "Fixed backup GPT table location on $device." >> $logFile + else + echo "No GPT issues detected on $device." >> $logFile + fi +} + +# List all block devices +devices=$(lsblk -dno NAME | grep -E '^sd|^nvme|^vd|^mmcblk') + +# Check and fix each device +for dev in $devices; do + check_and_fix_gpt /dev/$dev +done + ################################ # FS EXPAND # extend sd card to maximum capacity