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可永久生效。