Parted – A useful information!
Recently I had to work on a “Parted” based server. Not always we’ll get chances to work on “parted” based servers. Hence I thought of documenting it. Parted is a command which helps you to modify hard-disk partitions. More than a command, it’s a GNU utility. Using Parted we can add, delete and edit partitions along with the file systems located on them.
More than that, suppose think of a criteria that you need to partition a 6TB hard-disk on a Linux server. Most possibly we’ll think of fdisk utility. I’ve to say sorry, because fdisk can’t partition hard-drives more than 2TB in a Linux server. Fdisk will parttion only upto 2TB and around 4TB will remain as unused space.
Hence, in that situation “parted” is the only solution. So, you can refer to this article if you need to partition a hard-drive which is greater than 2TB.
If you’re first time to “parted”, be careful in doing it because the changes are written to the disk immediately. So please make sure you’ve selected the correct disk before start working on it. Here in this example, the disk size is only 500 GB but I’m using parted to partition it.
First, we can check if “parted” is available on the server. For that we can use the following command:
You’ll get a similar output if you have parted command available.
If “parted” isn’t available on your server, you can install it using the following yum command in a RHEL server:
# yum install parted
Now, we can check the partitions available on the hard-drives. For that we can use “print” command in “parted” prompt. By-default, “parted” selects the first drive /dev/sda.
# parted print
This will also shows the model number of the hard-disk, size of the hard-disk, partition table and the partitions.
To quit the “parted” prompt, we can use “quit”. Also to switch to different hard-drives we can use “select” command.
# parted select /dev/sdb
Now, we can see how we can partition a hard-disk using “parted” command. Here, I’m going to partition /dev/sdb.
1. Set disk label.
We can use “mklabel” command to set the partition table to GPT. “GPT” means GUID partition table format. To set the disk label, enter the “parted” prompt and then use the following commands:
#parted select /dev/sdb mklabel gpt print ---> This is to verify whether gpt is set as the partition table.
2. Partitioning using “parted”
We can directly enter the /dev/sdb “parted” prompt or we can use “parted” command then “select /dev/sdb” to enter into it.
# parted /dev/sdb mkpart primary 0GB 500GB print
Here, as my hard-disk size is 500 GB, I’m using it as the end point. Use according to your requirement.
3. Format the partition
Now we can use “mkfs” to format it.
# mkfs.ext4 /dev/sdb1
4. Mounting the partition
Now, we can create a directory and mount it. In my case I’m using it as a backup drive.
# mkdir /backupx # mount /dev/sdb1 /backupx
For permanent mounting, we need to add it in /etc/fstab.
That’s it! Hope you like the article!
3 thoughts on “How to partition a hard drive using “parted” command?”
it is easy to understand. thank you very much
You’re most welcome, Prashantha!
Thanks for your help.
mkpart primary 0GB 500GB
can also be used with
mkpart primary 0% 100%