Joey Boggs has uploaded a new change for review. Change subject: move find_grub_cfg to more reusable bootloader installation function and wrap existing code ......................................................................
move find_grub_cfg to more reusable bootloader installation function and wrap existing code Change-Id: I73d9cb0e8494719184b9e7c7039ca0770b7e0370 Signed-off-by: Joey Boggs <[email protected]> --- M src/ovirt/node/utils/system.py M src/ovirtnode/ovirtfunctions.py 2 files changed, 49 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/87/24787/1 diff --git a/src/ovirt/node/utils/system.py b/src/ovirt/node/utils/system.py index d8861d7..ab04f6f 100644 --- a/src/ovirt/node/utils/system.py +++ b/src/ovirt/node/utils/system.py @@ -68,6 +68,13 @@ return sys.version_info[:2] == (2, 6) +def booted_from_local_disk(): + """If the system is running from an installed disk + """ + return any(arg in open("/proc/cmdline").read().split() for arg + in ["LABEL=Root", "LABEL=RootBackup"]) + + def is_rescue_mode(): """If the system is running in rescue mode """ @@ -598,21 +605,55 @@ return os.path.exists("/sbin/grub2-install") @staticmethod - def find_grub_cfg(): + def get_grub_paths(): cfg_path = None + efi_dir = None + grub_suffix = None + # iscsi if Filesystem.by_label("Boot"): - cfg_path = "/boot/grub/grub.conf" - elif os.path.ismount("/dev/.initramfs/live"): if not Bootloader.is_grub2(): - cfg_path = "/dev/.initramfs/live/grub/grub.conf" + cfg_path = "/boot/grub/grub.conf" else: - cfg_path = "/dev/.initramfs/live/grub2/grub.cfg" - elif os.path.ismount("/run/initramfs/.live"): - cfg_path = "/liveos/grub/grub.conf" + cfg_path = "/boot/grub/grub.cfg" + # online grub config locations + if booted_from_local_disk(): + if os.path.ismount("/dev/.initramfs/live"): + if not Bootloader.is_grub2(): + cfg_path = "/dev/.initramfs/live/grub/grub.conf" + else: + cfg_path = "/dev/.initramfs/live/grub2/grub.cfg" + elif os.path.ismount("/run/initramfs/.live"): + cfg_path = "/liveos/grub/grub.conf" + # bios offline paths else: + if not Bootloader.is_grub2(): + cfg_path = "/liveos/grub2/grub.conf" + else: + cfg_path = "/liveos/grub/grub.cfg" + + # efi for grub/grub2 + if is_efi(): + if not os.path.exists("/boot/efi/EFI/redhat"): + efi_dir = "fedora" + else: + efi_dir = "redhat" + + if not Bootloader.is_grub2(): + grub_suffix = "conf" + else: + grub_suffix = "cfg" + + cfg_path = "/boot/efi/EFI/%s/grub.%s" % (efi_dir, grub_suffix) + + if not cfg_path: raise RuntimeError("Failed to find the path for grub.[cfg|conf]") + return cfg_path + + @staticmethod + def find_grub_cfg(): + cfg_path = Bootloader.get_grub_paths() return File(cfg_path) class Arguments(base.Base): diff --git a/src/ovirtnode/ovirtfunctions.py b/src/ovirtnode/ovirtfunctions.py index 40fba45..270311e 100644 --- a/src/ovirtnode/ovirtfunctions.py +++ b/src/ovirtnode/ovirtfunctions.py @@ -260,6 +260,7 @@ # return 0 if booted from local disk # return 1 if booted from other media +# legacy in ovirt.node.utils.system def is_booted_from_local_disk(): ret = system_closefds("grep -q LABEL=Root /proc/cmdline") if ret == 0: -- To view, visit http://gerrit.ovirt.org/24787 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I73d9cb0e8494719184b9e7c7039ca0770b7e0370 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node Gerrit-Branch: master Gerrit-Owner: Joey Boggs <[email protected]> _______________________________________________ node-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/node-patches
