Skip to content

[HELPER] Fix swap helpers#2192

Open
ewilly wants to merge 2 commits intoYunoHost:devfrom
ewilly:patch-2
Open

[HELPER] Fix swap helpers#2192
ewilly wants to merge 2 commits intoYunoHost:devfrom
ewilly:patch-2

Conversation

@ewilly
Copy link
Contributor

@ewilly ewilly commented Oct 3, 2025

The problem

Related to YunoHost/issues#2670

Solution

  • ynh_add_swap helper: check if main partition is a btrfs file system before applying chattr
  • ynh_del_swap : check that the file is mounted as swap before trying swappoff

PR Status

...

How to test

...

* ynh_add_swap helper: check if main partition is a btrfs file system before applying chattr
* ynh_del_swap : check that the file is mounted as swap before trying swappoff
@kay0u
Copy link
Member

kay0u commented Oct 6, 2025

I'm not sure it's available on debian, but we can use this for swapfile on btrfs:

btrfs subvolume create /ynh_swap/
btrfs filesystem mkswapfile --size 4g --uuid clear /ynh_swap/swap_$app

Because from what I saw, if there is a swapfile on a subvolume (/ for example), the snapshot fails

if [[ "$root_fs_type" == "btrfs" ]]; then
chattr +C "/swap_$app"
else
echo "Skipping chattr +C for swap because the root filesystem is btrfs which doesn't support this attribute"
Copy link
Member

@zamentur zamentur Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Skipping chattr +C for swap because the root filesystem is btrfs which doesn't support this attribute"
echo "Skipping chattr +C for swap because the root filesystem is '$root_fs_type' which doesn't support this "no copy-on-write" attribute"

# try to set the No_COW attribute on the swapfile with chattr (depending of the filesystem type)
chattr +C "/swap_$app" 2> /dev/null
local root_fs_type=$(cat /proc/mounts | awk '{ if ($2 == var) print $3 }' var="/")
if [[ "$root_fs_type" == "btrfs" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add f2fs https://elixir.bootlin.com/linux/v6.18.6/A/ident/FS_NOCOW_FL

Suggested change
if [[ "$root_fs_type" == "btrfs" ]]; then
if [[ "$root_fs_type" == "btrfs" || "$root_fs_type" == "f2fs" ]]; then

@zamentur
Copy link
Member

zamentur commented Jan 22, 2026

I'm not sure it's available on debian, but we can use this for swapfile on btrfs:

btrfs subvolume create /ynh_swap/
btrfs filesystem mkswapfile --size 4g --uuid clear /ynh_swap/swap_$app

Because from what I saw, if there is a swapfile on a subvolume (/ for example), the snapshot fails

In my ynh-dev container (using btrfs) it's available

@kay0u could you say if the snapshot fail with chattr +C or without ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants