summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2025-08-11 00:33:33 +0200
committerAhmed Abdelhalim <[email protected]>2025-08-11 00:33:33 +0200
commitb94d56f916c275ba73e4cd668629652993a96107 (patch)
tree7b265cb5c6d94e51eecfcb1cb805aa46a845dbf3 /roles
parentd3e78a37b6d907ecbfc817db6ba4c7a71f8a96c3 (diff)
Add Raspberry Pi5 support to bootstrap
Diffstat (limited to 'roles')
-rw-r--r--roles/bootstrap/tasks/install-archlinux.yml6
-rw-r--r--roles/bootstrap/tasks/install-raspberry.yml84
-rw-r--r--roles/bootstrap/tasks/install-ubuntu.yml17
-rw-r--r--roles/bootstrap/tasks/main.yml24
-rw-r--r--roles/bootstrap/templates/raspberry.cmdline.j27
-rw-r--r--roles/bootstrap/templates/raspberry.config.j216
-rw-r--r--roles/bootstrap/vars/debian.yml29
7 files changed, 157 insertions, 26 deletions
diff --git a/roles/bootstrap/tasks/install-archlinux.yml b/roles/bootstrap/tasks/install-archlinux.yml
index c467be8..f91b1eb 100644
--- a/roles/bootstrap/tasks/install-archlinux.yml
+++ b/roles/bootstrap/tasks/install-archlinux.yml
@@ -2,14 +2,8 @@
- name: "Run pacstrap"
ansible.builtin.command:
cmd: "pacstrap -K {{ mnt_root_path }} base linux linux-firmware"
- register: bootstrap_result
changed_when: true
-- name: "Display bootstrap output"
- ansible.builtin.debug:
- var: bootstrap_result.stdout_lines
- verbosity: 1
-
- name: "Generate fstab"
ansible.builtin.shell:
cmd: "genfstab -t PARTLABEL {{ mnt_root_path }} > {{ mnt_root_path }}/etc/fstab"
diff --git a/roles/bootstrap/tasks/install-raspberry.yml b/roles/bootstrap/tasks/install-raspberry.yml
new file mode 100644
index 0000000..f19b104
--- /dev/null
+++ b/roles/bootstrap/tasks/install-raspberry.yml
@@ -0,0 +1,84 @@
+---
+- name: "Include distribution vars"
+ ansible.builtin.include_vars: "{{ ansible_distribution | lower }}.yml"
+
+- name: "Ensure install dependencies are installed on live environment"
+ ansible.builtin.apt:
+ state: "present"
+ update_cache: true
+ pkg:
+ - "debootstrap"
+ - "arch-install-scripts"
+ - "gnupg"
+ - "bash"
+
+- name: "Run debootstrap"
+ ansible.builtin.command:
+ cmd: "debootstrap
+ {{ bootstrap_opts }}
+ {{ bootstrap_distro.name }}
+ {{ mnt_root_path }}
+ {{ bootstrap_distro.mirror_url }}"
+ changed_when: true
+
+- name: "Generate fstab"
+ ansible.builtin.shell:
+ cmd: "genfstab -t PARTLABEL {{ mnt_root_path }} > {{ mnt_root_path }}/etc/fstab"
+ changed_when: true
+
+- name: "Configure apt in chroot"
+ ansible.builtin.copy:
+ dest: "{{ item.dest }}"
+ mode: "0640"
+ content: "{{ item.content }}"
+ with_items:
+ - dest: "{{ mnt_root_path }}/etc/apt/preferences.d/ignored-package"
+ content: "{{ bootstrap_apt_ignored_preferences }}"
+ - dest: "{{ mnt_root_path }}/etc/apt/sources.list"
+ content: "{{ bootstrap_apt_sources }}"
+
+- name: "Download signing key"
+ ansible.builtin.get_url:
+ url: "https://archive.raspberrypi.org/debian/raspberrypi.gpg.key"
+ dest: "/opt/raspberrypi.gpg.key"
+ force: true
+ mode: "0644"
+
+- name: "Dearmor signing key"
+ ansible.builtin.command:
+ cmd: "gpg -o {{ mnt_root_path }}/usr/share/keyrings/raspberrypi.gpg --dearmor /opt/raspberrypi.gpg.key"
+ changed_when: true
+
+- name: "Configure system in chroot"
+ ansible.builtin.command:
+ cmd: "arch-chroot {{ mnt_root_path }} {{ item }}"
+ changed_when: true
+ with_items:
+ - "apt-get update"
+ - "apt-get install -y {{ bootstrap_distro.packages | join(' ') }}"
+
+- name: "Copy kernel to boot partition"
+ # NOTE: Copying {{ mnt_root_path }}/boot/ doesn't work
+ # NOTE: Alternative, download latest fresh from https://github.com/raspberrypi/firmware/archive/refs/heads/master.zip
+ ansible.builtin.shell: |
+ cp -r /boot/firmware/* {{ mnt_boot_path }}/
+ changed_when: true
+
+- name: "Configure bootloader"
+ ansible.builtin.template:
+ src: "{{ item.src }}"
+ dest: "{{ item.dest }}"
+ mode: "0644"
+ with_items:
+ - src: "raspberry.config.j2"
+ dest: "{{ mnt_boot_path }}/config.txt"
+ - src: "raspberry.cmdline.j2"
+ dest: "{{ mnt_boot_path }}/cmdline.txt"
+
+- name: "Configure boot order"
+ ansible.builtin.shell: |
+ set -eo pipefail
+ rpi-eeprom-config --apply <(rpi-eeprom-config | sed 's/^BOOT_ORDER=.*/BOOT_ORDER={{ bootstrap_boot_order }}/')
+ args:
+ executable: "bash"
+ changed_when: true
diff --git a/roles/bootstrap/tasks/install-ubuntu.yml b/roles/bootstrap/tasks/install-ubuntu.yml
index 9e6801f..f1c28d7 100644
--- a/roles/bootstrap/tasks/install-ubuntu.yml
+++ b/roles/bootstrap/tasks/install-ubuntu.yml
@@ -18,14 +18,8 @@
{{ bootstrap_distro.name }}
{{ mnt_root_path }}
{{ bootstrap_distro.mirror_url }}"
- register: bootstrap_result
changed_when: true
-- name: "Display bootstrap output"
- ansible.builtin.debug:
- var: bootstrap_result.stdout_lines
- verbosity: 1
-
- name: "Generate fstab"
ansible.builtin.shell:
cmd: "genfstab -t PARTLABEL {{ mnt_root_path }} > {{ mnt_root_path }}/etc/fstab"
@@ -104,14 +98,3 @@
with_items:
- "{{ mnt_boot_path }}/{{ bootstrap_machine_id.stdout }}"
- "{{ mnt_boot_path }}/loader/entries/{{ bootstrap_machine_id.stdout }}-{{ bootstrap_kernel_version.stdout }}.conf"
-
-- name: "Configure hostname in chroot"
- ansible.builtin.copy:
- dest: "{{ mnt_root_path }}/etc/hostname"
- mode: "0644"
- content: "{{ hostname }}"
-
-- name: "Ensure ansible dependencies are installed in chroot"
- ansible.builtin.command:
- cmd: "arch-chroot {{ mnt_root_path }} apt-get install -y python3"
- changed_when: true
diff --git a/roles/bootstrap/tasks/main.yml b/roles/bootstrap/tasks/main.yml
index 723561d..3c239bf 100644
--- a/roles/bootstrap/tasks/main.yml
+++ b/roles/bootstrap/tasks/main.yml
@@ -9,6 +9,24 @@
ansible.builtin.include_tasks: "install-archlinux.yml"
when: ansible_os_family == "Archlinux"
-- name: "Install ubuntu"
- ansible.builtin.include_tasks: "install-ubuntu.yml"
- when: ansible_os_distribution == "Ubuntu"
+- name: "Install debian"
+ when: ansible_os_family == "Debian"
+ block:
+ - name: "Install ubuntu"
+ ansible.builtin.include_tasks: "install-ubuntu.yml"
+ when: ansible_distribution == "Ubuntu"
+
+ - name: "Install raspberry"
+ ansible.builtin.include_tasks: "install-raspberry.yml"
+ when: ansible_distribution == "Debian"
+
+ - name: "Configure hostname in chroot"
+ ansible.builtin.copy:
+ dest: "{{ mnt_root_path }}/etc/hostname"
+ mode: "0644"
+ content: "{{ hostname }}"
+
+ - name: "Ensure ansible dependencies are installed in chroot"
+ ansible.builtin.command:
+ cmd: "arch-chroot {{ mnt_root_path }} apt-get install -y python3"
+ changed_when: true
diff --git a/roles/bootstrap/templates/raspberry.cmdline.j2 b/roles/bootstrap/templates/raspberry.cmdline.j2
new file mode 100644
index 0000000..3e47837
--- /dev/null
+++ b/roles/bootstrap/templates/raspberry.cmdline.j2
@@ -0,0 +1,7 @@
+console=serial0,115200 \
+console=tty1 \
+root={{ partition_root.dev }} \
+rootfstype={{ partition_root.fstype }} \
+elevator=deadline \
+fsck.repair=yes \
+rootwait
diff --git a/roles/bootstrap/templates/raspberry.config.j2 b/roles/bootstrap/templates/raspberry.config.j2
new file mode 100644
index 0000000..7f02366
--- /dev/null
+++ b/roles/bootstrap/templates/raspberry.config.j2
@@ -0,0 +1,16 @@
+[pi5]
+dtparam=pciex1
+dtparam=pciex1_gen=2
+
+[all]
+arm_64bit=1
+arm_boost=1
+
+disable_overscan=1
+disable_fw_kms_setup=1
+
+camera_auto_detect=0
+display_auto_detect=0
+dtparam=audio=on
+
+auto_initramfs=1
diff --git a/roles/bootstrap/vars/debian.yml b/roles/bootstrap/vars/debian.yml
new file mode 100644
index 0000000..25e2764
--- /dev/null
+++ b/roles/bootstrap/vars/debian.yml
@@ -0,0 +1,29 @@
+---
+bootstrap_distro:
+ name: "bookworm" # => Debian 12/Raspberry OS
+ mirror_url: "http://deb.debian.org/debian"
+ packages:
+ - "raspberrypi-kernel"
+ - "raspberrypi-bootloader"
+ - "firmware-brcm80211"
+ - "systemd-sysv"
+ - "udev"
+ - "kmod"
+ - "rpi-eeprom"
+
+bootstrap_opts: "--arch=arm64 --include=systemd,udev"
+
+bootstrap_apt_ignored_preferences: ""
+
+# yamllint disable rule:line-length
+bootstrap_apt_sources: |
+ deb [signed-by=/usr/share/keyrings/raspberrypi.gpg] http://archive.raspberrypi.org/debian {{ bootstrap_distro.name }} main
+ deb http://deb.debian.org/debian {{ bootstrap_distro.name }} main
+
+# yamllint enable rule:line-length
+# 1 = SD card
+# f = Restart (loop back)
+# 6 = NVMe SSD
+# 4 = USB mass storage
+# 1 = SD card (fallback)
+bootstrap_boot_order: "0x1f641"