From 5ae29af922de3cff7c99e37022653dede5470d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Grondek?= Date: Fri, 19 Apr 2024 20:49:47 +0200 Subject: [PATCH] Add systemd-boot role --- localhost.yml | 1 + roles/systemd-boot/tasks/arch.yml | 69 +++++++++++++++++++ roles/systemd-boot/tasks/main.yml | 3 + .../templates/loader/entries/arch.conf.j2 | 4 ++ roles/systemd-boot/vars/main.yml | 6 ++ 5 files changed, 83 insertions(+) create mode 100644 roles/systemd-boot/tasks/arch.yml create mode 100644 roles/systemd-boot/tasks/main.yml create mode 100644 roles/systemd-boot/templates/loader/entries/arch.conf.j2 create mode 100644 roles/systemd-boot/vars/main.yml diff --git a/localhost.yml b/localhost.yml index 67b5fff..0986417 100644 --- a/localhost.yml +++ b/localhost.yml @@ -2,6 +2,7 @@ - hosts: localhost roles: - prepare + - systemd-boot - ubuntu - ubuntu-java - ubuntu-firefox diff --git a/roles/systemd-boot/tasks/arch.yml b/roles/systemd-boot/tasks/arch.yml new file mode 100644 index 0000000..09ff836 --- /dev/null +++ b/roles/systemd-boot/tasks/arch.yml @@ -0,0 +1,69 @@ +--- +- name: "[Arch] install efi drivers for ext4" + become: yes + community.general.pacman: + update_cache: yes + name: + - efifs + +- name: "[Arch] Install systemd-boot" + become: yes + shell: + cmd: | + bootctl --esp-path {{ efs }} --boot-path {{ boot }} install + +- name: "[Arch] Copy ext4 driver to systemd drivers" + become: yes + copy: + remote_src: true + content: /usr/lib/efifs-x64/ext2_x64.efi + dest: "{{ efs }}/EFI/systemd/drivers/ext2_x64.efi" + +- name: "[Arch] Add main entry" + become: yes + template: + src: loader/entries/arch.conf.j2 + dest: "{{ boot }}/loader/entries/arch.conf" + vars: + name: "" + variant: "" + version: "linux" + +- name: "[Arch] Add fallback entry" + become: yes + template: + src: loader/entries/arch.conf.j2 + dest: "{{ boot }}/loader/entries/arch-fallback.conf" + vars: + name: " Fallback" + variant: "-fallback" + version: "linux" + +- name: "[Arch] Check if lts kernel is installed" + stat: + path: "{{ boot }}/vmlinuz-linux-lts" + register: lts_kernel + +- name: "[Arch] Add lts entry" + become: yes + template: + src: loader/entries/arch.conf.j2 + dest: "{{ boot }}/loader/entries/arch-lts.conf" + vars: + name: " LTS" + variant: "" + version: "linux-lts" + when: + - lts_kernel.stat.exists + +- name: "[Arch] Add lts fallback entry" + become: yes + template: + src: loader/entries/arch.conf.j2 + dest: "{{ boot }}/loader/entries/arch-lts-fallback.conf" + vars: + name: " LTS Fallback" + variant: "-fallback" + version: "linux-lts" + when: + - lts_kernel.stat.exists diff --git a/roles/systemd-boot/tasks/main.yml b/roles/systemd-boot/tasks/main.yml new file mode 100644 index 0000000..6d32278 --- /dev/null +++ b/roles/systemd-boot/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- import_tasks: arch.yml + when: ansible_distribution == "Archlinux" diff --git a/roles/systemd-boot/templates/loader/entries/arch.conf.j2 b/roles/systemd-boot/templates/loader/entries/arch.conf.j2 new file mode 100644 index 0000000..1930a6a --- /dev/null +++ b/roles/systemd-boot/templates/loader/entries/arch.conf.j2 @@ -0,0 +1,4 @@ +title Arch Linux{{ name }} +linux /vmlinuz-{{ version }} +initrd /initramfs-{{ version }}{{ variant }}.img +options root={{ root }} cryptdevice={{ cryptdevice }} {{ options }} diff --git a/roles/systemd-boot/vars/main.yml b/roles/systemd-boot/vars/main.yml new file mode 100644 index 0000000..36632b8 --- /dev/null +++ b/roles/systemd-boot/vars/main.yml @@ -0,0 +1,6 @@ +--- +root: /dev/mapper/vgubuntu-root +cryptdevice: /dev/nvme0n1p3:cryptlvm +options: rw add_efi_memmap amd_pstate=active loglevel=3 +boot: /boot +efs: /boot/efi