Friday, June 28, 2013

adding swap space in linux

Adding swap space in linux


easy  way is to use dd and add it on


1. decide the mountpoint where you are going to create swapspace. In my example, I plan to add swapspace in "/media/db_disk" mount point.

cd /media/db_disk
as root user



[root@ovs1 Desktop]#  dd if=/dev/zero of=/media/db_disk/myswapfile3 bs=1M count=2048
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB) copied, 74.1111 s, 29.0 MB/s


checking the swap file

[root@ovs1 Desktop]# ls -l /media/db_disk/myswapfile3
-rw-r--r--. 1 root root 2147483648 Jun 28 15:45 /media/db_disk/myswapfile3


change the permission of the swap file

[root@ovs1 Desktop]#
ls -l /media/db_disk/myswapfile3
-rw-------. 1 root root 2147483648 Jun 28 15:45 /media/db_disk/myswapfile


run mkswap command to format and ready for swap file use

[root@ovs1 Desktop]# mkswap /media/db_disk/myswapfile3
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=c0928bcc-ffe3-47c1-9051-a9bf43c14228



add the swapfile to swap group

[root@ovs1 Desktop]# swapon /media/db_disk/myswapfile3
[root@ovs1 Desktop]# swapon -s
Filename                Type        Size    Used    Priority
/dev/dm-1                               partition    2064380    0    -1
/media/grid/swapfile1                   file        1048572    0    -2
/media/db_disk/myswapfile3              file        2097148    0    -3



now important thing is that we need to add this swapfile in automount list. otherwise after reboot it wont get appear in the swap list


/etc/fstab is the file which is readed to do automount during startup.

# /etc/fstab
# Created by anaconda on Thu Jan 12 13:21:03 2012
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_oraclelinux6-lv_root /                       btrfs    defaults        1 1
UUID=ed6b5002-07d3-4381-9057-47ee31704c78 /boot                   ext4    defaults        1 2
/dev/sde                /media/grid             ext4    defaults        0 0
/dev/sdf                /media/db_disk          ext4    defaults        0 0
/dev/sdg                /media/12c_db           ext4    defaults        0 0
/dev/mapper/vg_oraclelinux6-lv_swap swap                    swap    defaults        0 0
/media/grid/swapfile1   swapfile1               swap  defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0


now add the following line in /etc/fstab


/media/db_disk/myswapfile3 swapfile3            swap  defaults        0 0



[root@ovs1 Desktop]#
[root@ovs1 Desktop]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Jan 12 13:21:03 2012
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_oraclelinux6-lv_root /                       btrfs    defaults        1 1
UUID=ed6b5002-07d3-4381-9057-47ee31704c78 /boot                   ext4    defaults        1 2
/dev/sde                /media/grid             ext4    defaults        0 0
/dev/sdf                /media/db_disk          ext4    defaults        0 0
/dev/sdg                /media/12c_db           ext4    defaults        0 0
/dev/mapper/vg_oraclelinux6-lv_swap swap                    swap    defaults        0 0
/media/grid/swapfile1   swapfile1               swap  defaults        0 0
/media/db_disk/myswapfile3 swapfile3            swap  defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

[root@ovs1 Desktop]#


now after restart the swap file will get automatically mounted

No comments:

Post a Comment