Add Swap Disk to Linux

Add Swap Disk to Linux

Add Swap Disk to CentOS

** NOT RESPONSIBLE FOR DATA LOSS, BE SMART, MAKE A BACKUP!! **

In a few select scenarios, there may be a time where adding RAM is not an option, however you may have plenty of disk space to work with. This is where swap can be extremely useful.

Login, and su to root

Linux swap disk: Login, and su to root

get a general idea how your disks are setup presently by doing a “fdisk -l” to view all block devices

Linux swap disk: get a general idea how your disks are setup presently by doing a "fdisk -l" to view all block…

great, at this point all we have is /dev/xvda (may be /dev/sda, or /dev/hda on your system)

Linux swap disk: great, at this point all we have is /dev/xvda (may be /dev/sda, or /dev/hda on your system)

also, you may want to verify that swap is actually enabled on your system as well using the swapon summary option

Linux swap disk: also, you may want to verify that swap is actually enabled on your system as well using the swapon…

also, you want to verify the problem is actually memory/swap, issue a free -m to see how much memory/swap is used.

Linux swap disk: also, you want to verify the problem is actually memory/swap, issue a free -m to see how much…

from here shutdown the system and add a new disk or block device to use for swap

Linux swap disk: shutdown the system and add a new disk or block device to use for swap

We have added a 10GB Swap disk in this example.  Once the sytem is back online, verify via fdisk -l that the new swap disk appears

Linux swap disk: We have added a 10GB Swap disk in this example. Once the sytem is back online, verify via fdisk -l…

great /dev/xvdb has appeared as a 10GB disk, now we just need to format it as swap.

do a fdisk to start partitioning the drive

Linux swap disk: do a fdisk to start partitioning the drive

format as follows:

Linux swap disk: format as follows

format the disk as swap

Linux swap disk: format the disk as swap

enable the disk for swapping

Linux swap disk: enable the disk for swapping

now if we do a swapon -s we will see the two disks available for swapping.

Linux swap disk: if we do a swapon -s we will see the two disks available for swapping.

free -m is alot happier

Linux swap disk: free -m is alot happier

Updating FSTAB:

Linux swap disk: Updating FSTAB

you would update fstab as follows:

Linux swap disk: you would update fstab as follows

if you wanted to disable the old swap disk, you can do so using the following:

Linux swap disk: if you wanted to disable the old swap disk, you can do so using the following

you can change the priority using the syntax of swapon -p 4

That’s it!

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Add new Hard Drive to CentOS Linux | Add a Disk to LVM and Expand Space

Leave a Reply

Your email address will not be published. Required fields are marked *