In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to create and expand the exchange partition in the Linux system, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
Users can create swap space during the installation of any Linux operating system or when necessary. If you forget to create it when installing Linux or if you want to add more space to the swap partition, you can create it or add it at any time.
Sometimes you need to add a little bit of swap space when you upgrade RAM after installation, for example, if you want to upgrade your system's RAM from 1GB to 2GB, then you have to upgrade your swap space (from 2GB to 4GB), because it uses double the capacity of physical RAM. (LCTT translation note: in fact, this is a misunderstanding, swap partitions do not have to be double the physical memory capacity, but the usual practice. In fact, if you have enough physical memory, you don't have to swap partitions at all-in this case, maybe you add physical memory, so there's no need to increase the size of the swap partition. )
Swap space is the space on the disk that is reserved for virtual memory when the physical memory (RAM random access memory) is full. If the system needs more memory resources when the RAM is fully loaded, the inactive pages in memory will be moved to swap space, which can help the system spend more time running the application, but it should not be treated as an extension of RAM.
It is recommended that you create a dedicated swap partition, but if you do not have a partition available, you can use swap files, or a combination of swap partitions and swap files. Swap space is usually recommended to users at least 4 GB, and users can also create swap space according to their own requirements and environment.
I found that most VM and CVM do not swap partitions, so in this case, we can use the following three methods to create, expand or increase swap space.
How to detect the current swap partition size
Use the free & swapon command to detect the size of the current swap partition space.
$free-htotal used free shared buff/cache availableMem: 2.0G 1.3G 139M 45M 483m 426MSwap: 2.0G 655M 1.4G $swapon-showNAME TYPE SIZE USED PRIO/dev/sda5 partition 2G 655.2m-1
The above output shows that the current swap partition space is 2GB.
Method 1: create a swap file through the fallocate command
The fallocate program is the best way to create pre-allocated size files immediately.
The following command creates a 1GB-sized / swapfile.
$sudo fallocate-l 1G / swapfile
Check to see if the file you created is the correct size.
$ls-lh / swapfile-rw-r--r-- 1 root root 1.0G Jun 7 09:49 / swapfile
Set the permissions for the file to 600 so that only root users can access the file.
$sudo chmod 600 / swapfile
Convert this file to a swap file by running the following command.
$sudo mkswap / swapfileSetting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=cda50e0e-41f3-49c7-af61-b8cb4a33a464
Make the swap file effective by running the following command.
$sudo swapon / swapfile
Add the newly created swap file to the fstab file so that changes to the swap partition space take effect even after reboot.
$vi / etc/fstab/swapfile swap swap defaults 0 0
Check the newly created swap file.
$swapon-- showNAME TYPE SIZE USED PRIO/dev/sda5 partition 2G 657.8M-1/swapfile file 1024M 0B-2
Now I can see a new / swapfile1 file for 1GB. Restart the system for the new swap file to take effect.
Method 2: create the swap file through the dd command
The dd command is another utility that helps us create pre-allocated size files immediately.
The following dd command creates / swapfile1 for 1GB.
$sudo dd if=/dev/zero of=/swapfile1 bs=1G count=11+0 records in1+0 records out1073741824 bytes (1.1 GB, 1.0 GiB) copied, 16.6154 s, 64.6 MB/s
Detailed explanation:
If=/dev/zero is the input file, and / dev/zero is a special file in a Unix-like operating system that provides as many empty characters (ASCII NUL,0x00) as you can read from it. Of=/swapfile1 settings output file. The one-time read and write size of bs=1G is 1GBcount=1 to copy only one input block.
Check to see if the file you created is the correct size.
$ls-lh / swapfile1-rw-r--r-- 1 root root 1.0G Jun 7 09:58 / swapfile1
Set the permissions for the file to 600 so that only root users can access the file.
$sudo chmod 600 / swapfile1
Convert this file to a swap file by running the following command.
$sudo mkswap / swapfile1Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=96def6d7-b2da-4954-aa72-aa32316ec993
Make the swap file effective by running the following command.
$sudo swapon / swapfile1
Add the newly created swap file to the fstab file so that changes to the swap partition space take effect even after reboot.
$vi / etc/fstab/swapfile1 swap swap defaults 0 0
Check the newly created swap file.
$swapon-- showNAME TYPE SIZE USED PRIO/dev/sda5 partition 2G 1.3G-1/swapfile file 1024M 0B-2/swapfile1 file 1024M 0B-3
Now I can see a new 1GB / swapfile1. Restart the system for the new swap file to take effect.
Method 3: create swap files through hard disk partitions
We also recommend using hard disk partitions to create swap partitions.
If you have created a new partition on your other hard drive with the fdisk command, suppose we have created a partition called / dev/sda4.
Use the mkswap command to convert this partition to a swap partition.
$sudo mkswap / dev/sda4
Make the swap file effective by running the following command.
$sudo swapon / dev/sda4
Add the new swap file to the fstab file so that the changes to the swap partition take effect even if the system is rebooted.
$vi / etc/fstab/dev/sda4 swap swap defaults 0 0 checks the newly created swap file. $swapon-- showNAME TYPE SIZE USED PRIO/dev/sda5 partition 2G 1.3G-1/swapfile file 1024M 0B-2/swapfile1 file 1024M 0B-3/dev/sda4 partition 1G 0B-4
I can see the / dev/sda4 of the new swap partition 1GB. Restart the system to use the new swap partition.
Thank you for reading this article carefully. I hope the article "how to create and expand Exchange Partition in Linux system" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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.