Re: efi msdos puzzle

2019-09-10 Thread Michael van Elst
pr...@cam.ac.uk (Patrick Welche) writes:

>gpt add -a 4k -l efi0 -s 525256 -t efi wd0

Some other things.

Since your disk is using 512 byte logical blocks, you can chose smaller
clusters and thus a smaller filesystem. Performance for the EFI partition
isn't really a requirement, in particular for reading.

Microsoft requests a minimum EFI partition size of 100MB. Otherwise
Windows installation or recovery may fail. Others recommend at least 500MB.
It is possible that some UEFI code follows such recommendations and fails
to recognize an otherwise valid partition.

Even when none of the caveats matter, some free space comes handy, e.g. if
you want to keep multiple kernels or a multi-boot environment.

Greetings,
-- 
-- 
Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: efi msdos puzzle

2019-09-10 Thread Michael van Elst
pr...@cam.ac.uk (Patrick Welche) writes:

>gpt add -a 4k -l efi0 -s 525256 -t efi wd0

With 2 FATs.

4 + 64 * 2 + 65525 * 1 = 65657 4k sectors (or 525256 0.5k sectors).

-- 
-- 
Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: efi msdos puzzle

2019-09-10 Thread Michael van Elst
pr...@cam.ac.uk (Patrick Welche) writes:

>(https://en.wikipedia.org/wiki/File_Allocation_Table#FAT32
>suggests:
>Min. volume size   256 MiB-36 KiB (with 65525 clusters and 4 KiB sectors)

>maybe that should be a '+' sign...)

The image consists of:

- reserved sectors (e.g. boot sector, info sector)
- FAT sectors * FAT replication count
- data clusters

Minimal reserved sectors are 16kByte or 4 sectors.

A FAT32 needs 4 bytes per entry, for 65525 clusters (plus 2 reserved entries)
it needs 64 sectors.

Minimal FAT replication count is 1.

Minimal cluster size is one sector.

-> 4 + 1 * 64 + 65525 * 1 = 65593 sectors or 262372 KiB.

% newfs_msdos -F 32 -n 1 -S 4096 -b 4096 -s 65593 -C 262372k fat32image
fat32image: 65525 sectors in 65525 FAT32 clusters (4096 bytes/cluster)
MBR type: 11
bps=4096 spc=1 res=4 nft=1 mid=0xf0 spt=63 hds=255 hid=0 bsec=65593 bspf=64 
rdcl=2 infs=1 bkbs=2

% fsck_msdos -f fat32image
** fat32image
Invalid signature in fsinfo blockfix? [yn] y

% fsck_msdos -f fat32image
** fat32image
** Phase 1 - Read and Compare FATs
** Phase 2 - Check Cluster Chains
** Phase 3 - Checking Directories
** Phase 4 - Checking for Lost Files
1 files, 262096 free (65524 clusters)

One cluster (one sector) is already used by the root directory.

The 65525 cluster minimum is pretty artificial because FAT16 is
good enough for up to 65524 clusters.

More at:
https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system

-- 
-- 
Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: efi msdos puzzle

2019-09-10 Thread Patrick Welche
On Mon, Sep 09, 2019 at 05:53:03PM +0100, Patrick Welche wrote:
> On Mon, Sep 09, 2019 at 11:23:49AM -0500, Jonathan A. Kollasch wrote:
> > On Mon, Sep 09, 2019 at 04:58:01PM +0100, Patrick Welche wrote:
> > > gpt add -a 1024k -l efi0 -s 256M -t efi wd0   (on -current/amd64)
> > > 
> > > dk0: efi0, 524288 blocks at 2048, type: msdos
> > > 
> > > # newfs_msdos -F 32 -b 4096 /dev/rdk0
> > > newfs_msdos: 65404 clusters too few clusters for FAT32, need 65525
> > > 
> > > but 65525 * 8 = 524200 < 524288 ?
> > > 
> > > Where does 65404 come from?
> > > 
> > 
> > The FATs and various other FS internal data structures take space,
> > apparently to the tune of 132 clusters, or 1056 sectors, or 540672 bytes.
> > 
> > A 32-bit FAT for up to 65408 clusters is 511 sectors, FAT32 keeps a
> > duplicate copy of the fat, so you're up to 1022 sectors used already.
> > 
> > There's also the boot sector and it's backup, the file system
> > information block(s?), any reserved sectors, and I forget how
> > it worked on FAT32 (it's different than FAT16/12) but maybe also the
> > root directory entries.
> > 
> > The bit-width of the FAT is a function of the number of data clusters,
> > you'll just end up getting failures like this if you specify any more
> > than two of the partition/FS size, the cluster size, and the FAT width.
> > 
> > Microsoft was helpful enough to publish the FAT spec specifically for
> > use in the EFI context.
> 
> Thanks - I'll experiment to find the magic number!

gpt add -a 4k -l efi0 -s 525256 -t efi wd0

seems to be the minimum...


Cheers,

Patrick


Re: efi msdos puzzle

2019-09-09 Thread Patrick Welche
On Mon, Sep 09, 2019 at 11:23:49AM -0500, Jonathan A. Kollasch wrote:
> On Mon, Sep 09, 2019 at 04:58:01PM +0100, Patrick Welche wrote:
> > gpt add -a 1024k -l efi0 -s 256M -t efi wd0   (on -current/amd64)
> > 
> > dk0: efi0, 524288 blocks at 2048, type: msdos
> > 
> > # newfs_msdos -F 32 -b 4096 /dev/rdk0
> > newfs_msdos: 65404 clusters too few clusters for FAT32, need 65525
> > 
> > but 65525 * 8 = 524200 < 524288 ?
> > 
> > Where does 65404 come from?
> > 
> 
> The FATs and various other FS internal data structures take space,
> apparently to the tune of 132 clusters, or 1056 sectors, or 540672 bytes.
> 
> A 32-bit FAT for up to 65408 clusters is 511 sectors, FAT32 keeps a
> duplicate copy of the fat, so you're up to 1022 sectors used already.
> 
> There's also the boot sector and it's backup, the file system
> information block(s?), any reserved sectors, and I forget how
> it worked on FAT32 (it's different than FAT16/12) but maybe also the
> root directory entries.
> 
> The bit-width of the FAT is a function of the number of data clusters,
> you'll just end up getting failures like this if you specify any more
> than two of the partition/FS size, the cluster size, and the FAT width.
> 
> Microsoft was helpful enough to publish the FAT spec specifically for
> use in the EFI context.

Thanks - I'll experiment to find the magic number!

(https://en.wikipedia.org/wiki/File_Allocation_Table#FAT32
suggests:
Min. volume size   256 MiB-36 KiB (with 65525 clusters and 4 KiB sectors)

maybe that should be a '+' sign...)


Cheers,

Patrick


Re: efi msdos puzzle

2019-09-09 Thread Jonathan A. Kollasch
On Mon, Sep 09, 2019 at 04:58:01PM +0100, Patrick Welche wrote:
> gpt add -a 1024k -l efi0 -s 256M -t efi wd0   (on -current/amd64)
> 
> dk0: efi0, 524288 blocks at 2048, type: msdos
> 
> # newfs_msdos -F 32 -b 4096 /dev/rdk0
> newfs_msdos: 65404 clusters too few clusters for FAT32, need 65525
> 
> but 65525 * 8 = 524200 < 524288 ?
> 
> Where does 65404 come from?
> 

The FATs and various other FS internal data structures take space,
apparently to the tune of 132 clusters, or 1056 sectors, or 540672 bytes.

A 32-bit FAT for up to 65408 clusters is 511 sectors, FAT32 keeps a
duplicate copy of the fat, so you're up to 1022 sectors used already.

There's also the boot sector and it's backup, the file system
information block(s?), any reserved sectors, and I forget how
it worked on FAT32 (it's different than FAT16/12) but maybe also the
root directory entries.

The bit-width of the FAT is a function of the number of data clusters,
you'll just end up getting failures like this if you specify any more
than two of the partition/FS size, the cluster size, and the FAT width.

Microsoft was helpful enough to publish the FAT spec specifically for
use in the EFI context.

Jonathan Kollasch