Skip to content

Commit

Permalink
Merge pull request #71 from NeroReflex/bootloader_no_frer_kernel
Browse files Browse the repository at this point in the history
Bootloader no frzr kernel
  • Loading branch information
NeroReflex authored Aug 25, 2024
2 parents cf85113 + 898017d commit 5ac6bba
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 42 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ __Q__ Is it easy to create a proof-of-concept distro that is compatible with frz
__A__ Absolutely: frzr wants to be hackable and easy to work with in every aspect: just create a btrfs subvolume and run your preferred command to write a rootfs (debootstrap, pacstrap or whatever). Then create a snapshot of it with btrfs send and that file can be deployed on real hardware!


__Q__ Can a distro be shipped with its own kernel?

__A__ Yes and this is the preferred method. The user can boot a deployment only if such deployment comes with its own kernel or the user has installed one
already via the dedicated *frzr kernel* tool!


__Q__ Are there rules to follow?

__A__ There are conventions: for example a distro should __NOT__ assume it's the only distro installed, and *SHOULD NOT* cause harm to other deployments for example by writing to the efi partition.
Expand Down
21 changes: 12 additions & 9 deletions __frzr
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ prepare_efi_partition() {

local default_config_entry=""

local default_entry_filename="frzr.conf"

# create /loader/entries in the EFI system partition (if it does not exists already)
mkdir -p ${efi_mount_path}/loader/entries

Expand Down Expand Up @@ -860,7 +862,14 @@ prepare_efi_partition() {
if echo "${systemd_boot_update_result}" | grep -q 'ERROR'; then
echo "ERROR: Could not add bootloader entry: ${systemd_boot_update_result}"
else
default_boot_cfg="${boot_entry}"
# Write "${EFI_MOUNT_PATH}/loader/entries/${default_entry_filename}" so that frzr will make use of the new kernel
# WARNING: btrfs_rootfs_uuid being empty means gpt-auto will be used
local default_boot_entry_generation_res=$(generate_systemd_boot_cfg "${version}" "${default_entry_filename}" "${version}" "${efi_mount_path}" "${amd_ucode}" "${intel_ucode}" "${vmlinuz_file}" "${initramfs_file}" "${additional_arguments}" "" "")
if echo "${boot_entry_generation_res}" | grep -Fq "ERROR"; then
echo "ERROR: Could not add bootloader entry: ${default_boot_entry_generation_res}"
else
default_boot_cfg="${boot_entry}"
fi
fi
else
echo "ERROR: Could not copy '${boot_dir}/${initramfs_file}' to '${efi_mount_path}/${version}/${initramfs_file}'"
Expand All @@ -872,21 +881,15 @@ prepare_efi_partition() {
done

# override the default deployment boot with the user-provided one
if [ -f "${efi_mount_path}/loader/entries/frzr_kernel.conf" ]; then
default_boot_cfg="frzr_kernel.conf"
if [ -f "${efi_mount_path}/loader/entries/${default_entry_filename}" ]; then
default_boot_cfg="${default_entry_filename}"
fi

# write the default boot entry
if [ -z "$default_boot_cfg" ]; then
echo "ERROR: no bootable kernel found"
else
echo "default ${default_boot_cfg}" > "${efi_mount_path}/loader/loader.conf"

# If frzr-kernel has been used this is a development machine: add a boot timeout so that different kernels can be used
if [ "${default_boot_cfg}" = "frzr_kernel.conf" ]; then
echo "timeout 3" >> "${efi_mount_path}/loader/loader.conf"
fi

echo "OK"
fi
fi
Expand Down
36 changes: 24 additions & 12 deletions __frzr-bootloader
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ frzr_bootloader() {
;;

"BOOTLOADER")

# Check if a (supported) bootloader is present and if not install it

# Install systemd-boot as the bootloader
# Check if a (supported) bootloader is present and if not
# install systemd-boot as the bootloader
if [ ! -f "${EFI_MOUNT_PATH}/EFI/systemd/systemd-bootx64.efi" ]; then
TASK_MSG="Installing systemd-boot to '${EFI_MOUNT_PATH}' as the bootloader"
if ! bootctl --esp-path="${EFI_MOUNT_PATH}/" install; then
Expand Down Expand Up @@ -164,25 +162,36 @@ frzr_bootloader() {
continue
fi

# Read additional boot arguments (to be added to the kernel cmdline) from the deployed image
# Initialize an empty deployment kernel cmdline
local deployment_arguments=""

# Read additional boot arguments (to be added to the kernel cmdline) from the deployed image
if [ -f "${SUBVOL}/usr/lib/frzr.d/bootconfig.conf" ]; then
local bootconf_args=$(cat "${SUBVOL}/usr/lib/frzr.d/bootconfig.conf")
local bootconf_args=$(cat "${SUBVOL}/usr/lib/frzr.d/bootconfig.conf")
deployment_arguments="$deployment_arguments ${bootconf_args}"
else
TASK_WARNING=1
TASK_WARNING_MSG="Could not read '${SUBVOL}/usr/lib/frzr.d/bootconfig.conf': default kernel cmdline will be used"
TASK_WARNING_MSG="Could not read '${SUBVOL}/usr/lib/frzr.d/bootconfig.conf': skipped"
send_data
fi

# Read additional boot arguments (to be added to the kernel cmdline) from the deployed image
if [ -f "${SUBVOL}/etc/kernel/cmdline" ]; then
local kernel_cmdline_args=$(cat "${SUBVOL}/etc/kernel/cmdline")
deployment_arguments="$deployment_arguments ${kernel_cmdline_args}"
else
TASK_WARNING=1
TASK_WARNING_MSG="Could not read '${SUBVOL}/etc/kernel/cmdline': skipped"
send_data
fi

# Read additional boot arguments (to be added to the kernel cmdline) from the user file
local additional_arguments="$deployment_arguments"
if [ -f "${EFI_MOUNT_PATH}/frzr_bootconfig.conf" ]; then
local user_bootconf_args=$(cat "${EFI_MOUNT_PATH}/frzr_bootconfig.conf")
additional_arguments="$additional_arguments ${user_bootconf_args}"
local user_bootconf_args=$(cat "${EFI_MOUNT_PATH}/frzr_bootconfig.conf")
deployment_arguments="$deployment_arguments ${user_bootconf_args}"
else
TASK_WARNING=1
TASK_WARNING_MSG="Could not read '${EFI_MOUNT_PATH}/frzr_bootconfig.conf': deployment cmdline will be used"
TASK_WARNING_MSG="Could not read '${EFI_MOUNT_PATH}/frzr_bootconfig.conf': skipped"
send_data
fi

Expand All @@ -196,7 +205,7 @@ frzr_bootloader() {
fi

# This is used to update the EFI partition: setting up systemd-boot (or whatever else bootlader might be supported) to boot the new deployment
local efi_update_result=$(prepare_efi_partition "${NAME}" "${EFI_MOUNT_PATH}" "${SUBVOL}/boot" "${additional_arguments}" "${rootfs_uuid}" "${rootfs_subvolid}")
local efi_update_result=$(prepare_efi_partition "${NAME}" "${EFI_MOUNT_PATH}" "${SUBVOL}/boot" "${deployment_arguments}" "${rootfs_uuid}" "${rootfs_subvolid}")
if echo "${efi_update_result}" | grep -q 'ERROR'; then
# bootloader configuration could not be updated
TASK_ERROR=1
Expand All @@ -221,6 +230,7 @@ frzr_bootloader() {

RUNNING=false
;;

"FAIL")
# This state should only be used if the unlock failed

Expand All @@ -231,6 +241,7 @@ frzr_bootloader() {
send_data
RUNNING=false
;;

*)
TASK_STATE="UNKNOWN_ERROR"

Expand All @@ -239,6 +250,7 @@ frzr_bootloader() {
send_data
RUNNING=false
;;

esac
done

Expand Down
30 changes: 15 additions & 15 deletions __frzr-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -512,20 +512,6 @@ frzr_deploy() {
TASK_STATE="CLEANUP"
send_data

# This is used to update the EFI partition: setting up systemd-boot (or whatever else bootlader might be supported) to boot the new deployment
local efi_update_result=$("${BASH_SOURCE%/*}/frzr-bootloader" "${NAME}")
if echo "${efi_update_result}" | grep -Fq 'ERROR'; then
# bootloader configuration could not be updated
TASK_ERROR=1
TASK_ERROR_MSG="Could not update the EFI partition: ${efi_update_result}"
STATE="FAIL"
send_data
continue
fi

# Remove download artifacts (if any)
rm -f ${MOUNT_PATH}/*.img.*

# Lazy umount the deployed system (find all mounted subdirectories under the parent directory and unmount the mounted subdirectories)
TASK_MSG="Post-install umount of '${SUBVOL}'"
send_data
Expand Down Expand Up @@ -556,6 +542,17 @@ frzr_deploy() {
continue
fi

# This is used to update the EFI partition: setting up systemd-boot (or whatever else bootlader might be supported) to boot the new deployment
local efi_update_result=$("${BASH_SOURCE%/*}/frzr-bootloader" "${NAME}")
if echo "${efi_update_result}" | grep -Fq 'ERROR'; then
# bootloader configuration could not be updated
TASK_ERROR=1
TASK_ERROR_MSG="Could not update the EFI partition: ${efi_update_result}"
STATE="FAIL"
send_data
continue
fi

# Activates the new deployed image by making it the default btrfs subvolume
# systemd-equipped initramfs images will automount the default subvolume as the rootfs
TASK_MSG="Activating the new deployment (subvolid=${subvolid}) as the default subvolume"
Expand All @@ -567,7 +564,10 @@ frzr_deploy() {
send_data
continue
fi


# Remove download artifacts (if any)
rm -f "${MOUNT_PATH}"/*.img*

STATE="SUCCESS"
;;
"SUCCESS")
Expand Down

0 comments on commit 5ac6bba

Please sign in to comment.