addpart - Linux
Overview
addpart is a command-line utility used to add a new partition to a block device or hard drive. It can create partitions of various types, including primary, extended, and logical partitions.
Syntax
addpart [options] <device> [start] [end] [size]
Options/Flags
- -t, –type: Specify the partition type (e.g., primary, extended, logical).
- -s, –size: Set the partition size in sectors, bytes, or units (e.g., "M" for megabytes).
- -l, –label: Assign a label to the partition.
- -i, –id: Specify the partition ID (e.g., 83 for Linux).
- -b, –bootable: Mark the partition as bootable.
- -c, –check: Check for errors before committing changes.
- -f, –force: Force the operation without prompting for confirmation.
- -v, –verbose: Enable verbose output.
- -h, –help: Display help information.
Examples
Create a new primary partition of 100MB on /dev/sda:
addpart -t primary /dev/sda 100M
Create a new logical partition of 5GB on /dev/mapper/myvg:
addpart -t logical /dev/mapper/myvg 5G
Create a new extended partition that spans the entire disk:
addpart -t extended /dev/sda
Common Issues
- Incorrect partition type: Ensure the specified partition type is compatible with the file system you intend to use.
- Overlapping partitions: Make sure the start and end sectors do not overlap with existing partitions.
- Insufficient space: Verify that the device has enough free space to accommodate the new partition.
- Block device is busy: Close any programs or processes accessing the block device before attempting to add a partition.
Integration
Combine with fdisk: Use fdisk to create a partition table before adding partitions with addpart.
Use with mkfs: Create a file system on the newly created partition using commands like mkfs.ext4 or mkfs.fat.
Partition scripts: Integrate addpart into scripts to automate partition creation tasks.
Related Commands
- fdisk: Manipulate partition tables.
- partprobe: Update partition information in the kernel.
- parted: Partition disk drives from the command line.
- sgdisk: Manage GPT partition tables.