What command would you use to create an ext4 filesystem?

Below the instructions to create a new ext4 partition on a new hard drive with

sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
5 (tested on Ubuntu 14.04.4 LTS x64).
sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
5 supports GUID Partition Table (GPT) and subsequently can be used for partitions above 2TB, unlike
sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
8.

Use

sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
9 to see the logical name of your new hard drive:

   description: ATA Disk
   product: ST6000NM0024-1HT
   vendor: Seagate
   physical id: 0.0.0
   bus info: scsi@1:0.0.0
   logical name: /dev/sdb
   version: SN05
   serial: Z4D30T30
   size: 5589GiB (6001GB)
   configuration: ansiversion=5 sectorsize=4096

The logical name is

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
0. We can get started:

sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)

With

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
1, we can see the GPT got created:

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

We also need to know the size of the disk (we will use MB as the unit):

sudo parted /dev/sdb print unit MB print free

which indicates:

Disk /dev/sdb: 6001175MB

We can now create the primary partition so that it takes the entire hard drive space. To set the partition label:

sudo parted --align optimal /dev/sdb mkpart primary ext4 0% 6001175MB 

(see https://unix.stackexchange.com/a/49274/16704 if you want to know why we use

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
2)

With

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
1, we can see the primary partition label got created:

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  6001GB  6001GB  xfs          primary

We then need to use mkfs to actually create the partition:

sudo mkfs.ext4 /dev/sdb1

The partition is now created, we need to mount it. To do so,

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
4 and add the following line (
username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
5 is the folder in which we choose to mount the new partition):

/dev/sdb1       /crimea ext4 defaults   0       0      

We create the folder and reload

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
6:

sudo mkdir /crimea
sudo mount -a # Remount /etc/fstab without rebooting in Linux

You can see the new mounted partition using

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
7:

sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
0

In

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
4, instead of using
username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
9 you could use its
sudo parted /dev/sdb print unit MB print free
0, which you can find with
sudo parted /dev/sdb print unit MB print free
1:

sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
1

Otherwise you could simply do

sudo parted /dev/sdb print unit MB print free
2:

sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
2

The new line

username@server:~$ sudo parted /dev/sdb print
Model: ATA ST6000NM0024-1HT (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags
6 will be:

sudo parted /dev/sdb mklabel gpt # Creating the GUID Partition Table (GPT)
3

https://unix.stackexchange.com/a/137868/16704 explains why it's best to use UUID (liquidat, cc by-sa 3.0):

The advantage of using the UUID is that it is independent from the actual device number the operating system gives your hard disk. Image you add another hard disk to the system, and for some reason the OS decides that your old disk is now

sudo parted /dev/sdb print unit MB print free
4 instead of
sudo parted /dev/sdb print unit MB print free
5. Your boot process would be screwed up if fstab would point to the device name. However, in case of the UUIDs, it would be fine.

What is the command to make a filesystem?

The newfs command is a friendlier version of the mkfs command that is used to create file systems.

What is ext4 file system in Linux?

The ext4 file system is a scalable extension of the ext3 file system, which was the default file system of Red Hat Enterprise Linux 5. Ext4 is the default file system of Red Hat Enterprise Linux 6, and can support files and file systems up to 16 terabytes in size.

How to create a Linux file system?

To create a filesystem, there are three steps:.
Create partitions using fdisk or Disk Utility. ... .
Format the partitions using mkfs or Disk Utility..
Mount the partitions using the mount command or automate it using the /etc/fstab file..

How to mount ext4 filesystem in Linux?

Give the new disk a label using the mklabel command. Now create a partition using the mkpart command, give it additional parameters like “primary” or “logical” depending on the partition type that you wish to create. Now select ext4 as the file system type. Set the start and end to establish the size of the partition.