Announcement

Collapse
No announcement yet.

How to create a swap storage on existing file system.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create a swap storage on existing file system.

    How to create a swap storage on existing file system.


    RedHat OS uses swap as a type of “Virtual Memory “in case your physical memory begins to run low. This capacity can be helpful for the system that don’t have enough physical memory ( RAM ).
    You can define swap on your existing file system wherever you got free space instead of arranging a separate partition.

    Follow the steps to achieve these settings. :)

    Steps-1


    Check the free space available on your existing storage.
    Code:
    [root@test /]# df –h
    
    Output
    
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg_test-lv_root
                          7.5G  3.5G  4.8G  47%	/
    tmpfs              495M  260K  495M   1% 	/dev/shm
    /dev/sda1         485M   33M  428M   8% 	/boot
    I have 4.8G available on my root ‘/’.

    Step-2
    Create swap on ‘/’ (root)
    We will create 1G file using ‘dd’ command to create an output file size which is desirable.
    Code:
    dd if=/dev/zero of=/swap1Gfile bs=1024 count=1048576
    
    Output:
    
    1048576+0 records in
    1048576+0 records out
    1073741824 bytes (1.1 GB) copied, 34.4907 s, 31.1 MB/s
    Note: “count” calculations based on 1024×1024
    It will create a 1 GB file on root partition.

    Step-3

    Now we have ‘/swap1Gfile’ swap on root it’s time to overlay swap file system on it.
    let’s do it .
    Code:
    mkswap /swap1Gfile
    
    Output :
    
    mkswap: /swap1Gfile: warning: don't erase bootbits sectors
            on whole disk. Use -f to force.
    Setting up swapspace version 1, size = 1048572 KiB
    no label, UUID=630c36e3-4a50-4a9b-99a5-08b849813e10
    Step-4

    Using ‘swapon’ we will Active swap to perform as an additional virtual memory in case system kernel is in panic situation just cause of shortage of RAM.
    Code:
    swapon -v /swap1Gfile
    
    Output :
    
    swapon on /swap1Gfile
    swapon: /swap1Gfile: insecure permissions 0644, 0600 suggested.
    swapon: /swap1Gfile: found swap signature: version 1, page-size 4, same byte order
    swapon: /swap1Gfile: pagesize=4096, swapsize=1073741824, devsize=1073741824
    Step-5
    Verify it’s loaded or not
    Code:
    swapon -s
    
    Output :
    Filename Type Size Used Priority
    /dev/dm-1 partition 2031608 0 -1
    /swap1Gfile file 1048568 0 -2
    Step-6



    For making this changes permanent lets add this swap file as a swap storage into the ‘/etc/fstab’ file to survive on reboot.

    Code:
    Add the below line in your ‘/etc’fstab’ file.
    
    /swap1Gfile              swap         swap    defaults        0 0
    Step-7
    Once off swap partitions in order to read ‘/etc/fstab’ changes.
    Code:
    swapoff -a
    Use this below command to read swap partitions from ‘/etc/fstab’ file.

    Code:
    swapon -a
    Verify it works or not
    Code:
    swapon -s
    
    Output :
    Filename Type Size Used Priority
    /dev/dm-1 partition 2031608 0 -1
    /swap1Gfile file 1048568 0 -2
    Last edited by kuldeep; 02-24-2015, 01:07 AM.
Working...
X