Hi,
I will explain how to create or Add Swap partition in Linux if it doesn’t exist in this post.
When you check swap partition or file whether it exists or not, if it does not exist then you should create or add.
This is occurred fresh install of Linux and probably it is forgetten.
Check Swap size like following.
[[email protected] ~]# free -m total used free shared buffers cached Mem: 24111 5064 19046 3600 33 4437 -/+ buffers/cache: 593 23517 Swap: 0 0 0 [[email protected] ~]#
If it is not created like above then we need to create or add it like following steps.
I have used /dev/sdb disk for this.
Format /dev/sdb disk with fdisk. [[email protected] ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x59a8f188. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): Using default value 2610 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [[email protected] ~]#
Create Swap partition like following. [[email protected] ~]# [[email protected] ~]# mkswap /dev/sdb1 Setting up swapspace version 1, size = 20964788 KiB no label, UUID=97809171-047f-440d-9e1c-df329313b00a [[email protected] ~]# [[email protected] ~]#
Add following entry to the /etc/fstab.
/dev/sdb1 swap swap defaults 0 0 [[email protected] ~]# vi /etc/fstab
Activate swap partition like following steps.
[[email protected] ~]# [[email protected] ~]# swapon -s Filename Type Size Used Priority [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# swapon -va swapon on /dev/sdb1 swapon: /dev/sdb1: found swap signature: version 1, page-size 4, same byte order swapon: /dev/sdb1: pagesize=4096, swapsize=21467947008, devsize=21467948544 [[email protected] ~]#
When I check swap partition, it is created like following.
[[email protected] ~]# free -m total used free shared buffers cached Mem: 24111 7805 16305 3600 70 5028 -/+ buffers/cache: 2706 21404 Swap: 20473 0 20473 [[email protected] ~]#
You can list it like following.
[[email protected] ~]# [[email protected] ~]# swapon -s Filename Type Size Used Priority /dev/sdb1 partition 20964788 0 -1 [[email protected] ~]# [[email protected] ~]#
Do you want to learn Linux System Administration for Beginners, then read the following articles.
https://ittutorial.org/linux-administration-tutorial-for-beginners/
2,673 views last month, 2 views today