当前位置: 首页 > news >正文

What’s the Difference Between fdisk and parted

1. Overview

In this tutorial, we’ll discuss the difference between the fdisk and parted commands. We use these commands to manipulate storage devices. The fdisk andpartedcommands perform the same function, butpartedhas more options. First, we’ll look at each command separately, and then later, we’ll discuss their differences.

2. ThefdiskCommand

fdiskis a menu-guided program for creating and manipulating partition tables. It understands MS-DOS-type partition tables and BSD- or SUN-type disk labels.Initially,fdiskwasn’t designed for large partitions because it couldn’t accept GUID partition tables. But, the recent version supports GPT, though using MBR (for drives less than 2TB) is recommended.

GPT support is currently new and, therefore, it’s deemed an experimental phase. Further, the latest versions offdiskdeprecated the use of cylinders as the default display unit and MS-DOS compatibility by default.fdiskhas an interactive command-line menu that allows us to use letters to specify actions:

<span style="color:#000000"><span style="background-color:#ffffff"><code class="language-bash">$ sudo fdisk /dev/sda Welcome to fdisk (util-linux 2.37.2). Changes will remain <strong><span style="color:#a38be1 !important">in</span></strong> memory only, <strong><span style="color:#a38be1 !important">until</span></strong> you decide to write them. Be careful before using the write <span style="color:#a38be1 !important">command</span>. This disk is currently <strong><span style="color:#a38be1 !important">in</span></strong> use - repartitioning is probably a bad idea. It<span style="color:#a38be1 !important">'s recommended to umount all file systems, and swapoff all swap partitions on this disk. Command (m for help): m Help: GPT M enter protective/hybrid MBR Generic d delete a partition F list free unpartitioned space l list known partition types n add a new partition p print the partition table t change a partition type v verify the partition table i print information about a partition</span></code>Copy</span></span>

When usingfdisk, the sectors must be specified in absolute terms using sector numbers. If we’re creating a sector, the size must be set in absolute terms to specify the beginning of that sector. For instance, using 80M as the first sector of a disk indicates that the sector is 80 MiB from the beginning of the disk.

When we’re using the absolute position in sector numbers or as positions, the measuring unit (its size) should be in kibibytes (K), mebibytes (M), gibibytes (G), and tebibytes (T). Also, it’s possible to express relative terms by preceding the size with either a +size or a -size. For example, a +1G indicates a point 1 GiB after the start sector, while a -100M indicates a point 100 MiB before the last available sector.

fdiskperforms partition alignment automatically on the one-megabyte boundary if DOS compatibility mode has been disabled, making it compatible with various Advanced Format HDDs and SSDs. The default settings should give us accurate alignment.

3. ThepartedCommand

partedis an alternative command tofdisk. It’s a utility we use to manipulate disk partitions andhelps us to create space for new operating systems, reorganize disk usage, and copy data to new hard disks.partedcomes with better functionality thanfdisk, such as resizing (shrinking and extending partitions). In addition, it supports multiple partition table formats, including MS-DOS and GPT.

3.1. How to Useparted

We can install it by installing thepartedpackage.It has two modes: command-line and interactive. The interactive mode makes partitioning simple as it reduces unnecessary repetition by automatically applying all partitioning commands to the selected device.If we’re using the interactive mode, the prompt changes from a dollar sign ($) to (parted):

<span style="color:#000000"><span style="background-color:#ffffff"><code class="language-bash">$ sudo parted /dev/sda Using /dev/sda (parted) <span style="color:#a38be1 !important">print</span> Model: ATA VBOX HARDDISK (scsi) Disk /dev/sda: 26.8GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 540MB 538MB fat32 EFI System Partition boot, esp 3 540MB 26.8GB 26.3GB ext4 (parted)</code>Copy</span></span>

On the other hand, if we’re using the command-line mode, we run thepartedcommand together with the right options. If the command is successful, it doesn’t throw an error and the cursor moves to a new line. We must specify the partition/drive we want to run the command on:

<span style="color:#000000"><span style="background-color:#ffffff"><code class="language-bash">$ sudo parted /dev/sda <span style="color:#a38be1 !important">print</span> devices /dev/sda (26.8GB) $ sudo parted /dev/sda <span style="color:#a38be1 !important">print</span> free Model: ATA VBOX HARDDISK (scsi) Disk /dev/sda: 26.8GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 17.4kB 1049kB 1031kB Free Space 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 540MB 538MB fat32 EFI System Partition boot, esp 3 540MB 26.8GB 26.3GB ext4 4 26.8GB 26.8GB 512B primary 26.8GB 26.8GB 1031kB Free Space</code>Copy</span></span>

Let’s look at the syntax for creating a new partition:

<span style="color:#000000"><span style="background-color:#ffffff"><code class="language-bash">$ sudo parted mkpart part-type name fs-type start end</code>Copy</span></span>

Thepart-typerefers to theprimary, logical,orextended,and it’s only applicable if we use the MBR partition table. We replace thenameoption with a random partition name, and it’s mandatory for GPT partition tables. Thefs-typeparameter is optional. If we fill it, we replace it withfat16, fat32,xfs,ext2,ext3,ext4,Linux-swap,NTFS, orreiserfs.

To specify the beginning and end of a section, we replace the start and end options with the sizes that determine the starting and ending points of the partition, counting from the beginning of the disk. We can use express the sizes using size suffixes like MiB, GiB, or TiB. The default size is in megabytes. Also, if we don’t specify the size we want to partition, the default free space is used up.

Lastly, we must note thatthepartedcommand does not create the file system on the partition.

3.2. Creating a Partition Usingparted

Let’s create a partition of size 512B:

<span style="color:#000000"><span style="background-color:#ffffff"><code class="language-bash">$ sudo parted /dev/sda Using /dev/sda (parted) <span style="color:#a38be1 !important">print</span> free Model: ATA VBOX HARDDISK (scsi) Disk /dev/sda: 26.8GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 17.4kB 1049kB 1031kB Free Space 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 540MB 538MB fat32 EFI System Partition boot, esp 3 540MB 26.8GB 26.3GB ext4 26.8GB 26.8GB 1032kB Free Space (parted) mkpart primary ext4 26.8GB 26.8GB (parted) quit Information: You may need to update /etc/fstab. $ sudo parted -l /dev/sda Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 540MB 538MB fat32 EFI System Partition boot, esp 3 540MB 26.8GB 26.3GB ext4 4 26.8GB 26.8GB 512B primary</code>Copy</span></span>

If the hard drive is larger than 2 TB, it’s recommended that we usepartedto format it.

4. Differences BetweenfdiskandpartedCommands

Now, let’s have a look at the significant differences between these commands:

fdiskparted
When we runfdisk, the output is displayed using the partition type.Uses the file system to display partitions available in a storage device.
Performs partition alignment automatically on the one-megabyte boundary, but MS-DOS compatibility mode has to be disabled.When creating a partition, might warn about improper partition alignment but doesn’t alert when the alignment is proper, and it only aligns the partition start, not the size.
Doesn’t give us the option to shrink or extend the partition.We can extend a partition to utilize the unused disk space or shrink a partition to use its capacity for other purposes.
Only has an interactive mode in which we use letters to specify actions.Has both interactive and command-line modes. In both of these modes, we have to specify the right commands with the required options.

5. Conclusion

In this tutorial, we’ve looked at bothfdiskandpartedcommands. We’ve mentioned the modes each of these commands has and the kind of file systems they can support. The interactive mode should be the most preferred when usingpartedas it simplifies the process of creating partitions.

fdisksupports automatic alignment only if DOS is turned off whilepartedonly aligns the partition start.fdiskis present in most distros whilepartedis missing in some distributions and must be installed to be used. Lastly, we should be mindful when using eitherfdiskorpartedas misuse can result in the loss of important data.

http://www.jsqmd.com/news/424802/

相关文章:

  • 基于边缘计算的IoT设备分布式测试框架设计与实现
  • Disk Partitioning in Linux: fdisk, parted, and mkfs Guide
  • 项目管理工具软件
  • 云原生测试范式重构:性能与安全的融合挑战
  • ‌AI生成测试用例:基于LLM的需求歧义自动挖掘技术‌
  • AI测试必知:测试工程师如何选择大模型?
  • DoWhile循环
  • 测试脚本自愈系统:运行时异常的模式识别与动态修复
  • ROS2-通信机制2-01:分布式
  • P4564题解
  • 【开题答辩全过程】以 基于SSM的乡宁县星光影院电影购票微信小程序为例,包含答辩的问题和答案
  • 【开题答辩全过程】以 红色教育网站为例,包含答辩的问题和答案
  • Jenkins如何指定工作目录
  • 前端跨域问题详解
  • 基于GTID搭建MySQL主从使用xtrabackup工具
  • TRECVID 2004 Keyframes Transcripts数据集介绍,官网编号LDC2010V01
  • 摆脱论文困扰! 8个AI论文工具测评:本科生毕业论文+开题报告写作全攻略
  • PyTorch神经网络组件之Linear
  • 【开题答辩全过程】以 河北水利电力学院团委管理系统为例,包含答辩的问题和答案
  • TRECVID 2006 Keyframes数据集介绍,官网编号LDC2010V02
  • 2026冲刺用!倍受青睐的降AI率工具 —— 千笔·专业降AIGC智能体
  • 【开题答辩全过程】以 红色赣番门户网站开发为例,包含答辩的问题和答案
  • 打造C#联合Halcon的通用视觉框架2:开启流程化视觉开发之旅
  • 【开题答辩全过程】以 核酸检测预约系统为例,包含答辩的问题和答案
  • 2026年滑动管托厂家最新推荐,减少摩擦延长管道使用寿命 - 品牌鉴赏师
  • why a good language needs vision
  • 【开题答辩全过程】以 海钓服务系统为例,包含答辩的问题和答案
  • 基于卡尔曼滤波的目标轨迹预测与跟踪MATLAB仿真实现
  • While 循环
  • 基于STM32的电子秤PCB程序实现