Using fdisk to Create a Partition Table in Linux
Difference Between GPT and DOS Partition Tables
GPT (GUID Partition Table):- Supports disks larger than 2 TB.
- Allows for an almost unlimited number of partitions.
- Stores multiple copies of the partition table for redundancy.
- Uses CRC32 checksums for integrity verification
- Limited to 2 TB disk size.
- Supports up to 4 primary partitions (or 3 primary and 1 extended partition).
- No built-in redundancy or integrity checks.
Advantages of GPT Over DOS
- Supports Larger Disks: GPT can handle disks larger than 2 TB, whereas DOS is limited to 2 TB
- More Partitions: GPT allows for a virtually unlimited number of partitions, compared to DOS's limit of 4 primary partitions
- Redundancy: GPT stores multiple copies of the partition table, enhancing data recovery in case of corruption
- Integrity: GPT uses CRC32 checksums to ensure the integrity of the partition table
Creating Partitions with fdisk
Example 1: Single Partition on /dev/sdb
- Open fdisk for the device:
Code:sudo fdisk /dev/sdb
- Create a new partition table (GPT):
Code:g
- Create a new partition:
Code:n
- Write changes and exit:
Code:w
Example 2: Three Partitions on /dev/nvme0n1
- Open fdisk for the device:
Code:sudo fdisk /dev/nvme0n1
- Create a new partition table (GPT):
Code:g
- Create the first partition (50GB):
Code:n
- When prompted for the first sector, press Enter to accept the default.
- When prompted for the last sector, type +50G and press Enter.
- Create the second partition (100GB):
Code:n
- When prompted for the first sector, press Enter to accept the default.
- When prompted for the last sector, type +100G and press Enter.
- Create the third partition (rest of the disk):
Code:n
- When prompted for the first sector, press Enter to accept the default.
- When prompted for the last sector, press Enter to use the remaining space.
- Write changes and exit:
Code:w
Example 3: USB Thumb Drive on /dev/sdc
- Open fdisk for the device:
Code:sudo fdisk /dev/sdc
- Create a new partition table (GPT):
Code:g
- Create a new partition:
Code:n
- Write changes and exit:
Code:w
Partition Types
- Linux Filesystem: 83
- Linux Swap: 82
- EFI System: EF
- Microsoft Data: 07
- Linux Root: 8304
- Linux Data: 8300
Formatting Partitions
Single Partition Example
- Format the partition as ext4:
Code:
sudo mkfs.ext4 /dev/sdb1
Three Partitions Example
- Format the first partition as ext4:
Code:sudo mkfs.ext4 /dev/nvme0n1p1
- Format the second partition as xfs:
Code:sudo mkfs.xfs /dev/nvme0n1p2
- Format the third partition as exfat:
Code:sudo mkfs.exfat /dev/nvme0n1p3
USB Thumb Drive Example
- Format the partition as exfat:
Code:
sudo mkfs.exfat /dev/sdc1
Disk Format
Disk formatting involves preparing a storage device for use by an operating system, which includes creating a file system that organizes and manages files on the diskAdvantages of exFAT Over FAT32
- Larger File Size Support: exFAT supports files larger than 4 GB, unlike FAT32
- Larger Partition Size: exFAT can handle partitions larger than 8 TB, whereas FAT32 is limited to 8 TB
Getting UUID of Each Partition
- Use blkid to get the UUID:
Code:sudo blkid
- Example output:
Code:/dev/sdb1: UUID="123e4567-e89b-12d3-a456-426614174000" TYPE="ext4" /dev/nvme0n1p1: UUID="123e4567-e89b-12d3-a456-426614174001" TYPE="ext4" /dev/nvme0n1p2: UUID="123e4567-e89b-12d3-a456-426614174002" TYPE="xfs" /dev/nvme0n1p3: UUID="123e4567-e89b-12d3-a456-426614174003" TYPE="exfat" /dev/sdc1: UUID="123e4567-e89b-12d3-a456-426614174004" TYPE="exfat"
Using UUID in /etc/fstab to Automount Partitions
- Open /etc/fstab in a text editor:
Code:sudo nano /etc/fstab
- Add entries for each partition:
Code:UUID=123e4567-e89b-12d3-a456-426614174000 /mnt ext4 defaults 0 0 UUID=123e4567-e89b-12d3-a456-426614174001 /mnt/data1 ext4 defaults 0 0 UUID=123e4567-e89b-12d3-a456-426614174002 /mnt/data2 xfs defaults 0 0 UUID=123e4567-e89b-12d3-a456-426614174003 /mnt/data3 exfat defaults 0 0 UUID=123e4567-e89b-12d3-a456-426614174004 /mnt/usb exfat defaults 0 0
- Each partition needs its own mount point and individual line in /etc/fstab.
I hope this guide helps you understand how to use fdisk to create partition tables, format partitions, and set up automounting using UUIDs in Linux!
Last edited: