Skip to main content

Partitioning

====================================================================================

What is a partition?

Partitions allow you to divide a single physical disk into multiple, isolated sections. Each partition can be managed independently

Partition types in Linux

MBR- Master Boot Record

The Master Boot Record (MBR) is a special type of boot sector at the very beginning of a disk. The MBR contains important information about the disk's partitions and the filesystem, as well as executable code necessary to boot an operating system. MBR permits for up to 4 partitions on a storage device and also has limitations in the size of disks it can partition, as well as the size of partitions that can be created.

TLDR; MBR can partition a drive into 4 partitions. Not ideal for large drives. Old standard that's being phased out in favour of GPT.

GPT - GUID Partition Table

The GUID Partition Table (GPT) is a modern standard for the layout of partition tables on a physical storage device. GPT is part of the Unified Extensible Firmware Interface (UEFI) standard, which is designed to replace the older BIOS firmware interface used by PCs.

 

Benefits of GPT include: 

Larger Disk and Partition Support - GPT allows for a virtually unlimited number of partitions. GPT can support disks larger than 2 terabytes (TB), up to 9.4 zettabytes (ZB).

Redundancy - GPT stores a primary partition table at the beginning of the disk and a backup partition table at the end of the disk.

TLDR; GPT is more modern, handles larger disks & partitions, and also has redundancy features.

------------------------------------------------------------------------------------------------------------------------------------------------

Configuration & management of partitions

------------------------------------------------------------------------------------------------------------------------------------------------

fdisk 

fdisk (format disk) is a command-line utility that can be used for making changes to MBR disk partitions. 

fdisk is primarily designed for use with MBR partitioned disks. Check the disk partitioning your disk is using before making changes (fdisk -l /dev/devicename). If your disk is GPT, see here

View current partitions and partitioning standard:

fdisk -l /dev/devicename

To enter into the fdisk utility to manage partitions:

fdisk /dev/devicename 

We then have the following options available:

n - Create a new partition:

Example;

Let's say we have a single drive, and want to create a 10GB partition. This is aan GPTMBR drive.

Firstly, enter into the fdisk utility:
fdiskdisk /dev/diskname

We'reFrom then entered intothere, the fdiskfollowing mini-cli.options can be used to add a new partition with a size of 10GB.

Command (m for help): n
Partition type:
    p   primary
    e   extended
Select (default p): p
Partition number (4-128, default 4): #left at default value
First sector (34-16777182, default 16775168): #left at default value (typically)
Last sector, +/-sectors or +/-size{K,M,G,T,P} (16775168-16777182, default 16777182):  +10G

NOTE: Whenfdisk addingshouldn't partitions on an MBR disk, you'llreally be asked whether you want the disk to be primary or extended. The use caseused for apartitioning similarGPT example to this would be primary.drives.
NOTE: Leaving the last sector blank will automatically cause the remainder of space on the drive to be allocated.

d - Delete a partition

i- print current boot record:

------------------------------------------------------------------------------------------------------------------------------------------------

gdisk

gdisk is the GPT equivalent of fdisk, meaning that it's designed specifically for partitioning disks using the GPT formatting.

fdiskgdisk is primarily designed for use with MBRGPT partitioned disks. Check the disk partitioning your disk is using before making changes (fdisk -l /dev/devicename). If your disk is MBR, see here

View current partitions and partitioning standard:

gdisk -l /dev/devicename

To enter into the gdisk utility to manage partitions:

gdisk /dev/devicename

We then have the following options available:

n - Create a new partition:

d - Delete a partition

i- print current boot record: