Mastering Linux: How to Install and Use ‘Parted’

Illustration of a Linux terminal displaying the installation of the parted command used for manipulating disk partitions and filesystems

Are you looking to install the parted command on your Linux system but aren’t sure where to start? Many Linux users, particularly beginners, might find the task intimidating. Yet, parted is a powerful tool to manage disk partitions; it’s a utility worth mastering. Parted is readily available on most package management systems, making it a straightforward process once you know-how.

In this tutorial, we will guide you on how to install the parted command on your Linux system. We will show you methods for both APT and YUM-based distributions, delve into compiling parted from source, installing a specific version, and finally, how to use the parted command and ensure it’s installed correctly.

So, let’s dive in and begin installing parted on your Linux system!

TL;DR: How Do I Install and Use the ‘Parted’ Command in Linux?

The 'parted' command is usually pre-installed on most Linux distributions, you can verify this with, parted --version. However, if it’s not, you can install it on Debian-based distributions like Ubuntu with the command sudo apt-get install parted. For RPM-based distributions like CentOS, use the command sudo yum install parted.

# For Debian-based distributions like Ubuntu
sudo apt-get install parted

# For RPM-based distributions like CentOS
sudo yum install parted

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following NEW packages will be installed:
#   parted
# 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
# Need to get 42.3 kB of archives.
# After this operation, 175 kB of additional disk space will be used.
# Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 parted amd64 3.2-21 [42.3 kB]
# Fetched 42.3 kB in 1s (40.1 kB/s)
# Selecting previously unselected package parted.
# (Reading database ... 160837 files and directories currently installed.)
# Preparing to unpack .../parted_3.2-21_amd64.deb ...
# Unpacking parted (3.2-21) ...
# Setting up parted (3.2-21) ...
# Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

This is a basic way to install the ‘parted’ command in Linux, but there’s much more to learn about installing and using ‘parted’. Continue reading for more detailed information and advanced usage scenarios.

Understanding the ‘Parted’ Command in Linux

The ‘parted’ command is a disk partitioning and partition resizing program. It allows you to create, destroy, resize, move and copy ext2, linux-swap, FAT, FAT32, and reiserfs partitions. It’s an essential tool for Linux users who need to manage disk storage.

For beginners, the easiest way to install the ‘parted’ command is through the package manager that comes with your Linux distribution. This could be APT (Advanced Package Tool) for Debian-based distributions like Ubuntu or YUM (Yellowdog Updater, Modified) for RPM-based distributions like CentOS.

Installing ‘Parted’ with APT

If you’re using a Debian-based distribution like Ubuntu, you can install ‘parted’ using the APT package manager. Here’s how you can do it:

sudo apt update
sudo apt install parted

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed:
#   libparted2
# Suggested packages:
#   parted-doc
# The following NEW packages will be installed:
#   libparted2 parted
# 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
# Need to get 104 kB of archives.
# After this operation, 365 kB of additional disk space will be used.
# Do you want to continue? [Y/n] Y
# Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 libparted2 amd64 3.2-21 [90.9 kB]
# Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 parted amd64 3.2-21 [42.3 kB]
# Fetched 104 kB in 1s (103 kB/s)
# Selecting previously unselected package libparted2:amd64.
# (Reading database ... 160837 files and directories currently installed.)
# Preparing to unpack .../libparted2_3.2-21_amd64.deb ...
# Unpacking libparted2:amd64 (3.2-21) ...
# Selecting previously unselected package parted.
# Preparing to unpack .../parted_3.2-21_amd64.deb ...
# Unpacking parted (3.2-21) ...
# Setting up libparted2:amd64 (3.2-21) ...
# Processing triggers for libc-bin (2.27-3ubuntu1.2) ...
# Setting up parted (3.2-21) ...
# Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

In this example, we first updated the package lists for upgrades and new packages from repositories with sudo apt update. Then, we installed ‘parted’ with sudo apt install parted. The output shows that ‘parted’ and its dependencies were successfully installed.

Installing ‘Parted’ with YUM

For RPM-based distributions like CentOS, you can use the YUM package manager to install ‘parted’. Here’s how:

sudo yum check-update
sudo yum install parted

# Output:
# Loaded plugins: fastestmirror
# Loading mirror speeds from cached hostfile
#  * base: mirror.lug.udel.edu
#  * extras: mirror.lug.udel.edu
#  * updates: mirror.lug.udel.edu
# Resolving Dependencies
# --> Running transaction check
# ---> Package parted.x86_64 0:3.1-29.el7 will be installed
# --> Finished Dependency Resolution
# Dependencies Resolved
# ================================================================================
#  Package       Arch          Version                  Repository       Size
# ================================================================================
# Installing:
#  parted        x86_64        3.1-29.el7               base            610 k
# Transaction Summary
# ================================================================================
# Install  1 Package
# Total download size: 610 k
# Installed size: 1.8 M
# Is this ok [y/d/N]: y
# Downloading packages:
# parted-3.1-29.el7.x86_64.rpm                                     | 610 kB  00:00:00     
# Running transaction check
# Running transaction test
# Transaction test succeeded
# Running transaction
#   Installing : parted-3.1-29.el7.x86_64                                             1/1 
#   Verifying  : parted-3.1-29.el7.x86_64                                             1/1 
# Installed:
#   parted.x86_64 0:3.1-29.el7                                                            
# Complete!

In this example, we first checked for system updates with sudo yum check-update. Then, we installed ‘parted’ with sudo yum install parted. The output shows that ‘parted’ was successfully installed.

Installing ‘Parted’ from Source Code

If you want to compile ‘parted’ from source code, you’ll need to download the source code first. Here’s how you can do it:

wget http://ftp.gnu.org/gnu/parted/parted-3.3.tar.xz

# Output:
# --2022-04-01 12:00:00--  http://ftp.gnu.org/gnu/parted/parted-3.3.tar.xz
# Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b
# Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected.
# HTTP request sent, awaiting response... 200 OK
# Length: 1368488 (1.3M) [application/x-tar]
# Saving to: ‘parted-3.3.tar.xz’

This command will download the ‘parted’ source code from the official GNU FTP server. The output shows that the download was successful.

Next, you’ll need to extract the downloaded source code and navigate to the extracted directory:

tar -xf parted-3.3.tar.xz

cd parted-3.3

# Output:
# (no output)

The tar -xf parted-3.3.tar.xz command extracts the downloaded source code, and cd parted-3.3 changes the current directory to the extracted source code directory.

Finally, you can compile and install ‘parted’ using the standard ./configure, make, and make install commands:

./configure

# Output:
# checking for a BSD-compatible install... /usr/bin/install -c
# checking whether build environment is sane... yes
# checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
# checking for gawk... gawk
# checking whether make sets $(MAKE)... yes
# checking whether make supports nested variables... yes

make

# Output:
# make  all-recursive
# make[1]: Entering directory '/home/user/parted-3.3'
# Making all in lib

sudo make install

# Output:
# Making install in lib
# make[1]: Entering directory '/home/user/parted-3.3/lib'
# make[2]: Entering directory '/home/user/parted-3.3/lib'
# /usr/bin/mkdir -p '/usr/local/lib'
# /bin/bash ../libtool   --mode=install /usr/bin/install -c   libparted.la '/usr/local/lib'
# libtool: install: /usr/bin/install -c .libs/libparted.so.2.0.1 /usr/local/lib/libparted.so.2.0.1

In this example, ./configure checks your system for the necessary dependencies and prepares the makefile. make compiles the source code, and sudo make install installs the compiled binary to your system. The output shows that ‘parted’ was successfully compiled and installed.

Installing Different Versions of ‘Parted’

Different versions of ‘parted’ may have different features or compatibility with different versions of Linux distributions. Here’s how you can install a specific version of ‘parted’ using APT and YUM:

Installing a Specific Version with APT

sudo apt install parted=3.2-21

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following packages were automatically installed and are no longer required:
#   libparted2
# Use 'sudo apt autoremove' to remove them.
# The following packages will be DOWNGRADED:
#   parted
# 0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
# Need to get 42.3 kB of archives.
# After this operation, 0 B of additional disk space will be used.
# Do you want to continue? [Y/n] Y
# Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 parted amd64 3.2-21 [42.3 kB]
# Fetched 42.3 kB in 1s (40.1 kB/s)
# dpkg: warning: downgrading parted from 3.3-4ubuntu0.1 to 3.2-21
# (Reading database ... 160837 files and directories currently installed.)
# Preparing to unpack .../parted_3.2-21_amd64.deb ...
# Unpacking parted (3.2-21) over (3.3-4ubuntu0.1) ...
# Setting up parted (3.2-21) ...
# Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

In this example, we installed ‘parted’ version 3.2-21 with sudo apt install parted=3.2-21. The output shows that ‘parted’ was successfully downgraded to version 3.2-21.

Installing a Specific Version with YUM

sudo yum install parted-3.1-29.el7

# Output:
# Loaded plugins: fastestmirror
# Loading mirror speeds from cached hostfile
#  * base: mirror.lug.udel.edu
#  * extras: mirror.l ug.udel.edu
#  * updates: mirror.lug.udel.edu
# Resolving Dependencies
# --> Running transaction check
# ---> Package parted.x86_64 0:3.1-29.el7 will be installed
# --> Finished Dependency Resolution
# Dependencies Resolved
# ================================================================================
#  Package       Arch          Version                  Repository       Size
# ================================================================================
# Installing:
#  parted        x86_64        3.1-29.el7               base            610 k
# Transaction Summary
# ================================================================================
# Install  1 Package
# Total download size: 610 k
# Installed size: 1.8 M
# Is this ok [y/d/N]: y
# Downloading packages:
# parted-3.1-29.el7.x86_64.rpm                                     | 610 kB  00:00:00     
# Running transaction check
# Running transaction test
# Transaction test succeeded
# Running transaction
#   Installing : parted-3.1-29.el7.x86_64                                             1/1 
#   Verifying  : parted-3.1-29.el7.x86_64                                             1/1 
# Installed:
#   parted.x86_64 0:3.1-29.el7                                                            
# Complete!

In this example, we installed ‘parted’ version 3.1-29.el7 with sudo yum install parted-3.1-29.el7. The output shows that ‘parted’ was successfully installed.

Comparing Different Versions of ‘Parted’

Different versions of ‘parted’ come with different features and improvements. Here’s a summary of the key changes in recent versions of ‘parted’:

VersionKey Changes
3.3Added support for I/O error reporting
3.2Added support for EXT4 file system
3.1Added support for UDF file system

Using the ‘Parted’ Command

The ‘parted’ command is a powerful tool that allows you to manage disk partitions. Here’s how you can list all partitions on your system with ‘parted’:

sudo parted -l

# Output:
# Model: ATA ST1000LM024 HN-M (scsi)
# Disk /dev/sda: 1000GB
# Sector size (logical/physical): 512B/4096B
# Partition Table: gpt
# Disk Flags: 
#
# Number  Start   End     Size    File system     Name  Flags
#  1      1049kB  538MB   537MB   fat32                 boot, esp
#  2      538MB   1000GB  1000GB  ext4

In this example, sudo parted -l lists all partitions on your system. The output shows the details of each partition, including the start and end points, size, file system, and flags.

Verifying the Installation

After installing ‘parted’, you can verify that it’s installed correctly by checking its version:

parted --version

# Output:
# parted (GNU parted) 3.2

In this example, parted --version shows the installed version of ‘parted’. The output shows that ‘parted’ version 3.2 is installed on the system.

Exploring Alternative Disk Partitioning Tools

While ‘parted’ is a powerful tool for managing disk partitions on Linux, it’s not the only one. There are other tools available that offer different features and interfaces. Here, we will introduce two popular alternatives: ‘fdisk’ and ‘gparted’.

The ‘fdisk’ Command: Old but Gold

‘fdisk’ is another command-line utility for disk partitioning. It’s one of the oldest and widely used due to its simplicity and availability on almost all Linux distributions.

Here’s an example of how you can list all partitions on your system with ‘fdisk’:

sudo fdisk -l

# Output:
# Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
# Disk model: ST1000LM024 HN-M
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 4096 bytes
# I/O size (minimum/optimal): 4096 bytes / 4096 bytes
# Disklabel type: gpt
# Disk identifier: C2D3D3C2-3D3C-C2D3-3C3C-2D3C3D3C3D3C
#
# Device     Start        End    Sectors   Size Type
# /dev/sda1   2048     999423     997376   487M EFI System
# /dev/sda2 999424 1953523711 1952524288 930.5G Linux filesystem

In this example, sudo fdisk -l lists all partitions on your system. The output shows the details of each partition, including the start and end sectors, size, and type.

While ‘fdisk’ is less feature-rich compared to ‘parted’, it’s simpler to use and sufficient for basic partitioning tasks. However, ‘fdisk’ does not support GPT (GUID Partition Table) which is a limitation for modern systems with large disks.

The ‘GParted’ GUI Tool: Visual Disk Partitioning

‘GParted’ is a free partition editor for graphically managing disk partitions. It supports a wide range of file systems, including ext2, ext3, ext4, fat16, fat32, hfs, hfs+, linux-swap, NTFS, reiserfs, reiser4, ufs, xfs, and more.

To install ‘GParted’ on a Debian-based distribution, you can use the following command:

sudo apt install gparted

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed:
#   libparted-fs-resize0
# Suggested packages:
#   xfsprogs reiserfsprogs reiser4progs jfsutils ntfs-3g dosfstools mtools
# The following NEW packages will be installed:
#   gparted libparted-fs-resize0
# 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
# Need to get 1,035 kB of archives.
# After this operation, 5,632 kB of additional disk space will be used.
# Do you want to continue? [Y/n] Y
# Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 libparted-fs-resize0 amd64 3.2-21 [41.0 kB]
# Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 gparted amd64 0.30.0-3 [994 kB]
# Fetched 1,035 kB in 1s (1,010 kB/s)
# Selecting previously unselected package libparted-fs-resize0:amd64.
# (Reading database ... 160837 files and directories currently installed.)
# Preparing to unpack .../libparted-fs-resize0_3.2-21_amd64.deb ...
# Unpacking libparted-fs-resize0:amd64 (3.2-21) ...
# Selecting previously unselected package gparted.
# Preparing to unpack .../gparted_0.30.0-3_amd64.deb ...
# Unpacking gparted (0.30.0-3) ...
# Setting up libparted-fs-resize0:amd64 (3.2-21) ...
# Setting up gparted (0.30.0-3) ...
# Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
# Processing triggers for hicolor-icon-theme (0.17-2) ...

In this example, we installed ‘GParted’ with sudo apt install gparted. The output shows that ‘GParted’ was successfully installed.

‘GParted’ provides a graphical interface for managing disk partitions, making it more user-friendly than ‘parted’ and ‘fdisk’. However, it requires a graphical environment to run, which may not be available on all systems, especially servers.

In conclusion, ‘parted’, ‘fdisk’, and ‘GParted’ are all powerful tools for managing disk partitions on Linux. While ‘parted’ offers the most features, ‘fdisk’ is simpler to use and ‘GParted’ provides a user-friendly graphical interface. Depending on your needs and experience level, you may find one tool more suitable than the others. The key is to understand the strengths and weaknesses of each tool and choose the one that best fits your needs.

Troubleshooting Common ‘Parted’ Issues

While ‘parted’ is a powerful tool, you may encounter some issues when using it. Here are some common problems and their solutions.

Error: ‘Parted’ Command Not Found

If you receive a ‘command not found’ error when trying to run ‘parted’, it’s likely that ‘parted’ is not installed or not in your system’s PATH.

parted

# Output:
# Command 'parted' not found, but can be installed with:
# sudo apt install parted

In this case, you need to install ‘parted’ using your package manager as shown in the previous sections.

Error: Unable to Resize Partition

If you’re unable to resize a partition using ‘parted’, it might be because the partition is mounted. You can’t resize a mounted partition, so you’ll need to unmount it first.

sudo umount /dev/sda1

# Output:
# umount: /: target is busy

In this example, we tried to unmount the partition with sudo umount /dev/sda1, but the output shows that the target is busy. This means there are processes using the partition, so it can’t be unmounted. You may need to stop these processes or use a live CD/USB to unmount the partition.

Error: Unable to Create Partition

If you’re unable to create a partition, it might be because your disk is using an MBR partition table, which supports up to four primary partitions. If you need more partitions, you’ll need to create an extended partition, which can contain multiple logical partitions.

sudo parted /dev/sda mkpart primary ext4 1M 100M

# Output:
# Error: Partition(s) on /dev/sda are being used.

In this example, we tried to create a new partition with sudo parted /dev/sda mkpart primary ext4 1M 100M, but the output shows that the partitions on the disk are being used. This means you can’t create a new partition without deleting or resizing an existing one.

Remember that managing disk partitions can be risky, so always backup your important data before making any changes. And always double-check your commands before running them to avoid mistakes.

Understanding Disk Partitioning in Linux

Before we dive into the ‘parted’ command, it’s crucial to understand the concept of disk partitioning in Linux. Disk partitioning is the act of dividing a hard disk into multiple logical storage units referred to as partitions. Each partition functions as a separate disk, allowing you to manage your data more efficiently.

lsblk

# Output:
# NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
# sda      8:0    0 931.5G  0 disk 
# ├─sda1   8:1    0   487M  0 part /boot/efi
# ├─sda2   8:2    0   731G  0 part /
# ├─sda3   8:3    0 199.5G  0 part /home

In this example, lsblk lists all block devices, which includes the disk partitions. The output shows that the disk ‘sda’ is divided into three partitions: ‘sda1’, ‘sda2’, and ‘sda3’. Each partition is mounted at a different mount point and has a different size.

The Importance of Proper Disk Partitioning

Proper disk partitioning is crucial for several reasons. First, it enhances data organization. By separating your system files from user files, you can prevent a user from filling up the entire system disk and causing system instability.

Second, it improves performance. For instance, creating a separate partition for the swap space can speed up the system. Additionally, smaller partitions can be checked faster by file system checks.

Third, it increases security. By creating different partitions for different purposes, you can apply different mount options to each partition. For example, you can mount the /tmp partition with the ‘noexec’ option to prevent the execution of binaries from the /tmp directory.

Finally, it facilitates backups and system upgrades. By keeping user data on a separate partition, you can backup or upgrade your system without affecting user data.

In conclusion, understanding disk partitioning is fundamental to mastering the ‘parted’ command. By dividing your disk into logical units, you can manage your data more efficiently, improve system performance, enhance security, and facilitate backups and system upgrades.

The Role of Disk Partitioning in System Administration

Disk partitioning is more than just organizing your data; it plays a significant role in system administration and performance. By creating separate partitions for different purposes, you can optimize your system for specific tasks, improve performance, and enhance security.

For instance, you can create a separate partition for the /var directory, which often grows in size due to log files. By doing so, you can prevent the /var directory from filling up the root file system and causing system instability.

sudo parted /dev/sda mkpart primary ext4 100G 200G

# Output:
# Information: You may need to update /etc/fstab.

In this example, we created a new partition for the /var directory using the command sudo parted /dev/sda mkpart primary ext4 100G 200G. The output indicates that we may need to update /etc/fstab, which is the file system table that contains the configuration of all disk partitions.

Exploring Related Concepts: File Systems and RAID

Along with disk partitioning, there are other related concepts that you might find interesting, such as file systems and RAID (Redundant Array of Independent Disks).

A file system determines how data is stored and retrieved on a disk. Different file systems offer different features and performance characteristics. For example, ext4 is a popular file system on Linux due to its robustness and excellent performance.

RAID is a method of storing the same data in different places on multiple hard disks to protect data in the case of a drive failure. There are different RAID levels, each providing a different balance between performance, capacity, and data protection.

Further Resources for Mastering Disk Partitioning

  1. GNU Parted Manual: This is the official manual of ‘parted’ from GNU. It provides a comprehensive guide on how to use ‘parted’, from basic usage to advanced features.

  2. The Linux Documentation Project: This is a detailed guide on disk partitioning in Linux. It covers everything from the basics of disk partitioning to advanced topics like RAID.

  3. Arch Linux Wiki – Partitioning: The Arch Linux Wiki is a valuable resource for any Linux user. The Partitioning page provides an in-depth look at disk partitioning, including different partitioning schemes and tools.

Wrapping Up: Installing the ‘Parted’ Command in Linux

In this comprehensive guide, we’ve explored the ‘parted’ command, a powerful tool for managing disk partitions on Linux.

We began with the basics, learning how to install ‘parted’ on different Linux distributions. We then delved into more advanced topics, such as creating, resizing, and deleting partitions using ‘parted’. Along the way, we tackled common issues you might encounter when using ‘parted’, providing you with solutions and workarounds for each issue.

We also looked at alternative approaches to disk partitioning, comparing ‘parted’ with other tools like ‘fdisk’ and ‘GParted’. Here’s a quick comparison of these methods:

ToolCommand LineGUIGPT Support
‘Parted’YesNoYes
‘fdisk’YesNoNo
‘GParted’NoYesYes

Whether you’re just starting out with ‘parted’ or you’re looking to level up your disk partitioning skills, we hope this guide has given you a deeper understanding of ‘parted’ and its capabilities.

With its balance of power, flexibility, and ease of use, ‘parted’ is a valuable tool for any Linux user. Now, you’re well equipped to manage your disk partitions with confidence. Happy partitioning!