fdisk /dev/sdb #利用fdisk工具创建分区
N #新建分区
1 #输入分区序号
p #创建主分区
2048 #选择分区起始位置
+8G #选择分区大小
p #查看分区
w #保存并退出
[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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6fd48e66.
Command (m for help): n #新建一个分区,输入n后回车
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #创建主分区
Partition number (1-4, default 1): #输入分区序号,默认1,可以直接回车
First sector (2048-41943039, default 2048):2048 #输入分区其实位置,默认2048,可以直接回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +8G
Partition 1 of type Linux and of size 8 GiB is set
Command (m for help): p #查看分区
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 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 label type: dos
Disk identifier: 0x6fd48e66
Device Boot Start End Blocks Id System
/dev/sdb1 2048 16779263 8388608 83 Linux
Command (m for help): w #保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
partprobe /dev/sdb #通知内核识别新分区表
[root@localhost ~]# partprobe /dev/sdb
注:感兴趣的博友可以关注下面这篇文章,有分区规划与使用的详细介绍
mkswap
功能:格式化Swap分区
格式:mkswap分区
常用选项:-f 强制执行
[root@localhost ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 8388604 KiB
no label, UUID=0a4dff18-bdc8-4595-80b4-515292716156
swapon
功能:使用Swap分区
格式:swapon 选项 | swapon 分区
常用选项:-s 显示分区信息 -p 设置优先级 -h 查看帮助信息
swapoff
功能:关闭Swap分区
格式:swapoff 分区
[root@localhost ~]# swapon /dev/sdb1 #开启Swap分区
[root@localhost ~]# swapon -s #查看Swap分区
Filename Type Size Used Priority
/dev/dm-1 partition 2097148 40428 -1
/dev/sdb1 partition 8388604 0 -2
[root@localhost ~]# swapoff /dev/sdb1 #关闭Swap分区
[root@localhost ~]# swapon -s #查看Swap分区
Filename Type Size Used Priority
/dev/dm-1 partition 2097148 40184 -1
dd
功能:指定大小的块拷贝文件,并在拷贝的同时进行指定的转换
格式:dd if=源设备of=目标设备bs=块大小count=块数
[root@localhost ~]# dd if=/dev/zero of=/opt/wangwu.dd bs=1M count=2048
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB) copied, 4.19745 s, 512 MB/s
mkswap -f /opt/wangwu.dd
[root@localhost ~]# mkswap -f /opt/wangwu.dd
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=f4b92518-8841-48b9-9aeb-afa33fb9ae0d
swapon /opt/wangwu.dd #开启Swap分区
swapon -s #查看Swap分区
swapoff /opt/wangwu.dd #关闭Swap分区
swapon -s #查看Swap分区
]# mkswap -f /opt/wangwu.dd
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=f4b92518-8841-48b9-9aeb-afa33fb9ae0d
### 3、使用Swap分区
#### 1)命令
swapon /opt/wangwu.dd #开启Swap分区
swapon -s #查看Swap分区
swapoff /opt/wangwu.dd #关闭Swap分区
swapon -s #查看Swap分区
因篇幅问题不能全部显示,请点此查看更多更全内容