Linux: Extend vg (Virtual Group) with new harddisk

Task: One of my volume /u01 is full.  I need to expand the underlying volume  /dev/mapper/vg_Sem01-lv_oracle.  I want to add 50G.  A new harddisk /dev/sdb is added and is ready for use.


Check if the new harddisk /dev/sdb is detected by the Linux

[root@SEM01 ~]# fdisk -l

Disk /dev/sda: 80.5 GB, 80530636800 bytes
255 heads, 63 sectors/track, 9790 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesa
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001e9c8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        9791    78130176   8e  Linux LVM

Disk /dev/mapper/vg_Sem01-lv_root: 17.9 GB, 17909678080 bytes
255 heads, 63 sectors/track, 2177 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


Disk /dev/mapper/vg_Sem01-lv_swap: 8405 MB, 8405385216 bytes
255 heads, 63 sectors/track, 1021 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


Disk /dev/mapper/vg_Sem01-lv_oracle: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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


Disk /dev/sdb: 53.7 GB, 53687091200 bytes
64 heads, 32 sectors/track, 51200 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


List all the available physical volume

[root@SEM01 ~]# pvscan
  PV /dev/sda2   VG vg_Sem01   lvm2 [74.51 GiB / 0    free]
  Total: 1 [74.51 GiB] / in use: 1 [74.51 GiB] / in no VG: 0 [0   ]

only /dev/sda is available.  It is because the new harddisk is not formatted.


Add /dev/sdb to the pv list

[root@SEM01 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created

double check available pv again - pvscan

[root@SEM01 ~]# pvscan
  PV /dev/sda2   VG vg_Sem01     lvm2 [74.51 GiB / 0    free]
  PV /dev/sdb                       lvm2 [50.00 GiB]
  Total: 2 [124.51 GiB] / in use: 1 [74.51 GiB] / in no VG: 1 [50.00 GiB]

We can see that now /dev/sdb is on the list.

Add /dev/sdb into the volume group: /dev/mapper/vg_Sem01-lv_oracle

Before start of the job, display the details of all physical volume first. 
[root@SEM01 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_Sem01
  PV Size               74.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              19074
  Free PE               0
  Allocated PE          19074
  PV UUID               XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX


  "/dev/sdb" is a new physical volume of "50.00 GiB"

  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name
  PV Size               50.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX


Find out how many vg is in the system

[root@SEM01 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg_Sem01" using metadata type lvm2

[root@SEM01 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_Sem01
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               74.51 GiB
  PE Size               4.00 MiB
  Total PE              19074
  Alloc PE / Size       19074 / 74.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX


Add /dev/sdb into vg_Ssem01

[root@SEM01 ~]# vgextend  vg_Sem01 /dev/sdb
  Volume group "vg_Sem01" successfully extended


Use vgdisplay to check again.  There are new Free PE.

[root@SEM01 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_Sem01
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               124.50 GiB
  PE Size               4.00 MiB
  Total PE              31873
  Alloc PE / Size       19074 / 74.51 GiB
  Free  PE / Size       12799 / 50.00 GiB
  VG UUID               XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX


Use lvdisplay to display the current state of the logical volume

[root@SEM01 ~]# lvdisplay  /dev/vg_Sem01/lv_oracle
  --- Logical volume ---
  LV Path                /dev/vg_Sem01/lv_oracle
  LV Name                lv_oracle
  VG Name                vg_Sem01
  LV UUID                XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX
  LV Write Access        read/write
  LV Creation host, time SEM01.euicc.hksarg, 2013-09-06 10:31:09 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2


Add 12799 new free PE to lv_oracle

[root@SEM01 ~]# lvextend -l +12799 /dev/vg_Sem01/lv_oracle
  Extending logical volume lv_oracle to 100.00 GiB
  Logical volume lv_oracle successfully resized
[root@SEM01 ~]#



The logical volume became 100GB now

[root@SEM01 ~]# lvdisplay  /dev/vg_Sem01/lv_oracle
  --- Logical volume ---
  LV Path                /dev/vg_Sem01/lv_oracle
  LV Name                lv_oracle
  VG Name                vg_Sem01
  LV UUID                XXXXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXXXX
  LV Write Access        read/write
  LV Creation host, time SEM01.euicc.hksarg, 2013-09-06 10:31:09 +0800
  LV Status              available
  # open                 1
  LV Size                100.00 GiB
  Current LE             25599
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2


The file system will not resize automatically with the lv (Logical Volume).  The new space is not usable at this moment.

Online resize the file system

[root@SEM01 ~]# resize2fs  /dev/vg_Sem01/lv_oracle
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_Sem01/lv_oracle is mounted on /u01; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 7
Performing an on-line resize of /dev/vg_Sem01/lv_oracle to 26213376 (4k) blocks.
The filesystem on /dev/vg_Sem01/lv_oracle is now 26213376 blocks long.

check disk free now

[root@SEM01 ~]# df /u01
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_Sem01-lv_oracle
                     103208224  40331152  57635036  42% /u01

Now /u01 can use the new free space and the space utilization is dropped to a reasonable level.

Comments

Popular Posts