Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DietPi-Imager | Fix GPT backup partition table handling #7033

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .build/images/dietpi-imager
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,7 @@
# Move GPT backup partition table to end of drive
elif [[ $PART_TABLE_TYPE == 'gpt' ]]
then
G_DIETPI-NOTIFY 2 'GPT partition table detected, moving GPT backup partition table to end of drive...'
G_AG_CHECK_INSTALL_PREREQ gdisk
G_EXEC_OUTPUT=1 G_EXEC sgdisk -e "$FP_SOURCE"
G_SLEEP 0.5 # Give the root filesystem a little time to be detected
G_DIETPI-NOTIFY 2 'GPT partition table detected'
else
Error_Exit "Unknown partition table type ($PART_TABLE_TYPE), aborting..."
fi
Expand Down Expand Up @@ -512,9 +509,16 @@
# - WARNING: this assumes that the partitions in the table are in order (which we do in other places as well)
local last_part_end=$(sfdisk -qlo End "$FP_SOURCE" | tail -1) # 512 byte sectors
IMAGE_SIZE=$last_part_end
# Add 34 sectors for GPT backup partition table and 1 sector for MBR
# shellcheck disable=SC2015
[[ $PART_TABLE_TYPE == 'gpt' ]] && ((IMAGE_SIZE+=34)) || ((IMAGE_SIZE++))
# Add space for GPT backup partition table, or 1 sector for MBR
if [[ $PART_TABLE_TYPE == 'gpt' ]]
then
# Obtain first usable LBA, which defines the size of the GPT backup, else use 34 sectors as default: https://github.com/MichaIng/DietPi/issues/7024
local gpt_size=$(sgdisk -p "$FP_SOURCE" 2>&1 | mawk -F[\ ,] '/^First usable sector/{print $5}')
# shellcheck disable=SC2015
(( $gpt_size )) && ((IMAGE_SIZE+=$gpt_size)) || ((IMAGE_SIZE+=34))
else
((IMAGE_SIZE++))
fi
((IMAGE_SIZE*=512)) # 512 byte sectors => bytes

# RPi: Move configs to boot FAT partition to allow easier edit from Windows/macOS
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Enhancements:
- DietPi-Software | Snapcast: 64-bit ARM and Debian Bookworm + Trixie will have the now available packages from Snapcast installed, instead of those from the Debian repository.

Bug fixes:
- DietPi-Imager | Resolved an issue where the imager could have failed on GPT partitioned images, if either the source image size did not leave space for the GPT backup partition table, or the first usable LBA/sector was above 34. The GPT backup partition table is now created only at the end of the image generation, not anymore additionally at the start, and the required size it takes is correctly obtained. Many thanks to @SelfhostedPro and @disablewong for reporting this issue: https://github.com/MichaIng/DietPi/issues/7024, https://dietpi.com/forum/t/18035
- DietPi-Software | Snapcast: Resolved an issue where version 0.27.0 was installed, because since version 0.28.0, Snapcast is provided with client and server packages wrapped into one archive, instead having individual downloads for each package.

As always, many smaller code performance and stability improvements, visual and spelling fixes have been done, too much to list all of them here. Check out all code changes of this release on GitHub: https://github.com/MichaIng/DietPi/pull/ADDME
Expand Down