EXTEND DISK ON CENTOS 7

check RAM

$ free -m -h

or

$ sudo dmidecode –type 17 | grep Size

or

$ sudo cat /proc/meminfo

check disk

$ df -h

or this is better

$ lsblk

 

How to use fdisk

$ sudo fdisk /dev/sda

 Command (m for help): m
 Command action
 a toggle a bootable flag
 b edit bsd disklabel
 c toggle the dos compatibility flag
 d delete a partition
 g create a new empty GPT partition table
 G create an IRIX (SGI) partition table
 l list known partition types
 m print this menu
 n add a new partition
 o create a new empty DOS partition table
 p print the partition table
 q quit without saving changes
 s create a new empty Sun disklabel
 t change a partition's system id
 u change display/entry units
 v verify the partition table
 w write table to disk and exit
 x extra functionality (experts only)

 

Let’s Start!

1- we have sda1, sda1 now we will have sda3 partition. Type command n

 Command (m for help): n
 Partition type:
 p primary (2 primary, 0 extended, 2 free)
 e extended
 Select (default p): p
 Partition number (3,4, default 3): 3
 First sector (33554432-104857599, default 33554432): 33554432
 Last sector, +sectors or +size{K,M,G} (33554432-104857599, default 104857599):
 Using default value 104857599
 Partition 3 of type Linux and of size 34 GiB is set

 

2- Let’s continue by looking the partitions, type command p (we are still in fdisk console):

 Command (m for help): p
 Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
 Units = sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk label type: dos
 Disk identifier: 0x0000d963
 Device Boot Start End Blocks Id System
 /dev/sda1 * 2048 1026047 512000 83 Linux
 /dev/sda2 1026048 33554431 16264192 8e Linux LVM
 /dev/sda3 33554432 104857599 35651584 83 Linux

 

3- As you can see we have created a sda3 partition with system type Linux.

To change it to Linux LVM, type command t:

 Command (m for help): t
 Partition number (1-3, default 3): 3
 Hex code (type L to list all codes): L
 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
 4 FAT16 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
 a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
 b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
 c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
 e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
 f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
 14 Hidden FAT16 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
 1e Hidden W95 FAT1 80 Old Minix
 Hex code (type L to list all codes): 8e
 Changed type of partition 'Linux' to 'Linux LVM'

 

4- Let’s list again all the partitions, type command p:

Command (m for help): p
 Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
 Units = sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk label type: dos
 Disk identifier: 0x0000d963
 Device Boot Start End Blocks Id System
 /dev/sda1 * 2048 1026047 512000 83 Linux
 /dev/sda2 1026048 33554431 16264192 8e Linux LVM
 /dev/sda3 33554432 104857599 35651584 8e Linux LVM

 

5- save and exit, type command w

 Command (m for help): w
 The partition table has been altered!

6- we are not done yet, let’s reboot to get affected

$ sudo reboot

7- check the partition we have created using fdisk

$ sudo fdisk -l /dev/sda

 Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
 Units = sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk label type: dos
 Disk identifier: 0x0000d963
 Device Boot Start End Blocks Id System
 /dev/sda1 * 2048 1026047 512000 83 Linux
 /dev/sda2 1026048 33554431 16264192 8e Linux LVM
 /dev/sda3 33554432 104857599 35651584 8e Linux LVM

It seems that we are ok!

8- Assuming you created partition /dev/sda3, let’s now create the physical volume in that partition:

$ sudo pvcreate /dev/sda3
Physical volume “/dev/sda3” successfully created

9- This will give you the info on your current Volume Group. Note down the entry next to “VG Name”.

That’s your Volume Group name. centos_px1 is your volume group name here for db1 machine

$ sudo vgdisplay
$ sudo vgextend centos_px1 /dev/sda3
Volume group “centos_px1” successfully extended

Hint: Keep in mind
If you get a message saying /dev/sda3 could not be added to your Volume Group, you need to remove the physical volume and recreate it. Metadata might have gotten corrupt and thus the volume cannot be added to your Volume Group. So just do:

$ pvremove /dev/sda3

And then again:

$ pvcreate /dev/sda3

10- Let us check the size of a Volume Group now using vgs (you can skip this part, only to make sure).

$ sudo vgs
centos_px1 2 2 0 wz–n- 49.50g 34.00g

We can even see which PV are used to create particular Volume group using.

$ sudo pvscan

 PV /dev/sda2 VG centos_px1 lvm2 [15.51 GiB / 0 free]
 PV /dev/sda3 VG centos_px1 lvm2 [34.00 GiB / 34.00 GiB free]
 Total: 2 [49.50 GiB] / in use: 2 [49.50 GiB] / in no VG: 0 [0 ]

Here, we can see which Volume groups are under Which Physical Volumes. We have just added one pv and its totally free.

$ sudo lvdisplay

11- For getting the available Physical Extend size run again vgdisplay

$ sudo vgdisplay

You can see that we have 34.00 GiB free that equals 8703 PE, we will use 8703 in next extension step

--- Volume group ---
 VG Name centos_px1
 System ID
 Format lvm2
 Metadata Areas 2
 Metadata Sequence No 4
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 2
 Open LV 2
 Max PV 0
 Cur PV 2
 Act PV 2
 VG Size 49.50 GiB
 PE Size 4.00 MiB
 Total PE 12673
 Alloc PE / Size 3970 / 15.51 GiB
 Free PE / Size 8703 / 34.00 GiB
 VG UUID 3MwSIC-jtsW-GWd8-Vrw5-flMk-YP8r-n2z4qO

12- Let’s extend the logical volume by X GBs:

$ sudo lvextend -l +8703 /dev/centos_px1/root

Size of logical volume centos_px1/root changed from 13.91 GiB (3560 extents) to 47.90 GiB (12263 extents).
Logical volume root successfully resized

13 – Finally after Extending, we need to re-size the file-system using xfs_growfs

don’t use resize2fs, instead use ifs_growfs for CentOS 7. resize2fs fails in CentOS 7

$ sudo xfs_growfs /dev/centos_px1/root

14 – check out if extended

$ df -h or $ sudo lvdisplay

You will see that, it is expanded to 47.90 GiB

15- Finally reboot your server

$ sudo reboot

CHEERS!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s