In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to reduce the Linux swap partition of CentOS". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
When playing Linux with a virtual machine, the Linux hard disk space is often insufficient, and the host hard disk space is tight, what to do?
Many children's shoes assign 8G hard drives to Linux, while swap has 2G partitions when installing Linux in the default partition mode. Swap partitions are swap partitions, similar to Windows's virtual memory pagefile.sys. When there is insufficient memory, virtualize part of the hard disk space into memory use. When there is enough memory, it is not useful.
For the physical Linux, this 2G swap space is generally nothing, but for the virtual machine Linux with only 8G hard disk, 2G is very valuable. So-- reduce the Linux swap partition reclaim space.
Ways to reduce swap partitions:
1, first "df-h" and "fdisk-l" commands to check the current partition situation, as shown in the figure. The root partition is 5.5G.
In the figure / dev/mapper/vg_ "hostname"-lv_swap is the swap partition, which is 2G. The swap partition can also be seen with the free command.
2. Use the swapoff command to close the swap partition:
# swapoff / dev/mapper/vg_ "hostname"-lv_swap
Then use the free command to check whether swap has changed to 0.
3. Reduce the swap partition by 1500m with the lvreduce command:
# lvreduce-L-1500m / dev/mapper/vg_ "hostname"-lv_swap
Enter y, OK, and see the prompt that swap is reduced to 516m.
4. Re-set / dev/mapper/vg_ "hostname"-lv_swap to swap partition:
# mkswap / dev/mapper/vg_ "hostname"-lv_swap
5. Swapon enables swap partition:
# swapon / dev/mapper/vg_ "hostname"-lv_swap
Then use the free command to check whether the swap has changed to 516m.
Extend the root partition to utilize the recycled space
1. The 1500m reclaimed at this time is idle free space, and it has to be allocated to the root partition. Fortunately, the current Linux partition generally adopts the LVM partition mode, which can be easily expanded dynamically without destroying the existing data. The author here is using the graphical LVM (Logical Volume Manager) tool to dynamically extend the partition (if you do not install this tool, you need to install the rpm package of system-config-lvm). The master can also do it under the command line.
# system-config-lvm
Expand logical View-> lv_root, and click Edit Properties.
2. Click "use remaining" and you can see that 5.54G has increased to 7.0g. And then "OK".
3. Go back to the LVM interface and find that the free space has changed to zero.
4. Go back to command-line mode and check it with the "df-h" command. You can see that the root partition has grown to 6.9g. Dynamic expansion does not need to be restarted, takes effect immediately, and is done!
This is the end of the content of "how CentOS reduces Linux swap partitions". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.