Using parted command to create partitions in Linux?

Using parted command to create partitions in Linux?

 

Linux/Unix operating system provides various tools for disk partitioning and manipulation. GNU parted is one of them that can be used to create, view, delete, and modify partitions of a disk. It provides a text-based menu in the terminal for entering parted commands.

This article explains various uses of the parted command in a Linux system along with some examples. It is recommended to create a backup of your system before performing any operations on a disk.

How to install parted on Linux

Parted comes preinstalled on many Linux distributions. If it is not in your system you can use the following command to install it manually –

To install it on Debian/Ubuntu/Linux Mint, etc use –

sudo apt install parted

If you are using CentOS/RHEL or an aligned distribution then use –

sudo yum install parted

To install in Fedora use-

sudo dnf install parted

List partitions on a disk

To list all the partitions of a disk using the parted command you need to use the following command in your terminal-

sudo parted

and then use –

(parted) print

This will display the information including the partition number, size of the partition, filesystem, name of the partition, etc.

You can display the list of all partitions on a disk using a single command –

sudo parted -l

Switch to a different disk

If you have multiple disks on your system you can switch between them by using the select command.

sudo parted

And then use the given parted command –

(parted) select /dev/sdb

Replace the /dev/sdb with your disk name. Now you can see in the above image after executing the select command it starts using /dev/sdb.

Creating new partitions

You can create a new partition on a disk by using the parted command. To create a new partition you need to have some free space or unallocated space on the disk.

Here we have 32 GB of space on /dev/sdb. We will create a new partition of 15 GB on it, So let’s see how to create the partition.

Use the given command to create the first partition on /dev/sdb.

sudo parted /dev/sdb

First, create the disklabel (partition table ) on /dev/sdb by using –

(parted) mklabel msdos

Now use the mkpart command to create partition –

(parted) mkpart

You will be asked to enter the required information for creating a new partition. This includes partition type, filesystem type, start, and end values, etc. Now see the image below –

Format the created disk with the following command –

mkfs.ext4 /dev/sdb1

Deleting a partition

To delete a partition lets say /dev/sdb1, use the following commands-

sudo parted /dev/sdb

and use the given command to display all the partitions on the disk, find the partition number –

(parted) print

now to delete the partition use –

(parted) rm

This will ask the partition number. Once you enter it partition will be deleted.

You can perform many other tasks such as resizing, rescuing a partition, etc using the parted command in Linux. To know more about the options and command that can be used with parted command see its manual page –

man parted

Conclusion

Ok, that’s all for now. We advise you to be careful while working with parted, after execution it immediately makes changes to the disk. Now if you have a query please leave it in the comments below.

Previous [ubuntu] MicroSD won't format
Next How To Install & Use Cockpit Web Console On Ubuntu Server?
 

About author

You might also like

Commands 0 Comments

Top Command Usage With Example In Linux/Unix

This post was last updated on August 1st, 2020 at 08:47 pmThe top is one of the most frequently used command in Unix like operating systems for the administrative tasks.

Commands 0 Comments

Using fdisk command in Linux

The fdisk is a command-line utitlity used for disk manipulation in Linux/Unix. It provides a text-based menu in the terminal for entering commands. By using fdisk you can perform operations

Commands 0 Comments

Linux TAR Command

This post was last updated on May 27th, 2020 at 05:18 pmContents1 create:2 extracting:3 testing/viewing:4 Errors:5 Spaces in your filenames? create: tar -cvf mystuff.tar mystuff/ tar -czvf mystuff.tgz mystuff/ extracting:

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply