Home > System Tutorial > LINUX > body text

Detailed explanation of Linux hard disk partition fdisk and parted commands

WBOY
Release: 2024-02-09 16:36:27
forward
548 people have browsed it

In Linux systems, there are two main partition commands available: fdisk and parted. The fdisk command is widely used, but one limitation is that it does not support partitions larger than 2TB. If you need to create a partition larger than 2TB, then you need to use the parted command. Of course, the parted command can also be used to create smaller partitions. Now, let us take a look at how to use the fdisk command to partition.

The traditional MBR (Master Boot Record) partitioning method limits a hard disk to be divided into up to four primary partitions. Even if the hard disk still has unallocated space, you cannot continue to create more primary partitions.

Linux硬盘分区 fdisk 和 parted命令详解

If you need more partitions, you need to create logical partitions in the extended partition. The solution is as follows

Linux硬盘分区 fdisk 和 parted命令详解

fdisk command

View new disk information

[root@localhost ~]# fdisk ~l
#列出系统分区
[root@localhost ~]# fdisk 设备文件名
#给硬盘分区
Copy after login
Linux硬盘分区 fdisk 和 parted命令详解

Note: Never try to use fdisk on the current hard disk. This will completely delete the entire system. Be sure to find another hard disk or use a virtual machine.

The lower part of the information is the partition information, with a total of 7 columns, the meaning is as follows:

  • Device: The device file name of the partition.
  • Boot: Whether it is the boot partition. Here /dev/sda1 is the boot partition.
  • Start: Starting cylinder, representing where the partition starts.
  • End: Terminating cylinder, representing where the partition ends.
  • Blocks: The size of the partition, in KB.
  • id: ID of the file system in the partition. In the fdisk command, you can use "i" to view.
  • System: What is the system installed in the partition.

Partition Command

[root@localhost omc]# fdisk/dev/sda2
Copy after login
Linux硬盘分区 fdisk 和 parted命令详解

Enter p to list the current partition status of the disk

Linux硬盘分区 fdisk 和 parted命令详解

Enter n to create a new disk partition. First create two primary disk partitions:

Linux硬盘分区 fdisk 和 parted命令详解Linux硬盘分区 fdisk 和 parted命令详解Linux硬盘分区 fdisk 和 parted命令详解

Linux硬盘分区 fdisk 和 parted命令详解Linux硬盘分区 fdisk 和 parted命令详解Linux硬盘分区 fdisk 和 parted命令详解

fdisk interactive command is as follows:

Linux硬盘分区 fdisk 和 parted命令详解

parted command

The partprobe command tells the kernel to read the new partition table immediately, so that the newly created partition can be recognized without restarting the system.

The parted partitioning tool belongs to the GPT partitioning method. It is different from the traditional MBR partitioning method. It is limited to a maximum of 4 primary partitions. GPT partitioning provides redundancy of the partition table to achieve backup and security of the partition table.

Command format

[root@localhost omc]# parted 【选项】 【硬盘 【命令】】
Copy after login

1. View system partition table information

[root@localhost omc]# parted /dev/sdc print
Copy after login
Linux硬盘分区 fdisk 和 parted命令详解

2. Create partition

[root@localhost omc]# parted 【硬盘】 mkpart 分区类型 文件系统类型 开始 结束
Copy after login

其中,mkpart指令为创建新的分区,分区类型有:primary,logical,extended三种,文件系统类型有:fat16,fat32,ext2,ext3,linux-swap等,开始与结束标记区分开始与结束的位置(默认单位为MB)

示例

[root@localhost omc]# parted /dev/sdc mkpart primary ext3 1 2G
Copy after login

ext3的主分区,从磁盘的第1MB开始分区,到2GB的位置,大小为2GB的主分区

[root@localhost omc]# parted /dev/sdc mkpart primary ext3 2G 4G创建
Copy after login

创建一个容量为2GB的分区,从硬盘的第2个GB位置开始分区,到第4个GB的位置结束。

3、修改分区表格式

[root@localhost omc]# parted /dev/sdc mklabel gpt
Copy after login
Linux硬盘分区 fdisk 和 parted命令详解

4、删除分区

[root@localhost omc]# parted /dev/sdc rm2使用
Copy after login

rm指令可以删除分区

利用pared命令除了基本的分区创建和删除外,还可以进行分区检查,调整分区大小,还原误删除分区等操作。

The above is the detailed content of Detailed explanation of Linux hard disk partition fdisk and parted commands. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template