How To Practice A Swap File
Linux tin hold upwardly configured to role swap space, aka secondary disk storage, when physical retentiveness is running low. Swap spaces tin hold upwardly allocated every bit disk partitions ('swap partitions') or every bit files ('swap files'). While swap partitions are by together with large preferred over swap files, if your arrangement is a virtual person server (VPS) without a pre-configured swap partition, creating a swap file may hold upwardly your alone option. The next physical care for describes how to practise a swap file.
List swap spaces
Before yous practise a swap file, yous should offset depository fiscal establishment stand upwardly for whether the arrangement has whatsoever swap infinite pre-allocated. The easiest agency is to operate the free command.
$ gratis -h full used gratis shared buffers cached Mem: 497M 490M 6.2M 0B 14M 101M -/+ buffers/cache: 375M 121M Swap: 0B 0B 0B
The work labeled Swap inward a higher house tells yous that at that spot is no swap infinite configured.
Alternatively, operate the swapon ascendancy alongside the -s parameter:
$ sudo swapon -s Filename Type Size Used Priority
I prefer free because source privilege is non required to operate the command.
Create swap file
Follow the steps below to practise together with activate a swap file.
- Create a novel file pre-allocated alongside the desired file size. $ sudo fallocate -l 500M /var/swap.img
The inward a higher house ascendancy pre-allocates 500 megabytes for the file /var/swap.img.
- Secure the novel file. $ sudo chmod 600 /var/swap.img
- Make a swap file.
The next mkswap ascendancy sets upwardly /var/swap.img every bit a swap file.
$ sudo mkswap /var/swap.img Setting upwardly swapspace version 1, size = 511996 KiB no label, UUID=a0a90414-adab-4c50-8b27-0d27f0c34448 - Activate the swap file. $ sudo swapon /var/swap.img
After executing the inward a higher house swapon command, verify that the swap file is indeed enabled.
$ gratis -h full used gratis shared buffers cached Mem: 497M 464M 32M 0B 14M 104M -/+ buffers/cache: 346M 151M Swap: 499M 34M 465M $ sudo swapon -s Filename Type Size Used Priority /var/swap.img file 511996 35184 -1According to the inward a higher house output, the swap file has been enabled. However, unless yous consummate the adjacent step, the swap file volition hold upwardly disabled when yous reboot the machine.
- Update file arrangement table.
Add the swap file to the file arrangement tabular array using the next command:
$ sudo sh -c 'echo "/var/swap.img none swap sw 0 0" >> /etc/fstab'
0 Response to "How To Practice A Swap File"
Post a Comment