天天看点

通过交换文件来添加Linux交换分区

系统类型:RedHat Enterprise Linux5

登录用户:root

原有交换分区:1G

现在要通过添加交换文件的形式扩大系统的交换分区,为系统添加1G的交换分区。

1. 首先可以通过free -m命令来查看原有的Swap分区的大小Total为1019M。

[[email protected] ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1010        610        400          0         35        405

-/+ buffers/cache:        169        841

Swap:         1019          0       1019

2.创建/swapfile文件

[[email protected] ~]# dd if=/dev/zero of=/swapfile bs=1024 count=1024000

几秒中后会出现下面的提示:

1024000+0 records in

1024000+0 records out

1048576000 bytes (1.0 GB) copied, 49.1357 seconds, 21.3 MB/s

3.设置交换分区

[[email protected] ~]# mkswap /swapfile

Setting up swapspace version 1, size = 1048571 kB

4.马上启用交换分区

[[email protected] ~]# swapon /swapfile

5.如果再通过free -m来检查内存的时候就可以看到内容变大了

[[email protected] ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1010        991         19          0          1        803

-/+ buffers/cache:        186        824

Swap:         2019          0       2019

6.设置系统启动是自动打开交换分区,在/etc/fstab文件中加入一行

/swapfile               swap                    swap    defaults        0 0

即:

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-sda3         swap                    swap    defaults        0 0

/swapfile               swap                    swap    defaults        0 0


# Beginning of the block added by the VMware software

.host:/                 /mnt/hgfs               vmhgfs  defaults,ttl=5     0 0

# End of the block added by the VMware software



保存退出,这样下次启动系统之后自动启用了该swap。



打完收工。。。 。。。





Thomas Yang

2010/01/22



                                                                                                



      

继续阅读