• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

Parted commands in Linux with examples

{{postValue.id}}

Linux ‘ Parted’ Commands to Create, Delete and Rescue Disk Partitions

Parted is a command line tool that helps to manage the hard disk partitions. The Linux ‘ Parted’ Commands that are used to Create, delete and Rescue Disk Partitions is explained in this article.

To Install Parted on Linux

Parted is a pre-installed tool and if it is not available install it by using the following commands.

On Fedora 22+ versions

# dnf install parted


On Debian/Ubuntu systems

$ sudo apt-get install parted


On RHEL/CentOS and Fedora

[root@linuxhelp ~]# yum install parted -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package parted.x86_64 0:3.1-17.el7 will be updated
--->  Package parted.x86_64 0:3.1-23.el7 will be an update
.
.
.
  Verifying  : parted-3.1-17.el7.x86_64                                                                                                 2/2 

Updated:
  parted.x86_64 0:3.1-23.el7                                                                                                                

Complete!

To use parted command to manage partition

Run the following command, to manage partition. If you run parted command without any argument means it will take the default first hard disk of your system.

[root@linuxhelp ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type ' help'  to view a list of commands.
(parted)

To List Linux Disk Partitions

Run the following print command to list the partition of the specific hard disk and model.

(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  525MB   524MB   primary  xfs             boot
 2      525MB   2622MB  2097MB  primary  linux-swap(v1)
 3      2622MB  21.5GB  18.9GB  primary  xfs


To exit from parted type quit command.

(parted) quit                                                             
[root@linuxhelp ~]#

To use parted on specific hard drive

Now run the parted command with the hard disk path to manage the partition on the particular hard disk.

[root@linuxhelp ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type ' help'  to view a list of commands.
(parted) print
Error: /dev/sdb: unrecognised disk label
Model: VMware, VMware Virtual S (scsi)                                    
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
(parted)


Above example shows the hard drive currently has no partition created.

To Create Primary or Logical Partition in Linux

To generate primary or logical disk partitions use parted. Check for the disk before starting partition using print statement.

Now create a new label for the hard disk.

(parted) mklabel msdos


Use mkpart to create partition. The units are in MB so to generate 10 GB start the partition from 1 to 10000.

(parted) mkpart                                                           
Partition type?  primary/extended? primary                                
File system type?  [ext2]? ext4                                           
Start? 1                                                                  
End? 10000
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.0GB  9999MB  primary


Now exit from parted and run the following command to format partition in ext4 file system.


[root@linuxhelp ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
610800 inodes, 2441216 blocks
122060 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
75 block groups
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done


Important: While executing the above command select the correct disk where the partition to be done.

Now verify our results, by printing the partition table on our secondary disk. Under file system column, ext4 or the file system type that you have decided to use for your partition:


[root@linuxhelp ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type ' help'  to view a list of commands.
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.0GB  9999MB  primary  ext4

To Change Linux Partition Flag

The various flags that supports Partition are as follows.

lvm
lba
legacy_boot
swap
hidden
raid
irst
esp
palo
boot
root

Use ' set' statement inside parted to alter flag settings.

(parted) set 1 boot on
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.0GB  9999MB  primary  ext4         boot


It sets the value of boot flag to ' on' in the partition 1. Check the resultant by viewing print command.

To Delete Linux Partition

Use rm command to remove the disk partitions. First get the number of the disk by running print command.


(parted) rm 1                                                             
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End  Size  Type  File system  Flags

To Rescue Linux Disk Partition

' rescue' command is used to recover the lost partition within the starting and end point and stores them.

(parted) rescue
Start? 1                                                                  
End? 10000                                                                
searching for file systems... 1%        
(time left 02:20)Information: 
A ext4 primary partition was found at 1049kB ->  10.0GB.  
Do you want to add it to the partition table?Yes/No/Cancel? yes                                                      
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.0GB  9999MB  primary  ext4
boot

Tags:
sebastian
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

resizepart not working in 2.1 edition. why it so?

A

Version 2.1 is an older one and the option in there is called “resize”. See below: $ parted -v parted (GNU parted) 2.1 $ parted -h | grep resize resize NUMBER START END resize partition NUM

Q

I tried to resize my primary partition and it worked, the only problem i run into now is that linux thinks the whole partition is full but I know it’s all free space… How can I allocate this

A

Do you mean that the new partition is showed as allocated? If the whole partition is free, did you try to format it? Alternatively, you may try to run resize2fs on the partition you are resiz

Q

is there any alternative tool for it?

A

yeah , there is , some are 1.GParted 2.EASEUS Partition Master 3.gnome-disk-utility 4.Disk Utility

Q

Why the parted commands are used?

A

Parted Command to Manage Linux Disk Partitions.
Check Parted Command Version.
Check Linux Partitions.
Select Different Disk.

Q

By this command you can view the ported?

A

Create Primary or Logical Linux Partitions.
Verify Disk Partition Filesystem.
Find Linux Partition Number.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help legeek ?
Installation of the call center module

hello

I wish to install a call center in virtual with issabel, I downloaded the latest version of it , but I don' t arrive to install the call center module in issabel. please help me

thanks!

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.