Examine individual changes

From Gentoo Wiki
Abuse Filter navigation (Home | Recent filter changes | Examine past edits | Abuse log)
Jump to:navigation Jump to:search

This page allows you to examine the variables generated by the Abuse Filter for an individual change, and test it against filters.

Variables generated for this change

VariableValue
Edit count of the user (user_editcount)
16
Name of the user account (user_name)
'Kingmeffisto'
Age of the user account (user_age)
232239384
Page ID (page_id)
274224
Page namespace (page_namespace)
0
Page title (without namespace) (page_title)
'Swap'
Full page title (page_prefixedtitle)
'Swap'
Action (action)
'edit'
Edit summary/reason (summary)
'Encrypted SWAP with hibernate option'
Old content model (old_content_model)
'wikitext'
New content model (new_content_model)
'wikitext'
Old page wikitext, before the edit (old_wikitext)
'{{InfoBox stack |{{InfoBox wikipedia|Memory_paging|header=true}} |{{InfoBox todo|swapiness, remove swap files}} }} In the Linux/Unix world, the term '''swap''' is generally used as a synonym for [[wikipedia:Memory_paging|memory paging]]. Swap [[Article description::refers to both the act of moving memory pages between RAM and disk and the allocated space on the disk itself.]] Linux can use any combination of swap partition and/or swap files together; however swap space may not be necessary depending on the necessary requirements for the system in question. For example, a laptop that will be [[Suspend and hibernate|suspending to disk]] ([[Suspend and hibernate|hibernation]]) requires all pages in memory to be stored to disk, so swap is necessary in this case. Server systems equipped with large amount of memory and running at a constant load might not require swap at all. For further details, see the dedicated [[Knowledge_Base:Is_swap_space_really_necessary|Knowledge Base]] article. == Swap partition == As best practice, the Gentoo Handbook recommends, as part of the installation process, creating a swap [[Partition|partition]] with a size of twice the available system memory<ref>[[Handbook:AMD64/Installation/Disks#What_about_swap_space.3F]]</ref>. Swap partitions can be created and activated at any time as long as partitions are available and formatted correctly. === Creation === Presuming {{Path|/dev/sda2}} is the partition available to be used for swap: {{RootCmd |mkswap /dev/sda2 # Format the partition for swap. |swapon /dev/sda2 # # Activate the swap partition. }} Review the activated swaps with the {{c|swapon}} command: {{RootCmd|swapon --show}} To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to {{Path|fstab}}: {{FileBox|filename=/etc/fstab|1= /dev/sda2 none swap sw 0 0 }} == Swap files == In order to work around the more ridged constraints of disk partitions, an alternative is to use swap as an on-disk file. Files have the ability to be located ''inside'' disk partitions. This allows the system administrator the flexibility to resize or move the swap space as necessary to meet the demands of the system without having to open a [[Partition|partitioning tool]]. === Creation === The first step in creating a swap file is to allocate a file of the target swap size. Several standard utilities can be used for this purpose. {{c|fallocate}} (part of {{package|sys-apps/util-linux}}) will suffice for this example {{RootCmd |fallocate -l 12GiB 12G-swapfile # Create a file. |chmod 600 12G-swapfile # Restrict security on the file to root access only. |mkswap 12G-swapfile # Format the file swap. |swapon 12G-swapfile # Activate the swap file. }} Review the system swaps with the {{c|swapon}} command: {{RootCmd|swapon --show}} To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to {{Path|fstab}}: {{FileBox|filename=/etc/fstab|1= /12G-swapfile none swap sw 0 0 }} === Encrypted Swap === Since swap contents do not need to persist between boots, it's a good idea to encrypt them. It's easy using a swap file. {{RootCmd |dd if{{=}}/dev/zero of{{=}}swap count{{=}}2048 bs{{=}}1M |cryptsetup --type plain -d /dev/urandom open swap swap |swapon swap |swapon --show}} Then, edit {{Path|/etc/fstab}} and either {{Path|/etc/crypttab}} (if using systemd) or {{Path|/etc/conf.d/dmcrypt}} (if using OpenRC) to automatically active it: {{FileBox|filename=/etc/crypttab|1= swap /opt/swap /dev/urandom swap}} {{FileBox|filename=/etc/conf.d/dmcrypt|1= swap=swap source=/opt/swap }} {{FileBox|filename=/etc/fstab|1= /dev/mapper/swap none swap sw 0 0 }} Finally, if using OpenRC, enable the dmcrypt service: {{RootCmd|rc-update add dmcrypt boot}} === Btrfs === When using btrfs, set required attributes on the swap file disabling copy-on-write and compression. <ref>https://wiki.archlinux.org/title/Btrfs#Swap_file</ref> {{RootCmd | cd /path/to/swapfile | truncate -s 0 ./swapfile | chattr +C ./swapfile | btrfs property set ./swapfile compression none }} === OpenRC configuration === When using swap files which are not on the root filesystem, the service ordering in OpenRC should be changed via {{Path|/etc/conf.d/swap}}: {{FileBox|lang=bash|filename=/etc/conf.d/swap|1= # If you are only using local swap partitions, you should not change # this file. Otherwise, you need to uncomment the below rc_before line # followed by the appropriate rc_need line. rc_before="!localmount" # # If you are using swap files stored on local file systems, uncomment # this line. rc_need="localmount" # # If you are using swap files stored on network file systems or swap # partitions stored on network block devices such as iSCSI, uncomment # this line. #rc_need="netmount" }} == See also == * {{See also|Filesystem}} * {{See also|Zram}} * {{See also|Zswap}} == External resources == * Upstream kernel.org documentation on swap suspend - https://www.kernel.org/doc/html/latest/power/swsusp.html#swap-suspend == References == [[Category:Kernel]]'
New page wikitext, after the edit (new_wikitext)
'{{InfoBox stack |{{InfoBox wikipedia|Memory_paging|header=true}} |{{InfoBox todo|swapiness, remove swap files}} }} In the Linux/Unix world, the term '''swap''' is generally used as a synonym for [[wikipedia:Memory_paging|memory paging]]. Swap [[Article description::refers to both the act of moving memory pages between RAM and disk and the allocated space on the disk itself.]] Linux can use any combination of swap partition and/or swap files together; however swap space may not be necessary depending on the necessary requirements for the system in question. For example, a laptop that will be [[Suspend and hibernate|suspending to disk]] ([[Suspend and hibernate|hibernation]]) requires all pages in memory to be stored to disk, so swap is necessary in this case. Server systems equipped with large amount of memory and running at a constant load might not require swap at all. For further details, see the dedicated [[Knowledge_Base:Is_swap_space_really_necessary|Knowledge Base]] article. == Swap partition == As best practice, the Gentoo Handbook recommends, as part of the installation process, creating a swap [[Partition|partition]] with a size of twice the available system memory<ref>[[Handbook:AMD64/Installation/Disks#What_about_swap_space.3F]]</ref>. Swap partitions can be created and activated at any time as long as partitions are available and formatted correctly. === Creation === Presuming {{Path|/dev/sda2}} is the partition available to be used for swap: {{RootCmd |mkswap /dev/sda2 # Format the partition for swap. |swapon /dev/sda2 # # Activate the swap partition. }} Review the activated swaps with the {{c|swapon}} command: {{RootCmd|swapon --show}} To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to {{Path|fstab}}: {{FileBox|filename=/etc/fstab|1= /dev/sda2 none swap sw 0 0 }} === Encrypted SWAP with hibernate option === Assuming you want to have a LUKS encrypted swap partition and still be able to use hibernate (a.k.a. suspend to disk). The encrypted swap partition needs a known LUKS-key (keyfile, password, ..), since you’re ask to enter it in a very early phase of the boot process. The Kernel then has to decide whether to regularly boot the system or to load a hibernated RAM image from SWAP – if available. The creation of a LUKS encrypted swap partion isn’t different to any other LUKS encrypted partition, described in [[Dm-crypt#Creating_an_encrypted_storage_platform|Creating an encrypted storage platform]]. Just do {{c|mkswap}} instead of {{c|mkfs.*}} to that LUKS encrypted partition, to create SWAP. The UUID (i.e. <code>01b37ea8-74a5-4526-85c7-9fdf6dad34cb</code>), created when formatting as swap, is needed for the next step: Tell the bootloader (GRUB) where to resume from if hibernated: {{FileBox|filename=/etc/default/grub|1= GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb" }} In addidition (when using openrc with dracut, I’m not using systemd) you have to tell dracut the major an minor number of the belonging LUKS device, so it can create an appropriate initrd: {{RootCmd |lsblk|output=<pre> .. └─sdb1                                          8:22   0    32G  0 part    └─luks-cc166689-4246-41ae-86e8-84705b81ecc2 253:1 0 32G 0 crypt [SWAP] </pre>}} {{RootCmd |echo 253:1 > /sys/power/resume }} {{Note|The default value is <code>0:0</code>. Echo in this again to deactivate hibernation.}} {{Warning|Don't mix up the LUKS UUID (<code>cc166689-4246-41ae-86e8-84705b81ecc2</code>) and the SWAP UUID (<code>01b37ea8-74a5-4526-85c7-9fdf6dad34cb</code>).}} Finally, the initrd needs to be updated with this changes: {{RootCmd |dracut --hostonly --force }} Don’t forget the regular configuration of SWAP in {{Path|/etc/fstab}} and restart the system afterwards. {{FileBox|filename=/etc/fstab|1= # /dev/sdb1 (SWAP) UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb        none      swap    sw      0 0 }} {{Note|If you already had a LUKS encrypted SWAP using dmcrypt [[https://wiki.gentoo.org/wiki/Dm-crypt|dmcrypt]], inlcuding a configuration in {{Path|/etc/conf.d/dmcrypt}}, it’s obsolete now, since this LUKS device will now be opened earlier with the help of initrd.}} ==== Using full disk encryption ==== When already using full disk encryption with LUKS, it’ll now ask you two times when booting; to enter the LUKS-key for you root partition (as before) and in addition for your SWAP partition. It is possible to just decrypt the root partition and then use a LUKS keyfile to decrypt SWAP, stored on the just now decrypted root partition. Details and an easy example how to do this, can be found on [https://mirrors.edge.kernel.org/pub/linux/utils/boot/dracut/dracut.html#_crypto_luks_key_on_removable_device_support kernel.org]. == Swap files == In order to work around the more ridged constraints of disk partitions, an alternative is to use swap as an on-disk file. Files have the ability to be located ''inside'' disk partitions. This allows the system administrator the flexibility to resize or move the swap space as necessary to meet the demands of the system without having to open a [[Partition|partitioning tool]]. === Creation === The first step in creating a swap file is to allocate a file of the target swap size. Several standard utilities can be used for this purpose. {{c|fallocate}} (part of {{package|sys-apps/util-linux}}) will suffice for this example {{RootCmd |fallocate -l 12GiB 12G-swapfile # Create a file. |chmod 600 12G-swapfile # Restrict security on the file to root access only. |mkswap 12G-swapfile # Format the file swap. |swapon 12G-swapfile # Activate the swap file. }} Review the system swaps with the {{c|swapon}} command: {{RootCmd|swapon --show}} To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to {{Path|fstab}}: {{FileBox|filename=/etc/fstab|1= /12G-swapfile none swap sw 0 0 }} === Encrypted Swap === Since swap contents do not need to persist between boots, it's a good idea to encrypt them. It's easy using a swap file. {{RootCmd |dd if{{=}}/dev/zero of{{=}}swap count{{=}}2048 bs{{=}}1M |cryptsetup --type plain -d /dev/urandom open swap swap |swapon swap |swapon --show}} Then, edit {{Path|/etc/fstab}} and either {{Path|/etc/crypttab}} (if using systemd) or {{Path|/etc/conf.d/dmcrypt}} (if using OpenRC) to automatically active it: {{FileBox|filename=/etc/crypttab|1= swap /opt/swap /dev/urandom swap}} {{FileBox|filename=/etc/conf.d/dmcrypt|1= swap=swap source=/opt/swap }} {{FileBox|filename=/etc/fstab|1= /dev/mapper/swap none swap sw 0 0 }} Finally, if using OpenRC, enable the dmcrypt service: {{RootCmd|rc-update add dmcrypt boot}} === Btrfs === When using btrfs, set required attributes on the swap file disabling copy-on-write and compression. <ref>https://wiki.archlinux.org/title/Btrfs#Swap_file</ref> {{RootCmd | cd /path/to/swapfile | truncate -s 0 ./swapfile | chattr +C ./swapfile | btrfs property set ./swapfile compression none }} === OpenRC configuration === When using swap files which are not on the root filesystem, the service ordering in OpenRC should be changed via {{Path|/etc/conf.d/swap}}: {{FileBox|lang=bash|filename=/etc/conf.d/swap|1= # If you are only using local swap partitions, you should not change # this file. Otherwise, you need to uncomment the below rc_before line # followed by the appropriate rc_need line. rc_before="!localmount" # # If you are using swap files stored on local file systems, uncomment # this line. rc_need="localmount" # # If you are using swap files stored on network file systems or swap # partitions stored on network block devices such as iSCSI, uncomment # this line. #rc_need="netmount" }} == See also == * {{See also|Filesystem}} * {{See also|Zram}} * {{See also|Zswap}} == External resources == * Upstream kernel.org documentation on swap suspend - https://www.kernel.org/doc/html/latest/power/swsusp.html#swap-suspend == References == [[Category:Kernel]]'
Unified diff of changes made by edit (edit_diff)
'@@ -32,4 +32,53 @@ /dev/sda2 none swap sw 0 0 }} + + +=== Encrypted SWAP with hibernate option === +Assuming you want to have a LUKS encrypted swap partition and still be able to use hibernate (a.k.a. suspend to disk). The encrypted swap partition needs a known LUKS-key (keyfile, password, ..), since you’re ask to enter it in a very early phase of the boot process. The Kernel then has to decide whether to regularly boot the system or to load a hibernated RAM image from SWAP – if available. + +The creation of a LUKS encrypted swap partion isn’t different to any other LUKS encrypted partition, described in [[Dm-crypt#Creating_an_encrypted_storage_platform|Creating an encrypted storage platform]]. Just do {{c|mkswap}} instead of {{c|mkfs.*}} to that LUKS encrypted partition, to create SWAP. The UUID (i.e. <code>01b37ea8-74a5-4526-85c7-9fdf6dad34cb</code>), created when formatting as swap, is needed for the next step: + +Tell the bootloader (GRUB) where to resume from if hibernated: + +{{FileBox|filename=/etc/default/grub|1= +GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb" +}} + +In addidition (when using openrc with dracut, I’m not using systemd) you have to tell dracut the major an minor number of the belonging LUKS device, so it can create an appropriate initrd: + +{{RootCmd +|lsblk|output=<pre> +.. +└─sdb1                                          8:22   0    32G  0 part    + └─luks-cc166689-4246-41ae-86e8-84705b81ecc2 253:1 0 32G 0 crypt [SWAP] +</pre>}} + +{{RootCmd +|echo 253:1 > /sys/power/resume +}} + +{{Note|The default value is <code>0:0</code>. Echo in this again to deactivate hibernation.}} +{{Warning|Don't mix up the LUKS UUID (<code>cc166689-4246-41ae-86e8-84705b81ecc2</code>) and the SWAP UUID (<code>01b37ea8-74a5-4526-85c7-9fdf6dad34cb</code>).}} + +Finally, the initrd needs to be updated with this changes: + +{{RootCmd +|dracut --hostonly --force +}} + + +Don’t forget the regular configuration of SWAP in {{Path|/etc/fstab}} and restart the system afterwards. + +{{FileBox|filename=/etc/fstab|1= +# /dev/sdb1 (SWAP) +UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb        none      swap    sw      0 0 +}} + +{{Note|If you already had a LUKS encrypted SWAP using dmcrypt [[https://wiki.gentoo.org/wiki/Dm-crypt|dmcrypt]], inlcuding a configuration in {{Path|/etc/conf.d/dmcrypt}}, it’s obsolete now, since this LUKS device will now be opened earlier with the help of initrd.}} + +==== Using full disk encryption ==== +When already using full disk encryption with LUKS, it’ll now ask you two times when booting; to enter the LUKS-key for you root partition (as before) and in addition for your SWAP partition. It is possible to just decrypt the root partition and then use a LUKS keyfile to decrypt SWAP, stored on the just now decrypted root partition. Details and an easy example how to do this, can be found on [https://mirrors.edge.kernel.org/pub/linux/utils/boot/dracut/dracut.html#_crypto_luks_key_on_removable_device_support kernel.org]. + + == Swap files == @@ -57,4 +106,7 @@ /12G-swapfile none swap sw 0 0 }} + + + === Encrypted Swap === '
Old page size (old_size)
5168
Lines added in edit (added_lines)
[ 0 => '', 1 => '', 2 => '=== Encrypted SWAP with hibernate option ===', 3 => 'Assuming you want to have a LUKS encrypted swap partition and still be able to use hibernate (a.k.a. suspend to disk). The encrypted swap partition needs a known LUKS-key (keyfile, password, ..), since you’re ask to enter it in a very early phase of the boot process. The Kernel then has to decide whether to regularly boot the system or to load a hibernated RAM image from SWAP – if available.', 4 => '', 5 => 'The creation of a LUKS encrypted swap partion isn’t different to any other LUKS encrypted partition, described in [[Dm-crypt#Creating_an_encrypted_storage_platform|Creating an encrypted storage platform]]. Just do {{c|mkswap}} instead of {{c|mkfs.*}} to that LUKS encrypted partition, to create SWAP. The UUID (i.e. <code>01b37ea8-74a5-4526-85c7-9fdf6dad34cb</code>), created when formatting as swap, is needed for the next step:', 6 => '', 7 => 'Tell the bootloader (GRUB) where to resume from if hibernated:', 8 => '', 9 => '{{FileBox|filename=/etc/default/grub|1=', 10 => 'GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb"', 11 => '}}', 12 => '', 13 => 'In addidition (when using openrc with dracut, I’m not using systemd) you have to tell dracut the major an minor number of the belonging LUKS device, so it can create an appropriate initrd:', 14 => '', 15 => '{{RootCmd', 16 => '|lsblk|output=<pre>', 17 => '..', 18 => '└─sdb1                                          8:22   0    32G  0 part   ', 19 => ' └─luks-cc166689-4246-41ae-86e8-84705b81ecc2 253:1 0 32G 0 crypt [SWAP]', 20 => '</pre>}}', 21 => '', 22 => '{{RootCmd', 23 => '|echo 253:1 > /sys/power/resume', 24 => '}}', 25 => '', 26 => '{{Note|The default value is <code>0:0</code>. Echo in this again to deactivate hibernation.}}', 27 => '{{Warning|Don't mix up the LUKS UUID (<code>cc166689-4246-41ae-86e8-84705b81ecc2</code>) and the SWAP UUID (<code>01b37ea8-74a5-4526-85c7-9fdf6dad34cb</code>).}}', 28 => '', 29 => 'Finally, the initrd needs to be updated with this changes:', 30 => '', 31 => '{{RootCmd', 32 => '|dracut --hostonly --force', 33 => '}}', 34 => '', 35 => '', 36 => 'Don’t forget the regular configuration of SWAP in {{Path|/etc/fstab}} and restart the system afterwards.', 37 => '', 38 => '{{FileBox|filename=/etc/fstab|1=', 39 => '# /dev/sdb1 (SWAP) ', 40 => 'UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb        none      swap    sw      0 0', 41 => '}}', 42 => '', 43 => '{{Note|If you already had a LUKS encrypted SWAP using dmcrypt [[https://wiki.gentoo.org/wiki/Dm-crypt|dmcrypt]], inlcuding a configuration in {{Path|/etc/conf.d/dmcrypt}}, it’s obsolete now, since this LUKS device will now be opened earlier with the help of initrd.}}', 44 => '', 45 => '==== Using full disk encryption ====', 46 => 'When already using full disk encryption with LUKS, it’ll now ask you two times when booting; to enter the LUKS-key for you root partition (as before) and in addition for your SWAP partition. It is possible to just decrypt the root partition and then use a LUKS keyfile to decrypt SWAP, stored on the just now decrypted root partition. Details and an easy example how to do this, can be found on [https://mirrors.edge.kernel.org/pub/linux/utils/boot/dracut/dracut.html#_crypto_luks_key_on_removable_device_support kernel.org].', 47 => '', 48 => '', 49 => '', 50 => '', 51 => '' ]
Lines removed in edit (removed_lines)
[]
New page text, stripped of any markup (new_text)
' Resources Wikipedia This article has some todo items: swapiness, remove swap files In the Linux/Unix world, the term swap is generally used as a synonym for memory paging. Swap refers to both the act of moving memory pages between RAM and disk and the allocated space on the disk itself. Linux can use any combination of swap partition and/or swap files together; however swap space may not be necessary depending on the necessary requirements for the system in question. For example, a laptop that will be suspending to disk (hibernation) requires all pages in memory to be stored to disk, so swap is necessary in this case. Server systems equipped with large amount of memory and running at a constant load might not require swap at all. For further details, see the dedicated Knowledge Base article. Contents 1 Swap partition 1.1 Creation 1.2 Encrypted SWAP with hibernate option 1.2.1 Using full disk encryption 2 Swap files 2.1 Creation 2.2 Encrypted Swap 2.3 Btrfs 2.4 OpenRC configuration 3 See also 4 External resources 5 References Swap partition[edit | edit source] As best practice, the Gentoo Handbook recommends, as part of the installation process, creating a swap partition with a size of twice the available system memory&#91;1&#93;. Swap partitions can be created and activated at any time as long as partitions are available and formatted correctly. Creation[edit | edit source] Presuming /dev/sda2 is the partition available to be used for swap: root #mkswap /dev/sda2 # Format the partition for swap. root #swapon /dev/sda2 # # Activate the swap partition. Review the activated swaps with the swapon command: root #swapon --show To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to fstab: FILE /etc/fstab/dev/sda2 none swap sw 0 0 Encrypted SWAP with hibernate option[edit | edit source] Assuming you want to have a LUKS encrypted swap partition and still be able to use hibernate (a.k.a. suspend to disk). The encrypted swap partition needs a known LUKS-key (keyfile, password, ..), since you’re ask to enter it in a very early phase of the boot process. The Kernel then has to decide whether to regularly boot the system or to load a hibernated RAM image from SWAP – if available. The creation of a LUKS encrypted swap partion isn’t different to any other LUKS encrypted partition, described in Creating an encrypted storage platform. Just do mkswap instead of mkfs.* to that LUKS encrypted partition, to create SWAP. The UUID (i.e. 01b37ea8-74a5-4526-85c7-9fdf6dad34cb), created when formatting as swap, is needed for the next step: Tell the bootloader (GRUB) where to resume from if hibernated: FILE /etc/default/grubGRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb" In addidition (when using openrc with dracut, I’m not using systemd) you have to tell dracut the major an minor number of the belonging LUKS device, so it can create an appropriate initrd: root #lsblk.. └─sdb1 &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;8:22 &#160;&#160;0 &#160;&#160;&#160;32G &#160;0 part &#160;&#160; └─luks-cc166689-4246-41ae-86e8-84705b81ecc2 253:1 0 32G 0 crypt [SWAP] root #echo 253:1 &gt; /sys/power/resume NoteThe default value is 0:0. Echo in this again to deactivate hibernation. WarningDon't mix up the LUKS UUID (cc166689-4246-41ae-86e8-84705b81ecc2) and the SWAP UUID (01b37ea8-74a5-4526-85c7-9fdf6dad34cb). Finally, the initrd needs to be updated with this changes: root #dracut --hostonly --force Don’t forget the regular configuration of SWAP in /etc/fstab and restart the system afterwards. FILE /etc/fstab# /dev/sdb1 (SWAP) UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb &#160;&#160;&#160;&#160;&#160;&#160; none &#160;&#160;&#160;&#160; swap &#160;&#160;&#160;sw&#160;&#160;&#160;&#160;&#160;&#160;0 0 NoteIf you already had a LUKS encrypted SWAP using dmcrypt [[1]], inlcuding a configuration in /etc/conf.d/dmcrypt, it’s obsolete now, since this LUKS device will now be opened earlier with the help of initrd. Using full disk encryption[edit | edit source] When already using full disk encryption with LUKS, it’ll now ask you two times when booting; to enter the LUKS-key for you root partition (as before) and in addition for your SWAP partition. It is possible to just decrypt the root partition and then use a LUKS keyfile to decrypt SWAP, stored on the just now decrypted root partition. Details and an easy example how to do this, can be found on kernel.org. Swap files[edit | edit source] In order to work around the more ridged constraints of disk partitions, an alternative is to use swap as an on-disk file. Files have the ability to be located inside disk partitions. This allows the system administrator the flexibility to resize or move the swap space as necessary to meet the demands of the system without having to open a partitioning tool. Creation[edit | edit source] The first step in creating a swap file is to allocate a file of the target swap size. Several standard utilities can be used for this purpose. fallocate (part of sys-apps/util-linux) will suffice for this example root #fallocate -l 12GiB 12G-swapfile # Create a file. root #chmod 600 12G-swapfile # Restrict security on the file to root access only. root #mkswap 12G-swapfile # Format the file swap. root #swapon 12G-swapfile # Activate the swap file. Review the system swaps with the swapon command: root #swapon --show To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to fstab: FILE /etc/fstab/12G-swapfile none swap sw 0 0 Encrypted Swap[edit | edit source] Since swap contents do not need to persist between boots, it's a good idea to encrypt them. It's easy using a swap file. root #dd if=/dev/zero of=swap count=2048 bs=1M root #cryptsetup --type plain -d /dev/urandom open swap swap root #swapon swap root #swapon --show Then, edit /etc/fstab and either /etc/crypttab (if using systemd) or /etc/conf.d/dmcrypt (if using OpenRC) to automatically active it: FILE /etc/crypttabswap /opt/swap /dev/urandom swap FILE /etc/conf.d/dmcryptswap=swap source=/opt/swap FILE /etc/fstab/dev/mapper/swap none swap sw 0 0 Finally, if using OpenRC, enable the dmcrypt service: root #rc-update add dmcrypt boot Btrfs[edit | edit source] When using btrfs, set required attributes on the swap file disabling copy-on-write and compression. &#91;2&#93; root # cd /path/to/swapfile root # truncate -s 0 ./swapfile root # chattr +C ./swapfile root # btrfs property set ./swapfile compression none OpenRC configuration[edit | edit source] When using swap files which are not on the root filesystem, the service ordering in OpenRC should be changed via /etc/conf.d/swap: FILE /etc/conf.d/swap# If you are only using local swap partitions, you should not change # this file. Otherwise, you need to uncomment the below rc_before line # followed by the appropriate rc_need line. rc_before=&quot;!localmount&quot; # # If you are using swap files stored on local file systems, uncomment # this line. rc_need=&quot;localmount&quot; # # If you are using swap files stored on network file systems or swap # partitions stored on network block devices such as iSCSI, uncomment # this line. #rc_need=&quot;netmount&quot; See also[edit | edit source] Filesystem — a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve, and update data as well as manage the available space on the device(s) which contain it. Zram — a Linux kernel feature and userspace tools for creating compressible RAM-based block devices. Zswap — a lightweight compressed cache for swap pages. External resources[edit | edit source] Upstream kernel.org documentation on swap suspend - https://www.kernel.org/doc/html/latest/power/swsusp.html#swap-suspend References[edit | edit source] ↑ Handbook:AMD64/Installation/Disks#What_about_swap_space.3F ↑ https://wiki.archlinux.org/title/Btrfs#Swap_file'
Parsed HTML source of the new revision (new_html)
'<div class="mw-parser-output"><div id="infobox-stack" class="list-group" style="width: 25em; float: right; clear: right; font-size: 90%; margin-left: 1em;"> <div class="list-group-item text-center" style="padding-top: 3px; padding-bottom: 3px; background-color: #463C65; color: white;"><b>Resources</b></div> <div id="infobox" class="list-group-item" style="display: flex; align-items: center; padding: 5px; min-height: 3em;"><span style="display: inline-block; width: 3em; overflow: hidden; text-align: center;"><span class="fa fa-wikipedia-w fa-fw fa-2x"></span></span><span><a rel="nofollow" class="external text" href="https://en.wikipedia.org/wiki/Memory_paging">Wikipedia</a></span></div> <div id="infobox" class="list-group-item" style="display: flex; align-items: center; padding: 5px; min-height: 3em;"><span style="display: inline-block; width: 3em; overflow: hidden; text-align: center;"><span class="fa fa-list-alt fa-fw fa-2x"></span></span><span>This article has some todo items:<br /> <ul><li>swapiness, remove swap files</li></ul></span></div> </div> <p>In the Linux/Unix world, the term <b>swap</b> is generally used as a synonym for <a href="https://en.wikipedia.org/wiki/Memory_paging" class="extiw" title="wikipedia:Memory paging">memory paging</a>. Swap refers to both the act of moving memory pages between RAM and disk and the allocated space on the disk itself. </p><p>Linux can use any combination of swap partition and/or swap files together; however swap space may not be necessary depending on the necessary requirements for the system in question. For example, a laptop that will be <a href="/wiki/Suspend_and_hibernate" title="Suspend and hibernate">suspending to disk</a> (<a href="/wiki/Suspend_and_hibernate" title="Suspend and hibernate">hibernation</a>) requires all pages in memory to be stored to disk, so swap is necessary in this case. Server systems equipped with large amount of memory and running at a constant load might not require swap at all. For further details, see the dedicated <a href="/wiki/Knowledge_Base:Is_swap_space_really_necessary" title="Knowledge Base:Is swap space really necessary">Knowledge Base</a> article. </p> <div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div> <ul> <li class="toclevel-1 tocsection-1"><a href="#Swap_partition"><span class="tocnumber">1</span> <span class="toctext">Swap partition</span></a> <ul> <li class="toclevel-2 tocsection-2"><a href="#Creation"><span class="tocnumber">1.1</span> <span class="toctext">Creation</span></a></li> <li class="toclevel-2 tocsection-3"><a href="#Encrypted_SWAP_with_hibernate_option"><span class="tocnumber">1.2</span> <span class="toctext">Encrypted SWAP with hibernate option</span></a> <ul> <li class="toclevel-3 tocsection-4"><a href="#Using_full_disk_encryption"><span class="tocnumber">1.2.1</span> <span class="toctext">Using full disk encryption</span></a></li> </ul> </li> </ul> </li> <li class="toclevel-1 tocsection-5"><a href="#Swap_files"><span class="tocnumber">2</span> <span class="toctext">Swap files</span></a> <ul> <li class="toclevel-2 tocsection-6"><a href="#Creation_2"><span class="tocnumber">2.1</span> <span class="toctext">Creation</span></a></li> <li class="toclevel-2 tocsection-7"><a href="#Encrypted_Swap"><span class="tocnumber">2.2</span> <span class="toctext">Encrypted Swap</span></a></li> <li class="toclevel-2 tocsection-8"><a href="#Btrfs"><span class="tocnumber">2.3</span> <span class="toctext">Btrfs</span></a></li> <li class="toclevel-2 tocsection-9"><a href="#OpenRC_configuration"><span class="tocnumber">2.4</span> <span class="toctext">OpenRC configuration</span></a></li> </ul> </li> <li class="toclevel-1 tocsection-10"><a href="#See_also"><span class="tocnumber">3</span> <span class="toctext">See also</span></a></li> <li class="toclevel-1 tocsection-11"><a href="#External_resources"><span class="tocnumber">4</span> <span class="toctext">External resources</span></a></li> <li class="toclevel-1 tocsection-12"><a href="#References"><span class="tocnumber">5</span> <span class="toctext">References</span></a></li> </ul> </div> <h2><span class="mw-headline" id="Swap_partition">Swap partition</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=1" class="mw-editsection-visualeditor" title="Edit section: Swap partition">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=1" title="Edit section: Swap partition">edit source</a><span class="mw-editsection-bracket">]</span></span></h2> <p>As best practice, the Gentoo Handbook recommends, as part of the installation process, creating a swap <a href="/wiki/Partition" title="Partition">partition</a> with a size of twice the available system memory<sup id="cite_ref-1" class="reference"><a href="#cite_note-1">&#91;1&#93;</a></sup>. </p><p>Swap partitions can be created and activated at any time as long as partitions are available and formatted correctly. </p> <h3><span class="mw-headline" id="Creation">Creation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=2" class="mw-editsection-visualeditor" title="Edit section: Creation">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=2" title="Edit section: Creation">edit source</a><span class="mw-editsection-bracket">]</span></span></h3> <p>Presuming <span style="font-family: monospace; font-size: 95%">/dev/sda2</span> is the partition available to be used for swap: </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>mkswap /dev/sda2 # Format the partition for swap. </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>swapon /dev/sda2 # # Activate the swap partition. </code></span></div></div> <p>Review the activated swaps with the <span style="font-family: monospace; font-size: 95%; font-weight: bold;" class="tripleclick-separator">swapon</span> command: </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>swapon --show</code></span></div></div> <p>To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to <span style="font-family: monospace; font-size: 95%">fstab</span>: </p> <div class="box-caption"><span class="label" style="margin-right: .5em; background-color: #54487A">FILE</span> <strong><code style="border: none; background: none; color: #54487A; margin-right: .5em;">/etc/fstab</code></strong><strong></strong></div><pre class="captioned">/dev/sda2 none swap sw 0 0</pre> <p><br /> </p> <h3><span class="mw-headline" id="Encrypted_SWAP_with_hibernate_option">Encrypted SWAP with hibernate option</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=3" class="mw-editsection-visualeditor" title="Edit section: Encrypted SWAP with hibernate option">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=3" title="Edit section: Encrypted SWAP with hibernate option">edit source</a><span class="mw-editsection-bracket">]</span></span></h3> <p>Assuming you want to have a LUKS encrypted swap partition and still be able to use hibernate (a.k.a. suspend to disk). The encrypted swap partition needs a known LUKS-key (keyfile, password, ..), since you’re ask to enter it in a very early phase of the boot process. The Kernel then has to decide whether to regularly boot the system or to load a hibernated RAM image from SWAP – if available. </p><p>The creation of a LUKS encrypted swap partion isn’t different to any other LUKS encrypted partition, described in <a href="/wiki/Dm-crypt#Creating_an_encrypted_storage_platform" title="Dm-crypt">Creating an encrypted storage platform</a>. Just do <span style="font-family: monospace; font-size: 95%; font-weight: bold;" class="tripleclick-separator">mkswap</span> instead of <span style="font-family: monospace; font-size: 95%; font-weight: bold;" class="tripleclick-separator">mkfs.*</span> to that LUKS encrypted partition, to create SWAP. The UUID (i.e. <code>01b37ea8-74a5-4526-85c7-9fdf6dad34cb</code>), created when formatting as swap, is needed for the next step: </p><p>Tell the bootloader (GRUB) where to resume from if hibernated: </p> <div class="box-caption"><span class="label" style="margin-right: .5em; background-color: #54487A">FILE</span> <strong><code style="border: none; background: none; color: #54487A; margin-right: .5em;">/etc/default/grub</code></strong><strong></strong></div><pre class="captioned">GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb"</pre> <p>In addidition (when using openrc with dracut, I’m not using systemd) you have to tell dracut the major an minor number of the belonging LUKS device, so it can create an appropriate initrd: </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>lsblk</code></span></div><pre>.. └─sdb1 &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;8:22 &#160;&#160;0 &#160;&#160;&#160;32G &#160;0 part &#160;&#160; └─luks-cc166689-4246-41ae-86e8-84705b81ecc2 253:1 0 32G 0 crypt [SWAP] </pre></div> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>echo 253:1 &gt; /sys/power/resume </code></span></div></div> <div class="alert alert-info gw-box" style="padding-top: 8px; padding-bottom: 8px;"><strong><i class="fa fa-sticky-note-o fa-rotate-180"></i> Note</strong><br />The default value is <code>0:0</code>. Echo in this again to deactivate hibernation.</div> <div class="alert alert-danger gw-box" style="padding-top: 8px; padding-bottom: 8px;"><strong><i class="fa fa-exclamation-triangle"></i> Warning</strong><br />Don't mix up the LUKS UUID (<code>cc166689-4246-41ae-86e8-84705b81ecc2</code>) and the SWAP UUID (<code>01b37ea8-74a5-4526-85c7-9fdf6dad34cb</code>).</div> <p>Finally, the initrd needs to be updated with this changes: </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>dracut --hostonly --force </code></span></div></div> <p><br /> Don’t forget the regular configuration of SWAP in <span style="font-family: monospace; font-size: 95%">/etc/fstab</span> and restart the system afterwards. </p> <div class="box-caption"><span class="label" style="margin-right: .5em; background-color: #54487A">FILE</span> <strong><code style="border: none; background: none; color: #54487A; margin-right: .5em;">/etc/fstab</code></strong><strong></strong></div><pre class="captioned"># /dev/sdb1 (SWAP) UUID=01b37ea8-74a5-4526-85c7-9fdf6dad34cb &#160;&#160;&#160;&#160;&#160;&#160; none &#160;&#160;&#160;&#160; swap &#160;&#160;&#160;sw&#160;&#160;&#160;&#160;&#160;&#160;0 0</pre> <div class="alert alert-info gw-box" style="padding-top: 8px; padding-bottom: 8px;"><strong><i class="fa fa-sticky-note-o fa-rotate-180"></i> Note</strong><br />If you already had a LUKS encrypted SWAP using dmcrypt [<a rel="nofollow" class="external autonumber" href="https://wiki.gentoo.org/wiki/Dm-crypt%7Cdmcrypt">[1]</a>], inlcuding a configuration in <span style="font-family: monospace; font-size: 95%">/etc/conf.d/dmcrypt</span>, it’s obsolete now, since this LUKS device will now be opened earlier with the help of initrd.</div> <h4><span class="mw-headline" id="Using_full_disk_encryption">Using full disk encryption</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=4" class="mw-editsection-visualeditor" title="Edit section: Using full disk encryption">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=4" title="Edit section: Using full disk encryption">edit source</a><span class="mw-editsection-bracket">]</span></span></h4> <p>When already using full disk encryption with LUKS, it’ll now ask you two times when booting; to enter the LUKS-key for you root partition (as before) and in addition for your SWAP partition. It is possible to just decrypt the root partition and then use a LUKS keyfile to decrypt SWAP, stored on the just now decrypted root partition. Details and an easy example how to do this, can be found on <a rel="nofollow" class="external text" href="https://mirrors.edge.kernel.org/pub/linux/utils/boot/dracut/dracut.html#_crypto_luks_key_on_removable_device_support">kernel.org</a>. </p><p><br /> </p> <h2><span class="mw-headline" id="Swap_files">Swap files</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=5" class="mw-editsection-visualeditor" title="Edit section: Swap files">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=5" title="Edit section: Swap files">edit source</a><span class="mw-editsection-bracket">]</span></span></h2> <p>In order to work around the more ridged constraints of disk partitions, an alternative is to use swap as an on-disk file. Files have the ability to be located <i>inside</i> disk partitions. This allows the system administrator the flexibility to resize or move the swap space as necessary to meet the demands of the system without having to open a <a href="/wiki/Partition" title="Partition">partitioning tool</a>. </p> <h3><span class="mw-headline" id="Creation_2">Creation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=6" class="mw-editsection-visualeditor" title="Edit section: Creation">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=6" title="Edit section: Creation">edit source</a><span class="mw-editsection-bracket">]</span></span></h3> <p>The first step in creating a swap file is to allocate a file of the target swap size. Several standard utilities can be used for this purpose. <span style="font-family: monospace; font-size: 95%; font-weight: bold;" class="tripleclick-separator">fallocate</span> (part of <a rel="nofollow" class="external text" href="https://packages.gentoo.org/packages/sys-apps/util-linux">sys-apps/util-linux</a>) will suffice for this example </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>fallocate -l 12GiB 12G-swapfile # Create a file. </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>chmod 600 12G-swapfile # Restrict security on the file to root access only. </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>mkswap 12G-swapfile # Format the file swap. </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>swapon 12G-swapfile # Activate the swap file. </code></span></div></div> <p>Review the system swaps with the <span style="font-family: monospace; font-size: 95%; font-weight: bold;" class="tripleclick-separator">swapon</span> command: </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>swapon --show</code></span></div></div> <p>To avoid manually activating the swap file across reboots, append a line (adjusting the path as necessary) to <span style="font-family: monospace; font-size: 95%">fstab</span>: </p> <div class="box-caption"><span class="label" style="margin-right: .5em; background-color: #54487A">FILE</span> <strong><code style="border: none; background: none; color: #54487A; margin-right: .5em;">/etc/fstab</code></strong><strong></strong></div><pre class="captioned">/12G-swapfile none swap sw 0 0</pre> <p><br /> </p><p><br /> </p> <h3><span class="mw-headline" id="Encrypted_Swap">Encrypted Swap</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=7" class="mw-editsection-visualeditor" title="Edit section: Encrypted Swap">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=7" title="Edit section: Encrypted Swap">edit source</a><span class="mw-editsection-bracket">]</span></span></h3> <p>Since swap contents do not need to persist between boots, it's a good idea to encrypt them. It's easy using a swap file. </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>dd if=/dev/zero of=swap count=2048 bs=1M </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>cryptsetup --type plain -d /dev/urandom open swap swap </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>swapon swap </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>swapon --show</code></span></div></div> <p>Then, edit <span style="font-family: monospace; font-size: 95%">/etc/fstab</span> and either <span style="font-family: monospace; font-size: 95%">/etc/crypttab</span> (if using systemd) or <span style="font-family: monospace; font-size: 95%">/etc/conf.d/dmcrypt</span> (if using OpenRC) to automatically active it: </p> <div class="box-caption"><span class="label" style="margin-right: .5em; background-color: #54487A">FILE</span> <strong><code style="border: none; background: none; color: #54487A; margin-right: .5em;">/etc/crypttab</code></strong><strong></strong></div><pre class="captioned">swap /opt/swap /dev/urandom swap</pre> <div class="box-caption"><span class="label" style="margin-right: .5em; background-color: #54487A">FILE</span> <strong><code style="border: none; background: none; color: #54487A; margin-right: .5em;">/etc/conf.d/dmcrypt</code></strong><strong></strong></div><pre class="captioned">swap=swap source=/opt/swap</pre> <div class="box-caption"><span class="label" style="margin-right: .5em; background-color: #54487A">FILE</span> <strong><code style="border: none; background: none; color: #54487A; margin-right: .5em;">/etc/fstab</code></strong><strong></strong></div><pre class="captioned">/dev/mapper/swap none swap sw 0 0</pre> <p>Finally, if using OpenRC, enable the dmcrypt service: </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code>rc-update add dmcrypt boot</code></span></div></div> <h3><span class="mw-headline" id="Btrfs">Btrfs</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=8" class="mw-editsection-visualeditor" title="Edit section: Btrfs">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=8" title="Edit section: Btrfs">edit source</a><span class="mw-editsection-bracket">]</span></span></h3> <p>When using btrfs, set required attributes on the swap file disabling copy-on-write and compression. <sup id="cite_ref-2" class="reference"><a href="#cite_note-2">&#91;2&#93;</a></sup> </p> <div class="cmd-box"><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code> cd /path/to/swapfile </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code> truncate -s 0 ./swapfile </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code> chattr +C ./swapfile </code></span></div><div><code style="color: #ef2929; font-weight: bold;">root <span style="color:royalblue;">#</span></code><span class="tripleclick-separator"></span><span style="-moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all;"><code> btrfs property set ./swapfile compression none </code></span></div></div> <h3><span class="mw-headline" id="OpenRC_configuration">OpenRC configuration</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=9" class="mw-editsection-visualeditor" title="Edit section: OpenRC configuration">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=9" title="Edit section: OpenRC configuration">edit source</a><span class="mw-editsection-bracket">]</span></span></h3> <p>When using swap files which are not on the root filesystem, the service ordering in OpenRC should be changed via <span style="font-family: monospace; font-size: 95%">/etc/conf.d/swap</span>: </p> <div class="box-caption"><span class="label" style="margin-right: .5em; background-color: #54487A">FILE</span> <strong><code style="border: none; background: none; color: #54487A; margin-right: .5em;">/etc/conf.d/swap</code></strong><strong></strong></div><pre class="captioned"><div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span></span><span class="c1"># If you are only using local swap partitions, you should not change</span> <span class="c1"># this file. Otherwise, you need to uncomment the below rc_before line</span> <span class="c1"># followed by the appropriate rc_need line.</span> <span class="nv">rc_before</span><span class="o">=</span><span class="s2">&quot;!localmount&quot;</span> <span class="c1">#</span> <span class="c1"># If you are using swap files stored on local file systems, uncomment</span> <span class="c1"># this line.</span> <span class="nv">rc_need</span><span class="o">=</span><span class="s2">&quot;localmount&quot;</span> <span class="c1">#</span> <span class="c1"># If you are using swap files stored on network file systems or swap</span> <span class="c1"># partitions stored on network block devices such as iSCSI, uncomment</span> <span class="c1"># this line.</span> <span class="c1">#rc_need=&quot;netmount&quot;</span> </pre></div></pre> <h2><span class="mw-headline" id="See_also">See also</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=10" class="mw-editsection-visualeditor" title="Edit section: See also">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=10" title="Edit section: See also">edit source</a><span class="mw-editsection-bracket">]</span></span></h2> <ul><li><a href="/wiki/Filesystem" title="Filesystem">Filesystem</a> — a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve, and update data as well as manage the available space on the device(s) which contain it.</li> <li><a href="/wiki/Zram" title="Zram">Zram</a> — a Linux kernel feature and userspace tools for creating compressible RAM-based block devices.</li> <li><a href="/wiki/Zswap" title="Zswap">Zswap</a> — a lightweight compressed cache for swap pages.</li></ul> <h2><span class="mw-headline" id="External_resources">External resources</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=11" class="mw-editsection-visualeditor" title="Edit section: External resources">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=11" title="Edit section: External resources">edit source</a><span class="mw-editsection-bracket">]</span></span></h2> <ul><li>Upstream kernel.org documentation on swap suspend - <a rel="nofollow" class="external free" href="https://www.kernel.org/doc/html/latest/power/swsusp.html#swap-suspend">https://www.kernel.org/doc/html/latest/power/swsusp.html#swap-suspend</a></li></ul> <h2><span class="mw-headline" id="References">References</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Swap&amp;veaction=edit&amp;section=12" class="mw-editsection-visualeditor" title="Edit section: References">edit</a><span class="mw-editsection-divider"> | </span><a href="/index.php?title=Swap&amp;action=edit&amp;section=12" title="Edit section: References">edit source</a><span class="mw-editsection-bracket">]</span></span></h2> <div class="mw-references-wrap"><ol class="references"> <li id="cite_note-1"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a></span> <span class="reference-text"><a href="/wiki/Handbook:AMD64/Installation/Disks#What_about_swap_space.3F" title="Handbook:AMD64/Installation/Disks">Handbook:AMD64/Installation/Disks#What_about_swap_space.3F</a></span> </li> <li id="cite_note-2"><span class="mw-cite-backlink"><a href="#cite_ref-2">↑</a></span> <span class="reference-text"><a rel="nofollow" class="external free" href="https://wiki.archlinux.org/title/Btrfs#Swap_file">https://wiki.archlinux.org/title/Btrfs#Swap_file</a></span> </li> </ol></div> '
Unix timestamp of change (timestamp)
1652453222