8 Partx Command Usage Examples in Linux

Take Your Linux Skills to the Next Level All courses, certifications, ad-free articles & community — from $8/mo
Join Root →
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Access to Linux certifications (RHCSA, RHCE, LFCS and LFCA)
Access new courses on release
Get access to weekly newsletter
Priority help in comments
Private Telegram community
Connect with the Linux community
From $8/mo · or $59/yr billed annually · Cancel anytime

Partx is a simple yet useful command line utility oriented towards maintenance of your Linux system. It is used to tell the kernel about the presence and numbering of partitions on a disk.

In this short article, we will explain useful Partx command usage with examples in Linux. Note that you need to run partx with root privileges, otherwise use the sudo command to gain root privileges.

1. To list the partition table of disk, you can run any of the following commands. Note that, in this case, partx will see sda10 as a whole-disk rather than as a partition (replace /dev/sda10 with the appropriate device node you want to deal with on your system):

# partx --show /dev/sda10
OR 
# partx --show /dev/sda10 /dev/sda 
List Partition on a Disk
List Partition on a Disk

2. To lists all sub-partitions on /dev/sda (note that the device is used as a whole-disk), run:

# partx --show /dev/sda
List All Partitions on a Disk
List All Partitions on a Disk

3. You can also specify the range of partitions to show using the --nr option. Use the -o option to define the output columns. It can be used for the --show or other related options.

For example to print the start and end sectors of partition 10 on /dev/sda, run:

# partx -o START, END --nr 10 /dev/sda
Print Start and End Sectors of Partition
Print Start and End Sectors of Partition

4. To read the disk and try to add all partitions to the system, use the -a and -v (verbose mode) option as follows.

# partx -v -a /dev/sdb 

5. To lists the length in sectors and human-readable size of partition 3 on /dev/sdb, run the following command.

 
# partx -o SECTORS,SIZE  /dev/sdb3 /dev/sdb 

6. To add the specified partitions, 3 to 5 (inclusive) on /dev/sdb, use the following command.

# partx -a --nr 3:5 /dev/sdb

7. You can also remove partitions using -d flag. For example, to remove the last partition on /dev/sdb, use the following command. In this example, the --nr -1:-1 means the last partition on the disk.

# partx -d --nr -1:-1 /dev/sdb

8. To specify the partition table type, use the -t flag and to disable the headers, use the -g flag.

# partx -o START -g --nr 5 /dev/sdb

You might also like to read these following related articles:

  1. 8 Linux ‘Parted’ Commands to Create, Resize and Rescue Disk Partitions
  2. How to Create a New Ext4 File System (Partition) in Linux
  3. How to Clone a Partition or Hard drive in Linux
  4. Top 6 Partition Managers (CLI + GUI) for Linux
  5. 9 Tools to Monitor Linux Disk Partitions and Usage in Linux

For more information, read the partx manual entry page (by running man partx). You can ask questions or share your thoughts with us via the feedback form below.

Root Plan
Premium Linux Education for Serious Learners

Take Your Linux Skills to the Next Level

Root members get full access to every course, certification prep track, and a growing library of hands-on Linux content — with new courses added every month.

What You Get
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Access to Linux certifications (RHCSA, RHCE, LFCS and LFCA)
Access new courses on release
Get access to weekly newsletter
Priority help in comments
Private Telegram community
Connect with the Linux community
Ravi Saive
I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 Comment

Leave a Reply
  1. “It is used to tell the kernel about the presence and numbering of partitions on a disk.”

    Why should the kernel be told about the presence and numbering of partitions? Isn’t the kernel already aware of all disks and partitions on the system because of the hardware identification modules that run during bootup?

    When you use the '-d' option, are you actually deleting the partition, or are just telling the kernel not to “see” the partition?

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Root Plan Premium Linux Education for Serious Learners

Before You Go - Upgrade Your Linux Skills

Root members get everything in one place, with new courses added every month.

What You Get
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Linux certifications: RHCSA, RHCE, LFCS and LFCA
Access new courses on release
Weekly newsletter, priority support & Telegram community
Join Root Today and Start Learning Linux the Right Way
Structured courses, certification prep, and a community of Linux professionals - all in one membership.
Join Root Plan →
$8/mo · or $59/yr billed annually