zoukankan      html  css  js  c++  java
  • Adding Swap Files

     Adding Swap Files  

    If you do not have free disk space to create a swap partition and you do need to add swap space urgently, you can use a swap file as well. From a performance perspective, it does not even make that much difference if a swap file is used instead of a swap device such as a partition or a logical volume, and it may help you fixing an urgent need in a timely manner.  (如果没有多余的磁盘空间来增加交换分区,可使用交换文件代替。从性能方面来看,swap file跟swap device没多少区别)

    To add a swap file, you need to create the file first. The  dd if=/dev/zero of=/ swapfile bs=1M count=100  command would add 100 blocks with a size of 1 Mebibyte from the /dev/zero device (which generates 0s) to the /swapfile file. The result is a 100 MiB file that can be configured as swap. To do so, you can follow the same procedure as for swap partitions. First use  mkswap /swapfile  to mark the file as a swap file, after which you can use  swapon /swapfile  to active it. 

    例如:把原来的swap空间大小从2147MB添加到2247MB

    [root@rhel7 ~]# free -m
                  total        used        free      shared  buff/cache   available
    Mem:           1840          91        1603           8         144        1605
    Swap:          2147           0        2147
    [root@rhel7 /]# touch swapfileTest
    [root@rhel7 /]# dd if=/dev/sda of=/swapfileTest bs=1M count=100
    100+0 records in
    100+0 records out
    104857600 bytes (105 MB) copied, 1.45588 s, 72.0 MB/s
    [root@rhel7 /]# mkswap /swapfileTest 
    mkswap: /swapfileTest: warning: don't erase bootbits sectors
            (dos partition table detected). Use -f to force.
    Setting up swapspace version 1, size = 102396 KiB
    no label, UUID=c011c102-304a-4cb2-8106-2c69500a82a8
    [root@rhel7 /]# swapon /swapfileTest 
    swapon: /swapfileTest: insecure permissions 0644, 0600 suggested.    -----有提示,需要设置权限#chmod 0600 /swapfileTest
    [root@rhel7 /]# free -m --比原来的2147添加的100MB
                  total        used        free      shared  buff/cache   available
    Mem:           1840          91        1398           8         350        1598
    Swap:          2247           0        2247
    [root@rhel7 /]# 

     将配置写入到etc/fstab文件中,否则重启系统后不生效:

    # vi  /etc/fstab,增加如下行

    /swapfileTest             swap          swap    defaults        0 0  

  • 相关阅读:
    Vue中事件委托的使用
    java提取每个汉字的首字母
    想把大脑存进电脑,我为什么要写博客
    CF 1606 D题题解
    js前端 音频波形图像展示
    js前端 仪表盘实现
    js前端 bootstrap select的使用
    UOS系统维护命令
    linux 打印机管理常用命令
    linux 调用shell命令
  • 原文地址:https://www.cnblogs.com/rusking/p/5735786.html
Copyright © 2011-2022 走看看