I haven’t played around much with commands to create partitions and filesystems in Linux. This is the reason I decided to put together this practical tutorial for myself and to share with the world. But, first I decided to take a little trip to Staten Island on the Ferry.

Create Partitions and Filesystems in Linux

To manage MBR and GPT Partition. Tools to use are:

  • fdisk → For MBR (older, BIOS-based systems, up to 2TB disks).
  • gdisk or parted → For GPT (modern, UEFI-based, larger disks).

fdisk example command:

sudo fdisk /dev/sdb        # open disk /dev/sdb
# inside fdisk:
  n   # create new partition
  p   # primary
  1   # partition number
      # accept default start
  +2G # size = 2GB
  w   # write changes

Example with GPT (parted):

sudo parted /dev/sdc
(parted) mklabel gpt               # create GPT partition table
(parted) mkpart primary ext4 1MiB 2GiB
(parted) mkpart primary linux-swap 2GiB 4GiB
(parted) print
(parted) quit

Create Filesystems with mkfs

Once the partition is created (e.g., /dev/sdb1), you can format it:

EXT filesystems (common in Linux). You can use either below:

sudo mkfs.ext2 /dev/sdb1
sudo mkfs.ext3 /dev/sdb2
sudo mkfs.ext4 /dev/sdb3

XFS (great for large files, modern distros):

sudo mkfs.xfs /dev/sdb4

VFAT (for USB sticks, cross-platform with Windows):

sudo mkfs.vfat -F 32 /dev/sdb5

exFAT (newer removable media, Windows/macOS support):

sudo mkfs.exfat /dev/sdb6

Handling Swap Partitions

Swap partitions extend RAM usage to disk:

sudo mkswap /dev/sdb7       # format as swap
sudo swapon /dev/sdb7       # enable swap
sudo swapoff /dev/sdb7      # disable swap

To make swap permanent → add to /etc/fstab:

/dev/sdb7 none swap sw 0 0

Basic Knowledge of Btrfs

Btrfs = “B-tree filesystem”, modern FS with advanced features:

  • Supports multi-device volumes (like RAID).
  • Compression built-in (zlib, zstd, lzo).
  • Subvolumes = lightweight partitions inside a filesystem.

Create Btrfs filesystem:

sudo mkfs.btrfs /dev/sdb1

Multi-device (RAID-like):

sudo mkfs.btrfs -m raid1 -d raid1 /dev/sdb1 /dev/sdb2

Mount with compression:

sudo mount -o compress=zstd /dev/sdb1 /mnt/btrfs

Create subvolumes:

sudo btrfs subvolume create /mnt/btrfs/data
sudo btrfs subvolume create /mnt/btrfs/logs

List subvolumes:

sudo btrfs subvolume list /mnt/btrfs

Real-life sysadmin workflow:

  1. Plug in new disk → lsblk or fdisk -l to detect.
  2. Partition with fdisk or parted.
  3. Format with mkfs.* or mkswap.
  4. Mount it (mount /dev/sdb1 /mnt/data).
  5. Add permanent entry in /etc/fstab.

How to find the filesystem type for a partition?

As a sysadmin you often need to check what filesystem type a partition is using.
There are several commands you can use in Linux:

lsblk -f (fastest, most common):

lsblk -f

Example output:

NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda
├─sda1 ext4         1a2b3c4d-5678-90ef-ghij-klmnopqrst   /
├─sda2 swap         1234abcd-5678-90ef-ghij-klmnopqrst   [SWAP]
└─sda3 xfs          2233abcd-4455-6677-8899-aabbccddeeff /data

blkid (shows filesystem info directly):

sudo blkid /dev/sda1

Example output:

/dev/sda1: UUID="1a2b3c4d-5678" TYPE="ext4" PARTLABEL="primary"

file -s (reads filesystem signature):

sudo file -s /dev/sda1

Example output:

/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=1a2b3c4d...

df -Th (check mounted partitions):

df -Th

Example output:

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda1      ext4   50G   20G   27G  43% /
/dev/sda3      xfs   100G   10G   90G  10% /data

Looking at /etc/fstab (persistent mounts):

cat /etc/fstab

You might see something like:

UUID=1a2b3c4d-5678-90ef / ext4 defaults 0 1
UUID=2233abcd-4455-6677 /data xfs defaults 0 2

Consider supporting my work by purchasing one of my T-Shirt and/or coffee mugs designs. You can go to my shop here. You can contact me if you have any questions. Thank you!

Leave a comment

Your email address will not be published. Required fields are marked *