parent
fd025bd81c
commit
7a6f674714
@ -1,5 +1,5 @@ |
|||||||
--- |
--- |
||||||
- name: Configure system. |
- name: Configure system. |
||||||
hosts: arch |
hosts: all |
||||||
|
|
||||||
roles: |
roles: |
||||||
|
@ -0,0 +1,6 @@ |
|||||||
|
disksetup_strategy: efi_gpt_btrfs |
||||||
|
# partitioning_priv_device_node: /dev/sda |
||||||
|
|
||||||
|
# grub_theme_name: xenlism |
||||||
|
|
||||||
|
# configure_root_password: password |
@ -0,0 +1,10 @@ |
|||||||
|
GRUB_TIMEOUT=5 |
||||||
|
GRUB_DISTRIBUTOR="Arch" |
||||||
|
GRUB_CMDLINE_LINUX_DEFAULT="" |
||||||
|
GRUB_CMDLINE_LINUX="" |
||||||
|
GRUB_PRELOAD_MODULES="btrfs part_gpt" |
||||||
|
GRUB_TIMEOUT_STYLE=menu |
||||||
|
GRUB_TERMINAL_INPUT=console |
||||||
|
GRUB_GFXMODE=auto |
||||||
|
GRUB_GFXPAYLOAD_LINUX=keep |
||||||
|
GRUB_DISABLE_RECOVERY=true |
@ -0,0 +1,23 @@ |
|||||||
|
--- |
||||||
|
- name: Install required packages. |
||||||
|
command: arch-chroot {{ partitioning_root_mount_point }} pacman -Sy grub efibootmgr os-prober --noconfirm |
||||||
|
changed_when: true |
||||||
|
|
||||||
|
- name: Copy grub default config. |
||||||
|
template: |
||||||
|
src: files/grub |
||||||
|
dest: "{{ partitioning_root_mount_point }}/etc/default/grub" |
||||||
|
owner: root |
||||||
|
group: root |
||||||
|
mode: 0644 |
||||||
|
|
||||||
|
- name: Install grub. |
||||||
|
command: |
||||||
|
cmd: arch-chroot {{ partitioning_root_mount_point }} grub-install --efi-directory=/boot/efi --bootloader-id=grub |
||||||
|
creates: "{{ partitioning_root_mount_point }}/boot/efi/EFI/grub" |
||||||
|
|
||||||
|
- name: Install theme. |
||||||
|
include_role: |
||||||
|
name: grub-theme |
||||||
|
vars: |
||||||
|
chroot: "{{ partitioning_root_mount_point }}" |
@ -0,0 +1,32 @@ |
|||||||
|
--- |
||||||
|
##### Public variables used by the rest of the playbook ##### |
||||||
|
partitioning_root_mount_point: "/mnt" |
||||||
|
|
||||||
|
##### Private variables used only by the partitioning roles ##### |
||||||
|
|
||||||
|
# Two partitions will be created on this device node |
||||||
|
# * xxx1 will be used by /boot/efi |
||||||
|
# * xxx2 will be the root partition |
||||||
|
partitioning_priv_device_node: "/dev/sda" |
||||||
|
|
||||||
|
# The size of the ESP partition to be created |
||||||
|
partitioning_priv_esp_size: "{{ 512 * 1024 * 1024 }}" |
||||||
|
|
||||||
|
# btrfs subvolumes are laid out in a flat fashion: |
||||||
|
# |
||||||
|
# toplevel (default subvolume, not mounted) |
||||||
|
# +-- @ (to be mounted at /) |
||||||
|
# +-- @home (to be mmounted at /home) |
||||||
|
# +-- ... |
||||||
|
# |
||||||
|
partitioning_priv_btrfs_subvolumes: "{{ partitioning_priv_core_btrfs_subvolumes + partitioning_priv_extra_btrfs_subvolumes }}" |
||||||
|
|
||||||
|
# These subvolumes should always be present. DO NOT OVERRIDE. |
||||||
|
partitioning_priv_core_btrfs_subvolumes: |
||||||
|
- name: "@" |
||||||
|
mountpoint: / |
||||||
|
|
||||||
|
# Other subvolumes can be added here, beginning with an @. |
||||||
|
partitioning_priv_extra_btrfs_subvolumes: |
||||||
|
- name: "@home" |
||||||
|
mountpoint: /home |
@ -0,0 +1,33 @@ |
|||||||
|
--- |
||||||
|
- name: Create EFI system partition |
||||||
|
parted: |
||||||
|
device: "{{ partitioning_priv_device_node }}" |
||||||
|
state: present |
||||||
|
label: gpt |
||||||
|
number: 1 |
||||||
|
name: ESP |
||||||
|
part_start: "{{ 1024 * 1024 }}B" |
||||||
|
part_end: "{{ partitioning_priv_esp_size | int + 1024 * 1024 - 1 }}B" |
||||||
|
flags: |
||||||
|
- esp |
||||||
|
|
||||||
|
- name: Create root partition |
||||||
|
parted: |
||||||
|
device: "{{ partitioning_priv_device_node }}" |
||||||
|
state: present |
||||||
|
label: gpt |
||||||
|
number: 2 |
||||||
|
name: root |
||||||
|
part_start: "{{ partitioning_priv_esp_size | int + 1024 * 1024 }}B" |
||||||
|
|
||||||
|
- name: Enumerate created partitions. |
||||||
|
shell: | |
||||||
|
set -e -o pipefail |
||||||
|
lsblk -n -o PATH {{ partitioning_priv_device_node | quote }} | tail -n +2 |
||||||
|
register: _partitions |
||||||
|
changed_when: false |
||||||
|
|
||||||
|
- name: Assign partitions to variables. |
||||||
|
set_fact: |
||||||
|
partitioning_priv_esp_device_node: "{{ _partitions.stdout_lines[0] }}" |
||||||
|
partitioning_priv_root_device_node: "{{ _partitions.stdout_lines[1] }}" |
@ -0,0 +1,31 @@ |
|||||||
|
--- |
||||||
|
- name: Format the boot partition with vfat. |
||||||
|
filesystem: |
||||||
|
device: "{{ partitioning_priv_esp_device_node }}" |
||||||
|
state: present |
||||||
|
type: vfat |
||||||
|
|
||||||
|
- name: Format the root partition with btrfs. |
||||||
|
filesystem: |
||||||
|
device: "{{ partitioning_priv_root_device_node }}" |
||||||
|
state: present |
||||||
|
type: btrfs |
||||||
|
|
||||||
|
- name: Mount the default subvolume. |
||||||
|
mount: |
||||||
|
state: mounted |
||||||
|
src: "{{ partitioning_priv_root_device_node }}" |
||||||
|
path: "{{ partitioning_root_mount_point }}" |
||||||
|
fstype: btrfs |
||||||
|
opts: defaults,noatime,compress=zstd |
||||||
|
|
||||||
|
- name: Create subvolumes. |
||||||
|
command: |
||||||
|
cmd: btrfs subvolume create {{ (partitioning_root_mount_point + "/" + item.name) }} |
||||||
|
creates: '{{ (partitioning_root_mount_point + "/" + item.name) }}' |
||||||
|
with_items: "{{ partitioning_priv_btrfs_subvolumes }}" |
||||||
|
|
||||||
|
- name: Unmount the default subvolume. |
||||||
|
mount: |
||||||
|
state: unmounted |
||||||
|
path: "{{ partitioning_root_mount_point }}" |
@ -0,0 +1,17 @@ |
|||||||
|
--- |
||||||
|
- name: Fail if not using EFI. |
||||||
|
fail: |
||||||
|
msg: Must boot using EFI for this disksetup strategy. |
||||||
|
when: not efi_mode |
||||||
|
|
||||||
|
- name: Make sure root mount point is unmounted. |
||||||
|
command: umount -R {{ partitioning_root_mount_point }} |
||||||
|
changed_when: true |
||||||
|
register: result |
||||||
|
failed_when: result.rc != 0 and "not mounted" not in result.stderr |
||||||
|
|
||||||
|
- include_tasks: "{{ item }}" |
||||||
|
with_items: |
||||||
|
- format-disk.yml |
||||||
|
- format-parts.yml |
||||||
|
- mount.yml |
@ -0,0 +1,22 @@ |
|||||||
|
--- |
||||||
|
- name: Mount btrfs subvolumes. |
||||||
|
include_tasks: mount_btrfs-subvolume.yml |
||||||
|
with_items: "{{ partitioning_priv_btrfs_subvolumes }}" |
||||||
|
loop_control: |
||||||
|
loop_var: subvolume |
||||||
|
|
||||||
|
- name: Make EFI mount point. |
||||||
|
file: |
||||||
|
path: "{{ partitioning_root_mount_point }}/boot/efi" |
||||||
|
state: directory |
||||||
|
recurse: true |
||||||
|
owner: root |
||||||
|
group: root |
||||||
|
mode: 0700 |
||||||
|
|
||||||
|
- name: Mount EFI boot partition. |
||||||
|
mount: |
||||||
|
state: mounted |
||||||
|
src: "{{ partitioning_priv_esp_device_node }}" |
||||||
|
path: "{{ partitioning_root_mount_point }}/boot/efi" |
||||||
|
fstype: vfat |
@ -0,0 +1,17 @@ |
|||||||
|
--- |
||||||
|
- name: Make btrfs subvolume mount point. |
||||||
|
file: |
||||||
|
state: directory |
||||||
|
path: "{{ (partitioning_root_mount_point + subvolume.mountpoint) | quote }}" |
||||||
|
owner: root |
||||||
|
group: root |
||||||
|
mode: 0755 |
||||||
|
|
||||||
|
- name: Mount btrfs subvolume. |
||||||
|
command: > |
||||||
|
mount |
||||||
|
-t btrfs |
||||||
|
-o defaults,noatime,compress=zstd,subvol={{ subvolume.name }} |
||||||
|
{{ partitioning_priv_root_device_node }} |
||||||
|
{{ (partitioning_root_mount_point + subvolume.mountpoint) | quote }} |
||||||
|
changed_when: true |
@ -0,0 +1,30 @@ |
|||||||
|
--- |
||||||
|
- name: Generate fstab. |
||||||
|
include_role: |
||||||
|
name: genfstab |
||||||
|
vars: |
||||||
|
chroot: "{{ partitioning_root_mount_point }}" |
||||||
|
|
||||||
|
- name: Check if btrfs-progs is installed. |
||||||
|
command: arch-chroot {{ partitioning_root_mount_point }} |
||||||
|
pacman -Qk btrfs-progs |
||||||
|
register: _btrfs_progs_installed |
||||||
|
failed_when: false |
||||||
|
changed_when: false |
||||||
|
|
||||||
|
- name: Install btrfs-progs. |
||||||
|
command: arch-chroot {{ partitioning_root_mount_point }} |
||||||
|
pacman -Sy btrfs-progs --noconfirm |
||||||
|
when: _btrfs_progs_installed.rc != 0 |
||||||
|
|
||||||
|
- name: Configure mkinitcpio. |
||||||
|
mkinitcpio: |
||||||
|
state: present |
||||||
|
path: "{{ partitioning_root_mount_point }}/etc/mkinitcpio.conf" |
||||||
|
binaries: /usr/bin/btrfs |
||||||
|
hooks: |
||||||
|
- btrfs |
||||||
|
|
||||||
|
- name: Run mkinitcpio. |
||||||
|
command: arch-chroot {{ partitioning_root_mount_point }} mkinitcpio -P |
||||||
|
changed_when: true |
Loading…
Reference in new issue