Last active
March 30, 2024 03:02
-
-
Save mchangrh/741c0753c7736c4b842502e6a9ab9f1c to your computer and use it in GitHub Desktop.
Universal U(EFI) bootstrap from inside
This file contains 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
#!/bin/bash | |
# USAGE: ./bootstrap.sh <swap_partition> | |
# DESCRIPTION: Overwrites swap partition with netboot.xyz image and adds efibootmgr entry for next boot | |
# LICENSE: LGPL3.0-only | |
# for OCI, currently you'll have to connect to your console via VNC after reboot | |
# https://docs.oracle.com/en-us/iaas/Content/Compute/References/serialconsole.htm#Connecti | |
# and proceed through the "graphical" installer | |
# adapted from alpine-bootstrap v1.0 by sdomi http://sdomi.pl/weblog/12-bootstrapping-alpine-on-oraclecloud/ | |
set -eo pipefail | |
# set variables | |
swap=$1 | |
disk="" | |
part="" | |
if [[ "$(whoami)" != "root" ]]; then | |
echo "This script needs to be run as root." | |
exit 1 | |
fi | |
# functions | |
function findcmd { | |
if ! command -V "$1" > /dev/null 2>&1; then | |
echo "$1 not found. Please install it." | |
exit 1 | |
fi | |
} | |
function findswap { | |
# check if provided swap is mounted | |
if [[ -n "$swap" ]] && swapon --show=name --noheadings | grep -q "$swap"; then | |
echo "Swap found from argument: $swap" | |
else | |
# find all swaps | |
# shellcheck disable=SC2162 | |
read -a swapdefns <<< "$(swapon --show=name,type --noheadings)" | |
# check if swap is a partition | |
if [[ "${swapdefns[1]}" == "partition" ]]; then | |
swap="${swapdefns[0]}" | |
elif [[ "${swapdefns[1]}" == "file" ]]; then | |
echo "Swap is a file. Please specify a swap partition." | |
exit 1 | |
else | |
echo "No swap partition found?" | |
echo "We'll need a 3MB+ partition. Specify which with $0 <dev_path>" | |
exit 1 | |
fi | |
# parse partition and disk | |
fi | |
disk=$(grep -Poh "^([\w\/]+)(?:[0-9])$" <<< "$swap") | |
part=$(grep -Poh "[0-9]$" <<< "$swap") | |
} | |
# check for commands | |
findcmd curl && | |
findcmd dd && | |
findcmd efibootmgr && | |
findcmd grep && | |
findcmd swapon && | |
findcmd swapoff | |
# find swap | |
findswap | |
echo "Annihilating swap ..." | |
swapoff "$swap" | |
echo "Downloading netboot.xyz to swap partition ..." | |
curl -sL https://boot.netboot.xyz/ipxe/netboot.xyz.img | dd of="$swap" | |
echo "Adding efibootmgr entry ..." | |
efibootmgr -cq -d "$disk" -p "$part" -L netboot.xyz -l "\EFI\BOOT\BOOTX64.EFI" | |
echo "Setting netboot.xyz as first boot option ..." | |
order=$(efibootmgr | grep netboot.xyz | grep -Poh "[0-9]{4}") | |
efibootmgr -qo "$order" | |
echo "Reboot your machine to enter netboot.xyz" |
This file contains 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
#!/bin/bash | |
# USAGE: ./ol7.sh | |
# DESCRIPTION: OL7 to netboot.xyz script | |
# LICENSE: LGPL3.0-only | |
# for OCI, currently you'll have to connect to your console via VNC after reboot | |
# https://docs.oracle.com/en-us/iaas/Content/Compute/References/serialconsole.htm#Connecti | |
# and proceed through the "graphical" installer | |
# adapted from alpine-bootstrap v1.0 by sdomi http://sdomi.pl/weblog/12-bootstrapping-alpine-on-oraclecloud/ | |
set -eo pipefail | |
if [[ "$(whoami)" != "root" ]]; then | |
echo "This script needs to be run as root." | |
exit 1 | |
fi | |
# check for OL7.9 | |
if ! grep -q "Oracle Linux Server 7.9" /etc/oracle-release; then | |
echo "This script is for Oracle Linux 7.9 only. Later versions use a swapfile instead of swap partition." | |
exit 1 | |
fi | |
# we know swap is on /dev/sda2 | |
swapoff -a | |
# download netboot.xyz image | |
curl -sL https://boot.netboot.xyz/ipxe/netboot.xyz.img | dd of="/dev/sda2" | |
efibootmgr -cq -d /dev/sda -p 2 -L netboot.xyz -l "\EFI\BOOT\BOOTX64.EFI" | |
order=$(efibootmgr | grep netboot.xyz | grep -Poh "[0-9]{4}") | |
efibootmgr -qo "$order" | |
echo "Reboot your machine to enter netboot.xyz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment