Skip to content

Commit

Permalink
playbooks/ci_reboot_on_usb_drive: add a playbook to reboot on USB drive
Browse files Browse the repository at this point in the history
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é <[email protected]>
  • Loading branch information
dupremathieu authored and eroussy committed May 30, 2023
1 parent 715409b commit 0e39994
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions playbooks/ci_reboot_on_usb_drive.yaml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions scripts/configure_boot_next_usb_drive.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0e39994

Please sign in to comment.