-
Notifications
You must be signed in to change notification settings - Fork 211
dom0_kernel_installer: Add new menuentry for installed kernel #3894
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
Open
pupacha
wants to merge
1
commit into
main
Choose a base branch
from
pavan/fix_kernel_installer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
from lisa import schema | ||
from lisa.node import Node | ||
from lisa.operating_system import CBLMariner | ||
from lisa.tools import Cat, Cp, Echo, Ln, Ls, Lsblk, Sed, Tar, Uname | ||
from lisa.tools import Cat, Chmod, Cp, Echo, Ln, Ls, Lsblk, Sed, Tar, Uname | ||
from lisa.util import UnsupportedDistroException, field_metadata | ||
|
||
from .kernel_installer import BaseInstaller, BaseInstallerSchema | ||
|
@@ -59,6 +59,25 @@ class BinaryInstallerSchema(BaseInstallerSchema): | |
), | ||
) | ||
|
||
additional_grub_file: str = field( | ||
default="", | ||
metadata=field_metadata( | ||
required=False, | ||
), | ||
) | ||
target_grub_file_path: str = field( | ||
default="", | ||
metadata=field_metadata( | ||
required=False, | ||
), | ||
) | ||
default_grub_id: str = field( | ||
default="", | ||
metadata=field_metadata( | ||
required=False, | ||
), | ||
) | ||
|
||
|
||
class BinaryInstaller(BaseInstaller): | ||
@classmethod | ||
|
@@ -87,13 +106,21 @@ def install(self) -> str: | |
initrd_image_path: str = runbook.initrd_image_path | ||
kernel_modules_path: str = runbook.kernel_modules_path | ||
kernel_config_path: str = runbook.kernel_config_path | ||
additional_grub_file: str = runbook.additional_grub_file | ||
target_grub_file_path: str = runbook.target_grub_file_path | ||
default_grub_id: str = runbook.default_grub_id | ||
vmlinux_image_path: str = runbook.vmlinux_image_path | ||
|
||
uname = node.tools[Uname] | ||
current_kernel = uname.get_linux_information().kernel_version_raw | ||
|
||
mariner_version = int(node.os.information.version.major) | ||
|
||
if mariner_version != 2: | ||
assert ( | ||
additional_grub_file | ||
), "additional_grub_file for new kernel is required" | ||
|
||
# Kernel absolute path: /home/user/vmlinuz-5.15.57.1+ | ||
# Naming convention : vmlinuz-<version> | ||
new_kernel = os.path.basename(kernel_image_path).split("-")[1].strip() | ||
|
@@ -191,12 +218,90 @@ def install(self) -> str: | |
node.get_pure_path(f"/boot/config-{new_kernel}"), | ||
) | ||
|
||
_update_mariner_config( | ||
if mariner_version == 2: | ||
_update_mariner_config( | ||
node, | ||
current_kernel, | ||
new_kernel, | ||
mariner_version, | ||
) | ||
|
||
return new_kernel | ||
|
||
node.shell.copy( | ||
PurePath(additional_grub_file), | ||
node.get_pure_path("/var/tmp/additional_grub_file"), | ||
) | ||
if not target_grub_file_path: | ||
target_grub_file_path = "/etc/grub.d/40_custom_kernel" | ||
_copy_kernel_binary( | ||
node, | ||
current_kernel, | ||
new_kernel, | ||
mariner_version, | ||
node.get_pure_path("/var/tmp/additional_grub_file"), | ||
node.get_pure_path(target_grub_file_path), | ||
) | ||
node.tools[Chmod].chmod( | ||
path=target_grub_file_path, | ||
permission="755", | ||
sudo=True, | ||
) | ||
|
||
cat = node.tools[Cat] | ||
sed = node.tools[Sed] | ||
|
||
# Replace all the placeholders in the additional grub file | ||
vmlinuz_replacement = f"vmlinuz-{new_kernel}" | ||
initrd_replacement = f"initramfs-{new_kernel}.img" | ||
sed.substitute( | ||
regexp="REPL_KERNEL_VERSION", | ||
replacement=vmlinuz_replacement, | ||
file=target_grub_file_path, | ||
sudo=True, | ||
) | ||
sed.substitute( | ||
regexp="REPL_INITRD_VERSION", | ||
replacement=initrd_replacement, | ||
file=target_grub_file_path, | ||
sudo=True, | ||
) | ||
|
||
lsblk = node.tools[Lsblk] | ||
root_partition = lsblk.find_partition_by_mountpoint("/", force_run=True) | ||
sed.substitute( | ||
regexp="REPL_UUID", | ||
replacement=root_partition.uuid, | ||
file=target_grub_file_path, | ||
sudo=True, | ||
) | ||
sed.substitute( | ||
regexp="REPL_PARTUUID", | ||
replacement=root_partition.part_uuid, | ||
file=target_grub_file_path, | ||
sudo=True, | ||
) | ||
|
||
# Comment out the existing GRUB_DEFAULT line | ||
grub_default_file = "/etc/default/grub" | ||
sed.substitute( | ||
regexp="^GRUB_DEFAULT=", | ||
replacement="#GRUB_DEFAULT=", | ||
file=grub_default_file, | ||
sudo=True, | ||
) | ||
LiliDeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Add the new GRUB_DEFAULT line with the new kernel | ||
node.execute( | ||
f"sed -i.bak '1i GRUB_DEFAULT={default_grub_id}' {grub_default_file}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can sed tool have the method to do this? if no, can you add the method in the sed tool? |
||
shell=True, | ||
sudo=True, | ||
) | ||
cat.read(grub_default_file, sudo=True, force_run=True) | ||
|
||
grub_cfg = "/boot/grub2/grub.cfg" | ||
node.execute( | ||
f"grub2-mkconfig -o {grub_cfg}", | ||
sudo=True, | ||
shell=True, | ||
) | ||
cat.read(grub_cfg, sudo=True, force_run=True) | ||
|
||
return new_kernel | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.