How to add swap file in linux.
1. Log in as a root user
su - root
2. Create Storage File
[root@cor ~]# dd if=/dev/zero of=/extraswap bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 3.58675 seconds, 299 MB/s
Where
if=/dev/zero : Read from /dev/zero file. /dev/zero is a special file in that provides as many null characters to build storage file called /swapfile1.
of=/swapfile1 : Read from /dev/zero write storage file to /extraswap
bs=1024 : Read and write 1024 BYTES bytes at a time.
count=1073741824 : Copy only 1073741824 BLOCKS input blocks.
3.Set Up a Linux Swap Area
[root@cor ~]# mkswap /extraswap
Setting up swapspace version 1, size = 1073737 kB
4. check
[root@cor /]# cd /
[root@cor /]# du -sh extraswap
1.1G extraswap
[root@cor /]#
5. Setup correct file permission for security reasons,
[root@cor /]# chown root:root /extraswap
[root@cor /]# chmod 0600 /extraswap
[root@cor /]#
6.Finally, activate /extraswap swap space immediately
[root@cor /]# swapon /extraswap
[root@cor /]#
7. check swap memory with new value
[root@cor /]# free -m
total used free shared buffers cached
Mem: 7619 7563 55 0 397 6234
-/+ buffers/cache: 930 6688
Swap: 7167 0 7167
[root@cor /]#
8. Update /etc/fstab file
To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using a text editor such as vi:
# vi /etc/fstab
Append the following line:
/extraswap swap swap defaults 0 0
-Save and close the file. Next time Linux comes up after reboot, it enables the new swap file for you automatically
9. How do I Verify Swap is Activated or Not
[root@cor /]# free -m
10.How can I display swap usage summary on Linux
[root@cor /]# swapon -s
11. How can I disable devices and files for paging and swapping on Linux
[root@cor /]# swapoff /extraswap
[root@cor /]# swapon -s
1. Log in as a root user
su - root
2. Create Storage File
[root@cor ~]# dd if=/dev/zero of=/extraswap bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 3.58675 seconds, 299 MB/s
Where
if=/dev/zero : Read from /dev/zero file. /dev/zero is a special file in that provides as many null characters to build storage file called /swapfile1.
of=/swapfile1 : Read from /dev/zero write storage file to /extraswap
bs=1024 : Read and write 1024 BYTES bytes at a time.
count=1073741824 : Copy only 1073741824 BLOCKS input blocks.
3.Set Up a Linux Swap Area
[root@cor ~]# mkswap /extraswap
Setting up swapspace version 1, size = 1073737 kB
4. check
[root@cor /]# cd /
[root@cor /]# du -sh extraswap
1.1G extraswap
[root@cor /]#
5. Setup correct file permission for security reasons,
[root@cor /]# chown root:root /extraswap
[root@cor /]# chmod 0600 /extraswap
[root@cor /]#
6.Finally, activate /extraswap swap space immediately
[root@cor /]# swapon /extraswap
[root@cor /]#
7. check swap memory with new value
[root@cor /]# free -m
total used free shared buffers cached
Mem: 7619 7563 55 0 397 6234
-/+ buffers/cache: 930 6688
Swap: 7167 0 7167
[root@cor /]#
8. Update /etc/fstab file
To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using a text editor such as vi:
# vi /etc/fstab
Append the following line:
/extraswap swap swap defaults 0 0
-Save and close the file. Next time Linux comes up after reboot, it enables the new swap file for you automatically
9. How do I Verify Swap is Activated or Not
[root@cor /]# free -m
10.How can I display swap usage summary on Linux
[root@cor /]# swapon -s
11. How can I disable devices and files for paging and swapping on Linux
[root@cor /]# swapoff /extraswap
[root@cor /]# swapon -s
No comments:
Post a Comment