面试题:
1.小于2TB的磁盘 使用fdisk分区 MBR
2.大于2TB的磁盘 使用parted分区 GPT
对小于2T的磁盘分区: fdisk
第一步: 添加一块新的硬盘
vmware: 右键--->设置-->添加-->硬盘--》下一步
物理机: 拿到新的硬盘-->直接插入到面板处即可 支持热插拔
云服务器: 阿里云 亚马逊云 在线磁盘扩容
第二步: 查看是否可以识别到第二块磁盘
[root@oldboy:~]# fdisk -l 重启生效[root@oldboy:~]# reboot[root@oldboy:~]# fdisk -l
Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512=512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
第三步: 磁盘分区 类似打隔断
[root@oldboy:~]# fdisk /dev/sdb
Command (m forhelp): m # 按m 显示菜单
Help:
d delete a partition # 删除分区
n add a new partition # 创建分区
p print the partition table # 打印分区
m print this menu # 显示菜单
w write table to disk and exit# 保存并退出
q quit without saving changes # 退出不保存
Command (m forhelp): n # 创建分区
Partition type
p primary (0 primary, 0 extended, 4free)
e extended (container for logical partitions)
Select (default p): # 创建主分区
Using default response p.
Partition number (1-4, default 1): # 分区的编号 sdb1
First sector (2048-1048575999, default 2048): # 开始的大小
Last sector, +/-sectors or +/-size{
K,M,G,T,P}(2048-1048575999, default 1048575999): +100G #分区大小
Command (m forhelp): p # 查看分区表
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048209717247209715200 100G 83 Linux
Command (m forhelp): n #分区
Partition type
p primary (1 primary, 0 extended, 3free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2): # 分区编号
First sector (63-1048575999, default 63):
Last sector, +/-sectors or +/-size{
K,M,G,T,P}(63-1048575999, default 1048575999): +100G # 大小
Created a new partition 2 of type'Linux' and of size 100 GiB.
Command (m forhelp): d # 删除分区
Partition number (1-4, default 4): # 默认删除最后面的编号
划分扩展分区:
Command (m forhelp): n
Partition type
p primary (3 primary, 0 extended, 1free)
e extended (container for logical partitions)
Select (default e):
Using default response e.
Selected partition 4
First sector (419432449-1048575999, default 419432449):
Last sector, +/-sectors or +/-size{
K,M,G,T,P}(419432449-1048575999, default 1048575999): # 直接回车给所有的空间
基于扩展分区划分逻辑分区:
Command (m forhelp): n
All primary partitions are in use.
Adding logical partition 5
First sector (419432512-1048575999, default 419432512):
Last sector, +/-sectors or +/-size{
K,M,G,T,P}(419432512-1048575999, default 1048575999): +100G # 第一个逻辑分区给100G
Created a new partition 5 of type'Linux' and of size 100 GiB.
查看最后的分区结果:
Command (m forhelp): p
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048209717247209715200 100G 83 Linux
/dev/sdb2 63209715263209715201 100G 83 Linux
/dev/sdb3 209717248419432448209715201 100G 83 Linux
/dev/sdb4 4194324491048575999629143551 300G 5 Extended
/dev/sdb5 419432512629147712209715201 100G 83 Linux
/dev/sdb6 6291477761048575999419428224 200G 83 Linux
Command (m forhelp): w #保存并且推出
查看磁盘分区信息:
[root