Search This Blog

Monday 8 August 2016

How to extend Root Partition in LVM


I had an adhoc plan to install latest version of OEM13C on my existing RAC VM’s instead of creating a dedicated machine for OEM. But, Root filesystem space about to exhaust and I felt there is no room for one Repository DB. Initially I added 20GB of normal disks to each of the VM’s and Just followed the below steps to extend the root partition.

[root@vm2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_vm1-lv_root
                       36G   25G  8.6G  75% /
tmpfs                  12G  1.6G   11G  14% /dev/shm
/dev/sda1             485M  110M  351M  24% /boot

Root partition has only 8.6 GB of free space; I am going to extend this now.
Newly added disk sdl

Disk /dev/sdl: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Logical Volume information

[root@vm2 ~]# lvs
  LV      VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_root vg_vm1 -wi-ao---- 35.57g
  lv_swap vg_vm1 -wi-ao----  3.94g

Follow the below steps to create partition on the new disk and change partition type from Linux to LVM(8e)

[root@vm2 ~]# fdisk /dev/sdl
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6d8ac917.
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)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

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.

My already mounted filesystem is of type ext4.  So, formatting the newly created partition using the below command.

[root@vm2 ~]# mkfs.ext4 /dev/sdl1
mke2fs 1.43-WIP (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Initialize the newly created partition as physical volume
[root@vm2 ~]# pvcreate /dev/sdl1
  Physical volume "/dev/sdl1" successfully created

Check the Volume Groups using the below command

[root@vm2 ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  vg_vm1   1   2   0 wz--n- 39.51g    0

Extend the new Volume Group with new Physical Volume

[root@vm2 ~]# vgextend vg_vm1 /dev/sdl1
  Volume group "vg_vm1" successfully extended

Extend the Logical Volume (lv_root) with all Free space of VG.

[root@vm2 ~]# lvextend -l +100%FREE /dev/vg_vm1/lv_root
  Size of logical volume vg_vm1/lv_root changed from 35.57 GiB (9106 extents) to 55.56 GiB (14224 extents).
  Logical volume lv_root successfully resized.

Finally Resize the Filesystem

[root@vm2 ~]# resize2fs /dev/vg_vm1/lv_root
resize2fs 1.43-WIP (20-Jun-2013)
Filesystem at /dev/vg_vm1/lv_root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
Performing an on-line resize of /dev/vg_vm1/lv_root to 14565376 (4k) blocks.
The filesystem on /dev/vg_vm1/lv_root is now 14565376 blocks long.

Verify the filesystem size

[root@vm2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_vm1-lv_root
                       55G   25G   28G  48% /
tmpfs                  12G  1.6G   11G  14% /dev/shm
/dev/sda1             485M  110M  351M  24% /boot
[root@vm2 ~]# lvs
  LV      VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_root vg_vm1 -wi-ao---- 55.56g
  lv_swap vg_vm1 -wi-ao----  3.94g
[root@vm2 ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  vg_vm1   2   2   0 wz--n- 59.50g    0










No comments:

Post a Comment