Fedora Installer trying to format my EFI partition when I didn't tell it to


No matter how I configure the install, it is saying that it will format sda1 as the EFI partition. Yes, sda1 is my EFI partition but because Fedora recommends a large EFI partition I already created sda7 and even mounted it as /boot/efi. I don’t want to format sda1.

Fedora installation and the installer is underwhelming. It’s not as safe and working as Windows. The Anaconda installer lacks proper partition management like gparted (and Anaconda is the only thing running on Atomic), encountered bugs which resulted in failure of installation with some configuration on Atomic (reported to Bugzilla), couldn’t boot my Atomic installation by default because I didn’t do the mount points as required which wasn’t intuitive, and out of all you really had code it as a web app and use python. Basic performance is underwhelming, but I’ll let it pass as you don’t go using an installer frequently.

Some one should properly document how to install Fedora and Fedora Atomic completely from the command line. Or create a quick TUI.

That is a great idea, I would use those instructions.

That sounds like this bug: 2436310 – UI: Misleading "Format as EFI" label at the review and install step when insalling as "share disk with another operating system"

Doing some testing, The text “format as efi” is shown whether the efi partition is created as a new partition or if an existing efi partition is used without being (re)formatted. If an existing efi partiton is considered too small, a new efi partiton is created with the same text shown.

If it is creating another EFI partition on the same disk, that might be another bug. The Boot Loader Specification indicates that there should only be one EFI partition per disk.

I have something like that in my notes, but it is for installing Fedora Linux on ZFS. FWIW, I can share it here. :slightly_smiling_face:

Guide

Boot a Fedora Linux live image and start a terminal session.

# become root

sudo -i

# locate at least two identical drives to be partitioned and formatted

lsblk --nodeps --paths -o name,size,model

# erase all the partitions and filesystems from the disks

wipefs -a /dev/sda
wipefs -a /dev/sdb

# install the gdisk package which provides the sgdisk (scripted-gdisk) command

dnf install -y gdisk

# on each disk, create two partitions – the first partition will be the ESP and the second will be for ZFS

sgdisk -n 0:0:+4GiB -t 0:ef00 -c 0:"boot@a" /dev/sda
sgdisk -n 0:0:0 -t 0:8304 -c 0:"root@a" /dev/sda
sgdisk -n 0:0:+4GiB -t 0:ef00 -c 0:"boot@b" /dev/sdb
sgdisk -n 0:0:0 -t 0:8304 -c 0:"root@b" /dev/sdb

# verify that things look right so far

lsblk -Q 'TYPE=="part"' --paths -o name,size,parttypename,partlabel
NAME        SIZE PARTTYPENAME         PARTLABEL
/dev/sda1     4G EFI System           boot@a
/dev/sda2 890.3G Linux root (x86-64)  root@a
/dev/sdb1     4G EFI System           boot@b
/dev/sdb2 890.3G Linux root (x86-64)  root@b

# format the ESPs with the VFAT filesystem

mkfs.vfat /dev/sda1
mkfs.vfat /dev/sdb1

# if df -h /run shows a size less than 3G, increase it.

[[ $(($(findmnt -nbo size /run)/10**9)) -lt 3 ]] && mount -o remount,size=3G /run

# remove the deprecated zfs-fuse package if it is installed

rpm -e --nodeps zfs-fuse

# download and install the latest zfs-release repo and OpenPGP certificate

git clone --no-checkout --depth 1 https://github.com/zfsonlinux/zfsonlinux.github.com/ ~/zfs-release
cd ~/zfs-release
git restore --staged fedora && git restore fedora
source /etc/os-release
find ~/zfs-release \
	| grep "zfs-release-[0-9]\+-[0-9]\+.fc${VERSION_ID}.noarch.rpm" \
	| sort | tail -n 1 | xargs -r dnf install -y

# install and activate zfs

dnf install -y --repo=fedora kernel-devel
dnf install -y zfs
modprobe zfs

# generate a random hostid (stored at /etc/hostid)

zgenhostid

# format the remaining partitions with ZFS

PROPS=(
	-o ashift=12
	-O mountpoint=none
	-O acltype=posix
	-O canmount=off
	-O compression=on
	-O dnodesize=auto
	-O relatime=on
	-O xattr=sa
)
zpool create -f -R /mnt "${PROPS[@]}" root mirror /dev/disk/by-partlabel/root@{a,b}

# verify that the ZFS pool looks correct

zpool list -v

# create a new filesystem on the ZFS pool and mount it

zfs create -o canmount=noauto -o mountpoint="/" root/0
zfs mount root/0

# verify that the new ZFS root filesystem is mounted at /mnt

findmnt /mnt
TARGET SOURCE FSTYPE OPTIONS
/mnt   root/0 zfs    rw,relatime,seclabel,xattr,posixacl,casesensitive

# set up a chroot environment for the OS installation

ALTROOT=/mnt
BINDMNT=(dev proc sys run)
for i in "${BINDMNT[@]}"; do
	mount -o X-mount.mkdir=755 --rbind "/$i" "$ALTROOT/$i"
	mount --make-rslave "$ALTROOT/$i"
done
mount -o X-mount.mkdir=755 --bind "/tmp" "$ALTROOT/tmp"

# define a list of packages to be excluded from the installation

XXX=(
	grub2-\*
	os-prober
	dracut-config-rescue
	zfs-fuse
	avahi
)

# common parameters for the next few dnf runs

PARAMS=(
	-y
	--use-host-config
	--installroot=/mnt
	--repo=fedora
	--releasever=${VERSION_ID:?}
)

# install Fedora Linux on the new ZFS filesystem

dnf "${PARAMS[@]}" "${XXX[@]/*/--exclude=&}" group install core

# make sure the excluded packages are blocked from future installation

(
	IFS=','
	chroot /mnt env LANG=C dnf config-manager setopt "excludepkgs=${XXX[*]}"
)

# set a password for the root account

chroot /mnt passwd root

# for server installations, show the service OK/FAILED status on boot-up

dnf "${PARAMS[@]}" install plymouth-theme-script
chroot /mnt plymouth-set-default-theme details

# remove old/invalid UEFI boot entries

dnf "${PARAMS[@]}" install efibootmgr
for i in $(efibootmgr | grep -i '^boot[0-9a-f]\{4\}' | cut -c 5-8); do
	efibootmgr -b "$i" -B
done

# remove any content that might have been copied to /boot

rm -rf /mnt/boot/*

# mount the first ESP under the new OS’s mountpoint

MNT_OPTS=(
	dmask=0077
	fmask=0177
	context=system_u:object_r:boot_t:s0
	shortname=lower
	flush
	discard
	noexec
	nodev
	nosuid
	nosymfollow
)
mkdir /mnt/boot@a
(
	IFS=','
	mount -o "${MNT_OPTS[*]:?}" /dev/sda1 /mnt/boot@a
)
mount -o bind /mnt/boot@a /mnt/boot

# install and configure systemd-boot

dnf "${PARAMS[@]}" install systemd-boot-unsigned
chroot /mnt bootctl install --graceful --no-variables --esp-path=/boot
cat << END > /mnt/etc/kernel/cmdline
root=zfs:root/0 quiet rhgb
END
cat << END > /mnt/etc/kernel/install.conf
layout=bls
BOOT_ROOT=/boot
END
cat << 'END' > /mnt/etc/kernel/install.d/91-loaderentry-update-title.install
#!/usr/bin/sh

set -e

trap 'exit 0' exit

COMMAND="${1:?}"
KERNEL_VERSION="${2:?}"

[ "$COMMAND" = "add" ]
[ "$KERNEL_INSTALL_LAYOUT" = "bls" ]

ENTRY_TOKEN="${KERNEL_INSTALL_ENTRY_TOKEN:?}"
BOOT_ROOT="${KERNEL_INSTALL_BOOT_ROOT:?}"

LOADER_ENTRY="$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION.conf"

ROOTFS=''
for option in $(grep '^options\s' "$LOADER_ENTRY"); do
	ROOTFS="$(expr "$option" : 'root=zfs:\(.*\)')" && break
done

[ -n "$ROOTFS" ]

sed -i -e '/^title\s/ { \| ('"$ROOTFS"')$|! s|$| ('"$ROOTFS"')|; }' \
	"$LOADER_ENTRY"
END
chmod +x /mnt/etc/kernel/install.d/91-loaderentry-update-title.install

# copy the hostid from the Fedora Linux live environment so ZFS doesn’t complain about being mounted on a different system

cp /etc/hostid /mnt/etc

# install ZFS on the new OS

find ~/zfs-release \
	| grep "zfs-release-[0-9]\+-[0-9]\+.fc${VERSION_ID:?}.noarch.rpm" \
	| sort | tail -n 1 | xargs -r dnf "${PARAMS[@]:?}" install
PARAMS+=(--repo=zfs)
dnf "${PARAMS[@]}" install kernel kernel-devel zfs zfs-dracut
sed -i '
	1 i timeout 10
	/^[#[:space:]]*timeout\s.*$/ d
' /mnt/boot/loader/loader.conf
chroot /mnt efibootmgr -C \
	-d /dev/sda1 \
	-l /efi/systemd/systemd-bootx64.efi \
	-L "SD-BOOT A"

# install systemd-boot on the remaining ESPs (repeat as necessary)

umount /mnt/boot
mkdir /mnt/boot@b
(
	IFS=','
	mount -o "${MNT_OPTS[*]:?}" /dev/sdb1 /mnt/boot@b
)
mount -o bind /mnt/boot@b /mnt/boot
chroot /mnt bootctl install --graceful --no-variables --esp-path=/boot
KVER=($(ls -v /mnt/lib/modules))
chroot /mnt kernel-install add "${KVER[-1]:?}" "/lib/modules/${KVER[-1]}/vmlinuz"
sed -i '
	1 i timeout 10
	/^[#[:space:]]*timeout\s.*$/ d
' /mnt/boot/loader/loader.conf
chroot /mnt efibootmgr -C \
	-d /dev/sdb1 \
	-l /efi/systemd/systemd-bootx64.efi \
	-L "SD-BOOT B"

# set the boot order

(
	shopt -s lastpipe
	efibootmgr | grep '^Boot\S*\sSD-BOOT [A-Z]\s' | cut -c 5-8 | readarray -t BOOTORDER
	IFS=','
	efibootmgr -o "${BOOTORDER[*]}"
)

# create /etc/fstab

MNT_OPTS+=(
	nofail
	x-systemd.before=bootbind.service
)
for i in boot@{a,b}; do
	(
		IFS=','
		printf 'PARTLABEL=%s /%s vfat %s 0 0\n' "$i" "$i" "${MNT_OPTS[*]}" >> /mnt/etc/fstab
	)
done

# install bootsync to keep the ESP content synchronized
# TODO: look into replacing this with bootupd (but not until sd-boot is supported)

dnf "${PARAMS[@]:?}" install git-core selinux-policy-devel gettext-envsubst rsync
chroot /mnt bash -e <<- 'END'
	shopt -s lastpipe
	mktemp -p /tmp -d temp.XXX | read REPO
	trap "rm -rf '$REPO'" exit
	cd "$REPO"
	git clone --depth 1 https://github.com/gregory-lee-bartholomew/bootsync.git .
	make install
	make sepolicy_install
END

# update the OS

PARAMS+=(
	--repo=updates
	--exclude=kernel\*
)
dnf "${PARAMS[@]}" update

# make sure the SELinux labels are reset on first boot

printf -- '-F' > /mnt/.autorelabel

# 2369250 – fallback initramfs images are being corrupted

cat <<- 'END' > "/mnt/etc/dkms/framework.conf.d/override.conf"
post_transaction=""
END

# install a few wrapper scripts to help with updating ZFS

printf -v supplements '%s' \
	https://raw.githubusercontent.com \
	/gregory-lee-bartholomew/fedora-on-zfs \
	/refs/heads/main/supplements
for i in dnf zfs-update kernel-update; do
	curl -s "$supplements/$i" > /mnt/usr/local/bin/$i
	chmod +x /mnt/usr/local/bin/$i
done

Suggested Next Steps

Which specification is that?. The ultimate specifications for uefi boot should be the uefi specification itself, which is a really hard to read because it is long and contains a lot of details. A lot of real world UEFI computers boots fine regardless how many partitions are marked as ESP, and can perhaps even boot from any fat file system whether marked as ESP or not.

If the ESP is too small but still being used, the install may silently fail in install the boot loader, and you would never know until you see the reboot fail.

I tried that with a fat16 ESP file system which would bee to small and therefore not used. Then I expanded the partition but the file system itself remained too small as it somehow hit a size limit when trying to grow it. The install procedure did not notice that and appeared to complete normally, but the reboot would just fail.

I’m just reading the one that shows up with a simple Google search:

From BootLoaderSpec:

… if the OS is installed on a disk with GPT disk label, and if the ESP partition already exists but is too small, a new suitably sized (let’s say 500MB) partition with GPT type GUID of bc13c2ff-59e6-4262-a352-b275fd6f7172 shall be created and it should be used as $BOOT.

bc13c2ff-59e6-4262-a352-b275fd6f7172 is the Extended Boot Loader Partition.

Yeah, I would stick with FAT32/VFAT. IIRC, FAT16 is limited to 2GiB.


I haven’t attempted to read it closely, but doesn’t the UEFI spec include that auto discovery mechanism which allows you to drop a /efi/boot/boot<arch>.efi file on the ESP and that will be used by default if there are no programmed entries in the firmware (e.g. if someone resets their BIOS or it loses its battery charge or something like that)? How would that work with multiple ESPs? Would it pick the first ESP or the last ESP or something else? I think UEFI spec was written with the idea that there should only be one ESP per disk, even if that isn’t spelled out anywhere. Just my two cents. :slightly_smiling_face:

You refer to an out of date page. The current one is at https://uapi-group.org/specifications/specs/boot_loader_specification/.

EFI/BOOT/BOOTX64.EFI is specifically needed by removable devices.