Centos swap file ไม ม การใข งาน เป น 0k

Linux has the facility to divide its physical RAM into tiny chunks of memory called as Pages. Swapping is a method by which a page of memory can be copied to the pre-configured space on the hard disk which is called Swap Space, to free that particular page of memory. Thus, the combination of physical memory and the swap space is the actual amount of virtual memory available.

Use of Swap Space

Swapping is critical for two obvious reasons.

  • First, if the system needs more memory than physically available memory, the kernel swaps out less utilized pages and provides memory to the current application(process) that requires the memory instantly
  • Next, a significant number of pages utilized by an application or process during its initial phase may only be used for initialization and then be never used again. The system shall swap out those pages and free the memory for other applications(process) or even the disk cache

Methods to Increase Swap Space on CentOS 7

There are two methods by which we can increase the swap space:

  1. Swap Partition
  2. Swap File

Let’s discuss each of the methods in detail.

Method 1 – Swap Partition

Prerequisites to check before creating swap partition

  1. Check the available swap space using the command below:

“ swapon -s “

  1. Check the system overall space using the command below:

“ free -m “

  1. Check the available space on the drive, using the command below:

“ df -h “

Creating swap partition:

  1. Create a partition for swap space using the following command below:
  2. Type “ n “ to proceed to create a new partition and press Enter
  3. Select which type of partition you want (Primary, Extended). Here we will select the Primary Partition. Type p and press Enter
  4. Then enter the partition number, and press Enter
  5. Then, select the first sector and last sector to be Default………….. Press Enter

You can list the Partitions using the command “ p “

Similarly, Press “ l “ to listed the below ID

press ” t ” to change the partition ID and select 82 for Linux Swap / So

Command (m for help) “ p “ below the created swap partition to be listed.

press ” w ” to save command.

Refresh the system settings using the command “partprobe /dev/sda1”

“mkswap /dev/sda1” Use this command to format the created partition

“Swapon /dev/sda1” type this command to activate the swap partition

“Cat /proc/swaps” use this command to verify the activated partition to below

“Vim /etc/fstab” Type the command to add the newly created partition to fstab configuration file

Save and exit the fstab page.

Reboot the System.

After reboot, check the created partition whether it is listed or not using the command “cat /proc/swaps “

Method 2 – Swap File

No additional hard drive available in system, create a file for use the swap space increase.

Creating swap file:

Use the command below to create a swap File ” dd if=/dev/zero of=/root/vembuswap bs=1M count=1024 “ and press the enter.

Check the newly created swap File permission using the command ‘ “ ls -l /root/vembuswap “

Set a swap File permission use command ” chmod 600 /root/vembuswap “

Make the file as swap file using command “mkswap /root/vembuswap ”

Activate the newly created swap file command “swapon /root/vembuswap “

Add a newly created swap file entry to fstab page use command ” vim /etc/fstab ”

Once add the fstab page Save & exit

Verify the newly created swap file in available using the command ” swapon -s ” Use the command: “ free -m “check the free memory also.

Steps for extending Swap Space on Linux with a Swap File in CentOS 8

We first need to find out the size of the existing swap space and partition using the commands ‘free -m’ and ‘swapon -s’

A swap partition with a capacity of 4 GB is used in my case. So we will be extending swap space by 1 GB

(Note that all of the below-mentioned commands require sudo privileges to make changes)

If you like to create a file of size 1GB, run the below command:

As per your requirements, replace the values for ‘ bs ‘ and ‘ count ‘.

Keep in mind: bs 🡪 sets of block size count 🡪 number of blocks

You can also use the fallocate command to create a file, as below command.

Set the permissions of the swap file to ‘600’ by running the chmod command on it.

If the file does not have a swap area, run the mkswap command.

In the fstab file, add the below entry to vi editors to edit the fstab file.

Run the swapon command to enable swap space on the file and which will eventually extend the swap space,

After that, you can run the below commands to verify the swap space.

So, when we checked before, the swap space was 4 GB. And now it has been extended to 5 GB.

Conclusion

Managing swap space is a critical aspect of system administration. With proper planning and usage, swapping can provide more benefits to Linux users.

Embark on an incredible journey with the amazing Linux Backup Solution!

Secure your vital data with the magic of Linux backup—a robust shield for safeguarding your valuable information. Try it for free!

Ready to start your adventure? Download BDRSuite now and shield your Linux world with ease, bringing tranquility.

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

I am a Systems and Networking Engineer, managing everything that comes under IT. I have been with Vembu for over 10 years.

Toplist

โพสต์ล่าสุด

แท็ก

ไทยแปลอังกฤษ แปลภาษาไทย โปรแกรม-แปล-ภาษา-อังกฤษ พร้อม-คำ-อ่าน lmyour แปลภาษา แปลภาษาอังกฤษเป็นไทย pantip ไทยแปลอังกฤษ ประโยค แอพแปลภาษาอาหรับเป็นไทย ห่อหมกฮวกไปฝากป้าmv ระเบียบกระทรวงการคลังว่าด้วยการจัดซื้อจัดจ้างและการบริหารพัสดุภาครัฐ พ.ศ. 2560 แปลภาษาอาหรับ-ไทย Terjemahan พจนานุกรมศัพท์ทหาร หยน แปลภาษา มาเลเซีย ไทย Bahasa Thailand ข้อสอบภาษาอังกฤษ พร้อมเฉลย pdf บบบย tor คือ จัดซื้อจัดจ้าง การ์ดแคปเตอร์ซากุระ ภาค 4 ชขภใ ยศทหารบก เรียงลําดับ ห่อหมกฮวกไปฝากป้า หนังเต็มเรื่อง เขียน อาหรับ แปลไทย แปลภาษาอิสลามเป็นไทย Google map กรมพัฒนาฝีมือแรงงาน อบรมออนไลน์ กระบวนการบริหารทรัพยากรมนุษย์ 8 ขั้นตอน ข้อสอบคณิตศาสตร์ พร้อมเฉลย ค้นหา ประวัติ นามสกุล อาจารย์ ตจต แจ้ง ประกาศ น้ำประปาไม่ไหล แปลบาลีเป็นไทย แปลภาษา ถ่ายรูป แปลภาษาจีน แปลภาษามลายู ยาวี โรงพยาบาลภมูพลอดุยเดช ที่อยู่ Google Drive Info TOR คือ กรมพัฒนาฝีมือแรงงาน ช่างไฟฟ้า กรมพัฒนาฝีมือแรงงาน อบรมฟรี 2566 กลยุทธ์ทางการตลาด มีอะไรบ้าง การบริหารทรัพยากรมนุษย์ มีอะไรบ้าง การประปาส่วนภูมิภาค การ์ดแคปเตอร์ซากุระ ภาค 3 ขขขขบบบยข ่ส ข่าว น้ำประปา วันนี้ ข้อสอบโอเน็ต ม.6 มีกี่ตอน ตารางธาตุ ประปาไม่ไหล วันนี้