Linux扩充SWAP分区

    xiaoxiao2021-03-25  86

    扩充SWAP分区

     

    --查看硬盘分区情况-- [root@DBSyncDes ~]# free              total       used       free     shared    buffers     cached Mem:       3237804    1191656    2046148          0     171784     582244 -/+ buffers/cache:     437628    2800176 Swap:      2096472          0    2096472

    [root@DBSyncDes ~]# free -m              total       used       free     shared    buffers     cached Mem:          3161       1163       1998          0        167        568 -/+ buffers/cache:        427       2734 Swap:         2047          0       2047

    [root@DBSyncDes ~]# cat /proc/swaps Filename                                Type            Size    Used    Priority /dev/sda2                               partition       2096472 0       -1

    [root@DBSyncDes ~]# df -hl 文件系统              容量  已用 可用 已用% 挂载点 /dev/sda1             224G  9.5G  203G   5% / tmpfs                 1.6G     0  1.6G   0% /dev/shm

    --创建存放swap文件的文件夹-- [root@DBSyncDes ~]# mkdir /swap

    --进入-- [root@DBSyncDes ~]# cd /swap/ [root@DBSyncDes swap]# ll 总计 0

    --使用dd命令创建swap文件-- [root@DBSyncDes swap]# dd if=/dev/zero of=extra-swap bs=32k count=196608 196608+0 records in 196608+0 records out 6442450944 bytes (6.4 GB) copied, 63.0981 seconds, 102 MB/s

    [root@DBSyncDes swap]# ll 总计 6297616 -rw-r--r-- 1 root root 6442450944 09-03 01:22 extra-swap

    --格式化新创建的swap文件-- [root@DBSyncDes swap]# mkswap extra-swap Setting up swapspace version 1, size = 6442446 kB

    --激活该swap文件-- [root@DBSyncDes swap]# swapon extra-swap

    --查看扩充后的结果-- [root@DBSyncDes swap]# swapon -s Filename                                Type            Size    Used    Priority /dev/sda2                               partition       2096472 4       -1 /swap/extra-swap                        file            6291448 0       -2

    [root@DBSyncDes swap]# cat /proc/swaps Filename                                Type            Size    Used    Priority /dev/sda2                               partition       2096472 4       -1 /swap/extra-swap                        file            6291448 0       -2

    [root@DBSyncDes swap]# free              total       used       free     shared    buffers     cached Mem:       3237804    3112800     125004          0      37560    2607056 -/+ buffers/cache:     468184    2769620 Swap:      8387920          4    8387916

    [root@DBSyncDes swap]# free -m              total       used       free     shared    buffers     cached Mem:          3161       3039        122          0         36       2545 -/+ buffers/cache:        457       2704 Swap:         8191          0       8191

    [root@DBSyncDes swap]# df -hl 文件系统              容量  已用 可用 已用% 挂载点 /dev/sda1             224G   16G  197G   8% / tmpfs                 1.6G     0  1.6G   0% /dev/shm

    --修改fstab文件,使扩充的swap文件随机启动-- [root@DBSyncDes swap]# vi /etc/fstab

    LABEL=/                 /                       ext3    defaults        1 1 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 LABEL=SWAP-sda2         swap                    swap    defaults        0 0 /swap/extra-swap        swap                    swap    defaults        0 0

    [root@DBSyncDes swap]# 注:若想卸载掉新挂载的swap分区文件,可使用swapoff swapfilename命令即可。

     

     

    转载请注明原文地址: https://ju.6miu.com/read-32988.html

    最新回复(0)