How to add a Swap partition file in Linux

Source: Internet
Author: User
Article Title: how to add a Swap partition file in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

1. Check the current partition (use free-m or cat/proc/swaps)


       
        [root@db2 root]# free -m              total       used       free     shared    buffers     cached Mem:          1006         84        922          0         11         38 -/+ buffers/cache:         35        971 Swap:            0          0          0             [root@db2 root]#
       

2. Increase swap partition File Size

If no swap exists, add the following to determine the size of the new swap file. Multiply the size by 1024 to determine the size of the block. For example, if the block size of a 64 MB swap file is 65536, enter the following command as the root user at the shell prompt, where count is equal to the expected block size.

       
        [root@db2 root]# dd if=/dev/zero of=/home/swap bs=1024 count=1024000 1024000+0 records in 1024000+0 records out             [root@db2 root]#
       

Run the following command to set the file exchange:

       
        [root@db2 root]# mkswap /home/swap Setting up swapspace version 1, size = 1023996 KiB             [root@db2 root]#
       

3. Enable swap partition File

To enable the swap file immediately instead of automatically enabling it during boot, run the following command:

       
        [root@db2 root]# swapon /home/swap
       

Check the added exchange information:

       
        [root@db2 root]# free -m              total       used       free     shared    buffers     cached Mem:          1006        994         12          0          4        929 -/+ buffers/cache:         60        946 Swap:          999          0        999             [root@db2 root]#
       

To enable it during boot, edit the/etc/fstab file to include the following lines (/home/swap defaults 0 0 ):

       
        [root@db2 root]# vi /etc/fstab LABEL=/                 /                   ext3    defaults        1 1        LABEL=/boot             /boot               ext2    defaults        1 2      /home/swap               swap                    swap    defaults        0 0 none                    /dev/pts                devpts  gid=5,mode=620  0 0      none                    /proc                   proc    defaults        0 0      none                    /dev/shm                tmpfs   defaults        0 0      LABEL=/usr              /usr                    ext3    defaults        1 2      /dev/sda5               swap                    swap    defaults        0 0      /dev/cdrom              /mnt/cdrom              iso9660 noauto,owner,kudzu,ro 0 0/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0               /home/swap               swap                    swap    defaults        0 0
       

Next time the system boots, it will enable the new swap file and check the added information again:

       
        [root@db2 oracledb]# free -m                                                                  total       used       free     shared    buffers     cached        Mem:          1006        979         27          0          6        917        -/+ buffers/cache:         54        952                                         Swap:          999          0        999                                                     [root@db2 oracledb]#
       

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.