动态添加交换分区 swap

1.当系统中磁盘不能再分区时,可以通过dd命令创建一个较大的文件,然后用文件构建交换分区

查看当前的交换分区

 

[root@zhu1 ~]# free -m
total       used       free     shared    buffers     cached
Mem:           514        508          6          0        115        192
-/+ buffers/cache:        200        314
Swap:         1498          0       1498

2.dd命令创建一个1G的文件

 

[root@zhu1 ~]# dd if=/dev/zero of=/root/swapfile  bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 16.1442 seconds, 66.5 MB/s

3.格式化为交换分区

 

[root@zhu1 ~]# mkswap /root/swapfile
Setting up swapspace version 1, size = 1073737 kB

4.启动交换分区

 

[root@zhu1 ~]# free -m
total       used       free     shared    buffers     cached
Mem:           514        503         10          0          1        405
-/+ buffers/cache:         96        418
Swap:         1498          0       1497
[root@zhu1 ~]# swapon /root/swapfile
[root@zhu1 ~]# free -m
total       used       free     shared    buffers     cached
Mem:           514        504         10          0          1        406
-/+ buffers/cache:         96        418
Swap:         2522          0       2521
[root@zhu1 ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/hda2                               partition   1534196 1004    -1
/root/swapfile                          file        1048568 0   -2

 

5.设置自动挂载

 

[root@zhu1 ~]# vim /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
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-hda2         swap                    swap    defaults        0 0
/root/swapfile          swap                    swap    defaults        0 0
~

当该交换分区不需要时可关闭并删除

 

[root@zhu1 ~]# swapoff /root/swapfile
[root@zhu1 ~]# rm /root/swapfile
[root@zhu1 ~]# free -m
total       used       free     shared    buffers     cached
Mem:           514        107        407          0          1         14
-/+ buffers/cache:         91        423
Swap:         1498          0       1497

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(动态,count,shared,seconds,records)