Create a swap partition under Linux

Source: Internet
Author: User

in centos6.8 System for columns , Creating swap partitions

view the swap partition of the current system

[Email protected] ~]# swapon-sfilenametypesizeused Priority/dev/sda3 partition20725720 -1

create /dev/sdb1 partition

[[email protected] ~]# fdisk -l /dev/sdbdisk  /dev/sdb: 214.7 gb, 214748364800 bytes255 heads, 63 sectors/track,  26108 cylindersunits = cylinders of 16065 * 512 = 8225280  bytesSector size  (logical/physical): 512 bytes / 512 bytesi/o  size  (Minimum/optimal): 512 bytes / 512 bytesdisk identifier:  0x420e5771    device boot      start          End      Blocks   Id   System/dev/sdb1                1         523     4200966    83  linux 

Format the partition :

[[email protected] ~]# mkswap/dev/sdb1setting up swapspace version 1, size = 4200960 kibno label, uuid=37ea704c-7fdd-4969 -a58d-19021c5a023a


to mount the swap partition manually :

[Email protected] ~]# swapon/dev/sdb1[[email protected] ~]# Swapon-sfilenametypesizeusedpriority/dev/sda3 PARTITION20725720-1/DEV/SDB1 partition42009600-2

writes mount option to /etc/fstab in

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/86/7C/wKiom1fAPxiSDanrAACIPsUoaJI875.png "title=" Picture 1.png "alt=" Wkiom1fapxisdanraacipsuoaji875.png "/>


Activate newly added swap partition in /etc/fstab

[Email protected] ~]# swapon-a

to view swap partitions within the system :

[[email protected] ~]# swapon - sfilenametypesizeusedpriority/dev/sda3                                 partition20725720  -1/dev/sdb1                                 partition42009600  -2 

However, there are priority levels for multiple swap partitions, in order of use, The higher priority is used by the system first. If you do not manually specify a priority When you mount it, each time you create a swap partition, the priority value is equal to the previous interchange partition priority value minus 1.

the user assigns a priority to the new swap partition, priority of 0 to 32767 must be specified

the benefits of assigning priorities, some swap partitions are stored on high-performance disks, and some are even on the outer tracks of the disk, these can improve the performance of the switching partition, in order for these high-performance switched partitions to execute first , the priority must be specified.

Create a partition /DEV/SDB2, Assuming the performance of this block is higher than the above two blocks.

[[EMAIL PROTECTED] ~]# FDISK -L /DEV/SDB DISK /DEV/SDB: 214.7 GB,  214748364800 bytes255 heads, 63 sectors/track, 26108 cylindersunits =  cylinders of 16065 * 512 = 8225280 bytesSector size  ( logical/physical): 512 bytes / 512 bytesi/o size  (minimum/optimal):  512 bytes / 512 bytesdisk identifier: 0x420e5771    device  boot      start         end       Blocks   Id  System/dev/sdb1                1          523     4200966   83  Linux/dev/sdb2              524        1046      4200997+  83  linux format [[Email protected] ~]# swapon  /DEV/SDB2 Write/etc/fstab

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/86/7C/wKioL1fAP23wJ7AiAACI9bi8z98968.png "title=" Picture 2.png "alt=" Wkiol1fap23wj7aiaaci9bi8z98968.png "/>

re-read /etc/fstab to view the contents of the swap partition.

[Email protected] ~]# swapon-a[[email protected] ~]# Swapon-sfilenametypesizeusedpriority/dev/sda3                               PARTITION20725720-1/DEV/SDB1 PARTITION42009600-2/DEV/SDB2 partition42009920 1


/DEV/SDB2 priority is higher than /dev/sda3 and /dev/sdb1, using the swap partition takes precedence over /dev/sda2

There is also a problem : when the swap partition is already mounted, the Mount option is modified, or the size of the swap partition is changed, the swap-a can not be used to read when re-mounted Etc/fstab, the device that has been mounted, it is not automatically re-mounted. If you want to mount it again, you need to unmount the partition first and then use swapon-a to mount the partition again.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/86/7C/wKiom1fAP8WgKYkVAABTlVUErOc372.png "title=" Picture 3.png "alt=" Wkiom1fap8wgkykvaabtlvueroc372.png "/>

re-read, priority hasn't been repaired.

[Email protected] ~]# swapon-a[[email protected] ~]# Swapon-sfilenametypesizeusedpriority/dev/sda3                               PARTITION20725720-1/DEV/SDB1 PARTITION42009600-2/DEV/SDB2 partition42009920 1


first uninstall, , the priority is changed.

[email protected] ~]# swapoff /dev/sdb1[[email  protected] ~]# swapon -a [[email protected] ~]# swapon - sfilenametypesizeusedpriority/dev/sda3                                 partition20725720  -1/dev/sdb1                                 partition42009600   2/dev/sdb2                                 partition42009920   1 


When you format a swap partition, you can specify the priority level

SWAP-P #/dev/sdb1 # Specifies the priority in the process of formatting Arabic numerals

Create a swap partition under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.