
delpart Command in Linux
The delpart command in Linux temporarily forgets the partition on a disk. Unlike other tools, delpart does not modify the partition table, it only tells the kernel to forget about the specific partition. This is advantageous when quick partition management and disk testing are needed.
The delpart command is part of the util-linux package, not a standalone command. By default, it is available on most Linux distributions. However, if it is not available on your Linux system, you can install the util-linux package.
Table of Contents
Here is a comprehensive guide to the options available with the delpart command −
Note − To use the delpart command, you need superuser (sudo) privileges.
Syntax of delpart Command
The syntax for using the delpart command in Linux is as follows −
delpart [device] [partition]
Here, the [device] indicates the storage device file, while the [partition] is the partition number.
Using delpart Command in Linux
This section demonstrates the usage of the delpart command in Linux −
You need the device name, partition number, and mount point to delete a Linux partition.
Various command line tools are used to list the devices and partitions of the system, such as −

In the above output, vda is the main disk, while vda1, vda3, and vda4 are partitions. Note that the lsblk tool does not list the complete device name. However, we have identified the mount point /mnt/partition.
To list the device name, use the fdisk command with the -l flag. Where, the -l flag lists the partition table −
sudo fdisk -l

The device name is identified as /dev/vda4.
The mount point can also be identified using the df command −
df -h

To display standard output in human-readable form, use the -h flag.
To avoid data corruption, unmounting the partition before deleting it is a good practice.
To unmount the partition, use the umount command with the mount point. In our case, the mount point is /mnt/partition.
sudo umount /mnt/partition
The partition has been unmounted, verify it using the lsblk command.

To temporarily delete the partition /dev/vda4, use the following command −
sudo delpart /dev/vda 4

To verify, whether the partition has been deleted, list the devices −
ls /dev/vda*

The output now shows that the removed partition is back.
To learn more about the delpart command, display help in the terminal using the following command −
delpart --help
Getting Back the Removed Partition
To get back the temporarily removed partition, use the partprobe command. It essentially asks the kernel to re-read the partition table.
sudo partprobe

The output is now showing that the removed partition is back.
Conclusion
The delpart command in Linux primarily disconnects a partition from kernel awareness. Temporarily removing the partition from the drive is especially handy when troubleshooting partition issues.