diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-08-11 00:33:33 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-08-11 00:33:33 +0200 |
| commit | b94d56f916c275ba73e4cd668629652993a96107 (patch) | |
| tree | 7b265cb5c6d94e51eecfcb1cb805aa46a845dbf3 | |
| parent | d3e78a37b6d907ecbfc817db6ba4c7a71f8a96c3 (diff) | |
Add Raspberry Pi5 support to bootstrap
| -rw-r--r-- | host_vars/raspberryiso.local.yml | bin | 0 -> 577 bytes | |||
| -rw-r--r-- | host_vars/raspberryiso.local.yml.example | 25 | ||||
| -rw-r--r-- | inventory/hosts.yml | 2 | ||||
| -rw-r--r-- | molecule/default/prepare.yml | 1 | ||||
| -rw-r--r-- | raspberry.md | 14 | ||||
| -rw-r--r-- | roles/bootstrap/tasks/install-archlinux.yml | 6 | ||||
| -rw-r--r-- | roles/bootstrap/tasks/install-raspberry.yml | 84 | ||||
| -rw-r--r-- | roles/bootstrap/tasks/install-ubuntu.yml | 17 | ||||
| -rw-r--r-- | roles/bootstrap/tasks/main.yml | 24 | ||||
| -rw-r--r-- | roles/bootstrap/templates/raspberry.cmdline.j2 | 7 | ||||
| -rw-r--r-- | roles/bootstrap/templates/raspberry.config.j2 | 16 | ||||
| -rw-r--r-- | roles/bootstrap/vars/debian.yml | 29 |
12 files changed, 199 insertions, 26 deletions
diff --git a/host_vars/raspberryiso.local.yml b/host_vars/raspberryiso.local.yml Binary files differnew file mode 100644 index 0000000..04b3db2 --- /dev/null +++ b/host_vars/raspberryiso.local.yml diff --git a/host_vars/raspberryiso.local.yml.example b/host_vars/raspberryiso.local.yml.example new file mode 100644 index 0000000..6a98993 --- /dev/null +++ b/host_vars/raspberryiso.local.yml.example @@ -0,0 +1,25 @@ +--- +hostname: "rpi5.local" +partition_disk: "/dev/mmcblk0" +partition_wipe: true +partition_boot: + num: 1 + name: "boot" + flags: [boot, esp] + part_start: "0%" + part_end: "200MiB" + fstype: "vfat" + fstype_opts: "-F 32 -n boot" + dev: "{{ partition_disk }}p1" + mount_path: "/mnt/boot/firmware" + fstab_opts: "defaults,noatime" +partition_root: + num: 2 + name: "root" + part_start: "200MiB" + part_end: "100%" + fstype: "ext4" + dev: "{{ partition_disk }}p2" + mount_path: "/mnt" +partition_extras: [] +configure_playbook_dir: "../ansible-distro-configure" diff --git a/inventory/hosts.yml b/inventory/hosts.yml index 77bf618..28e3f10 100644 --- a/inventory/hosts.yml +++ b/inventory/hosts.yml @@ -8,3 +8,5 @@ live_environments: ansible_user: root ubuntuiso.local: ansible_user: ubuntu + raspberryiso.local: + ansible_user: pi diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 5f33e7f..885103f 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -8,6 +8,7 @@ distro_hostname_mapping: archlinux: "archlinux.local" ubuntu: "ubuntu.local" + debian: "rpi5.local" - name: "Create virtual disk image" become: true diff --git a/raspberry.md b/raspberry.md new file mode 100644 index 0000000..4c19723 --- /dev/null +++ b/raspberry.md @@ -0,0 +1,14 @@ +# Install Raspberry Pi 5 + +- Download [Raspberry Pi Imager](https://www.raspberrypi.com/software/) +- Create a bootable USB using the imager + - OS: Raspberry PI OS LITE + - Hostname: `raspberryiso` + - Username/Password: `pi:raspberry` + - Enable SSH (Use password authentication) +- Turn off the raspberry pi and remove the SD card +- Insert the bootable USB and turn the PI +- Wait for the PI to start +- SSH into the PI using the username/password configured +- Insert the SD Card +- Make sure the PI boot order is set to `BOOT_ORDER=0x1f461` using `sudo rpi-eeprom-config --edit` 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" |
