How to create partition and format a Linux Disk as Ext4 from the Command Line

For the code, I’m just going to assume the drive is /dev/sdb. If you’re following this, make sure you’re using the correct drive name.

Unmount The Drive

Only needed if it’s been mounted already.

sync
umount /dev/sdb1

Prepare the Drive

Fire up fdisk

fdisk /dev/sdb

If you already have a filesystem on the disk, wipe it.

Press d

Now create a new primary partition.

Press n

Enter the partition type.

Press p (primary)

Enter the partition number.

Press 1

It’ll now ask you to set the start and end cylinders on the disk. Just hit return for each to accept the defaults.

Change the system type to Linux.

Press t
Enter 83

Write the changes to disk (this can’t be undone).

Press w

Create the Filesystem

Format the new partition using Ext4.

mkfs.ext4 /dev/sdb1

It’ll now go off and start writing the filesystem. This can take a bit of time, but it should give you an update on what’s being written.

Mount Your Drive

Now your partition has been created, you need to mount it somewhere to use it. Here I’m using /mnt/user/ext/.

mount /dev/sdb1 /mnt/user/ext/

  • 6 Users Found This Useful
Was this answer helpful?

Related Articles

Connecting using PuTTY on Windows workstations

Configuring PuTTY In PuTTY, under Session, enter your Host Name Under Connection choose Data...

How to install the php-mcrypt module on a Plesk server

Question How to install the php-mcrypt module on a Plesk server? Answer Notes: The solution in...

Windows: Accessing Your Server with Remote Desktop

This article explains how to use Remote Desktop to access your Windows server’s desktop from...

What is Reverse DNS?

Reverse DNS (rDNS) is name resolution that looks up an IP addresses to obtain a domain name,...

What is Reverse DNS?

Reverse DNS (rDNS) is name resolution that looks up an IP addresses to obtain a domain name,...