[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): t
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 239.9 GB, 239902654464 bytes, 468559872 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 label type: dos
Disk identifier: 0x93de47a2
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104859647 52428800 82 Linux swap / Solaris
/dev/sdb2 104859648 468559871 181850112 83 Linux
接下来我们使用mkswap命令将/dev/sdb1格式化为swap文件系统,然后使用命令blkid查看分区的文件系统类型。可以看出,/dev/sdb1已经是swap类型的文件系统了。下面的输出中有两点需要注意:(1)mkswap命令的输出中有wiping old xfs signature,这是因为/dev/sdb1之前已经被格式化为xfs类型的系统了;(2)blkid命令的输出中没有看到/dev/sda2与/dev/sdb2,这是因为这两个分区还没有被格式化为某种类型的文件系统。
[root@localhost ~]# mkswap /dev/sdb1
mkswap: /dev/sdb1: warning: wiping old xfs signature.
Setting up swapspace version 1, size = 52428796 KiB
no label, UUID=5a24c22c-f06f-47b3-a85e-de9168d03d4e
[root@localhost ~]# blkid
/dev/sda1: UUID="da3cfe99-417c-4e06-b652-22171c0c340a" TYPE="xfs"
/dev/sdb1: UUID="5a24c22c-f06f-47b3-a85e-de9168d03d4e" TYPE="swap"