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

fdisk/sfdisk: creates scripts that don't work #830

Closed
smurfix opened this issue Jul 28, 2019 · 2 comments
Closed

fdisk/sfdisk: creates scripts that don't work #830

smurfix opened this issue Jul 28, 2019 · 2 comments

Comments

@smurfix
Copy link

smurfix commented Jul 28, 2019

Cf. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=931087

I have created a GPT-partitioned image where the first partition
needs to start at block 64. The problem is that fdisk/sfdisk is unable to
replicate this partition layout using an sfdisk script, because the
generated script doesn't work when it's read back in.

This seems to be a problem with interpreting the "table-length" value.
It appears to be multiplied by 4 instead of divided by 4 when checking
sector limits.

# ls -l /tmp/bmb_root
-rw-r--r-- 1 smurf smurf 1170228224 Jun 25 22:16 /tmp/bmb_root
# bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
1170228224/512-34
2285568

# cat /tmp/lb  ### minimum/maximum working LBA values
label: gpt
label-id: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C
device: /tmp/bmb_root
unit: sectors
table-length: 8
first-lba: 34
last-lba: 2285568

# sfdisk /tmp/bmb_root </tmp/lb
Checking that no-one is using this disk right now ... OK

Disk /tmp/bmb_root: 1,1 GiB, 1170228224 bytes, 2285602 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: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C

Created a new GPT disklabel (GUID: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C).
Partition table length changed from 128 to 8.

New situation:
Disklabel type: gpt
Disk identifier: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C

# sfdisk -d /tmp/bmb_root 
label: gpt
label-id: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C
device: /tmp/bmb_root
unit: sectors
first-lba: 4
last-lba: 2285598
table-length: 8
# 

Note the shifting "last-lba" value.

@smurfix
Copy link
Author

smurfix commented Nov 8, 2021

Umm, nobody has looked into this? Owch.

@karelzak
Copy link
Collaborator

karelzak commented Nov 10, 2021

Sorry for the delay. It works for me, tested with v2.37.2 and the current upstream too:

# dd if=/dev/zero of=~/img bs=512 count=2285602
1170228224 bytes (1.2 GB, 1.1 GiB) copied, 3.08157 s, 380 MB/s

# cat ~/gpt
label: gpt
label-id: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C
device: /tmp/bmb_root
unit: sectors
table-length: 8
first-lba: 34
last-lba: 2285568

# sfdisk ~/img < ~/gpt
Checking that no-one is using this disk right now ... OK

Disk /root/img: 1.09 GiB, 1170228224 bytes, 2285602 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

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Done.
Created a new GPT disklabel (GUID: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C).
The maximal number of partitions is 8 (default is 128).

New situation:
Disklabel type: gpt
Disk identifier: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C

The partition table has been altered.
Syncing disks.

# sfdisk -d ~/img
label: gpt
label-id: 3C0E3DAC-3069-354E-BA0E-CB74029F5A5C
device: /root/img
unit: sectors
first-lba: 34
last-lba: 2285568
table-length: 8
sector-size: 512

I guess it's fixed since commit fb64d93.

Thanks for your report and patience :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants