Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the mkswap command in Linux

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use the mkswap command in Linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The Linux common command mkswap command is used to establish a swap partition on a file or device.

Mkswap establishes and sets up SWAP switching partitions

Add that you need to use the sawpon command to start using the exchange after it has been built. The last optional parameter specifies the size of the swap area, but this parameter is set for backward compatibility and is not necessary to use. The entire file or device is generally used as the swap area.

Syntax mkswap (option) (parameter) option-c: check for damaged blocks before establishing a swap area;-f: add this parameter when establishing a swap area on a SPARC computer;-v0: establish an old swap area, which is the default value;-v1: create a new swap area. Parameter device: specify the device file or swap file corresponding to the swap space.

Check the swap space size of the system for an example:

Free-m total used free shared buffers cached Mem: 377 180 197 0 19 110-/ + buffers/cache: 50 327 Swap: 5720 572 View the current swap space (file (s) / partition (s)):

Swapon-s is equivalent to cat / proc/swaps adding swap space.

Add a swap partition or add a swap file. It is recommended that you add a swap partition; however, if you do not have much free space available, add a swap file.

Add a swap partition as follows:

Use fdisk to create the swap partition (assuming / dev/sdb2 is the created swap partition), and use the mkswap command to set the swap partition:

Mkswap / dev/sdb2 enables swapping:

Swapon / dev/sdb2 writes / etc/fstab to enable at boot time:

/ dev/sdb2 swap swap defaults 00 adds a swap file as follows:

Create a swap file with a size of 512m:

Dd if=/dev/zero of=/swapfile1 bs=1024 count=524288 uses the mkswap command to set up the swap file:

Mkswap / swapfile1 enables swapping:

Swapon / swapfile1 writes / etc/fstab to enable at boot time:

After / swapfile1 swap swap defaults 00 has added a new swap partition and enabled it, please check the output of the cat / proc/swaps or free command to ensure that the swap partition is enabled.

Delete swap space:

Disable swapping:

Swapoff / dev/sdb2 removes items from / etc/fstab and deletes partitions using fdisk or yast tools.

This is the end of the article on "how to use mkswap commands in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report