LinuxCommandLibrary

addpart

Add a new partition to a disk

TLDR

Tell the kernel about the existence of the specified partition

$ addpart [device] [partition] [start] [length]
copy

SYNOPSIS

addpart DEVICE PARTITION
addpart DEVICE PARTITION START END

PARAMETERS

DEVICE
    The disk device (e.g., /dev/sda or /dev/nvme0n1) on which the partition resides.

PARTITION
    The numerical identifier of the partition to be added or re-read (e.g., 1 for the first partition).

START
    The starting sector of the partition. This is an optional parameter typically used to explicitly define the partition's extent for the kernel.

END
    The ending sector of the partition. This, along with START, defines the partition's boundaries and is also optional.

DESCRIPTION

addpart is a utility used to inform the Linux kernel about the existence of a new partition on a disk. It does not create or modify partition tables on the storage device; instead, it reads the on-disk partition table and tells the kernel to re-read it, specifically for a designated partition. This command is particularly useful when a partition has been created or resized using tools like fdisk, sfdisk, or parted, and the kernel needs to be made aware of these changes without requiring a full system reboot.

On many modern Linux distributions, addpart is a symbolic link to the more general partx utility, which provides broader functionality for manipulating partition information visible to the kernel. While addpart focuses on adding a single specified partition, partx can re-read the entire partition table for a device or list partitions.

CAVEATS

The addpart command does not create or modify partitions on the disk. It only instructs the kernel to re-read the partition table for a specified partition. Changes made to the disk's partition table using tools like fdisk, sfdisk, or parted must be saved first.

For automatic detection of partition table changes, udev rules often handle this, or partprobe is a more general utility. In many modern systems, partprobe or partx -a are preferred for comprehensive partition table re-scanning.

KERNEL VS. ON-DISK PARTITION TABLES

When you create or modify partitions using tools like fdisk or parted, these changes are written to the disk's partition table. However, the Linux kernel maintains its own in-memory representation of the partition table. For the operating system to recognize and use the newly created or modified partitions, the kernel's in-memory table must be updated. addpart (or partx) serves this purpose, explicitly instructing the kernel to refresh its view of a specific partition without requiring a system reboot. If the kernel's view is not updated, attempts to mount or access the new partition will fail.

HISTORY

addpart is part of the util-linux package, a collection of essential Linux utilities. Its primary role was to manually inform the kernel about new partition layouts. With the advent and widespread adoption of udev and the partprobe utility, the manual execution of addpart or partx -a became less frequently necessary, as these systems often automatically detect and process partition table changes. On many current Linux distributions, addpart is implemented as a symbolic link to the more versatile partx command, inheriting its functionality.

SEE ALSO

partx(8), fdisk(8), sfdisk(8), parted(8), partprobe(8), kpartx(8), udev(7)

Copied to clipboard