Why does parted need a filesystem type when creating a partition, and how does its action differ from a utility like mkfs.ext4?

5,480

A partition can have a type. The partition type is a hint as in "this partition is designated to serve a certain function". Many partition types are associated with certain file-systems, though the association is not always strict or unambiguous. You can expect a partition of type 0x07 to have a Microsoft compatible file-system (e.g. FAT, NTFS or exFAT) and 0x83 to have a native Linux file-system (e.g. ext2/3/4).

The creation of the file-system is indeed a completely independent and orthogonal step (you can put whatever file-system wherever you want – just do not expect things to work out of the box).

parted defines the partition as in "a part of the overall disk". It does not actually need to know the partition type (the parameter is optional). In use however, auto-detection of the file-system and henceforth auto-mounting may not work properly if the partition type does not correctly hint to the file-system.

A partition is a strictly linear piece of storage space. The mkfs.ext4 and its variants create file-systems so you can have your actual directory tree where you can conveniently store your named files in.

Share:
5,480

Related videos on Youtube

David M
Author by

David M

Updated on September 18, 2022

Comments

  • David M
    David M over 1 year

    I am partitioning a disk with the intent to have an ext4 filesystem on the partition. I am following a tutorial, which indicates that there are two separate steps where the ext4 filesystem needs to be specified. The first is by parted when creating the partition:

    sudo parted -a opt /dev/sda mkpart primary ext4 0% 100%

    The second is by the mkfs.ext4 utility, which creates the filesystem itself:

    sudo mkfs.ext4 -L datapartition /dev/sda1

    My question is: what exactly are each of these tools doing? Why is ext4 required when creating the partition? I would have thought the defining of the partition itself was somewhat independent of the constituent file system.

    (The tutorial I'm following is here: https://www.digitalocean.com/community/tutorials/how-to-partition-and-format-storage-devices-in-linux)

  • Hermann
    Hermann over 4 years
    Yes, that is specifically the point. Back in the day, most file-systems were proprietary and not documented. Not knowing what to look for, you could not tell whether a partition was unused (and filled with random left-over data) or holding a file-system you did not happen to know. Also, partitions can hold data even without a file-system. Popular examples are the Linux swap space (memory extension) or a "BIOS boot partition" (can hold a boot-loader).
  • davolfman
    davolfman over 4 years
    A good example of a partition type being different from a file system is the EFI System Partion which UEFI systems read bootloaders from instead of the MBR. While formatted with FAT 16 or FAT 32, the partition type is a special type for EFI on both MBR and GPT partition tables.
  • Garo
    Garo over 4 years
    I tried to explain what the partitiontype is used for, what the filesystemtype is used for and what the difference is in my comment. But for the full info see en.wikipedia.org/wiki/Partition_type and en.wikipedia.org/wiki/File_system
  • JdeBP
    JdeBP over 4 years
    For another approach, see jdebp.uk./FGA/determining-filesystem-type.html , which makes the same point.