Similar to mount, there are mainly two ways to mount and enable swap partitions:
swapon -a,
enabling all swaps listed in /etc/fstab.
A ready to use service to do this
is provided for each supported Kernel and named swap-fstab
The source directory is contained in the kernel specific packages:
goetia-linux,
goetia-freebsd,
... .
The second approach is highly recommended for the reasons listed on the mount page.
Create the following oneshot
source directory
in the src/swap/swap-@PART@
subdirectory of the
system configuration directory.
swap-@PART@ ├── dependencies.d │ ├── mount-dev # empty/arbitrary │ └── mount-sys # empty/arbitrary ├── up # see below ├── down # see below └── type # oneshot
with the following up script:
#!/bin/execlineb -P fdmove -c 2 1 swapon @PARTITION_OR_SWAPFILE@
and the following down script:
#!/bin/execlineb -P fdmove -c 2 1 swapoff @PARTITION_OR_SWAPFILE@
replace
@PARTITION_OR_SWAPFILE@
with the path of the partition or swap file;
or generate it from a UUID or PARTUUID
(see the mount page)
and @PART@
with a descriptive name of the swap partition.
If an encrypted swap file is desired, just put it on an already encrypted, mounted partition and follow the procedure for unencrypted swap.
The following will format the partition with a random key. This will happen during every boot, which eliminates the need to decrypt the swap partition during boot.
Create the following oneshot
source directory
in the src/swap/swap-@PART@
subdirectory of the
system configuration directory.
swap-@PART@ ├── dependencies.d │ ├── random-seed-load # empty/arbitrary │ ├── mount-dev # empty/arbitrary │ └── mount-sys # empty/arbitrary ├── up # see below ├── down # see below └── type # oneshot
with the following up script:
#!/bin/execlineb -P
fdmove -c 2 1
if {
redirfd -a 2 /dev/null
cryptsetup open
--allow-discards
--perf-no_read_workqueue
--perf-no_write_workqueue
--type plain
--key-file /dev/urandom
@PARTITION@ swap-@PART@
}
if { mkswap -q /dev/mapper/swap-@PART@ }
swapon -d /dev/mapper/swap-@PART@
and the following down script:
#!/bin/execlineb -P
fdmove -c 2 1
if -x0 { swapoff /dev/mapper/swap-@PART@ }
# hack since swapoff exits before finishing
# the actual swapoff
# resulting in device or resource busy
# during the command below
foreground { sleep 1 }
cryptsetup close swap-@PART@
replace
@PARTITION@
with the path of the partition;
or generate it from a UUID or PARTUUID
(see the mount page)
and @PART@
with a descriptive name of the swap partition.