使用fdisk进程磁盘分区

192 阅读3分钟

前言

前面使用fio工具进行磁盘测试的时候,加密是针对每个分区进行的,所以需要创建一个独立的分区来进行测试,就用到了fdisk命令。

fdisk磁盘分区

首先使用lsblk查看当前系统中的块设备信息,里面就有磁盘的相关信息。

root@keep-VirtualBox:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0    7:0    0     4K  1 loop /snap/bare/5
loop1    7:1    0  63.3M  1 loop /snap/core20/1822
loop2    7:2    0 248.8M  1 loop /snap/gnome-3-38-2004/99
loop3    7:3    0  63.3M  1 loop /snap/core20/1828
loop4    7:4    0 346.3M  1 loop /snap/gnome-3-38-2004/119
loop5    7:5    0  49.8M  1 loop /snap/snapd/17950
loop6    7:6    0  45.9M  1 loop /snap/snap-store/599
loop7    7:7    0  91.7M  1 loop /snap/gtk-common-themes/1535
loop8    7:8    0  49.9M  1 loop /snap/snapd/18357
loop9    7:9    0    46M  1 loop /snap/snap-store/638
loop10   7:10   0  65.2M  1 loop /snap/gtk-common-themes/1519
sda      8:0    0   100G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0     1K  0 part
└─sda5   8:5    0  99.5G  0 part /
sdb      8:16   0    10G  0 disk
└─sdb1   8:17   0    10G  0 part
sr0     11:0    1  58.3M  0 rom

可以看到有一个sdb的磁盘,里面分了一个区sdb1,这个是我分区好了的。为了安全起见,我也不建议大家直接使用实际的机器来测试,我这边使用的是virtualbox的虚拟机,手动添加了一个额外的磁盘。 具体步骤:设置->存储->控制器SATA -- 添加虚拟硬盘 。。。

# 使用fdisk -l /dev/sdb查看磁盘信息

root@keep-VirtualBox:~# fdisk -l /dev/sdb
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x429cd5e6



可以看到增加了一块10G的独立磁盘/dev/sdb,每个sector大小为512bytes, 需要在上面增加一个10G的分区。

# 使用fdisk命令分区

fdisk /dev/sdb

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n # 输入n创建新分区
Partition number (1-128, default 1):
First sector (34-20969472, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20969472, default 20969472): 20969472 # 输入计算好的结束扇区索引

Created a new partition 1 of type 'Linux filesystem' and of size 10 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.

Command (m for help): w # 输入w使修改生效
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


OK,这样就分区好了。


行动,才不会被动!

欢迎关注个人公众号 微信 -> 搜索 -> fishmwei,沟通交流。

博客地址: fishmwei.github.io

掘金主页: juejin.cn/user/208432…