Bug 195174 - bsdinstall(8) does not align partitions at 4k (or more)
Summary: bsdinstall(8) does not align partitions at 4k (or more)
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.1-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Allan Jude
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-19 19:08 UTC by Mark.Martinec
Modified: 2016-07-21 13:36 UTC (History)
11 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark.Martinec 2014-11-19 19:08:05 UTC
Mark Martinec wrote (2014-10-10):
  https://lists.freebsd.org/pipermail/freebsd-stable/2014-October/080509.html

An install of a 10.1 from an installation ISO DVD. Apart from
choosing a ZFS filesystem, other options were left to their default.
In particular, the align-to-4k ZFS options was left enabled.

The ZFS really ended up with ashift 12, but neither the swap
nor the zfs partition is 4k aligned:

# gpart show /dev/ada0
=>       34  625142381  ada0  GPT  (298G)
          34       1024     1  freebsd-boot  (512K)
        1058    8388608     2  freebsd-swap  (4.0G)
     8389666  616752749     3  freebsd-zfs  (294G)

I find this unacceptable and surprising,
regardless of what the underlying media is.


Patrick M. Hausen wrote (2014-11-19):
  https://lists.freebsd.org/pipermail/freebsd-stable/2014-November/081080.html

I just installed a new machine with 10.1-RELEASE using the memstick
installer and chosing ZFS mirror root as the disk layout.

I did check the "4k" option, watched the installer do the necessary
gnop dance and the pool seems to be OK:
[...]
But this puzzles me a bit:
None of the start sector numbers is a multiple of 8, neither are
the end sectors a multiple of 8 minus 1.
So the pool uses a 4k block size but it starts on an odd multiple
of 2k on the platter - do I see this correctly?
[...]


In summary:

- the bsdinstall should align GPT partition as a bare minimum
  at a 4k boundaries regardless of the underlying media;

- in my opinion the first (freebsd-boot) partition should be
  aligned at 512kB with a size of 512kB, and all following
  GPS partitions should be aligned at 1 MB by default.
Comment 1 petrek729 2015-01-03 08:32:41 UTC
I have the same problem, what's more, with this setting the swap partition is not configured correctly, after rebooting the installer, swapon fails complaining it can't find ada0p2 at all although "gpart show" confirms it's where it should be. Swap works with auto partitioning if No for 4K is set.
Comment 3 Allan Jude freebsd_committer 2015-02-06 00:19:52 UTC
(In reply to Devin Teske from comment #2)

The change to vfs.zfs.min_auto_ashift=12 only affects ZFS (it is the replacement for gnop), it does not change the actual partition alignment (controlled with the -a flag when using gpart add)

the zfsboot code will need to be modified to use -a 4k or -a 1m when creating the non-boot partitions. I am not sure what the correct way to handle this is for MBR though.
Comment 4 timp87 2015-02-10 10:46:33 UTC
There is even a thread on forum.
https://forums.freebsd.org/threads/freebsd-10-failed-installing-on-zfs-root.45049/
Comment 5 Mark.Martinec 2015-06-23 15:19:58 UTC
Any chance of fixing installer's gpart partition alignment problem
in time for 10.2 ?  It should do something like:

gpart add -t freebsd-boot -a 512k -s 512k da0
gpart add -t freebsd-swap -a 1m -s 2g     da0
gpart add -t freebsd-zfs  -a 1m           da0
Comment 6 timp87 2015-06-23 15:36:55 UTC
(In reply to Mark.Martinec from comment #5)
Why 1m?
I hope it will be fixed before 10.2, but I think it won't
Comment 7 Kurt Jaeger freebsd_committer 2015-06-23 16:00:12 UTC
1m for the 4k alignment in any corner case, as far as I understand.
Comment 8 Mark.Martinec 2015-06-23 16:36:54 UTC
The only waste when aligning the boot partition at 512k (1024 blocks)
instead of 4k (40 blocks) is 492 kilobytes wasted. All partitions
that follow will be 1M aligned with no waste (assuming boot partition
is 512kB in size, which seems to be a recommended size nowadays).

I think that we are way past the times where one would care for a
wasted 0.48 MB on a disk (1024-40)*512./1024/1024. Those that build
appliances on microcontrollers have other worries anyway and do not
care for bsdinstall.

1MB alignment is beneficial for SSD devices, some of which do not
care to report physical sector size. Consider also tiny computers
that run off an SD card or USB key. And 0.48 MB wasted on a
spinning disk seems like a non-issue to me.

Even Microsoft is now aligning all partitions at 1MB, regardless
of the underlying media (according to Wikipedia).
Comment 9 Kurt Jaeger freebsd_committer 2015-06-23 17:15:31 UTC
ping'ed to re to fix for 10.2-REL
Comment 10 Allan Jude freebsd_committer 2015-07-12 20:23:48 UTC
(In reply to petrek729 from comment #1)

The swap issue was an unrelated bug having to do with geom_label's disk_ident type stealing the device and not making it accessible via the gpt label.

It was fixed here: https://svnweb.freebsd.org/base?view=revision&revision=r266107

By using /dev/$disk$swappart instead of /dev/gpt/swap$index
Comment 11 Allan Jude freebsd_committer 2015-07-12 21:27:48 UTC
I have created a patch to align to 4k for the boot partition (not really necessary) and 1mb for the swap/zfs partitions.

I am slightly concerned about aligning MBR to 4k, because of the way the bootloader is stuffed into the partition. Aligning the partitions caused the machine to not boot correctly, however aligning the BSD partition table inside the MBR first, seems to work.


The patch is currently awaiting review: https://reviews.freebsd.org/D3062
Comment 12 commit-hook freebsd_committer 2015-07-14 19:57:18 UTC
A commit references this bug:

Author: allanjude
Date: Tue Jul 14 19:57:11 UTC 2015
New revision: 285557
URL: https://svnweb.freebsd.org/changeset/base/285557

Log:
  Make bsdinstall's zfsboot script align partitions to 4k/1m when the user requests it

  PR:		195174
  Reviewed by:	darius
  Approved by:	brueffer
  MFC after:	3 days
  Relnotes:	yes
  Sponsored by:	ScaleEngine Inc.
  Differential Revision:	https://reviews.freebsd.org/D3062

Changes:
  head/usr.sbin/bsdinstall/scripts/zfsboot
Comment 13 commit-hook freebsd_committer 2015-07-20 16:18:18 UTC
A commit references this bug:

Author: allanjude
Date: Mon Jul 20 16:17:44 UTC 2015
New revision: 285721
URL: https://svnweb.freebsd.org/changeset/base/285721

Log:
  MFC:	r285482
  	A variable was misspelled resulting in chmod executing on the installer instead of on the target chroot

  PR:	191402

  MFC:	r285553
  	make /var/audit its own dataset so it is not part of the OS boot environment

  PR:	199864

  MFC:	r285554
  	Set a mountpoint on the root of the pool so user-created datasets have a mountpoint to inherit

  MFC:	r285557
  	Make bsdinstall's zfsboot script align partitions to 4k/1m when the user requests it

  PR:	195174

  Approved by:	re (gjb), brueffer
  Relnotes:	yes
  Sponsored by:	ScaleEngine Inc.

Changes:
_U  stable/10/
  stable/10/usr.sbin/bsdinstall/scripts/zfsboot
Comment 14 Will Green 2015-07-27 23:01:01 UTC
Been experimenting with 10.2-RC1 and this seems to work as expected. :)
Comment 15 Dron 2016-07-20 09:42:39 UTC
Hello.
FreeBSD 10.3 - UFS auto partitioning not aligning partitions, manual partitioning not aligning partitions. Tried on GPT, but think MBR have same issue.
Comment 16 Mark.Martinec 2016-07-21 13:36:46 UTC
(In reply to Dron from comment #15)

Indeed, a 10.3 install specifying UFS on GPT
does *not* align partitions on 4k. Here is a result:

=>       34  125829053  ada0  GPT  (60G)
         34       1024     1  freebsd-boot  (512K)
       1058  119536640     2  freebsd-ufs  (57G)
  119537698    6291388     3  freebsd-swap  (3.0G)
  125829086          1        - free -  (512B)


On the other hand, the FreeBSD-11.0 got it (mostly) right:

Installing FreeBSD-11.0-BETA1-amd64-disc1.iso
on VirtualBox, specifying UFS and GPT:

  Auto (UFS) - Guided Disk Setup
  <Entire Disk>
  GPT - GUID Partition Table

*does* get partitions 4k aligned:

$ gpart show
=>       40  125829040  ada0  GPT  (60G)
         40       1024     1  freebsd-boot  (512K)
       1064  119536640     2  freebsd-ufs  (57G)
  119537704    6291375     3  freebsd-swap  (3.0G)
  125829079          1        - free -  (512B)

It would still be nicer to have freebsd-ufs and freebsd-swap partitions
aligned on 1 MB, the same as with a ZFS install - there is no reason
for a UFS/GPT to align partitions differently from ZFS/GPT.