0

I made an image of /dev/sdc. The free space before the first partition isn't reporting the same byte sizes, but why?

The start position is reported as 1024B on the drive and 16384B on the image?

# parted /dev/sdc u b p free
Model: ASMT 2105 (scsi)
Disk /dev/sdc: 500107862016B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start     End            Size           Type     File system  Flags
        1024B     1048575B       1047552B                Free Space
 1      1048576B  500107862015B  500106813440B  primary  btrfs


                                                                          
# parted d1/drive1.sdc.img u b p free
Model:  (file)
Disk /mnt/4/d1/drive1.sdc.img: 500107862016B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start     End            Size           Type     File system  Flags
        16384B    1048575B       1032192B                Free Space
 1      1048576B  500107862015B  500106813440B  primary  btrfs

Edit: I created the image like so

# pv /dev/sdc > d1/drive1.sdc.img

Edit2: After running md5sum on both, they show same hash

# dd if=/dev/sdc | md5sum; pv d1/drive1.sdc.img | md5sum
2
  • Just to rule it out as a factor, could you edit your question to include how you created the image. Jul 31, 2021 at 8:28
  • In the partition table there is no actual entry for free space. In general free space is what is not allocated to any partition, except some sectors at the beginning (and sometimes at the end) are or may be used for different things (including the partition table itself), while not being formally allocated to any partition. It seems parted guesses how many such sectors may be there; it does this differently in both cases. I don't know why and therefore it's not an answer. IMO what you observed is a quirk of the the tool. Jul 31, 2021 at 18:37

1 Answer 1

1

This is nothing to worry about, this is just parted not being able to get the "disk" geometry because it's not a disk but a file. If you create a loop file from the image, the free space start should be the same.

With the disk image file:

(parted) p free                                                           
Model:  (file)
Disk /home/vtrefny/disk.img: 104857600B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End         Size        Type  File system  Flags
        16384B  104857599B  104841216B        Free Space

With a loop device:

(parted) p free                                                           
Model: Loopback device (loopback)
Disk /dev/loop2: 105MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type  File system  Flags
        1024B  105MB  105MB        Free Space

Internally parted creates a "fake" metadata partition at the start (and end for GPT) of the disk to protect the partition table from being overwritten when creating a new partition. First free space starts after this metadata partition. AFAICT for disks size of this metadata partition is calculated as 1 + sector_size / 512 sectors (2 sectors for 512 B sector size disks) and hardcoded to 32 sectors (= 16 KiB/16384 B) for files (I might be wrong here, this is result of me staring into parted code and playing with pyparted).

In general, when creating a partition its start is aligned for optimal performance and things like sector size, optimal IO size or grain size of the disk are taken into account and tools like parted and fdisk sometimes show the "free space" already aligned (even with a "real" disk, fdisk will print the start of the free space as 1 MiB instead of 1 KiB shown by parted).

4
  • TL;DR. Avoid parted. It does crazy stuff.
    – Tom Yan
    Aug 1, 2021 at 5:16
  • @Tom Yan If not using parted, then what?
    – Rucent88
    Aug 1, 2021 at 7:01
  • @Rucent88 fdisk / gdisk.
    – Tom Yan
    Aug 1, 2021 at 7:07
  • I also prefer fdisk but I don't think parted is bad. Some stuff around GPT and flags is kinda weird, but in general it is a good tool. But from a programmer pow I definitely like libfdisk more than libparted. Aug 1, 2021 at 7:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .