-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refinement] boot_control.grub: improve robustness against boot load/init, split out ota_status control and slot mount logic #257
Conversation
…y itself instead of standby slot creator doing so
@obi-t4 Some changes are required due to update to the documentation, so I will turn the PR to draft for now. |
… initrd.img are with the same version
…s_symlinks now takes params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm yet reviewing but did you confirm that this is working on the USB installer environment?
GRUB_CFG_FNAME: str = "grub.cfg" | ||
GRUB_CFG_PATH: str = "/boot/grub/grub.cfg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GRUB_CFG_FNAME: str = "grub.cfg" | |
GRUB_CFG_PATH: str = "/boot/grub/grub.cfg" | |
GRUB_CFG_FNAME: str = "grub.cfg" | |
GRUB_CFG_PATH: str = f"/boot/grub/{GRUB_CFG_FNAME}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And fix spelling inconsistencies: FNAME
and FILE
GRUB_CFG_FNAME
..
BOOT_OTA_PARTITION_FILE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@obi-t4 Ah about the constant naming, currently I am using the following rules:
FNAME
means the constant only contains the file name,FPATH
means the constant contains the file full path,
A single FILE
is not good, I will prepare another PR to update the configs constant naming.
@obi-t4 Yes, otaclient grub boot controller supports automatically migrating a normal ubuntu installation to use ota-partition boot mechanism(and it will take effect starts from next reboot). |
( More precisely is, otaclient grub boot controller supports automatically migrating any system booted with general grub installation(booted with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments, please have a check.
otaclient/app/boot_control/_grub.py
Outdated
def get_active_slot(self) -> str: | ||
return self.active_slot | ||
def __init__(self) -> None: | ||
ab_detecter = GrubABPartitionDetecter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the correct spelling is detector
.
ab_detecter = GrubABPartitionDetecter() | |
ab_detector = GrubABPartitionDetector() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bodong-Yang Do you have a plan to fix this spelling in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@obi-t4 Ah sorry I am waiting for the test result from your side. After test is completed I will resolve all the comments at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated and fixed at 48c06ac.
self._prepare_kernel_initrd_links(self.active_ota_partition_folder) | ||
self._ensure_ota_partition_symlinks(active_slot=self.active_slot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to know why these two lines are needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two methods are to ensure the required symlinks are presented at the time just before grub-reboot is called.
If required symlinks are presented, these two methods won't do others things, otherwise they will re-generate the missing symlinks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, the re_symlink_atomic
method used by these two methods will check the symlink before actually creating symlink again. So if the symlink is presented and already points to correct target, this method will do nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional comments for this method are added at ebb0c4c.
@Bodong-Yang |
NOTE: |
@Bodong-Yang Test is working as expected! |
@obi-t4 I will resolve all the pending PR comments now, please wait a moment. Updated: Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
https://github.com/tier4/autoware_ecu_system_setup/pull/817 発行のタイミングでOTA image作成が実施されており、正常動作確認はパスしている。 |
Description
This PR introduces several internal refinements to grub boot_control implementation as follow. With this PR, grub boot_control implementation aligns with grub boot control design documentation.
Robustness improved over boot control load/init
This PR refines the grub boot_control procedures, aligns the behavior with the design document. Comparing to the previous implementation, it handles the condition of ota-partition symlink broken and migration from non-ota-partition booted system properly during boot_control loading, please check Behavior changes for more details.
Also, during finalizing switch boot, previously otaclient will do the ota-partition symlink switching before doing
grub-update
, this potentially breaks the atomic switching boot. This PR fixes this issue.OTAStatusFilesControl
andSlotMountHelper
These two classes are common shared helper classes that implement ota_status files control and slots preparing/mounting, which can be used by any detailed boot_control implementation(previously only used by
rpi_boot
, this PR makegrub_boot
also use these classes). They are introduced since #182 .The goal for introducing these classes is to abstract ota_status files control and slots preparing/mounting from detailed boot_control implementation, improve boot_control implementation's cohesive, reduce code duplication and ease maintaining.
Especially, the
OTAStatusFilesControl
class aligns with ota_status control design.Split out ota_status files control and slot preparing/mounting from boot_control implementation
This PR splits and removes the ota_status files control logic from grub boot_control implementation, using
OTAStatusFilesControl
andSlotMountHelper
instead of mixins combination (OTAStatusMixin, VersionControlMixin, PrepareMountMixin
, these mixins are deprecated in flavor ofOTAStatusFilesControl
andSlotMountHelper
classes).Now grub boot_control doesn't implement the ota_status files control and slot preparing/mounting, but using APIs from
OTAStatusFilesControl
andSlotMountHelper
, making grub boot_control implementation more focuses on grub control logic, reduce code duplication and ease the maintaining.Related documents
Check list
Changes
common.OTAStatusFilesControl
: split loading and parsingstatus
andslot_in_use
file into two methods,common.OTAStatusFilesControl
: takesforce_initialize
param in__init__
, ota_status will initialize if boot_control is initialized,common.SlotMountHelper
:standby_boot_dir
is always<standby_slot_mp>/boot
, standby_slot creator no-longer needs to care about where the kernel/initrd.img should be placed, this will be handled by boot_controller,protocol
: renameget_ota_status
toget_booted_ota_status
to distinguish this ota_status with live_ota_status maintained by otaclient,grub_boot
: remove_SymlinkABPartitionDetecter
, only detect AB partition by partition information(GrubABPartitionDetecter
),grub_boot
: useOTAStatusFilesControl
to handle ota_status files control, switch boot detecting, etc, remove superseded/overridden codes,grub_boot
: useSlotMountHelper
to handle slots preparing/mounting in each update phases, remove superseded/overridden codes,grub_boot
: refine boot loading procedures, checking the present of ota-partition files during loading, handles the case of ota-partition symlink corrupted, in such case a full boot_control initializing will engage and all ota-partition files will be recreated,grub_boot
: indicatesOTAStatusFilesControl
to initialize unconditionally if boot_control is initialized,grub_boot
:_get_current_booted_kernel_and_initrd
now use standard way to detect booted initrd.img,grub_boot
:_prepare_kernel_initrd_links
now uses first found kernel, and try to find the corresponding initrd.img with the same version string,grub_boot
: splitensure_ota_partition_symlinks
into two new methods_ensure_ota_partition_symlinks
and_ensure_standby_slot_boot_files_symlinks
,grub_boot
: removereprepare_standby_ota_partition_file
andreprepare_active_ota_partition_file
methods, nowgrub_reboot_to_standby
andfinalizing_switch_boot
implements boot control with helper methods on their own,grub_boot
:grub_reboot_to_standby
andfinalizing_switch_boot
now ensure the present of all ota-partition symlinks before grub-update,grub_boot
:finalizing_switch_boot
now does switch boot after grub-update, before grub-update all ota-partition symlinks will be ensured,rpi_boot
: change according toboot_control.ota_status -> boot_control.booted_ota_status
rename,config
: addDEFAULT_VERSION_STR
, value is empty string to align with previous implementation,ota_client
: change according toboot_control.get_ota_status -> boot_control.get_booted_ota_status
API rename,test_grub
to make it work again,test_ota_status_control
,test_rpi_boot
andtest_ota_client
.Behavior changes
Does this PR introduce behavior change(s)?
Previous behavior
CMDHelperFuncs
._prepare_kernel_initrd_links
, grub boot_control will use the first bound kernel and first found initrd.img, but these two files might have different version.Behavior with this PR
OTAStatusFilesControl
during each OTA stages.SlotMountHelper
during each OTA stages._prepare_kernel_initrd_links
, grub boot control will use the first found kernel, and use its version string to find corresponding initrd.img.Breaking change
Does this PR introduce breaking change?