diff options
| author | Fredrik Salomonsson <plattfot@posteo.net> | 2026-05-19 18:57:19 -0700 |
|---|---|---|
| committer | Florian Pelz <pelzflorian@pelzflorian.de> | 2026-06-07 00:48:58 +0200 |
| commit | f6f93f6d8f8efa5a8fb0e07ba88c0d49d801a25d (patch) | |
| tree | 54e949d99393029e3fe785e0e483fe497aed6252 | |
| parent | 8810c9ea9aea071f0d94b735a8027a67f7e4dc1e (diff) | |
doc: Add documentation for btrfs swap file.
* doc/guix.texi (Keyboard Layout and Networking and Partitioning): Add
btrfs example with a subvolume.
(Proceeding with the Installation): Note about dependencies when using
subvolumes in btrfs for the swap file.
(Swap Space): Add info on how to get the offset to the swap file when
using btrfs.
Merges: guix/guix!8829
Change-Id: I0c9c271d73520966ac8a7e87ca9d93120134cf41
Signed-off-by: Florian Pelz <pelzflorian@pelzflorian.de>
| -rw-r--r-- | doc/guix.texi | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index f5efd34024e..a9930d01e6b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -153,6 +153,7 @@ Copyright @copyright{} 2026 Nguyễn Gia Phong@* | |||
| 153 | Copyright @copyright{} 2026 Yarl Baudig@* | 153 | Copyright @copyright{} 2026 Yarl Baudig@* |
| 154 | Copyright @copyright{} 2026 Joan Vilardaga Castro@* | 154 | Copyright @copyright{} 2026 Joan Vilardaga Castro@* |
| 155 | Copyright @copyright{} 2026 Nemin@* | 155 | Copyright @copyright{} 2026 Nemin@* |
| 156 | Copyright @copyright{} 2026 Fredrik Salomonsson@* | ||
| 156 | 157 | ||
| 157 | Permission is granted to copy, distribute and/or modify this document | 158 | Permission is granted to copy, distribute and/or modify this document |
| 158 | under the terms of the GNU Free Documentation License, Version 1.3 or | 159 | under the terms of the GNU Free Documentation License, Version 1.3 or |
| @@ -2717,7 +2718,7 @@ bootloaders. | |||
| 2717 | 2718 | ||
| 2718 | Once you are done partitioning the target hard disk drive, you have to | 2719 | Once you are done partitioning the target hard disk drive, you have to |
| 2719 | create a file system on the relevant partition(s)@footnote{Currently | 2720 | create a file system on the relevant partition(s)@footnote{Currently |
| 2720 | Guix System can mount only ext4, btrfs, JFS, F2FS, and XFS file systems | 2721 | Guix System can mount only ext4, Btrfs, JFS, F2FS, and XFS file systems |
| 2721 | at boot time. In particular, code that reads file system UUIDs and | 2722 | at boot time. In particular, code that reads file system UUIDs and |
| 2722 | labels works only for these file system types. The code for bcachefs is | 2723 | labels works only for these file system types. The code for bcachefs is |
| 2723 | in place, but support for loading out-of-tree kernel modules in the | 2724 | in place, but support for loading out-of-tree kernel modules in the |
| @@ -2784,12 +2785,18 @@ mkswap /dev/sda3 | |||
| 2784 | swapon /dev/sda3 | 2785 | swapon /dev/sda3 |
| 2785 | @end example | 2786 | @end example |
| 2786 | 2787 | ||
| 2787 | Alternatively, you may use a swap file. For example, assuming that in | 2788 | Alternatively, you may use a swap file, whose size can be trivially |
| 2788 | the new system you want to use the file @file{/swapfile} as a swap file, | 2789 | modified at a later date. Creating a swap file will look a bit |
| 2789 | you would run@footnote{This example will work for many types of file | 2790 | different depending on what sort of file system your new system is |
| 2790 | systems (e.g., ext4). However, for copy-on-write file systems (e.g., | 2791 | using. We therefore have two examples on how to create a swap file, the |
| 2791 | btrfs), the required steps may be different. For details, see the | 2792 | first will work for many types of file systems (e.g., ext4) but not |
| 2792 | manual pages for @command{mkswap} and @command{swapon}.}: | 2793 | Btrfs@footnote{For other copy-on-write file systems, the required steps |
| 2794 | may also be different. For details, see the manual pages for | ||
| 2795 | @command{mkswap} and @command{swapon}.}. The second example is | ||
| 2796 | specifically for Btrfs. | ||
| 2797 | |||
| 2798 | For the common case, assuming that in the new system you want to use the | ||
| 2799 | file @file{/swapfile} as a swap file, you would run: | ||
| 2793 | 2800 | ||
| 2794 | @example | 2801 | @example |
| 2795 | # This is 10 GiB of swap space. Adjust "count" to change the size. | 2802 | # This is 10 GiB of swap space. Adjust "count" to change the size. |
| @@ -2800,6 +2807,35 @@ mkswap /mnt/swapfile | |||
| 2800 | swapon /mnt/swapfile | 2807 | swapon /mnt/swapfile |
| 2801 | @end example | 2808 | @end example |
| 2802 | 2809 | ||
| 2810 | When you use Btrfs the steps for creating a swap file are slightly | ||
| 2811 | different and it comes with a few caveats. I.e. it must be on a single | ||
| 2812 | device, the filesystem must only have @code{single} as the data profile | ||
| 2813 | and the subvolume that contains the active swap file or files cannot be | ||
| 2814 | snapshotted. It is therefore best to put the swap file in a separate | ||
| 2815 | subvolume to allow to snapshot the rest of the filesystem. This example | ||
| 2816 | assumes the label for the Btrfs file system is @code{btrfs-pool} and the | ||
| 2817 | subvolume for the root is @code{rootfs}. | ||
| 2818 | |||
| 2819 | @example | ||
| 2820 | # Temporarily unmount btrfs-pool | ||
| 2821 | umount /mnt | ||
| 2822 | # Mount the top level subvolume | ||
| 2823 | mount LABEL=btrfs-pool -o subvolid=5 /mnt | ||
| 2824 | # Create the subvolume (swap) that will hold the swap file | ||
| 2825 | cd /mnt && btrfs subvolume create swap && cd - | ||
| 2826 | # Remount the target file system | ||
| 2827 | unmount /mnt | ||
| 2828 | mount LABEL=btrfs-pool -o subvol=rootfs /mnt | ||
| 2829 | # Create the directory where it should mount the swap subvolume | ||
| 2830 | mkdir /mnt/swap | ||
| 2831 | # Mount the swap subvolume | ||
| 2832 | mount LABEL=btrfs-pool -o subvol=swap /mnt/swap | ||
| 2833 | # Create a 10 GiB of swap space. It accepts k/m/g/e/p as suffix | ||
| 2834 | btrfs filesystem mkswapfile --size 10G /mnt/swap/swapfile | ||
| 2835 | # Activate the swap file | ||
| 2836 | swapon /mnt/swap/swapfile | ||
| 2837 | @end example | ||
| 2838 | |||
| 2803 | Note that if you have encrypted the root partition and created a swap | 2839 | Note that if you have encrypted the root partition and created a swap |
| 2804 | file in its file system as described above, then the encryption also | 2840 | file in its file system as described above, then the encryption also |
| 2805 | protects the swap file, just like any other file in that file system. | 2841 | protects the swap file, just like any other file in that file system. |
| @@ -2865,6 +2901,10 @@ Be sure that your file system labels match the value of their respective | |||
| 2865 | your @code{file-system} configuration uses the @code{file-system-label} | 2901 | your @code{file-system} configuration uses the @code{file-system-label} |
| 2866 | procedure in its @code{device} field. | 2902 | procedure in its @code{device} field. |
| 2867 | 2903 | ||
| 2904 | If you are using Btrfs and your swap file is in a subvolume make sure to | ||
| 2905 | list the root partition as its dependency in its @code{file-system} | ||
| 2906 | entry to make sure everything is mounted in the right order. | ||
| 2907 | |||
| 2868 | @item | 2908 | @item |
| 2869 | If there are encrypted or RAID partitions, make sure to add a | 2909 | If there are encrypted or RAID partitions, make sure to add a |
| 2870 | @code{mapped-devices} field to describe them (@pxref{Mapped Devices}). | 2910 | @code{mapped-devices} field to describe them (@pxref{Mapped Devices}). |
| @@ -19813,6 +19853,15 @@ $ sudo filefrag -e /swapfile | grep '^ *0:' | cut -d: -f3 | cut -d. -f1 | |||
| 19813 | 92514304 | 19853 | 92514304 |
| 19814 | @end smallexample | 19854 | @end smallexample |
| 19815 | 19855 | ||
| 19856 | Note that if the swap file is on a Btrfs file system use @command{btrfs | ||
| 19857 | inspect-internal map-swapfile -r} instead of @command{filefrag} to get | ||
| 19858 | the offset as the latter will not give the right offset. | ||
| 19859 | |||
| 19860 | @smallexample | ||
| 19861 | $ sudo btrfs inspect-internal map-swapfile -r /swapfile | ||
| 19862 | 163845376 | ||
| 19863 | @end smallexample | ||
| 19864 | |||
| 19816 | @node User Accounts | 19865 | @node User Accounts |
| 19817 | @section User Accounts | 19866 | @section User Accounts |
| 19818 | 19867 | ||
