1

I have a sparse backing file (NTFS) (made via dd seek=) that's a partial image of a damaged disk. The size as given by ls matches the original disk. However, when looping it, /proc/partitions shows it as about half the size as the original disk. It seems like losetup is ignoring the final sparse extend of the file because it has no data following it.

As a result, if I use losetup -P (or kpartx) the partitioning fails on a partition extending past the size given by /proc/partitions.

How can I resolve this without expanding the file? (Perhaps writing to the last sector will help, but I would like to avoid touching the image).

More info:

cat /proc/partitions (for the loop and the disk):

 7        5  264173760 loop5
 8        0  488386584 sda

stat on the backing file:

  File: gordon.dsk
  Size: 500107862016    Blocks: 31986416   IO Block: 4096   regular file

lsblk --bytes:

loop5       7:5    0  270513930240  1 loop
sda         8:0    0  500107862016  0 disk

sfdisk output:

The backup GPT table is corrupt, but the primary appears OK, so that will be used.
Disk gordon.dsk: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: {redacted}

Device          Start       End   Sectors   Size Type
gordon.dsk1      2048   1230847   1228800   600M Windows recovery environment
gordon.dsk2   1230848   1845247    614400   300M EFI System
gordon.dsk3   1845248   2107391    262144   128M Microsoft reserved
gordon.dsk4   2107392 944205823 942098432 449.2G Microsoft basic data
gordon.dsk5 944205824 976773119  32567296  15.5G Windows recovery environment
  • Please add more details (ls -l file, sfdisk -l file, /proc/partitions, etc). Maybe you didn't extend it enough? notice that dd uses 512 bytes blocks. – mosvy Oct 25 '18 at 20:38
  • I don't know this problem, but can you post your kernel version (uname -r) please? – sourcejedi Oct 25 '18 at 21:30
  • add the output of sfdisk -l your_backing_file too (sfdisk doesn't need a device, also works with regular files). – mosvy Oct 25 '18 at 21:33
  • @mosvy I already allocated the last sector as a workaround, but I believe it showed all the relevant partitions beforehand... – afuna Oct 25 '18 at 22:03
  • @sourcejedi 4.15.0-36-generic – afuna Oct 25 '18 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.