Welcome to the Linux Foundation Forum!

LAB 16.1 - OpenSuse Leap 16 - BTRS filesystem - swapon <file> not allowed

Hi all,

Just FYI:

swapon command does not allow to follow the lab exercise on my OpenSuse 16 (Leap) environment (installed with defaults), throwing the following errors:

v4l4nd3@opensuse16:~> sudo swapon -v swapfile
swapon: /home/v4l4nd3/swapfile: el propietario 1000 del fichero no es seguro; se sugiero 0 (root).
swapon: /home/v4l4nd3/swapfile: firma encontrada [tamaño de página=4096, firma=swap]
swapon: /home/v4l4nd3/swapfile: tamaño de página=4096, tamaño de intercambio=1073741824, tamaño de dispositivo=1073741824
swapon /home/v4l4nd3/swapfile
swapon: /home/v4l4nd3/swapfile: swapon ha fallado: Argumento inválido

Reading the swapon man it says there are some caveats when creating swap files on a BTRFS filesystem.

Regards,
Pablo.

Comments

  • luisviveropena
    luisviveropena Posts: 1,312

    Hi Pablo,

    Yes, BTRFS need some few extras. It can be done as follows, from the documentation here:

    https://btrfs.readthedocs.io/en/latest/Swapfile.html

    1.- I'm running openSUSE Leap 16.

    luis@opensuse:~> cat /etc/os-release
    NAME="openSUSE Leap"
    VERSION="16.0"
    ID="opensuse-leap"
    ID_LIKE="suse opensuse"
    VERSION_ID="16.0"
    PRETTY_NAME="openSUSE Leap 16.0"
    ANSI_COLOR="0;32"
    CPE_NAME="cpe:/o:opensuse:leap:16.0"
    BUG_REPORT_URL="https://bugs.opensuse.org"
    HOME_URL="https://www.opensuse.org/"
    DOCUMENTATION_URL="https://en.opensuse.org/Portal:Leap"
    LOGO="distributor-logo-Leap"

    2.- luis@opensuse:~> truncate -s 0 swapfile

    3.- luis@opensuse:~> chattr +C swapfile

    4.- luis@opensuse:~> fallocate -l 1G swapfile

    I used 1GB for the file, as in the pdf file for this lab.

    5.- luis@opensuse:~> chmod 0600 swapfile

    6.- luis@opensuse:~> sudo mkswap swapfile
    mkswap: swapfile: insecure file owner 1000, fix with: chown 0:0 swapfile
    Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
    no label, UUID=88f22c11-6031-49b9-9813-3d921cc7d2b3

    7.- luis@opensuse:~> sudo chown 0:0 swapfile

    8.- luis@opensuse:~> sudo swapon swapfile

    9.- luis@opensuse:~> cat /proc/swaps
    Filename Type Size Used Priority
    /dev/sda3 partition 2098152 0 -2
    /home/luis/swapfile file 1048572 0 -3

    I hope that helps!

    Regards,
    Luis.

  • valande
    valande Posts: 5

    Thank you so much Luis.
    I will try again on my OpenSuse environment using those BTRFS tricks.

    Kind regards,
    Pablo.

  • luisviveropena
    luisviveropena Posts: 1,312

    Hi Pablo, it's a pleasure!

    Regards,
    Luis.

Categories

Upcoming Training