From 09138174d48a344e2c6b2d815f326c7e06dbed8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C5=A1per=20Fele-=C5=BDor=C5=BE?= Date: Fri, 12 Sep 2025 15:43:10 +0200 Subject: [PATCH] Fix swap on linux+btrfs --- roles/fri_base/tasks/main_lin.yml | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/roles/fri_base/tasks/main_lin.yml b/roles/fri_base/tasks/main_lin.yml index 203ab5c..154d6ea 100644 --- a/roles/fri_base/tasks/main_lin.yml +++ b/roles/fri_base/tasks/main_lin.yml @@ -1,6 +1,55 @@ - name: Enable multiarch command: dpkg --add-architecture i386 +- name: Create swap btrfs subvolume + command: btrfs subvolume create /swap + ignore_errors: True + +- name: Create swap directory if it does not exist + file: + path: /swap + state: directory + +- name: Create btrfs swap + command: btrfs filesystem mkswapfile --size 4g /swap/swap.img + ignore_errors: True + +- name: Create swap image if it does not exist + shell: fallocate -l 4G /swap/swap.img && mkswap /swap/swap.img + args: + creates: /swap/swap.img + ignore_errors: True + +- name: Change swap file permissions + file: path="/swap/swap.img" + owner=root + group=root + mode=0600 + +- name: Write swap entry in fstab + mount: name=none + src=/swap/swap.img + fstype=swap + opts=sw + passno=0 + dump=0 + state=present + +- name: Activate swap + command: "swapon /swap/swap.img" + ignore_errors: True + +- name: Make sure default swap entry does not exist + mount: + path: none + src: /swap.img + fstype: swap + state: absent + +- name: Make sure default swap is not used + command: swapoff /swap/swap.img + ignore_errors: True + - name: Install generally useful packages apt: name: