We can go with the parted program here since it is easier than fdisk. Before adding a swap partition, we have to check which hard disk has sufficient space to be used as swap. We can do that by issuing print at the parted prompt. With the information we receive, we determine how much space we will use and at what partition. Assume that we will add 1 GB of swap space to /dev/hdc1. The syntax that we will use in parted is
mkpartfs partition-type filesystem-type start end
where start and end are the megabytes from the beginning of the disk (partition-type can be primary, extended or logical but extended and logical are used only for MS-DOS and MIPS labels). Further assuming that the free space on /dev/hdc1 starts at the 520th megabyte, the ending will be 520 + 1024 (1 Gigabyte of space) = 1544. So our command will be
mkpartfs primary linux-swap 520 1024
After reserving the space, we format it with swap partition type, using
mkswap /dev/hdc1
Then we enable it by swapon /dev/hdc1. And finally, to activate it in boot time, we add it to /etc/fstab by adding the following line:
/dev/hdc1 swap swap defaults 0 0
As we have seen, we check the swap by cat /proc/swaps or free.