Create Swap Partition in Linux: Step-by-Step Guide
Here is how to create and use a swap partition in a Linux system:
- Create a swap partition.
- Use fdisk or another disk partitioning tool to create a new partition, with the type set as Linux swap.
- Format the partition as swap format by using the command: mkswap /dev/sdX (X is the disk and partition number where your swap partition is located).
- Enable swap partition.
- Enable swap partition using the swapon command: swapon /dev/sdX.
- To permanently enable the swap partition, it needs to be added to the /etc/fstab file: echo “/dev/sdX swap swap defaults 0 0” >> /etc/fstab.
- Check the usage status of the swap partition.
- Check the system memory and swap usage by using the free command: free -h.
- Check the currently enabled swap partitions using the command swapon -s.
The above is the method for creating and using a swap partition in a Linux system.