Reference website: http://blog.csdn.net/hshl1214/article/details/6048278
The original post written very well, I put the steps to paste out, test system: rhel6.4 x64
1. Create a new disk partition as a swap partition
[[email protected]/]# free-m//view current swap information
Total used free shared buffers Cached
mem:1878 348 1530 0 19 156
-/+ buffers/cache:172 1706
swap:4031 0 4031
[[email protected]/]# swapoff-a//Deactivate swap space
[[email protected]/]# free-m//See if Deactivate
Total used free shared buffers Cached
mem:1878 345 1532 0 19 156
-/+ buffers/cache:169 1709
swap:0 0 0
[[email protected]/]# FDISK/DEV/SDB//Enter the SDB hard drive (there is extra unused disk space in the SDB hard drive)
Warning:dos-compatible mode is deprecated. It ' s strongly recommended to
Switch off the mode (command ' C ') and change display units to
Sectors (Command ' u ').
Command (M for help): N//New partition
Command Action
E Extended
P primary partition (1-4)
P//Create primary partition
Partition number (1-4): 2//sdb The second primary partition of a hard disk
First cylinder (8193-10240, default 8193)://From the hard disk which cylinder starts, enter key default (can write corresponding number)
Using Default Value 8193
Last cylinder, +cylinders or +size{k,m,g} (8193-10240, default 10240)://from which cylinder of the hard drive starts, enter key defaults
Using Default Value 10240
Command (M for help): P//view changed partition status, p: Print partition information
disk/dev/sdb:10.7 GB, 10737418240 bytes
Heads, Sectors/track, 10240 cylinders
Units = Cylinders of 2048 * 1048576 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0xb92c060c
Device Boot Start End Blocks Id System
/DEV/SDB1 1 8192 8388592 Linux
/DEV/SDB2 8193 10240 2097152-up Linux
Command (M for help): t//Start modifying/DEV/SDB2 properties to swap id:82
Partition number (1-4): 2//Select the partition you want to modify
Hex code (type L to list codes)://swap partition ID
Changed system type of partition 2 to Swap/solaris (Linux)
Command (M for help): P//view changed partition status
disk/dev/sdb:10.7 GB, 10737418240 bytes
Heads, Sectors/track, 10240 cylinders
Units = Cylinders of 2048 * 1048576 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0xb92c060c
Device Boot Start End Blocks Id System
/DEV/SDB1 1 8192 8388592 Linux
/DEV/SDB2 8193 10240 2097152 the Linux swap/solaris//Here is changed to swap attribute
Command (M for help): w//Save changes
The partition table has been altered!
Calling IOCTL () to re-read partition table.
Warning:re-reading the partition table failed with error 16:device or resource busy.
The kernel still uses the old table. The new table is being used at
The next reboot or after you run Partprobe (8) or KPARTX (8)
Syncing disks.
[Email protected]/]# MKSWAP/DEV/SDB2
/dev/sdb2:no such file or directory//modify requires restart
[[email protected]/]# reboot//restart
[Email protected] ~]# fdisk-l
[[email protected] ~]# MKSWAP/DEV/SDB2//Format swap partition
Setting up Swapspace version 1, size = 2097148 KiB
No label, UUID=2D26D5AD-4EE2-4C1D-B90C-7CF4060FD9A9
[[email protected] ~]# SWAPON/DEV/SDB2//Enable swap
[[email protected] ~]# free-m//See if swap capacity is larger, determine if the operation is successful
Total used free shared buffers Cached
mem:1878 348 1529 0 18 156
-/+ buffers/cache:173 1704
swap:6079 0 6079[[email protected] ~]# Vi/etc/fstab
/DEV/SDB2 swap swap defaults 0 0//enable the system to start from on, add a line at the end of the file
###########################################################
2. Use a file as a swap partition
(immediately following the information above)
[[email protected] ~]# FREE-M//View initial information
Total used free shared buffers Cached
mem:1878 348 1529 0 18 156
-/+ buffers/cache:173 1704
swap:6079 0 6079
#创建要作为swap分区的文件: To increase the 1GB size of the swap partition, the command is written as follows, where count equals the number of blocks you want (bs*count= file size).
[[email protected] ~]# dd If=/dev/zero of=/root/swapfile bs=1m count=1024
1024+0 Records in
1024+0 Records out
1073741824 bytes (1.1 GB) copied, 12.1908 s, 88.1 MB/s
[[email protected] ~]# mkswap/root/swapfile//format swap partition file
Mkswap:/root/swapfile:warning:don ' t erase bootbits sectors
On whole disk. Use-f to force.
Setting up Swapspace version 1, size = 1048572 KiB
No label, uuid=3330e86b-ec5a-4423-bc08-07bcc3785495
[[email protected] ~]# swapon/root/swapfile//enable swap partition file
[[email protected] ~]# free-m//View the modified information to determine if the operation was successful
Total used free shared buffers Cached
mem:1878 1403 474 0 19 1180
-/+ buffers/cache:204 1674
swap:7103 0 7103
[Email protected] ~]# Vi/etc/fstab
/root/swapfile swap swap defaults 0 0//enable the system to start from on, add a line at the end of the file
3. Delete Swap space
[Email protected] ~]# Swapoff/root/swapfile
[Email protected] ~]# free-m
Total used free shared buffers Cached
mem:1878 1403 475 0 19 1180
-/+ buffers/cache:203 1674
swap:6079 0 6079
[Email protected] ~]#
2 ways to modify the Linux swap partition