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)

2 Answers 2


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.

  • This is exactly what I was looking for, thanks. Can you expand on what the partition type is used for? Is it just something that lets other software/OSes know what type of partition to expect without having to check the partition specifically?
    – David M
    Commented Nov 7, 2019 at 23:38
  • 1
    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).
    – Hermann
    Commented Nov 7, 2019 at 23:49
  • 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.
    – davolfman
    Commented Nov 8, 2019 at 0:08
  • 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
    – Garo
    Commented Nov 8, 2019 at 0:10
  • For another approach, see jdebp.uk./FGA/determining-filesystem-type.html , which makes the same point.
    – JdeBP
    Commented Nov 14, 2019 at 19:19

mkfs.something creates a filesystem on a already existing partition. In your case it:

  • looks for the first partition of the drive /dev/sda
  • creates a new filesystem on it of the filesystemtype ext4
  • gives it the label datapartition

But: None of this this will work if

  • the partition does not exist
  • it does exist but the partitiontype is set to a type that can't be used for the filesystemtype ext4. A partitiontype 'tells' the system what kind of filesystem(types) you can use on the partition. Setting a partitiontype does not create a filesystem, it only tells that the some filesystemtypes are possible. For example partitiontype 0x83 is meant for the filesystemtypes ext2, ext3, ext4, btrfs, ... but not for fat, ntfs, ...

The reason that you run parted first is because you want do the work that wasn't done by mkfs.ext4. In your case it creates a partition on /dev/sdaand sets the type to something that supports ext4. Now you have everything needed to run mkfs.ext4

You might notice that parted had a lot of options. In your case these options tell parted to make sure that the partitiontable is set for a optimal layout on the disk, that the partition should fill the entire disk and that it should be a primary instead of a logical partition. The reasons for these choices are for a completely different question. It's perfectly fine to make other choices, but the choices made are really 'sane' options for many usecases

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .