一.先创建一个分区

[root@magedu ~]# fdisk /dev/sdb

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

Building a new DOS disklabel with disk identifier 0x30783445.

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-261, default 1):

Using default value 1

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


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!


Calling ioctl() to re-read partition table.

Syncing disks.

好了,现在已经创建出了一个交换分区,最好重启电脑一下。如果不重启,则输入命令;

[root@magedu ~]# partprobe

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.

Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.

让内核重新读取分区表

二:

[root@magedu ~]# mkswap /dev/sdb1

Setting up swapspace version 1, size = 1060252 KiB

no label, UUID=11c8dda0-d607-4aec-81f6-43edff562ec8

获得/dev/sdb1的UUID ,

三:实现自动挂载:

[root@magedu ~]# echo " UUID=11c8dda0-d607-4aec-81f6- 43edff562ec8 swap swap defaults 0 0" >> /etc/fstab

[root@magedu ~]# swapon -a

[root@magedu ~]# swapon -s

FilenameTypeSizeUsedPriority

/dev/sda3 partition10485680-1

/dev/sdb1 partition10602480-2

好了,已经实现了自动挂载