Create Partition on New Disk using Parted on CentOS


Scenario: Create partition and Volume Group 60GB size from 100GB disk on new disk using Parted on CentOS
System: CentOS/RHEL 6 or 7

Steps:
Show new disk:
# fdisk -l | grep sd

[root@server ~]# fdisk -l | grep sd
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 81797119 39848960 8e Linux LVM
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
[root@server ~]#


We found new disk is /dev/sdb with total size 100GB

Create new Partition /dev/sdb1 in /dev/sdb using parted.
# parted /dev/sdb

[root@server ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? y
(parted) print free
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
 32.3kB 107GB 107GB Free Space

(parted) mkpart
Partition type? primary/extended? p
File system type? [ext2]?
Start? 0%
End? 100%
(parted) print free
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
 32.3kB 1049kB 1016kB Free Space
 1 1049kB 107GB 107GB primary

(parted) q
Information: You may need to update /etc/fstab.

[root@server ~]#
[root@server ~]# fdisk -l | grep sd
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
/dev/sdb1 2048 209715199 104856576 83 Linux
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 81797119 39848960 8e Linux LVM
[root@server ~]#

Found the new partition is /dev/sdb1

Create new Volume Group from new partition /dev/sdb1.

[root@server ~]# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created.
[root@server ~]# vgcreate VolNFS /dev/sdb1
 Volume group "VolNFS" successfully created
[root@server ~]# vgs
 VG #PV #LV #SN Attr VSize VFree
 VolGroup 1 5 0 wz--n- 38.00g 0
 VolNFS 1 0 0 wz--n- <100.00g <100.00g
[root@server ~]#

Create new 60GB size Logical Volume from VolNFS with name lv_nfs then format as xfs

[root@server ~]# lvcreate -L +60G -n lv_nfs VolNFS
 Logical volume "lv_nfs" created.
[root@server ~]# lvdisplay | grep nfs
 LV Path /dev/VolNFS/lv_nfs
 LV Name lv_nfs
[root@server ~]# mkfs.xfs /dev/VolNFS/lv_nfs
meta-data=/dev/VolNFS/lv_nfs isize=512 agcount=4, agsize=3932160 blks
 = sectsz=512 attr=2, projid32bit=1
 = crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=15728640, imaxpct=25
 = sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=7680, version=2
 = sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@server ~]#

Create directory then mount the new LV then mount permanently in fstab.

[root@server ~]# mkdir /NFSdisk
[root@server ~]# mount /dev/VolNFS/lv_nfs /NFSdisk/
[root@server ~]# vi /etc/fstab
#New disk
/dev/VolNFS/lv_nfs xfs defaults 0 1

Check new partition type df -h and found successfully mounted on /NFSdisk

[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-root 10G 1.2G 8.9G 12% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.7M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 232M 783M 23% /boot
/dev/mapper/VolNFS-lv_nfs 60G 33M 60G 1% /NFSdisk
/dev/mapper/VolGroup-home 5.0G 33M 5.0G 1% /home
/dev/mapper/VolGroup-opt 10G 33M 10G 1% /opt
/dev/mapper/VolGroup-var 10G 189M 9.9G 2% /var
tmpfs 183M 0 183M 0% /run/user/0
[root@server ~]#

In Parted by type m will show all parted menu.

(parted) m
 align-check TYPE N check partition N for TYPE(min|opt)
 alignment
 help [COMMAND] print general help, or help on
 COMMAND
 mklabel,mktable LABEL-TYPE create a new disklabel (partition
 table)
 mkpart PART-TYPE [FS-TYPE] START END make a partition
 name NUMBER NAME name partition NUMBER as NAME
 print [devices|free|list,all|NUMBER] display the partition table,
 available devices, free space, all found partitions, or a particular
 partition
 quit exit program
 rescue START END rescue a lost partition near START
 and END
 rm NUMBER delete partition NUMBER
 select DEVICE choose the device to edit
 disk_set FLAG STATE change the FLAG on selected device
 disk_toggle [FLAG] toggle the state of FLAG on selected
 device
 set NUMBER FLAG STATE change the FLAG on partition NUMBER
 toggle [NUMBER [FLAG]] toggle the state of FLAG on partition
 NUMBER
 unit UNIT set the default unit to UNIT
 version display the version number and
 copyright information of GNU Parted
(parted)

Leave a Reply

Your email address will not be published. Required fields are marked *