So it's created automagically with proper attributes.
# Create a swap file
(
image_install mkswap swapon swapoff stress
-
- dd if=/dev/zero of="${initdir:?}/swapfile" bs=1M count=48
- chmod 0600 "${initdir:?}/swapfile"
+ image_install -o btrfs
mkdir -p "${initdir:?}/etc/systemd/system/init.scope.d/"
cat >>"${initdir:?}/etc/systemd/system/init.scope.d/test-55-oomd.conf" <<EOF
# Activate swap file if we are in a VM
if systemd-detect-virt --vm --quiet; then
- mkswap /swapfile
+ if [[ "$(findmnt -n -o FSTYPE /)" == btrfs ]]; then
+ btrfs filesystem mkswapfile -s 64M /swapfile
+ else
+ dd if=/dev/zero of=/swapfile bs=1M count=64
+ chmod 0600 /swapfile
+ mkswap /swapfile
+ fi
+
swapon /swapfile
swapon --show
fi