Monday, 6 March 2017

Creating Swap partition in RedHat 7



How To create a Swap Space on Linux :


this articles helps to create a swap space using fdisk command, it is very much straight forward to create a swap space during the Linux installation itself, however at times we miss creating that, and need for doing below arises.

first just find out what is our disk :





in this case it is /dev/sda

1. Start fdisk command :


2. Create a new Partion :

press n to create a new parition, and select the default partition number (5 in my case), default First Sector and for Last Sector provide the size of the swap you wanted to create (+ 5G in my case)


and this will create a new partition.

3. Change the type of Partition :

now we need to change the type of partition to swap otherwise the default type (ext4) formatted partition will be created.

type t , and then select the partition number which type needs to be changed (5 in this case), and select type (14), you can list all the types by using command L


once this is done, save and write the configuration with "w" command

post saving the configuration, you might see a message like :

"Re-reading the partition Table failed with error 16 : device busy"

so you have to reboot the server so that new partition table can be used.

Command : shutdown -r now

4. make swap

post the reboot, run the command mkswap on the newly created partion


5. swapon :

run swapon /dev/sda5

and verify with free -g command that swap space is created :


6. make the swap space permanent :

to make this permanent, you will have to add the entry in the /etc/fstab file :

No comments:

Post a Comment