In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to use swap files on Linux systems to expand swap space", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use swap files to expand swap space on Linux systems.
Imagine a scenario where our Linux system runs out of swap space, in which case we want to use swap partitions to expand swap space, but in some cases there are no free partitions available on disk, so we can't expand it.
Therefore, in this case, we can use the swap file to increase the swap space.
Here is how to expand swap space on Linux using swap files
Let's first check the size of the existing swap space / partition, using the command 'free-m' or 'swapon-s'
My swap partition size is 2 GB, and we will extend the swap space to 1GB.
Step 1: use the following dd command to create an exchange file with the size of 1GB
The code is as follows:
[root@linuxtechi ~] # dd if=/dev/zero of=/swap_file bs=1G count=1
1: 0 records in
1: 0 records out
1073741824 bytes (1.1GB) copied, 414.898 s, 2.6MB/s
[root@linuxtechi ~] #
Replace the size of 'bs'' and 'count'' as you need.
Step 2: set the swap file permissions to 600
The code is as follows:
[root@linuxtechi ~] # chmod 600 / swap_file
Step 3: open the exchange area (swap_file) with a file
Open the exchange area with the mkswap command
The code is as follows:
[root@linuxtechi ~] # mkswap / swap_file
Setting up swapspace version 1, size = 1048572 KiB
No label, UUID=f7b3ae59-c09a-4dc2-ba4d-c02abb7db33b
[root@linuxtechi ~] #
Step 4: add an exchange file entry to the fstab file
Add the following entry to the fstab file so that the exchange file can continue to use each other after each restart.
The code is as follows:
/ swap_file swap swap defaults 0 0
Step 5: enable swap files with the command 'mkswap on'.
The code is as follows:
[root@linuxtechi ~] # swapon / swap_file
[root@linuxtechi ~] #
Step 6: check the swap space now
Note: to avoid unexpected situations, turn it off using the swapoff command as shown below, and re-enable the swap file using the swapon command shown in step 5 only if you need it.
The code is as follows:
[root@linuxtechi ~] # swapoff / swap_file
[root@linuxtechi ~] #
At this point, I believe you have a deeper understanding of "how to use swap files on Linux systems to expand swap space". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.