Table of Contents

Linux Commands#HDD

parted : How to use parted command in Linux with examples



Check Partition

parted -l
or
cat /proc/partitions 


parted command

Command Explanation Example
help help mkpart
print
quit
mklabel mklabel gpt ← You must use disk over 2TB.
mklabel msdos
mkpart mkpart primary 0 100%
mkpart primary ext4 0 100%
mkpart primary ext4 0% 100%
mkpart Linux 4096s 100%
mkpart data xfs 326G 100%
rm rm NUMBER
rm 1
mkpartfs
mkfs
check
cp
select
set set 1 lvm on ← If you use LVM.

Check partition

# parted /dev/DEVICE
(parted) print

Make partition

Making over 2TB partition

# parted /dev/sdc
(parted) mklabel gpt  <- over 2TB
(parted) print
(parted) mkpart primary 0 100%
(parted) print
(parted)quit

# mkfs -t ext4 /dev/sdc1   <- It takes a long time.

LVM

You need the 'set 1 lvm on'.

# parted /dev/sdc1
(parted) mklabel gpt           <- if you use over 2.5 partition.
(parted) unit GB     <-  change GB unit
(parted) mkpart primary 0 8590
(parted) set 1 lvm on
(parted) print

# pvcreate /dev/mapper/mpath0p1
# pvs

# vgcreate VG_DATA /dev/mapper/mpath0p1
# vgs
# vgdisplay  |grep "VG Name"
# vgdisplay  |grep "Free"
# vgdisplay  |grep "Total PE"

# lvcreate -l 127998  VG_DATA 
# lvs

# mkfs -t ext4 /dev/VG_DATA/lvol0     <- It takes a long time.
# mount /dev/VG_DATA/lvol0 /mnt