zig_parted — Disk Partitioning in Zig

I recently published zig_parted, a pure-Zig library for reading and writing MBR and GPT partition tables. It supports creating, resizing, and managing partitions directly through disk I/O — no external commands or dependencies required.

Why?

Most partitioning tools (fdisk, parted, gdisk) are C programs called via CLI. That works, but when you're building system-level tooling in Zig — like an installer or disk utility — you either shell out or link against C libraries. This library eliminates that gap.

What it does

Usage

Add it to your build.zig.zon and import:

A minimal example: create a 50 MB disk image, write an MBR with two partitions (Ext4 and Fat32), then inspect the result.

Partition types

The library includes partition type constants for:

TypeDescription
.Ext4Linux ext4
.Fat32FAT32
.NtfsNTFS
.LinuxSwapLinux swap
.LinuxLVMLinux LVM
.LinuxRAIDLinux RAID
.EfiEFI System Partition
.HfsPlusApple HFS/HFS+
.ApfsApple APFS
.FreeBSDFreeBSD
.OpenBSDOpenBSD
.NetBSDNetBSD
.SolarisSolaris

Caveats

Direct disk operations can modify partition tables. As the README says — always backup important data before use. This library is meant for controlled environments (installers, disk utilities) where you know what device you're targeting.

Links