In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Linux how to create swap exchange partition, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Create a new disk partition as a swap partition
1. Enter the console (log in to the system) as root and enter
The code is as follows:
# swapoff-a # stop all swap partitions
two。 Partition the disk with the fdisk command (for example: # fdisk / dev/sdb), add the swap partition, create a new partition, change the newly added partition id to 82 (Linux swap type) with the "t" command in fdisk, and finally write the operation to the hard disk with w (the operation before w is invalid).
3.
The code is as follows:
# mkswap / dev/sdb2 # format the swap partition. The sdb2 here depends on the actual partition device name displayed by the p command after you add it.
4.
The code is as follows:
# swapon / dev/sdb2 # start a new swap partition
5. To enable this swap partition automatically when the system boots, edit / etc/fstab and add the following line
The code is as follows:
/ dev/sdb2 swap swap defaults 0 0
Second, resize the swap partition
Sometimes, we need to add swap, for example, to install oracle. Here's how to increase the size of the swap partition.
The code is as follows:
Root@ubuntu:/home/zhangying# free-m
Total used free shared buffers cached
Mem: 3449 3256 193 0 723 1687
/ + buffers/cache: 845 2604
Swap: 254 0 254
The code is as follows:
Root@ubuntu:/home/zhangying# mkdir swap
Root@ubuntu:/home/zhangying# cd swap/
Root@ubuntu:/home/zhangying/swap# dd if=/dev/zero of=swaptmp bs=9024 count=100000
The read-in of 1000000's was recorded.
Recorded the write-out of 1000000: 0.
902400000 bytes (902 MB) replicated, 12.5008 seconds, 72.2 MB/ seconds
The code is as follows:
Root@ubuntu:/home/zhangying/swap# mkswap swaptmp
Mkswap: swaptmp: warning: don't erase bootbits sectors
On whole disk. Use-f to force.
Setting up swapspace version 1, size = 881244 KiB
No label, UUID=ed24d0cc-3af5-4278-b41a-df1ab7433f83
Root@ubuntu:/home/zhangying/swap# swapon swaptmp
Root@ubuntu:/home/zhangying/swap# free-m
Total used free shared buffers cached
Mem: 3449 3359 90 0 637 1930
-/ + buffers/cache: 7912657
Swap: 1115 0 1115
This is only temporary, if you restart the computer, the size of the swap partition is still restored to the original, if you do not want to restore to the original, see the following method.
The code is as follows:
Root@ubuntu:/home/zhangying/swap# swapoff swaptmp
Root@ubuntu:/home/zhangying/swap# rm swaptmp
Root@ubuntu:/home/zhangying/swap# free-m
Total used free shared buffers cached
Mem: 3449 3368 81 0 732 1895
-/ + buffers/cache: 739 2710
Swap: 254 6 248
There is also a situation where this temporary swap becomes non-temporary.
The code is as follows:
Nano / etc/fstab
/ home/zhangying/swap/swaptmp swap swap defaults 0 0
Note: this kind of boot automatically loads, the root load windows under the hard disk is the same, if the swaptmp file is lost, can not increase the size of the swap.
Third, use files as Swap partitions
1. Create a file to be a swap partition: increase the 1GB size of the swap partition, and the command is written as follows, where the count is equal to the number of blocks you want (bs*count= file size).
The code is as follows:
# dd if=/dev/zero of=/root/swapfile bs=1M count=1024
two。 Format to swap partition file:
The code is as follows:
# mkswap / root/swapfile # build the file system of swap
3. Enable swapping partition files:
The code is as follows:
# swapon / root/swapfile # enable swap files
4. To enable the system to power on itself, add a line to the file / etc/fstab:
The code is as follows:
/ root/swapfile swap swap defaults 0 0
The commands used to create and add swap partitions are: mkswap, swapon, etc., while you can use commands such as "swapon / dev/sdb2" to close a swap partition.
The following operation command demonstrates the operation of using a file as a Swap (including some checks before and after).
The code is as follows:
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3179 800 0 266 1873
-/ + buffers/cache: 1039 2940
Swap: 4095 0 4095
The code is as follows:
[root@jay-linux ~] # cat / etc/fstab
# partial output that has nothing to do with the subject has been omitted
/ dev/sda3 swap swap defaults 0 0
The code is as follows:
[root@jay-linux ~] # dd if=/dev/zero of=/root/swapfile bs=1M count=1024
1024000 records in
1024000 records out
1073741824 bytes (1.1GB) copied, 4.09017 s, 263MB/s
[root@jay-linux ~] # mkswap / root/swapfile
Setting up swapspace version 1, size = 1048572 KiB
No label, UUID=48a7ffd5-392f-4963-904c-3e67f0e5dfbe
The code is as follows:
[root@jay-linux ~] # swapon / root/swapfile
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3945 34 0 261 2628
-/ + buffers/cache: 1054 2924
Swap: 5119 0 5119
The code is as follows:
[root@jay-linux ~] # swapoff / dev/sda3
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3945 34 0 261 2629
-/ + buffers/cache: 1053 2925
Swap: 1023 0 1023
The code is as follows:
[root@jay-linux ~] # swapoff / root/swapfile
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3945 34 0 261 2629
-/ + buffers/cache: 1053 2926
Swap: 0 0 0
The code is as follows:
[root@jay-linux ~] # swapon / dev/sda3
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3946 33 0 261 2629
-/ + buffers/cache: 1054 2924
Swap: 4095 0 4095
The code is as follows:
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3179 800 0 266 1873
-/ + buffers/cache: 1039 2940
Swap: 4095 0 4095
The code is as follows:
[root@jay-linux ~] # cat / etc/fstab
# partial output that has nothing to do with the subject has been omitted
/ dev/sda3 swap swap defaults 0 0
The code is as follows:
[root@jay-linux ~] # dd if=/dev/zero of=/root/swapfile bs=1M count=1024
1024000 records in
1024000 records out
1073741824 bytes (1.1GB) copied, 4.09017 s, 263MB/s
[root@jay-linux ~] # mkswap / root/swapfile
Setting up swapspace version 1, size = 1048572 KiB
No label, UUID=48a7ffd5-392f-4963-904c-3e67f0e5dfbe
The code is as follows:
[root@jay-linux ~] # swapon / root/swapfile
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3945 34 0 261 2628
-/ + buffers/cache: 1054 2924
Swap: 5119 0 5119
The code is as follows:
[root@jay-linux ~] # swapoff / dev/sda3
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3945 34 0 261 2629
-/ + buffers/cache: 1053 2925
Swap: 1023 0 1023
The code is as follows:
[root@jay-linux ~] # swapoff / root/swapfile
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3945 34 0 261 2629
-/ + buffers/cache: 1053 2926
Swap: 0 0 0
The code is as follows:
[root@jay-linux ~] # swapon / dev/sda3
[root@jay-linux] # free-m
Total used free shared buffers cached
Mem: 3979 3946 33 0 261 2629
-/ + buffers/cache: 1054 2924
Swap: 4095 0 4095
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.