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 start end

PARAMETERS

device
    The device name where the partition exists (e.g., /dev/sda).

partition
    The partition number to add (e.g., 1 for the first partition).

start
    The starting sector of the partition.

end
    The ending sector of the partition.

DESCRIPTION

The addpart command is a simple utility used to inform the Linux kernel about the existence of a new partition on a storage device, without requiring a reboot. It does not create the partition; instead, it notifies the kernel about a partition that has already been created using another tool like fdisk, gdisk, or parted. This is useful in situations where the kernel hasn't automatically detected a newly created partition. Using addpart avoids the need to rescan the partition table of the entire disk which is more resource intensive. It's essential for making the partition immediately accessible after it is created. Note that using the command without proper understanding of partitions and device names can cause data loss.

The command takes the device name, partition number, and the start and end sectors as arguments.
It expects that the relevant partition table type (e.g., MBR or GPT) is already in place and correctly configured. It does not handle any partitioning tasks and is purely about informing the kernel about existing partitions.

CAVEATS

Incorrectly specifying the start and end sectors can lead to data corruption. Ensure you have accurate information from partitioning tools like fdisk or parted before using addpart. The command does not handle overlapping partitions. It is important that the partitions created don't have overlapping sectors. It also doesn't handle partition table creation.

Requires root privileges.

EXAMPLE USAGE

To add partition number 2 on /dev/sdb, starting at sector 2048 and ending at sector 1048575:
addpart /dev/sdb 2 2048 1048575

ERROR HANDLING

If addpart fails, it will typically print an error message to standard error. Common errors include incorrect parameters, invalid start or end sectors, or the device not existing. It returns a non-zero exit code in case of an error.

ALTERNATIVE TOOLS

Using partprobe or kpartx tools can rescan partition tables. If those commands can't recognize the new partition, addpart is the last resort.

HISTORY

addpart is part of the util-linux package, a suite of essential Linux utilities. Its development aligns with the broader needs of Linux system administration, providing a way to manage partitions without restarting the system. It has been a standard command for quite some time. Originally, after creating a new partition with tools like fdisk, users had to reboot to have the kernel recognize the new partition. `addpart` allows to skip this step, making it especially valuable in environments where downtime is undesirable. The command evolved alongside improvements in kernel partition handling and the introduction of different partition table schemes.

SEE ALSO

fdisk(8), gdisk(8), parted(8), delpart(8)

Copied to clipboard