Menu

addpart Command in Linux for Partition Management

Manage partitions using addpart command in Linux

addpart (add partition) is a basic tool which comes bundled with the util-linux package (It was formerly known as util-linux-ng). util-linux is a standard package, a utility software, distributed by the Linux Kernel Organization for use as part of the Linux operating system. It is a random collection of Linux utilities.

It provides information about the presence of the specified partition to the Linux kernel. The command is merely an "add partition" ioctl wrapper on the command line. This command is not used to modify partitions on a block device.

_addpart_module() { local cur COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" case $COMP_CWORD in 1) OPTS="--help --version $(lsblk -pnro name)" compopt -o bashdefault -o default COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) ;; 2) # FIXME: how to determine next free partition number ;; 3) COMPREPLY=( $(compgen -W "start" -- $cur) ) ;; 4) COMPREPLY=( $(compgen -W "length" -- $cur) ) ;; esac return 0 } complete -F _addpart_module addpart

Install addpart command

util-linux comes within the Linux kernel. But, you can also use these commands to install them manually.

Debian based - apt install util-linux
Alpine - apk add util-linux
Arch Linux - pacman -S util-linux
CentOS - yum install util-linux
Fedora - dnf install util-linux
OS X - brew install util-linux
Raspbian - apt-get install util-linux
Docker - docker run cmd.cat/addpart addpart

addpart Syntax

addpart <disk device> <partition number> <start> <length>

addpart Options

deviceThe disk device.
partitionThe partition number.
startThe beginning of the partition (in 512-byte sectors).
lengthThe length of the partition (in 512-byte sectors).
--helpdisplay this help and exit.
-V, --versionoutput version information and exit.

addpart Examples:

Show addpart syntax and usage.

If addpart isn’t provided with all four parameters, then it will display the following message.

$ addpart
addpart: not enough arguments
Try 'addpart --help' for more information.

View **addpart** help message.

You can use the -help option to view addpart help message.

$ addpart --help

Usage:
addpart <disk device> <partition number> <start> <length>

Linux terminal command: addpart, manage drive partitions

Check drive partitions in Linux

We can use lsblk command to list disk and partition information as follows:

![Use lsblk command in Linux terminal to list drive and partition information](https://s3.studytonight.com/tutorials/uploads/pictures/1672466099-133673.png)

Use addpart to interact with Linux kernel

To use this command with a system disk device, you may require root privilege. Also, the disk device should not be busy, it should be unmounted to the system.

To tell the Linux kernel about the existence of a file partition, we use the following syntax:

addpart disk_device partition_number start length

Now, Let’s use TAB completion (For BASH shell) to view all disk devices available.

$ addpart
/dev/sda /dev/sda10 /dev/sda12 /dev/sda3 /dev/sda5 /dev/sda7 /dev/sda9 --version
/dev/sda1 /dev/sda11 /dev/sda2 /dev/sda4 /dev/sda6 /dev/sda8 --help
$ addpart

From this list of available disk devices, choose one.

For the next argument we need to specify the partition number as follows.

addpart /dev/sda 1

Now you can specify the remaining two arguments; the name and the length of the partition (in 512-byte sectors).

addpart /dev/sda 1 1 1

Conclusion

In this article, we explored a basic Linux command line utility addpart, which is a part of Linux standard package called util-linux. It is used to interact with the Linux kernel and tell about the existing partitions. This command comes with four options that can be specified as device, partition, start and length.