On the previous post we have created swap space using dd command and also another method is can make a new swap partition using fdisk. To increase the amount of swap space to 2GB.

First off we have to create new partition using below commands,


-p specified that print  the partition,
-n specified to create new partition
-t Type of partition (for swap partition code type 82)
-w specified that write the changes (save)

Note : On Ubuntu use fdisk command without -cu option,
 
#  fdisk  -cu /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

Command (m for help):  p

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xa33b6c03

   Device Boot      Start         End      Blocks   Id  System
/dev/sda8       266799104   462108671    97654784   83  Linux

Command (m for help):  n
All primary partitions are in use
Adding logical partition 9
First sector (493533184-579295231, default 493533184):
Using default value 493533184
Last sector, +sectors or +size{K,M,G} (493533184-579295231, default 579295231): +2G

Command (m for help):   t
Partition number (1-9):   9
Hex code (type L to list codes):   82
Changed system type of partition 9 to 82 (Linux swap / Solaris)

Command (m for help):   p

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xa33b6c03
  
Device Boot      Start         End      Blocks   Id  System
/dev/sda8       266799104   462108671    97654784   83  Linux
/dev/sda9       493533184   497727487     2097152   82  Linux swap / Solaris

Once created the new partition, reboot the system,
 
# init 6

Make a New Swap Space:

Make a swap space  partition /dev/sda9
 
# mkswap  -f  /dev/sda9

 To find out swap area usage summary by device,
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=6e653ff7-fc88-4ae1-be07-7651036604ff

 To enable the swap partition,
 
# swapon /dev/sda9

To get swap size usage summary,
 
# swapon -s

Filename                                Type            Size    Used    Priority
/dev/sda1                               partition       5858300 0       -1
/dev/sda9                               partition       2097148 0       -2

check memory space
 
# free -m
             total       used       free     shared    buffers     cached
Mem:          1777       1422        355          0         81        712
-/+ buffers/cache:        628       1149
Swap:          7768          0       7768

Do you want to enable it at boot time open the /etc/fstab file and add below line,
 
# vim /etc/fstab

/swapfile       swap    swap    defaults        0       0

or
 
UUID=cc79c13d-ab21-4a64-89a6-54b4718184c1  swap swap  defaults     0    0

get UUID of swap partition using blkid command,
 
# blkid /swapfile

/swapfile: UUID="cc79c13d-ab21-4a64-89a6-54b4718184c1" TYPE="swap"

To disable the swap partition /dev/sda9 immediately,
 
# swapoff /dev/sda9