In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to create or expand swap partition in Linux, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
How to detect the current swap partition size
Use the free & swapon command to detect the size of the current swap partition space.
$free-h total used free shared buff/cache available Mem: 2.0G 1.3G 139M 45M 483M 426m Swap: 2.0G 655M 1.4G $swapon-show NAME 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 a * * method for immediately creating pre-allocated size files.
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 / swapfile Setting 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-- show NAME 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=1 1'0 records in 1'0 records out 1073741824 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 1GB.
Count=1 copies 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 / swapfile1 Setting 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-- show NAME 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
Check the newly created swap file.
$swapon-- show NAME 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 this is the answer to the question on how to create or expand the swap partition in Linux. I hope the above content can be of some help to you, if you still have a lot of questions unsolved. You can follow the industry information channel for more related knowledge.
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.