Stop Hand-Partitioning Disks: Practical systemd-repart on Linux
Stop Hand-Partitioning Disks: Practical systemd-repart on Linux You ship a minimal OS image. The target disk is 64 GB, 256 GB, or 2 TB. Root is still 8 GB. Swap does not exist. /home is not a partition yet. The usual fix is a one-off parted / gdisk script, a fragile installer hook, or “remember to resize after first boot.” That does not scale across VMs, bare metal, and image-based fleets.…
Stop Partitioning Disks Manually, Use systemd-repart for Linux
Systemd-repart simplifies disk partitioning for minimal Linux OS images. The solution addresses challenges faced when shipping a minimal OS image to various targets, such as 64 GB, 256 GB, or 2 TB disks. Root remains at 8 GB, while swap is absent, and /home is not yet a partition. Instead of fragile installer hooks or one-off scripts, systemd-repart offers a declarative config using GPT definitions in repart.d/*.conf files.
Systemd-repart operates on a block device or image file, adding missing partitions and growing existing ones to meet size/weight constraints. It is incremental and idempotent, meaning it does nothing if the table matches the config. By default, it only changes the partition table, unless you set specific options like Format, CopyFiles, CopyBlocks, Encrypt, or Verity.
The tool works on GPT disks, ignoring MBR. Partitions are matched by GPT type UUID, not by partition number. Filenames determine the definition order. Once a partition type is found, the corresponding config is used for that partition.
Three jobs are involved: first-boot disk takeover, offline image build, and safe preview. The first-boot disk takeover is done using systemd-repart.service in initrd, while offline image build uses systemd-repart --image=... / --empty=create. Filesystem growth is a separate concern, requiring a GPT flag and systemd-growfs command.
Prerequisites for using systemd-repart include a GPT disk or a new GPT image. The package is available as systemd-repart for Debian/Ubuntu, and root is required for real devices. Unprivileged builds can use loop files and userns. Ensure there is enough free space after the last partition you care about.
To build a minimal GPT image without touching real disks, create a sparse file, declare ESP + root + swap, format them, and inspect the result. Drop partition definitions under a dedicated definitions directory, and run systemd-repart with various parameters to simulate disk growth and preview changes before applying them.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.