ITPub博客

首页 > Linux操作系统 > Linux操作系统 > linux下增加swap分区

linux下增加swap分区

原创 Linux操作系统 作者:孤竹星 时间:2015-03-25 16:10:52 0 删除 编辑
1.创建swap分区
例如: 
# 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-13054, default 1):  
Using default value 1 
Last cylinder or +size or +sizeM or +sizeK (1-13054, default 13054): +100M 
Command (m for help): t 
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 
The partition table has been altered! 

2.同步分区表 
# partprobe

 
3.设置交换区 
# mkswap /dev/sdb1 

4.编辑/etc/fstab文件 
添加如下内容: 
/dev/sdb1    swap    swap    defaults    0 0 

5.启用swap分区 
# swapon -a 

6.验证swap分区是否启用
 
# swapon -s
 
Filename      Type         Size       Used   Priority 
/dev/sdb1    partition    104380    0       -2 

二、文件方式 

1.创建文件 
# dd if=/dev/zero of=/swapfile bs=1024 count=100
if=文件名:输入文件名,缺省为标准输入。即指定源文件。< if=input file >
of=文件名:输出文件名,缺省为标准输出。即指定目的文件。< of=output file >
bs=bytes:同时设置读入/输出的块大小为bytes个字节
count=blocks:仅拷贝blocks个块,块大小等于bs指定的字节数。
1G=1024mb
1mb=1024kb
1kb=1024bytes

 

2.查看文件属性 
# ls -lh /swapfile -rw-r--r-- 1 root root 100K Apr 24 16:54 /swapfile 

3.设置swap 
# mkswap /swapfile

 
4.编辑/etc/fstab文件 
添加如下内容:
 
/swapfile    swap    swap    defaults    0 0 

5.启用swap 
# swapon /swapfile 

6.验证swap是否启用 
# swapon -s 
Filename     Type    Size    Used    Priority 
/swapfile     file     92      0         -3 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28282660/viewspace-1473313/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-01-22

  • 博文量
    96
  • 访问量
    298368