阿里云ecs磁盘转为交换分区(swap)

介意换成root登录服务器.

  • lsblk
    这个是查看是否有磁盘,好选择对应的磁盘去做交换分区.
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  1024M  0 rom  
vda    253:0    0    40G  0 disk 
└─vda1 253:1    0    40G  0 part /
vdb    253:16   0    20G  0 disk
  • fdisk -l
    查看使用的磁盘.
Disk /dev/vda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000da36d

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83884031    41940992   83  Linux

Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/vdb doesn't contain a valid partition table
  • 设置交换分区
    通过上面,我们可以找到没有使用的磁盘.然后进行分区.

    • 分区命令
    mkswap -L NEWSWAP /dev/vdb

    会出现下面的信息:

    mkswap: /dev/vdb: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
    Setting up swapspace version 1, size = 20971516 KiB
    LABEL=NEWSWAP, UUID=d454305b-4d1d-4e57-826c-6fafc9a52d14

    然后再执行开启交换分区命令:

swapon /dev/vdb

最后查看内存中是否有这些交换分区.

free -h

你可能感兴趣的:(运维,服务器)