Skip to content

Commit

Permalink
get bootstrap hostname from uefi variable
Browse files Browse the repository at this point in the history
  • Loading branch information
perryflynn committed Apr 17, 2024
1 parent ebfee37 commit f5c6d6c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ a Dockerfile and some scripts to build a custom Arch Linux installer iso with ad
- `./archiso/build.sh` builds the container image
- `./archiso/pack.sh` runs the container image to build the Arch Linux ISO image

## Automatic hostname detection

The `perrys-bootstrapper.sh` script is using UEFI variables to fetch the hostname from the system and use the
correct ansible inventory variables.

Set hostname in UEFI variable:

```sh
echo -n wuseldusel > efi-hostname
efivar --name ed38a5bf-1135-4b0f-aa72-49d30b05dfd4-PerryHostname -w -f efi-hostname
```

Get the hostname from UEFI variable:

```sh
cat /sys/firmware/efi/efivars/PerryHostname-ed38a5bf-1135-4b0f-aa72-49d30b05dfd4
```

## How to install a OS

- Build the Arch Linux ISO image
Expand Down
34 changes: 29 additions & 5 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ set -e

export PYTHONUNBUFFERED=1

UEFI_HOSTNAME="/sys/firmware/efi/efivars/PerryHostname-ed38a5bf-1135-4b0f-aa72-49d30b05dfd4"

# Arguments
ARG_HELP=0
UNKNOWN_OPTION=0
ARG_FLAVOR=archlinux
ARG_HOSTNAME=""

# Arguments from cli
if [ $# -ge 1 ]
Expand All @@ -21,6 +24,10 @@ then
shift
ARG_FLAVOR=$1
;;
--hostname)
shift
ARG_HOSTNAME=$1
;;
-h|--help)
ARG_HELP=1
;;
Expand Down Expand Up @@ -51,18 +58,35 @@ then
echo
echo "Usage: $0 --flavor [debian|archlinux]"
echo
echo "-h, --help Print this help"
echo "--flavor os OS to bootstrap"
echo " one of 'debian' or 'archlinux'"
echo "-h, --help Print this help"
echo "--hostname myhost Override hostname of bootstrapped OS"
echo "--flavor os OS to bootstrap"
echo " one of 'debian' or 'archlinux'"
echo
exit
fi

loadkeys de
# Set hostname
hostnamectl hostname "${ARG_FLAVOR}iso"

# Expand disk size
mount -o remount,size=2G /run/archiso/cowspace

# Install tools
pacman --noconfirm --needed -Sy archlinux-keyring
pacman --noconfirm --needed -S ansible git

ansible-pull -U https://github.com/perryflynn/iac.git -C dev -l "bootstrap-$ARG_FLAVOR"
# Build arguments
extraargs=()

if [ -n "$ARG_HOSTNAME" ]; then
extraargs+=( "{ \"hostname\": \"$ARG_HOSTNAME\" }" )
elif [ -f "$UEFI_HOSTNAME" ]
extraargs+=( "{ \"hostname\": \"$(cat "$UEFI_HOSTNAME")\" }" )
fi

# Run ansible
ansible-pull \
-U https://github.com/perryflynn/iac.git -C dev \
-l "bootstrap-$ARG_FLAVOR" \
"${extraargs[@]}"
6 changes: 5 additions & 1 deletion inventory/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ all:
configuration:
hosts:

# retired Thinkpad X230 Laptop
# Default hostnames
mydemoarch:
mydemodebian:

# retired Thinkpad X230 Laptop
retired:
4 changes: 4 additions & 0 deletions local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- bootmode == 'uefi' or bootmode == 'bios'
- flavor == 'debian' or flavor == 'archlinux'

- name: Show hostname to use
debug:
var: hostname

- name: Set timezone
timezone:
name: "{{timezone}}"
Expand Down

0 comments on commit f5c6d6c

Please sign in to comment.