disk partition SIZE increase: RHEL6 RHEL7 inside VM

for RHEL6 or CentOS ONLY
    for debian flavor refer to this:
                http://www.turnkeylinux.org/blog/extending-lvm

vmWare KBNote Increasing the size of a disk partition (1004071):
      and Extending Logical Volume in a RHEL Virtual Machine(1006371)


0. Introduction on LVM , XFS

PV[s] (Physical Volumes) -> VG[s] (Volume Groups) -> LV[s] (Logical Volumes) -> Filesystems.
          i.e you pvcreate to =>  vgextend => lvextend OR lvcreate


Rhel-7 and centos 7 use XFS (extended file system). use "xfs_create" to add new disks/partitions.


1. Tried "parted resize "

[root@fts-vm-dev ~]# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
1      1049kB  525MB   524MB   primary  ext4         boot
2      525MB   21.5GB  20.9GB  primary               lvm

(parted) resize 2 525MB 40GB
WARNING: you are attempting to use parted to operate on (resize) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Error: Could not detect file system.

2. Tried system-config-lvm  did not work.

yum install system-config-lvm

System-config-lvm brings GUI, does not help much.

3.   vgdisplay
 --- Volume group ---
 VG Name               VolGroup
 System ID

 VG Size               19.51 GiB
 PE Size               4.00 MiB
 Total PE              4994
 Alloc PE / Size       4994 / 19.51 GiB
 Free  PE / Size       0 / 0
 VG UUID               rL4Ayd-6aGB-tUAz-zX7Y-zDJc-fVcg-2j5fmB
4. vgdisplay VolGroup
5. Fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes
….
  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       20480    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1-40960, default 1): 20481
Last cylinder, +cylinders or +size{K,M,G} (20481-40960, default 40960): 40960

Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes
...
  Device Boot      Start         End      Bl8ocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       20480    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/sda3           20481       40960    20971520   83  Linux

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): L
….
8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt
….
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       20480    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/sda3           20481       40960    20971520   8e  Linux LVM

Command (m for help): w
Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

REBOOTED>
fdisk -l

[root@fts-vm-dev ~]# fdisk -l
…./dev/sda3           20481       40960    20971520   8e  Linux LVM

5.  1.  PvCREATE then PvExtend(for rhel7 only)
[root@fts-vm-dev ~]# pvcreate /dev/sda3
 Physical volume "/dev/sda3" successfully created
[root@fts-vm-dev ~]# vgdisplay
 --- Volume group ---
 VG Name               VolGroup
 System ID
…..
 Alloc PE / Size       4994 / 19.51 GiB
 Free  PE / Size       0 / 0
 VG UUID               rL4Ayd-6aGB-tUAz-zX7Y-zDJc-fVcg-2j5fmB

6. Vgextend n vgdisplay

[root@fts-vm-dev ~]# vgextend VolGroup /dev/sda3    <-- add new disk to volume group
 Volume group "VolGroup" successfully extended
[root@fts-vm-dev ~]# vgdisplay VolGroup

root@fts-vm-dev ~]# vgdisplay VolGroup
 --- Volume group ---
 VG Name               VolGroup

 Act PV                2
 VG Size               39.50 GiB
 PE Size               4.00 MiB
 Total PE              10113
 Alloc PE / Size       4994 / 19.51 GiB
 Free  PE / Size       5119 / 20.00 GiB
...
7.
[root@fts-vm-dev ~]# vgdisplay VolGroup | grep Free
 Free  PE / Size       5119 / 20.00 GiB

8. Fdisk -l shows
/dev/sda2             502       20480    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/sda3           20481       40960    20971520   8e  Linux LVM

9.  LOGICAL Volume


 9.1  Lvdisplay and  lvextend lvdisplay  --- Logical volume ---
 LV Path                /dev/VolGroup/lv_root  LV Name                lv_root
 VG Name                VolGroup
….vailable
 # open                 1
 LV Size                15.57 GiB
….
9.2.  lvextend -L+19.9G /dev/VolGroup/lv_root  Rounding size to boundary between physical extents: 19.90 GiB
 Extending logical volume lv_root to 35.47 GiB
 Logical volume lv_root successfully resized
[root@fts-vm-dev ~]# ext2online /dev/VolGroup/lv_root -bash: ext2online: command not found

10. Resize2fs
resize2fs -p /dev/VolGroup/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 3
Performing an on-line resize of /dev/VolGroup/lv_root to 9298944 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 9298944 blocks long.


RHEL7.x use xfs_growfs /dev/rhel_fts-rhel73-gold/root
i.e xfs_growfs /dev/<VG_name>/<lv_name>

NOt sure?? XFS or ext4 or ext3... use "file -s /dev/sda*"


[root@fts-stage ~]# xfs_growfs /dev/rhel_fts-rhel73-gold/root

Refer to: https://www.devops.zone/cloud-services/grow-ext4-or-xfs-partitions-to-its-maximum-size/
             https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html




-------  ADDENDUM ----

When we ADD a new disk from VMware web client or client, it is /dev/sdb

First do an :
1.  "fdisk /dev/sdb for new physical volume /dev/sdb1 to be created.
             ( follow previous step 5 )
2.  Then pvcreate on /dev/sdb1

3. vgdisplay in RHEL7.x is NOT VolGroup  :
         VG Name               rhel_fts-rhel73-gold
Hence:
[root@fts-vm-ci-2 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@fts-vm-ci-2 ~]# vgextend VolGroup /dev/sdb1
  Volume group "VolGroup" successfully extended
[root@fts-vm-ci-2 ~]# fdisk /dev/sdb   <== create an LVM

if you screw up, do an
 vgreduce rhel_fts-rhel73-gold /dev/sdb1 --> works

vgreduce rhel_fts-rhel73-gold /dev/sdb1
vgdisplay
vgcreate vg-for-sdb /dev/sdb
vgcreate vg-for-sdb /dev/sdb1
vgdisply
vgdisplay
lvdisplay
ll /dev/| more
lvcreate --size 64G lv-u01 /dev/vg-u01
lvcreate --size 64G --name lv-u01 /dev/vg-u01
lvcreate --size 64G --name lv-u01 /dev/vg-for-sdb
lvcreate --size 63.999G --name lv-u01 /dev/vg-for-sdb
lvcreate --size 63.99G --name lv-u01 /dev/vg-for-sdb
  (OR)
   vgreduce --removemissing VolGroup
 And USE:
system-config-lvm with Xwindows Turned on on SSH as
ssh -X root@host  
and "pvremove /dev/sdb1" to remove physical volumes. 

Adding NEW disk /dev/sdc1 100Gig size
   13  pvcreate /dev/sdc1   <-- 1. create physical volume
   14  vgdisplay
   15  lvdisplay
   16  pvdisplay
   17  partprobe
   18  exit
   19  partprobe
   20  xclock
   21  vgdisplay
   22  vgextend ol /dev/sdc1  <-- NOT extending, need to create
   23  vgdisplay
   24  man vgcreate
   25  man vgextend
   26  man vgreduce
   27  vgdisplay
   28  vgreduce /dev/sdc1
   29  pvdisplay
   30  vgreduce --help
   31  vgreduce ol /dev/sdc1   <-- corrections, remove new disk from vol group 'ol'

   32  vgdisplay
   33  vgcreate --help
   34  vgcreate vg-u01 /dev/sdc1    <-- 2. create volume group
   35  vgdisplay
   36  lvdisplay
   37  lvcreate --size 100G --name lv-u01 /dev/vg-u01 <-- /dev/vg-u01 from vgdisplay
   38  lvcreate --size 99.99G --name lv-u01 /dev/vg-u01  <-- 3. create logical volume
   39  lvdisplay

   41  mkfs.xfs /dev/vg-u01/lv-u01   <-- 4. make xfs file system

   46  mkdir /u01
   47  mount /dev/vg-u01/lv-u01 /u01   <-- 5. mount it
          mount displays a line as:  /dev/mapper/vg--u01-lv--u01 on /u01 type xfs <-- add this to /etc/fstab   SEE it adds a "-" after "vg" and "lv"
   48  du -h /u01
   49  vi /etc/fstab 
               ( link: https://www.certdepot.net/rhel7-use-vfat-ext4-xfs-file-systems/ )
[root@fts-sb-olx u01]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Jan  9 17:51:41 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/ol-root     /                       xfs     defaults        0 0
UUID=0f73a353-3b94-42ff-9b3a-9eb8731d92cd /boot                   xfs     defaults        0 0
/dev/mapper/ol-swap     swap                    swap    defaults        0 0
dev/mapper/vg--u01-lv--u01   /u01                  xfs     defaults        1 2   <-- 2 fschk at boot
The above line is INVALID on fstab
The mount command


Popular Posts