linux fdisk_Linux fdisk教程示例

linux  fdisk

linux fdisk

Hi, creating and deleting partitions in Linux generally done in command line interface which makes some user confused. Here I will look it more detail but if you prefer GUI you can use gparted too

嗨,在Linux中创建和删除分区通常是在命令行界面中完成的,这使一些用户感到困惑。 在这里,我将对其进行详细介绍,但是如果您喜欢GUI,也可以使用gparted

(Man)

In order to get more detailed help man page of fdisk can be used.

为了获得更详细的帮助,可以使用fdisk的手册页。

$ man fdisk
Man
Man

帮帮我(Help)

Simple and fast way to get fdisk options with the parameters following command can be used.

可以使用使用以下命令的参数获取fdisk选项的简单快速方法。

$ fdisk -h
Help
Help
帮帮我

列出磁盘(List Disks)

Disk on the Linux system can be listed with the following fdisk command. In order to get detailed information about disks fdisk need root privileges. In the recent versions of Ubuntu the special disk named ram disks also listed with -l parameter.

可以使用以下fdisk命令列出Linux系统上的磁盘。 为了获得有关磁盘的详细信息,fdisk需要root特权。 在最新版本的Ubuntu中,名为ram disks的特殊磁盘也与-l列出 参数。

$ sudo fdisk -l
List Disk
List Disk
列出磁盘

As we see from the screenshot information like disk name, path, size, sectors count, logical and physical sector sizes are provided with the command.

屏幕截图中可以看到,该命令提供了磁盘名称,路径,大小,扇区数,逻辑和物理扇区大小等信息。

Fdisk交互式外壳 (Fdisk Interactive Shell)

Most of the features of fdisk is provided by interactive shell provided by fdisk. In order to start this shell the disk we want to operate should be provided like below.

fdisk的大多数功能由fdisk提供的交互式shell提供。 为了启动该外壳,应按如下所示提供我们要操作的磁盘。

$ fdisk /dev/vda
Interactive Shell
Interactive Shell
互动壳

列出分区(List Partitions)

We assume we are in the interactive fdisk shell with the related disk. In the fdisk shell which is shortcut of print will list partition information

我们假设我们与相关磁盘位于交互式fdisk外壳中。 在fdisk shell p中,这是打印的快捷方式,它将列出分区信息

p
List Partitions
List Partitions
列出分区

OR

要么

Disk listing command will provide partition list too

磁盘列表命令也将提供分区列表

列出特定磁盘的分区(List Partitions Of Specific Disk)

There are situations to only list specific disks partitions this can be accomplished by specifying disk path like below.

在某些情况下,仅列出特定的磁盘分区可以通过指定如下所示的磁盘路径来完成。

$ sudo fdisk -l /dev/vda
List Partitions Of Specific Disk
List Partitions Of Specific Disk
列出特定磁盘的分区

外壳帮助(Shell Help)

Interactive shell provides a lot of operations and commands. These commands can be get with the following command.

交互式外壳程序提供了许多操作和命令。 这些命令可以通过以下命令获取。

m
Shell Help
Shell Help
外壳帮助

更改分区类型(Change Partition Type)

As we now there are a lot of file system or partition type. Windows systems generally uses FAT,VFAT, NTFS on the other hand Linux/Unix systems prefer ext3,ext4,btrfs,xfs like file systems. Partition file system type can be specified with command.

由于我们现在有很多文件系统或分区类型。 Windows系统通常使用FAT,VFAT,NTFS,而Linux / Unix系统更喜欢ext3,ext4,btrfs,xfs等文件系统。 分区文件系统类型可以使用t命令指定。

t

Now we will select our partition number where for this example we haveonly one partition and selected by default.

现在,我们将选择分区号,在此示例中,我们只有一个分区,并且默认情况下已选中。

1

To set required partition type we can get list of supported partition types with command like below.

要设置所需的分区类型,我们可以使用L命令获取支持的分区类型列表,如下所示。

L

Linux type partition is OK for us which number is 83. we enter partition type number. By default all newly created partitions types are created as Linux partition type.

Linux类型分区对我们来说可以,编号为83。我们输入分区类型号。 默认情况下,所有新创建的分区类型都将创建为Linux分区类型。

83
Change Partition Type
Change Partition Type
更改分区类型

将更改写入磁盘(Write Changes To Disk)

While using fdisk interactive shell modifications are done in the ram which means they are no effective if we do not write them to the disks. We should write change to the disk with like below.

使用fdisk时,交互式shell修改是在ram中完成的,这意味着如果不将它们写入磁盘,它们将无效。 我们应该像下面这样用w将更改写入磁盘。

w
Write Changes To Disk
Write Changes To Disk
将更改写入磁盘

重新读取磁盘更改(Re-Read Disk Changes)

After writing disk changes to the disk because of some kernel performance mechanisms they are not directly written. So to make them effective from kernel side following command should be provided in the bash.

由于某些内核性能机制,将磁盘更改写入磁盘后,它们不会直接写入。 因此,为了使它们从内核方面有效,应在bash中提供以下命令。

$ partprobe

格式化磁盘Dos分区表 (Format Disk Dos Partition Table)

Every disks will have their own partition table to identify partitions their sizes, boot options etc. DOS is most used partition table because of the Windows popularity. DOS was default partition table for Windows operating systems. DOS partition table can only use up to 2 TB disks so use with cautiously. Because of the architectural restrictions DOS partition table can not use more than 2 TB

每个磁盘都有自己的分区表以标识其大小,引导选项等分区。由于Windows的流行,DOS是最常用的分区表。 DOS是Windows操作系统的默认分区表。 DOS分区表最多只能使用2 TB磁盘,因此请谨慎使用。 由于体系结构限制,DOS分区表不能使用超过2 TB

o
Format Disk Dos Partition Table
Format Disk Dos Partition Table
格式化磁盘Dos分区表

格式化磁盘GPT分区表(Format Disk GPT Partition Table)

GPT partition table is newer than DOS and fixes DOS partition table restrictions like disk size. GPT table supports disks bigger than 2 TB. To create new GPT partition table use following command.

GPT分区表比DOS更新,并修复了DOS分区表限制(如磁盘大小)。 GPT表支持大于2 TB的磁盘。 要创建新的GPT分区表,请使用以下命令。

g
Format Disk GPT Partition Table
Format Disk GPT Partition Table
格式化磁盘GPT分区表

创建分区(Create Partition)

Partition are specified parts of the disks. Partitions provides logical boundaries and makes disk multi part for different usage scenarios. First we will provide new partition command .

分区是磁盘的指定部分。 分区提供逻辑边界,并使磁盘成为不同使用场景的一部分。 首先,我们将提供新的分区命令n

n

Then provide partition type with 

然后用p提供分区类型

p

Now we will provide partition number which is by default 1.

现在我们将提供默认为1的分区号。

1

First sector of this partition. If we have no specific requirements we can use default one which is 2048

此分区的第一个扇区。 如果没有特殊要求,我们可以使用默认值2048

2048

The most important part is last sector number or size. We will set end boundary for this partition. If we enter without any parameter which will use default sector number which is the last unused sector on the disk. Alternative way is specifying disk size in kilobyte,megabyte, gigabyte, terabyte, petabyte. For example to create 10 GB partitions use +10G

最重要的部分是最后一个扇区号或大小。 我们将为此分区设置结束边界。 如果输入时不带任何参数,它将使用默认扇区号,该默认扇区号是磁盘上最后一个未使用的扇区。 另一种方法是指定磁盘大小,以千字节,兆字节,千兆字节,太字节,PB为单位。 例如,要创建10 GB分区,请使用+ 10G

+10G
Create Partition
Create Partition
创建分区

删除分区(Delete Partition)

Created partitions can be deleted easily with command 

可以使用命令d轻松删除创建的分区

d
Delete Partition
Delete Partition
删除分区

If there is more than one partition the partition number is asked. In example above it is not asked because of there is only one partition.

如果有多个分区,则会询问分区号。 在上面的示例中,由于只有一个分区,因此未询问。

LEARN MORE  What is Master Boot Record or MBR?
了解更多什么是主引导记录或MBR?

分区信息 (Partition Information)

Detailed information about the partitions can be get in the interactive shell with command.

可以使用i命令在交互式外壳中获取有关分区的详细信息。

Partition Information
Partition Information
分区信息

列出未分区的磁盘空间(List Unpartitioned Disk Space)

Partitions provides segmentation of disks for different usage scenarios. Some partitions can be created later and for these partitions some free or unpartitioned space can be left. Unpartitioned space can be listed with command F.

分区为不同的使用情况提供了磁盘分段。 稍后可以创建某些分区,并且可以为这些分区保留一些可用或未分区的空间。 未分区的空间可以用命令F列出

F
List Unpartitioned Disk Space
List Unpartitioned Disk Space
列出未分区的磁盘空间

启用启动标志(Enable Boot Flag)

Partitions those contains operating systems like Windows, Linux, Unix should be flagged as bootable. Partitions can be made bootable with command a . Actually command will toggle boot able flag which means if current flag is not bootable it will change to boot able vice versa.

包含Windows,Linux,Unix等操作系统的分区应标记为可引导。 可以使用命令a使分区可引导。 实际上,命令a将切换可启动标志,这意味着如果当前标志不可启动,则将更改为可启动标志,反之亦然。

a
Enable Boot Flag
Enable Boot Flag
启用启动标志

验证分区表(Verify Partition Table)

Partition tables can be simply verified like below.

可以像下面这样简单地验证分区表。

v
Verify Partition Table
Verify Partition Table
验证分区表

退出/退出(Quit/Exit)

After completing operations to quit or exit from fdisk interactive shell command can be used. Do not forget to save changes if you need them.

完成退出fdisk或从fdisk退出的操作后,可以使用交互式shell q命令。 如果需要,请不要忘记保存更改。

q
Quit/Exit
Quit/Exit
退出/退出

带有示例信息图Linux fdisk教程(Linux fdisk Tutorial With Examples Infographic)

Linux fdisk Tutorial With Examples Infographic

翻译自: https://www.poftut.com/linux-fdisk-tutorial-with-examples/

linux fdisk

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值