I have a 64GB SD card with Linux (Debian) installed on it. I want to move it to a smaller SD Card (16 GB).
I used resize2fs and cfdisk to resize the filesystem and partitions, so that now, they look like this:
Disk /dev/rdisk4: 122519552 sectors, 58.4 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): C133B5DA-A507-4080-8DBC-9FAD0E960A17
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 122519518
Partitions will be aligned on 2048-sector boundaries
Total free space is 93159357 sectors (44.4 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 1050623 512.0 MiB EF00
2 1050624 7342079 3.0 GiB 8200
3 7342080 15730687 4.0 GiB 8300
4 15730688 29362175 6.5 GiB 8300
Now, I want to take an image of it with dd.
According to this: https://en.wikipedia.org/wiki/GUID_Partition_Table The GPT backup header is the last 33 sectors. The last sector in use by my last partition is 29362175. As far as I can tell, sectors start at 0, so that's a total of 29362176 sectors, plus the 33 sectors for the GPT backup headers.
In the end, I would expect a command like this to work:
sudo dd if=/dev/rdisk4 of=disk4_backup.img bs=512 count=29362209
When I run that, the resulting disk4_backup.img is the size I expect (15033451008 bytes), but when I run gdisk on it:
gdisk disk4_backup.img
It tells me that the GPT backup header is corrupted. I'm pretty sure I can just get gdisk to fix it using the primary GPT header, but why can't I back up the backup-header in the first place? Is my math wrong? Are my assumptions about where the GPT backup header lies wrong?
Note: gdisk does NOT complain about my original 64 GB SD card with resized partitions. It's happy with the GPT headers on it.