From 0e399940637cd8a6eeb24795be081929a247ceb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Dupr=C3=A9?= Date: Fri, 26 May 2023 13:29:28 +0200 Subject: [PATCH] playbooks/ci_reboot_on_usb_drive: add a playbook to reboot on USB drive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ci_reboot_on_usb_drive.yaml is a playbook which configure the EFI next boot entry to reboot on an USB driver. Signed-off-by: Mathieu Dupré --- playbooks/ci_reboot_on_usb_drive.yaml | 15 +++++++++++++ scripts/configure_boot_next_usb_drive.sh | 28 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 playbooks/ci_reboot_on_usb_drive.yaml create mode 100644 scripts/configure_boot_next_usb_drive.sh diff --git a/playbooks/ci_reboot_on_usb_drive.yaml b/playbooks/ci_reboot_on_usb_drive.yaml new file mode 100644 index 000000000..dd7f6172c --- /dev/null +++ b/playbooks/ci_reboot_on_usb_drive.yaml @@ -0,0 +1,15 @@ +# Copyright (C) 2023 Savoir-faire Linux, Inc. +# SPDX-License-Identifier: Apache-2.0 + +--- +- name: Configure next reboot to boot on USB drive + hosts: + - cluster_machines + - standalone_machine + gather_facts: false + tasks: + - name: Configure the EFI to boot on USB drive + script: "../scripts/configure_boot_next_usb_drive.sh" + register: result + changed_when: result.rc == 0 + failed_when: result.rc == 1 or result.rc > 2 diff --git a/scripts/configure_boot_next_usb_drive.sh b/scripts/configure_boot_next_usb_drive.sh new file mode 100644 index 000000000..f5c45f2df --- /dev/null +++ b/scripts/configure_boot_next_usb_drive.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +if [ "$(id -u)" -ne 0 ]; then + echo "Please run as root" + exit 1 +fi + +if [ ! -d /sys/firmware/efi/efivars ]; then + echo "Please run on an EFI system" + exit 1 +fi + +if ! mount |grep -q /sys/firmware/efi/efivars; then + mount -t efivarfs efivarfs /sys/firmware/efi/efivars || exit 1 +fi + +usb_boot=$(efibootmgr |grep -i USB |cut -d ' ' -f 1 |grep -Eo '[0-9]+') +if [ -z "${usb_boot}" ]; then + echo "No USB boot option found" + exit 1 +fi + +if efibootmgr |grep -q "BootNext: ${usb_boot}" ; then + echo "USB boot option already set" + exit 2 +fi + +efibootmgr -n "${usb_boot}" || exit 1