FreeKB - Linux Commands fdisk (format disk partition)
Linux Commands - fdisk (format disk partition)

Formatting a storage device typically involves the following steps. This article includes the directions for steps 1 and 2.

  1. Create one or more partitions
  2. Assign a type to the partition
  3. Format each partition to use a certain type of file system

The fdisk command partitions a drive as MBR (master boot record). The gdisk command partitions a drive as GPT (GUID partition table). The parted command can partition a drive as either MBR or GPT. MBR is typically needed for systems with old hardware or software, because GPT is not backwards compatible with old hardware or software. gdisk or parted can be used if the system is using modern hardware and software. GPT is typically used if you need a create a partition greater than 2 TB.


To create a new partition

Type fdisk /dev/xxx and press enter, where xxx is a device, such as /dev/sda or /dev/sdb.

[root@server1 ~]# fdisk /dev/sdb


Type n and press enter to create a new partition.

Command (m for help): n


If you will have 1 - 4 partitions, each partition can be a primary partition. If you wil have 5 or more partition, partitions 1 - 3 can be primary, partition 4 must be extended, and then partitons 5 and above will be logical.

Select (default p): p


Select the partition number, where 1 is /dev/xxx1, 2 is /dev/xxx2, et cetera.

Partition number (2-4, default 2): 2


When prompted First sector, press enter to use the default first sector.

First sector (1234567-3456789, default 1234567):


When prompted Last sector, enter the size of the partition (such as +1GB or +512MB).

Last sector (1234567-3456789, default 1234567): +1GB


Type t and press enter to set the partition type.

Command (m for help): t


Type L to view all of the available codes. Type the code for the type you wish to use and press enter. For example, type 83 for Linux, 8e for Linux LVM (Logical Volume Group), or fd for Linux RAID auto.

Hex code (type L to list all codes): 83


Type w and press enter to write the changes.

Command (m for help): w


Use the partprobe command to update the system to recongize the new partition.

~]# partprobe


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter bdd53 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |