码迷,mamicode.com
首页 > 系统相关 > 详细

linux 新建swap 分区

时间:2015-06-04 17:35:22      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:swap 新建

   阿里云主机一般默认不带swap分区,需要手工新建。

1)查看磁盘情况:

  

[root@data_app ~]# fdisk -l


Disk /dev/xvda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00078f9c


    Device Boot      Start         End      Blocks   Id  System

/dev/xvda1   *           1        2611    20970496   83  Linux


Disk /dev/xvdb: 644.2 GB, 644245094400 bytes

255 heads, 63 sectors/track, 78325 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

从上面结果看需要在/dev/xvdb 设备新建一个swap 分区


2)新建分区 fdisk /dev/xvdb

 

[root@data_app ~]# fdisk /dev/xvdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x80639514.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won‘t be recoverable.


Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to

         switch off the mode (command ‘c‘) and change display units to

         sectors (command ‘u‘).


Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-78325, default 1): 

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-78325, default 78325): +32g

Unsupported suffix: ‘g‘.

Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)

            2^N: K  (KibiByte), M  (MebiByte), G  (GibiByte)

Last cylinder, +cylinders or +size{K,M,G} (1-78325, default 78325): +32G


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.

Syncing disks .      #####完成分区新建#


3)修改新建分区的system id 号,修改为swap 分区ID 82.



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


修改后结果如下:

    Device Boot      Start         End      Blocks   Id  System

/dev/xvdb1               1        4178    33559753+  82  Linux swap / Solaris

4)用mkswap创建swap

[root@data_app ~]# mkswap /dev/xvdb1

Setting up swapspace version 1, size = 33559748 KiB

no label, UUID=e42ec169-e5f8-4df6-a65a-51db3abbb0e0

5)开启swap 

 [root@data_app ~]# swapon /dev/xvdb1

6)检测swap是否开启

 

[root@data_app ~]# swapon -s

Filename                                Type            Size    Used    Priority

/dev/xvdb1                              partition       33559744        0       -1

7)编辑/etc/fstab,使swap可永久生效。

  /dev/xvdb1  swap       swap    defaults        0 0



linux 新建swap 分区

标签:swap 新建

原文地址:http://7712190.blog.51cto.com/7702190/1658398

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!