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).gdiskorparted→ 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 changesExample 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) quitCreate 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/sdb3XFS (great for large files, modern distros):
sudo mkfs.xfs /dev/sdb4VFAT (for USB sticks, cross-platform with Windows):
sudo mkfs.vfat -F 32 /dev/sdb5exFAT (newer removable media, Windows/macOS support):
sudo mkfs.exfat /dev/sdb6Handling 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 swapTo make swap permanent → add to /etc/fstab:
/dev/sdb7 none swap sw 0 0Basic 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/sdb1Multi-device (RAID-like):
sudo mkfs.btrfs -m raid1 -d raid1 /dev/sdb1 /dev/sdb2Mount with compression:
sudo mount -o compress=zstd /dev/sdb1 /mnt/btrfsCreate subvolumes:
sudo btrfs subvolume create /mnt/btrfs/data
sudo btrfs subvolume create /mnt/btrfs/logsList subvolumes:
sudo btrfs subvolume list /mnt/btrfsReal-life sysadmin workflow:
- Plug in new disk →
lsblkorfdisk -lto detect. - Partition with
fdiskorparted. - Format with
mkfs.*ormkswap. - Mount it (
mount /dev/sdb1 /mnt/data). - 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 -fExample 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 /datablkid (shows filesystem info directly):
sudo blkid /dev/sda1Example output:
/dev/sda1: UUID="1a2b3c4d-5678" TYPE="ext4" PARTLABEL="primary"file -s (reads filesystem signature):
sudo file -s /dev/sda1Example output:
/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=1a2b3c4d...df -Th (check mounted partitions):
df -ThExample output:
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 50G 20G 27G 43% /
/dev/sda3 xfs 100G 10G 90G 10% /dataLooking at /etc/fstab (persistent mounts):
cat /etc/fstabYou might see something like:
UUID=1a2b3c4d-5678-90ef / ext4 defaults 0 1
UUID=2233abcd-4455-6677 /data xfs defaults 0 2Consider 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!


