mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
PRF:20190128 fdisk - Easy Way To Manage Disk Partitions In Linux.md
@zhs852
This commit is contained in:
parent
ae5a36ec52
commit
f52e22c9f8
@ -1,49 +1,49 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zhs852)
|
||||
[#]: reviewer: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (fdisk – Easy Way To Manage Disk Partitions In Linux)
|
||||
[#]: via: (https://www.2daygeek.com/linux-fdisk-command-to-manage-disk-partitions/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
fdisk – Linux 下管理磁盘分区的利器
|
||||
fdisk:Linux 下管理磁盘分区的利器
|
||||
======
|
||||
|
||||
一块硬盘可以被划分成一个或多个逻辑磁盘,我们将其称作分区。我们对硬盘进行的划分信息被储存于建立在扇区 0 的分区表(MBR 或 GPT)中。
|
||||
|
||||
Linux 需要至少一个分区来当作 root 文件系统,所以我们不能在没有分区的情况下安装 Linux 系统。当我们创建一个分区时,我们必须将它格式化为一个适合的文件系统,否则我们就没办法往里面储存文件了。
|
||||
Linux 需要至少一个分区来当作根文件系统,所以我们不能在没有分区的情况下安装 Linux 系统。当我们创建一个分区时,我们必须将它格式化为一个适合的文件系统,否则我们就没办法往里面储存文件了。
|
||||
|
||||
要在 Linux 中完成分区的相关工作,我们需要一些工具。Linux 下有很多可用的相关工具,我们曾介绍过 **[Parted 命令][1]**。不过,今天我们的主角是 fdisk。
|
||||
要在 Linux 中完成分区的相关工作,我们需要一些工具。Linux 下有很多可用的相关工具,我们曾介绍过 [Parted 命令][1]。不过,今天我们的主角是 `fdisk`。
|
||||
|
||||
人人都喜欢用 fdisk,它是 Linux 下管理磁盘分区的最佳利器之一。它可以操作最大 `2TB` 的分区。大量 Linux 管理员都喜欢使用这个工具,因为当下 LVM 和 SAN 的原因,并没有多少人会用到 2TB 以上的分区。并且这个工具被世界上许多的基础设施所使用。如果你还是想创建比 2TB 更大的分区,请使用 **Parted 命令** 或 **cfdisk 命令**。
|
||||
人人都喜欢用 `fdisk`,它是 Linux 下管理磁盘分区的最佳利器之一。它可以操作最大 2TB 的分区。大量 Linux 管理员都喜欢使用这个工具,因为当下 LVM 和 SAN 的原因,并没有多少人会用到 2TB 以上的分区。并且这个工具被世界上许多的基础设施所使用。如果你还是想创建比 2TB 更大的分区,请使用 `parted` 命令 或 `cfdisk` 命令。
|
||||
|
||||
对磁盘进行分区和创建文件系统是 Linux 管理员的日常。如果你在许多不同的环境中工作,你一定每天都会重复几次这项操作。
|
||||
|
||||
### Linux 内核是如何理解硬盘的?
|
||||
|
||||
作为人类,我们可以很轻松地理解一些事情;但是电脑就不是这样了,它们需要合适的命名交流才能理解事情。
|
||||
作为人类,我们可以很轻松地理解一些事情;但是电脑就不是这样了,它们需要合适的命名才能理解这些。
|
||||
|
||||
在 Linux 中,外围设备都位于 `/dev` 挂载点,内核以一下的方式理解硬盘:
|
||||
在 Linux 中,外围设备都位于 `/dev` 挂载点,内核通过以下的方式理解硬盘:
|
||||
|
||||
* **`/dev/hdX[a-z]:`** IDE 硬盘被命名为 hdX
|
||||
* **`/dev/sdX[a-z]:`** SCSI 硬盘被命名为 sdX
|
||||
* **`/dev/xdX[a-z]:`** XT 硬盘被命名为 xdX
|
||||
* **`/dev/vdX[a-z]:`** 虚拟硬盘被命名为 vdX
|
||||
* **`/dev/fdN:`** 软盘被命名为 fdN
|
||||
* **`/dev/scdN or /dev/srN:`** CD-ROM 被命名为 /dev/scdN 或 /dev/srN
|
||||
* `/dev/hdX[a-z]:` IDE 硬盘被命名为 hdX
|
||||
* `/dev/sdX[a-z]:` SCSI 硬盘被命名为 sdX
|
||||
* `/dev/xdX[a-z]:` XT 硬盘被命名为 xdX
|
||||
* `/dev/vdX[a-z]:` 虚拟硬盘被命名为 vdX
|
||||
* `/dev/fdN:` 软盘被命名为 fdN
|
||||
* `/dev/scdN or /dev/srN:` CD-ROM 被命名为 `/dev/scdN` 或 `/dev/srN`
|
||||
|
||||
### 什么是 fdisk 命令?
|
||||
|
||||
fdisk 的意思是 <ruby>固定的磁盘<rt>Fixed Disk</rt></ruby> 或 <ruby>格式化磁盘<rt>Format Disk</rt></ruby>,它是命令行下允许用户对分区进行查看、创建、调整大小、删除、移动和复制的工具。它支持 MBR、Sun、SGI、BSD 分区表,但是它不支持 GUID 分区表(GPT)。它不是为操作大分区设计的。
|
||||
`fdisk` 的意思是 <ruby>固定磁盘<rt>Fixed Disk</rt></ruby> 或 <ruby>格式化磁盘<rt>Format Disk</rt></ruby>,它是命令行下允许用户对分区进行查看、创建、调整大小、删除、移动和复制的工具。它支持 MBR、Sun、SGI、BSD 分区表,但是它不支持 GUID 分区表(GPT)。它不是为操作大分区设计的。
|
||||
|
||||
fdisk 允许我们在每块硬盘上创建最多四个主分区。它们中的其中一个可以作为扩展分区,并下设多个逻辑分区。1-4 扇区作为主分区被保留,逻辑分区从扇区 5 开始。
|
||||
`fdisk` 允许我们在每块硬盘上创建最多四个主分区。它们中的其中一个可以作为扩展分区,并下设多个逻辑分区。1-4 扇区作为主分区被保留,逻辑分区从扇区 5 开始。
|
||||
|
||||
![磁盘分区结构图][3]
|
||||
|
||||
### 如何在 Linux 下安装 fdisk?
|
||||
|
||||
fdisk 作为核心组件内置于 Linux 中,所以你不必手动安装它。
|
||||
`fdisk` 作为核心组件内置于 Linux 中,所以你不必手动安装它。
|
||||
|
||||
### 如何用 fdisk 列出可用磁盘?
|
||||
|
||||
@ -52,36 +52,36 @@ fdisk 作为核心组件内置于 Linux 中,所以你不必手动安装它。
|
||||
```shell
|
||||
$ sudo fdisk -l
|
||||
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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: 0xeab59449
|
||||
|
||||
Device Boot Start End Sectors Size Id Type
|
||||
/dev/sda1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 20973568 62914559 41940992 20G 83 Linux
|
||||
/dev/sda1 * 20973568 62914559 41940992 20G 83 Linux
|
||||
|
||||
|
||||
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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 /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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 /dev/sdd: 10 GiB, 10737418240 bytes, 20971520 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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 /dev/sde: 10 GiB, 10737418240 bytes, 20971520 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
Units: sectors of 1 * 512 = 512 bytes
|
||||
Sector size (logical/physical): 512 bytes / 512 bytes
|
||||
I/O size (minimum/optimal): 512 bytes / 512 bytes
|
||||
```
|
||||
@ -93,19 +93,19 @@ I/O size (minimum/optimal): 512 bytes / 512 bytes
|
||||
```shell
|
||||
$ sudo fdisk -l /dev/sda
|
||||
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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: 0xeab59449
|
||||
|
||||
Device Boot Start End Sectors Size Id Type
|
||||
/dev/sda1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 20973568 62914559 41940992 20G 83 Linux
|
||||
/dev/sda1 * 20973568 62914559 41940992 20G 83 Linux
|
||||
```
|
||||
|
||||
### 如何列出 fdisk 所有的可用操作?
|
||||
|
||||
在 fdisk 中敲击 `m`,它便会列出所有可用操作:
|
||||
在 `fdisk` 中敲击 `m`,它便会列出所有可用操作:
|
||||
|
||||
```shell
|
||||
$ sudo fdisk /dev/sdc
|
||||
@ -158,7 +158,7 @@ Help:
|
||||
|
||||
### 如何使用 fdisk 列出分区类型?
|
||||
|
||||
在 fdisk 中敲击 `l`,它便会列出所有可用分区的类型:
|
||||
在 `fdisk` 中敲击 `l`,它便会列出所有可用分区的类型:
|
||||
|
||||
```shell
|
||||
$ sudo fdisk /dev/sdc
|
||||
@ -202,7 +202,7 @@ Command (m for help): l
|
||||
|
||||
如果你希望新建磁盘分区,请参考下面的步骤。比如我希望在 `/dev/sdc` 中新建四个分区(三个主分区和一个扩展分区),只需要执行下文的命令。
|
||||
|
||||
首先,请在操作 “First sector” 的时候先按下 `Enter`,然后在 “Last sector” 中输入你希望创建分区的大小(可以在数字后面加 KB、MB、G 和 TB)。例如,你希望为这个分区扩容 1GB,就应该在 “Last sector” 中输入 `+1G`。当你创建三个分区之后,fdisk 默认会将分区类型设为扩展分区,如果你希望创建第四个主分区,请输入 `p` 来替代它的默认值 `e`。
|
||||
首先,请在操作 “First sector” 的时候先按下回车,然后在 “Last sector” 中输入你希望创建分区的大小(可以在数字后面加 KB、MB、G 和 TB)。例如,你希望为这个分区扩容 1GB,就应该在 “Last sector” 中输入 `+1G`。当你创建三个分区之后,`fdisk` 默认会将分区类型设为扩展分区,如果你希望创建第四个主分区,请输入 `p` 来替代它的默认值 `e`。
|
||||
|
||||
```shell
|
||||
$ sudo fdisk /dev/sdc
|
||||
@ -227,7 +227,7 @@ Created a new partition 1 of type 'Linux' and of size 1 GiB.
|
||||
|
||||
Command (m for help): p
|
||||
Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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
|
||||
@ -269,7 +269,7 @@ Created a new partition 4 of type 'Extended' and of size 7 GiB.
|
||||
|
||||
Command (m for help): p
|
||||
Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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
|
||||
@ -303,7 +303,7 @@ Be careful before using the write command.
|
||||
|
||||
Command (m for help): F
|
||||
Unpartitioned space /dev/sdc: 7 GiB, 7515144192 bytes, 14678016 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
Units: sectors of 1 * 512 = 512 bytes
|
||||
Sector size (logical/physical): 512 bytes / 512 bytes
|
||||
|
||||
Start End Sectors Size
|
||||
@ -333,7 +333,7 @@ Created a new partition 5 of type 'Linux' and of size 1 GiB.
|
||||
|
||||
Command (m for help): p
|
||||
Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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
|
||||
@ -373,7 +373,7 @@ Partition 2 has been deleted.
|
||||
|
||||
Command (m for help): p
|
||||
Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
|
||||
Units: sectors of 1 core.md Dict.md lctt2014.md lctt2016.md lctt2018.md LICENSE published README.md scripts sources translated 512 = 512 bytes
|
||||
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
|
||||
@ -399,9 +399,9 @@ Syncing disks.
|
||||
|
||||
```shell
|
||||
$ sudo mkfs.ext4 /dev/sdc1
|
||||
or
|
||||
或
|
||||
$ sudo mkfs -t ext4 /dev/sdc1
|
||||
or
|
||||
或
|
||||
$ sudo mke2fs /dev/sdc1
|
||||
|
||||
mke2fs 1.43.5 (04-Aug-2017)
|
||||
@ -418,16 +418,14 @@ Writing superblocks and filesystem accounting information: done
|
||||
|
||||
当你在分区上建立文件系统时,以下重要信息会同时被创建:
|
||||
|
||||
* **`Filesystem UUID:`** UUID 代表了通用且独一无二的识别符,UUID 在 Linux 中通常用来识别设备。它 128 位长的数字代表了 32 个十六进制数。
|
||||
* **`Superblock:`** Superblock 储存了文件系统的元数据。如果某个文件系统的 Superblock 被破坏,我们就无法挂载它了(也就是说无法访问其中的文件了)。
|
||||
* **`Inode:`** Inode 是类 Unix 系统中文件系统的数据结构,它储存了所有除名称以外的文件信息和数据。
|
||||
* **`Journal:`** 日志式文件系统包含了用来修复电脑意外关机产生下错误信息的日志(Journal)。
|
||||
|
||||
|
||||
* `Filesystem UUID:` UUID 代表了通用且独一无二的识别符,UUID 在 Linux 中通常用来识别设备。它 128 位长的数字代表了 32 个十六进制数。
|
||||
* `Superblock:` 超级块储存了文件系统的元数据。如果某个文件系统的超级块被破坏,我们就无法挂载它了(也就是说无法访问其中的文件了)。
|
||||
* `Inode:` Inode 是类 Unix 系统中文件系统的数据结构,它储存了所有除名称以外的文件信息和数据。
|
||||
* `Journal:` 日志式文件系统包含了用来修复电脑意外关机产生下错误信息的日志。
|
||||
|
||||
### 如何在 Linux 中挂载分区?
|
||||
|
||||
在你创建完分区和文件系统之后,我们需要挂载它们以便使用。我们需要创建一个挂载点来挂载分区,使用 mkdir 来创建一个挂载点。
|
||||
在你创建完分区和文件系统之后,我们需要挂载它们以便使用。我们需要创建一个挂载点来挂载分区,使用 `mkdir` 来创建一个挂载点。
|
||||
|
||||
```shell
|
||||
$ sudo mkdir -p /mnt/2g-new
|
||||
@ -439,7 +437,7 @@ $ sudo mkdir -p /mnt/2g-new
|
||||
$ sudo mount /dev/sdc1 /mnt/2g-new
|
||||
```
|
||||
|
||||
如果你希望永久挂载某个分区,请将分区详情加入 fstab 文件。我们既可以输入设备名称,也可以输入 UUID。
|
||||
如果你希望永久挂载某个分区,请将分区详情加入 `fstab` 文件。我们既可以输入设备名称,也可以输入 UUID。
|
||||
|
||||
使用设备名称来进行永久挂载:
|
||||
|
||||
@ -449,8 +447,7 @@ $ sudo mount /dev/sdc1 /mnt/2g-new
|
||||
/dev/sdc1 /mnt/2g-new ext4 defaults 0 0
|
||||
```
|
||||
|
||||
Permanent mount using UUID Value. To get a UUID of the partition use blkid command.
|
||||
使用 UUID 来进行永久挂载(请使用 blkid 来获取 UUID):
|
||||
使用 UUID 来进行永久挂载(请使用 `blkid` 来获取 UUID):
|
||||
|
||||
```
|
||||
$ sudo blkid
|
||||
@ -464,7 +461,7 @@ $ sudo blkid
|
||||
UUID=d17e3c31-e2c9-4f11-809c-94a549bc43b7 /mnt/2g-new ext4 defaults 0 0
|
||||
```
|
||||
|
||||
使用 df 命令亦可:
|
||||
使用 `df` 命令亦可:
|
||||
|
||||
```
|
||||
$ df -h
|
||||
@ -487,7 +484,7 @@ via: https://www.2daygeek.com/linux-fdisk-command-to-manage-disk-partitions/
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhs852](https://github.com/zhs852)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user