In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the usage of mkswap command in Linux system". In daily operation, I believe that many people have doubts about the usage of mkswap command in Linux system. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the usage of mkswap command in Linux system". Next, please follow the editor to study!
Mkswap
Create a swap partition in a Linux device or file, and you must use swapon to use it after creation. There is usually a swap partition list in "/ etc/fstab" so that you can use it when you turn it on.
The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.
1. Grammar
Mkswap [- c] [- f] [- p PSZ] [- L label] [- U uuid] device [size]
The parameter device is usually a disk partition (similar to / dev/sdb7), but it can also be a file. The Linux kernel does not view the partition ID, but many installation scripts will assume that the partition of hexadecimal type 82 (Linux_SWAP) is swapped. (warning: Solaris also uses this type. Be careful not to close the Solaris partition.)
The parameter size is redundant, but retained for backward compatibility
The PSZ parameter specifies the page size to use. Specifying it is almost unnecessary (or even unwise), but some older versions of libc are about page size, so mkswap may have got it wrong. The symptom is that the subsequent Swapon fails because the exchange signature is not found. The typical value of PSZ is 4096 or 8192.
2. List of options
Option
Description
-c
Detect bad blocks before creating a swap partition. If so, print out the quantity.
-f
Enforcement. Without this option, mkswap refuses to erase the first block on the device with the partition table or the first block on the entire disk (for example, / dec/sda).
-p
Sets the page size. The default is 4096. It is generally not necessary to specify this parameter.
-L label
Specify a label to facilitate the use of swapon. Only applicable to the new style exchange area
-v1
Create a v1 version of the swap partition, which is only supported after the 2.5 kernel
-U uuid
Specify uuid, which generates uuid by default
3. Description
The switch head does not touch the first block. The boot loader or disk label can be there, but installation is not recommended. The recommended setting is to use a separate partition for the Linux swap area. Mkswap, like many other mkfs-like utilities, erases the first block so that the old system on disk can be deleted. Mkswap refuses to erase the first block, or the entire disk, on a device with a disk label.
The maximum useful size of the swap area depends on the architecture and kernel version, 1 GiB on i386, PPC, m68k, ARM, sparc, 512 MiB on MIPS, 128 GiB on alpha, and 3 TiB on sparc64. For kernels after 2.3.3, there is no such limitation. Note that prior to 2.1.117, the kernel allocated one byte to each page, but now it allocates two bytes, so the swap area 2 GIB in use may require two MIB kernel memory.
Currently, Linux allows 32 swap areas (this is the 8 before Linux2.4.10). The areas in use can be seen in the file "/ proc/swaps" (since 2.1.25). Mkswap rejects areas under 10 pages. If you don't know the page size used by your machine, you may be able to use "cat / proc/cpuinfo" to find it.
To set up a swap file, you must create the file before initializing it with mkswap, for example, using the following command:
# dd if=/dev/zero of=swapfile bs=1024 count=65536
Note that the swap file cannot contain any vulnerabilities (therefore, it is unacceptable to use cp (1) to create the file)
4. Examples
1) create a swap partition and specify a page size of 2048
[root@localhost ~] # mkswap-p 2048 / dev/sdb4 / / the page size 2048 is specified here, replacing the system default of 4096
Using user-specified page size 2048, instead of the system value 4096
Setting up swapspace version 1, size = 16382 KiB
No label, UUID=42f07b0e-0adb-47b6-a906-1209efabb981
2) create a swap partition, specify a page size of 4096, and specify label
[root@localhost] # mkswap-p 4096-L wj / dev/sdb4 / / the author's current system cannot use 2048 pages
Setting up swapspace version 1, size = 16380 KiB
LABEL=wj,UUID=c458a15d-50ee-4e10-a49b-b59add4879d5
3) use swap partition
[root@localhost ~] # swapon / dev/sdb4 / / use the specified partition
[root@localhost ~] # swapon-s / / View partition usage
Filename Type Size Used Priority
/ dev/dm-1 partition 2940920 0-1
/ dev/sdb4 partition 16376 0-2
At this point, the study of "the usage of mkswap commands in Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.