rhel6.5 online root partition volume group expansion

Keywords: Linux

  • Experimental environment

    Operating system type rhel6.5
    Virtual machine of KVM type

  • It is important to note that the root partition must be mounted using an extensible LVM volume group

  • Use the command df -h to view
[root@server6 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   18G  9.4G  7.1G  57% /
tmpfs                         487M     0  487M   0% /dev/shm
/dev/vda1                     485M   33M  427M   8% /boot

  • First you need to add a hard disk

  • Use the command to view the newly added hard disk with the size of 8G;
[root@server6 ~]# fdisk  -l

  • Key contents
  • To execute the partition command, you need to adjust the type to 8e
[root@server6 ~]# fdisk  -cu /dev/vdc 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xadcf4a9d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-16777215, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): 
Using default value 16777215

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

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

Calling ioctl() to re-read partition table.
Syncing disks.
  • Notify kernel to read partition table again
[root@server6 ~]# partx /dev/vdc
# 1:      2048- 16777215 ( 16775168 sectors,   8588 MB)
# 2:         0-       -1 (        0 sectors,      0 MB)
# 3:         0-       -1 (        0 sectors,      0 MB)
# 4:         0-       -1 (        0 sectors,      0 MB)
  • First make 'Physical Volume'
[root@server6 ~]# pvcreate /dev/vdc1 
  Physical volume "/dev/vdc1" successfully created
  • Use the command pvs to view
  • Add the made ones to the volume group
[root@server6 ~]# vgextend VolGroup /dev/vdc1 
  Volume group "VolGroup" successfully extended
  • View the size change of volume group through the command vgs
  • Expand logical volume group boundaries
[root@server6 ~]# lvextend -L +8G /dev/VolGroup/lv_root 
  Extending logical volume lv_root to 25.61 GiB
  Insufficient free space: 2048 extents needed, but only 2047 available
[root@server6 ~]# lvextend -l +2047 /dev/VolGroup/lv_root 
  Extending logical volume lv_root to 25.60 GiB
  Logical volume lv_root successfully resized
  • Perform boundary expansion for logical volume groups
[root@server6 ~]# resize2fs /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 = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/VolGroup/lv_root to 6711296 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 6711296 blocks long.
  • See the change of final result through df-h
[root@server6 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   26G  9.4G   15G  40% /
tmpfs                         487M     0  487M   0% /dev/shm
/dev/vda1                     485M   33M  427M   8% /boot
  • Screenshot of size comparison before and after

Posted by markmusicman on Thu, 02 Apr 2020 04:05:46 -0700