📜 ⬆️ ⬇️

Use paging file instead of partition

Maybe a button accordion, but it can be useful to someone ...
During the partitioning process, when installing most distributions, the installer strongly recommends creating a separate partition for swapping. But I think that this is not the best way to allocate space. It is much more convenient to use a regular file for this purpose. The main advantage of this method is that if the need arises, the file size can be easily changed (with the partition these things turn out much more difficult if, God forbid, the partition is located not at the end of the disk). The theoretical flaw is the slow access to the file due to the fragmentation of the file system on which it is located (only theoretical, since fragmentation is not such a big problem in Nix FS).
So, first create a “blank” - an empty file of a certain size, on which the swap will be located:
$ dd if=/dev/zero of=/path/to/swapfile bs=1M count=1024
A file of 1024 pieces of 1 megabytes in size will be created (thus dd will not consume all the RAM with its buffer)
Just a few words about the location of this file. In principle, it can be placed on any file system, it is important that it be mounted by the time it is activated (see below). Otherwise, the file must be placed in the root partition.
Now create the swap space on this file:
$ mkswap /path/to/swapfile
And now turn it on:
# swapon /path/to/swapfile
However, after rebooting, it will have to be re-enabled. You need to include the command to enable paging in the distribution launch scripts (in Debian, it is easiest to place it in /etc/rc.local, in other distributions you may need to create your own scripts).
Angoy, as they say!

')

Source: https://habr.com/ru/post/45827/


All Articles