Where does this "Physical size" value come from? Is it part of the partition table?
Yes.
See GUID Partition Table - Wikipedia
Is there any way for me to modify it so as to get rid of the "Unexpected end of data" error?
Yes.
It seems the standard Linux tools know how to fix up a truncated GPT disk.
Creating test-short.img with the same problem
$ dd if=/dev/zero bs=1M count=10 of=test.img 10+0 records in 10+0 records out 10485760 bytes (10 MB, 10 MiB) copied, 0.0161485 s, 649 MB/s $ gdisk test.img GPT fdisk (gdisk) version 1.0.8 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries in memory. Command (? for help): n Partition number (1-128, default 1): First sector (34-20446, default = 2048) or {+-}size{KMGTP}: Last sector (2048-20446, default = 20446) or {+-}size{KMGTP}: 18430 Current type is 8300 (Linux filesystem) Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to test.img. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. $ dd if=test.img bs=1M count=9 of=test-short.img 9+0 records in 9+0 records out 9437184 bytes (9.4 MB, 9.0 MiB) copied, 0.00650826 s, 1.5 GB/s
How to fix the problem
IIUC, you left one empty sector at the end of the image file, which we can use for the "secondary GPT header" (trailer?). Assuming the table has the usual 128 partition entries, you need to add another 32 sectors for those, and then you can fix the problem.
$ dd if=/dev/zero bs=512 count=32 >> test-short.img $ gdisk test-short.img GPT fdisk (gdisk) version 1.0.8 Warning! Disk size is smaller than the main header indicates! Loading secondary header from the last sector of the disk! You should use 'v' to verify disk integrity, and perhaps options on the experts' menu to repair the disk. Caution: invalid backup GPT header, but valid main header; regenerating backup header from main header. Warning! Error 25 reading partition table for CRC check! Warning! One or more CRCs don't match. You should repair the disk! Main header: OK Backup header: ERROR Main partition table: OK Backup partition table: ERROR Partition table scan: MBR: protective BSD: not present APM: not present GPT: damaged **************************************************************************** Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk verification and recovery are STRONGLY recommended. **************************************************************************** Command (? for help): p Disk test-short.img: 18464 sectors, 9.0 MiB Sector size (logical): 512 bytes Disk identifier (GUID): 01BD61C8-5DC3-42CA-824D-B5C1B3B09A77 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 20446 Partitions will be aligned on 2048-sector boundaries Total free space is 4030 sectors (2.0 MiB) Number Start (sector) End (sector) Size Code Name 1 2048 18430 8.0 MiB 8300 Linux filesystem Command (? for help): x Expert command (? for help): e Relocating backup data structures to the end of the disk Expert command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to test-short.img. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.
To confirm that test-short.img was fixed
$ gdisk test-short.img GPT fdisk (gdisk) version 1.0.8 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): p Disk test-short.img: 18464 sectors, 9.0 MiB Sector size (logical): 512 bytes Disk identifier (GUID): 01BD61C8-5DC3-42CA-824D-B5C1B3B09A77 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 18430 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 18430 8.0 MiB 8300 Linux filesystem Command (? for help): q