There are different options to create or manage partitions under Oracle Linux – fdisk is one of them. This post describes its usage and the use case when creating a new partition table. fdisk is a menu-driven program for the creation and manipulation of partition tables. It understands GPT (experimental for now), MBR, Sun, SGI, and BSD partition tables.

Hard disks can be divided into one or more logical disks called partitions. This division is recorded in the partition table, found in sector 0 of the disk. (In the BSD world one talks about ‘disk slices’ and a ‘disklabel’.)

Linux needs at least one partition, namely for its root file system. It can use swap files and/or swap partitions, but the latter is more efficient. So, usually one will want a second Linux partition dedicated as a swap partition. On Intel-compatible hardware, the BIOS that boots the system can often only access the first 1024 cylinders of the disk. For this reason, people with large disks often create a third partition, just a few MB large, typically mounted on /boot, to store the kernel image and a few auxiliary files needed at boot time, so as to make sure that this stuff is accessible to the BIOS. There may be reasons of security, ease of administration and backup, or testing, to use more than the minimum number of partitions.

The basic fdisk commands needed are:

  • p print the partition table
  • n create a new partition
  • d delete a partition
  • q quit without saving changes
  • w write the new partition table and exit

Changes you make to the partition table do not take effect until you issue the write (w) command.

Further information can be found at the man pages:

Partitioning a disk with fdisk

1. Run fdisk against the desired device “/dev/device_name”.

# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table

Command (m for help):

2. Choose option “p” to print the partition table of the disk:

Command (m for help): p
Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

3. Choose option “n” to create a new partition:

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607): 4056
Partition 1 of type Linux and of size 1004.5 KiB is set

Note: To create another partition choose option “n” again.

Here is an exaple of creating another partition on the same disk:

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (4057-8388607, default 4096):
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-8388607, default 8388607):
Using default value 8388607
Partition 2 of type Linux and of size 4 GiB is set

4. Check the partition table with the option “p“:

Command (m for help): p
Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Device Boot Start End Blocks Id System
/dev/sdc1 2048 4056 1004+ 83 Linux
/dev/sdc2 4096 8388607 4192256 83 Linux

5. Choose the option “w” to write the new partition or partitions.

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

6. Run the command partprobe to inform the OS of partition table changes: