linux-添加swap分区-129

 Linux 添加交换分区

系统环境:

--------------------------------------------

[root@CentOS-5 ~]# cat /etc/redhat-release

CentOS release 5.7 (Final)

[root@CentOS-5 ~]# uname -rv

2.6.18-274.7.1.el5 #1 SMP Thu Oct 20 16:21:01 EDT 2011

--------------------------------------------

1.通过添加分区实现

[root@CentOS-5 ~]# fdisk -l /dev/sdb

[root@CentOS-5 ~]# fdisk /dev/sdb    -----添加新的分区

 

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1 

First cylinder (1-391, default 1): 1

Last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100

 

Command (m for help): t         ------t   change a partition's system id

Selected partition 1

Hex code (type L to list codes): 82

Changed system type of partition 1 to 82 (Linux swap / Solaris)

 

Command (m for help): w

[root@CentOS-5 ~]# mkswap /dev/sdb1     -----格式化分区

[root@CentOS-5 ~]# swapon /dev/sdb1          ----添加建好的分区

[root@CentOS-5 ~]# swapon -s

Filename                                Type            Size    Used    Priority

/dev/sda2                               partition       1052248 0       -1

/dev/sdb1                               partition       803208  0       -2

[root@CentOS-5 ~]# vim /etc/fstab                  ----写入开机启动

/dev/sdb1               none                    swap    defaults        0 0

[root@CentOS-5 ~]# mount -a -o remount

 

2.通过添加文件实现

[root@CentOS-5 ~]# dd if=/dev/zero of=/opt/swap_file bs=4M count=25

[root@CentOS-5 ~]# mkswap /opt/swap_file

Setting up swapspace version 1, size = 104853 kB

[root@CentOS-5 ~]# swapon /opt/swap_file

[root@CentOS-5 ~]# swapon -s

Filename                                Type            Size    Used    Priority

/opt/swap_file                          file            102392  0       -3

[root@CentOS-5 ~]# echo '/opt/swap_file               none                    swap    defaults        0 0' >>/etc/fstab

[root@CentOS-5 ~]# mount -a -o remount

[root@CentOS-5 ~]# cat /proc/swaps

Filename                                Type            Size    Used    Priority

/dev/sda2                               partition       1052248 0       -1

/dev/sdb1                               partition       803208  0       -2

/opt/swap_file                          file            102392  0       -3

[root@CentOS-5 ~]#

你可能感兴趣的:(linux,swap分区)