[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: fdisk head inconsistency
From:       Michael Conrad <mconrad () intellitree ! com>
Date:       2019-10-02 0:14:26
Message-ID: ac588416-3ffc-d270-d29d-b72f984b8b07 () intellitree ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On 10/1/2019 6:58 PM, Mauro Condarelli wrote:
> The former consistently swears I have "Geometry: 245 heads, 62 
> sectors/track, 1021 cylinders",
> while the latter insists on "Geometry: 4 heads, 16 sectors/track, 
> 242560 cylinders".
> Physically the *same* card.
> Of course Debian Linux is accessing the card through a USB card reader 
> (hama a4504143, if it matters), while embedded Linux is accessing it 
> directly via MMC interface present on uController (MT7628)... which 
> could be a significant difference.

I just tried two versions of busybox fdisk (1.19.0, and 1.30.1) vs. two 
versions of util-linux fdisk (2.19, 2.34) and all four tools agree about 
the drive geometry of any drive I've tested on. I think you'll just need 
to do more experiments and see if you can pin down the problem on your end.

> I need to do this in a script and to use BB fdisk I need to print 
> previous partition data and manually set start of next one to 
> prev_end+1. This is "inconvenient" to do in a shell script.
> IMHO one of the two programs is severely broken and I would like to 
> understand which and how to fix it.
> Right now my "solution" is to disable BB fdisk and to install 
> util-linux one, but that, of course, has a cost in a severely 
> constrained embedded system with 16M total Flash space.
>
> Any advice welcome.

Very inconvenient to do in a shell script, I agree :-) and in fact I'd 
advise against parsing fdisk with a shell at all.   The four tools I just 
tested each had a different output format! That's a pretty good 
indication it could change in the future and break your script and blow 
away someone's data.   Also that 'bootable' flag is pretty annoying 
because its presence/absence changes the number of fields on the line.   
There's an "sfdisk" which is better for scripting, but no busybox applet 
for it. Still, it is safer than scripting input for fdisk.

You don't need to give CHS geometry to fdisk, just sector numbers.   You 
can get sector numbers direct from the kernel using 
/sys/class/block/$DEV/start and /sys/class/block/$DEV/size.   (or on old 
kernels, /sys/block/$DEV/$PART_DEV/{start,size} ).   You could then 
construct a script for fdisk and pipe that in.   Of course, this depends 
on the kernel having read the partition table, which might not be the 
case if you're formatting something from scratch, but there's 
'partprobe' for that.   You also have to worry about what kind of 
partition table it is, because the kernel can parse GPT partitions and 
then if you try forcibly adding a new one with fdisk it might blow away 
the GPT table.   I just checked, and 'gdisk' isn't available from busybox 
yet... so there might not be a safe way to do this with pure busybox tools.

Hope that helps.

-Mike



[Attachment #5 (text/html)]

<html><body>
<p>On 10/1/2019 6:58 PM, Mauro Condarelli wrote:</p>
<blockquote><p>The former consistently swears I have &ldquo;Geometry: 245 heads, 62 \
sectors/track, 1021 cylinders&rdquo;, while the latter insists on &ldquo;Geometry: 4 \
heads, 16 sectors/track, 242560 cylinders&rdquo;. Physically the \
<strong>same</strong> card. Of course Debian Linux is accessing the card through a \
USB card reader (hama a4504143, if it matters), while embedded Linux is accessing it \
directly via MMC interface present on uController (MT7628)&hellip; which could be a \
significant difference.</p></blockquote> <p>I just tried two versions of busybox \
fdisk (1.19.0, and 1.30.1) vs. two versions of util-linux fdisk (2.19, 2.34) and all \
four tools agree about the drive geometry of any drive I've tested on. I think you'll \
just need to do more experiments and see if you can pin down the problem on your \
end.</p> <blockquote><p>I need to do this in a script and to use BB fdisk I need to \
print previous partition data and manually set start of next one to prev_end+1. This \
is &ldquo;inconvenient&rdquo; to do in a shell script. IMHO one of the two programs \
is severely broken and I would like to understand which and how to fix it. Right now \
my &ldquo;solution&rdquo; is to disable BB fdisk and to install util-linux one, but \
that, of course, has a cost in a severely constrained embedded system with 16M total \
Flash space.</p> <p>Any advice welcome.</p></blockquote>
<p>Very inconvenient to do in a shell script, I agree <span \
class="smiley-happy">:-)</span> and in fact I'd advise against parsing fdisk with a \
shell at all.   The four tools I just tested each had a different output format! \
That's a pretty good indication it could change in the future and break your script \
and blow away someone's data.   Also that &lsquo;bootable&rsquo; flag is pretty \
annoying because its presence/absence changes the number of fields on the line.   \
There's an &ldquo;sfdisk&rdquo; which is better for scripting, but no busybox applet \
for it. Still, it is safer than scripting input for fdisk.</p> <p>You don't need to \
give CHS geometry to fdisk, just sector numbers.   You can get sector numbers direct \
from the kernel using /sys/class/block/$DEV/start and /sys/class/block/$DEV/size.   \
(or on old kernels, /sys/block/$DEV/$PART_DEV/{start,size} ).   You could then \
construct a script for fdisk and pipe that in.   Of course, this depends on the \
kernel having read the partition table, which might not be the case if you're \
formatting something from scratch, but there's &lsquo;partprobe&rsquo; for that.   \
You also have to worry about what kind of partition table it is, because the kernel \
can parse GPT partitions and then if you try forcibly adding a new one with fdisk it \
might blow away the GPT table.   I just checked, and &lsquo;gdisk&rsquo; isn't \
available from busybox yet&hellip; so there might not be a safe way to do this with \
pure busybox tools.</p> <p>Hope that helps.</p>
<p>-Mike</p>

<img src="https://u8477214.ct.sendgrid.net/wf/open?upn=dCCleNsAjkncO-2BKmpSXMox0Zzgog5 \
t6r-2BJ2aTvk-2FwJqXrCLaJ6B3dygMPOpv7-2B9gYCLcvZSL8TEfbXMLdXq48QP-2B-2FUmwpobwzxQdTx1o2 \
lpbPL4KTAO5OuzjB6A8dr6QUu7WKZYM3e5R0awPbwF-2BqiKf-2BAgXkjZMBumJk4smSHahWbEcsQvXvFiIOWG1HJAA6ormqQZOdNiMX1XsDdDmQidsXh3ztMOSmE5hVUp7NOo-3D" \
alt="" width="1" height="1" border="0" style="height:1px !important;width:1px \
!important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 \
!important;margin-right:0 !important;margin-left:0 !important;padding-top:0 \
!important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 \
!important;"/> </body></html>



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic