硬盘分区及格式化
-
本例要求熟悉硬盘分区结构,使用fdisk分区工具在磁盘 /dev/vdb 上按以下要求建立分区:
-
采用默认的 msdos 分区模式
1、第1个分区 /dev/vdb1 的大小为 200MiB
2、第2个分区 /dev/vdb2 的大小为 2000MiB
3、第3个分区 /dev/vdb3 的大小为 1000MiB,完成分区后
4、能够配置开机自动挂载 /dev/vdb2 分区:文件系统类型为 EXT4,将其挂载到 /mnt/part2 目录
fdisk分区工具用来建立msdos分区方案,其交互模式中的主要指令如下:
指令 | 用途 |
---|---|
m | 列出指令帮助 |
p | 查看当前的分区表信息 |
n | 新建分区 |
d | 删除分区 |
t | 更改分区标识 |
q | 放弃分区更改并退出 |
w | 保存对分区表所做的更改 |
步骤
实现此案例需要按照如下步骤进行。
步骤一:新建分区表
- 打开fdisk工具,操作磁盘/dev/vdb
[root@server0 ~]# fdisk /dev/vdb
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 0x9ac1bc10.
Command (m for help): //交互操作提示信息
- 新建第1个分区/dev/vdb1
Command (m for help): n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //类型为p(主分区)
Partition number (1-4, default 1): 1 //分区编号1
First sector (2048-20971519, default 2048): //起始位置默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +200M
Partition 1 of type Linux and of size 200 MiB is set //结束位置+200MiB大小
Command (m for help): p //确认当前分区表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 83 Linux
- 新建第2个分区/dev/vdb2
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p //类型为p(主分区)
Partition number (2-4, default 2): 2 //分区编号2
First sector (411648-20971519, default 411648): //起始位置默认
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +2000M
Partition 2 of type Linux and of size 2 GiB is set //结束位置+2000MiB大小
Command (m for help): p //确认当前分区表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 83 Linux
/dev/vdb2 411648 4507647 2048000 83 Linux
- 新建第3个分区/dev/vdb3
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (4507648-20971519, default 4507648):
Using default value 4507648
Last sector, +sectors or +size{K,M,G} (4507648-20971519, default 20971519): +1000M
Partition 3 of type Linux and of size 1000 MiB is set
Command (m for help): p //确认当前分区表
.. ..
Device Boot Start End Blocks Id System
/dev/vdb1 2048 411647 204800 83 Linux
/dev/vdb2 411648 4507647 2048000 83 Linux
/dev/vdb3 4507648 6555647 1024000 83 Linux
- 调整分区类型标识(可选)
将/dev/vdb1的类型(默认为83,表示EXT2/3/4分区)修改为8e(LVM设备):