Mir Sayeed Hassan – Oracle Blog

Oracle DBA – Tips & Techniques | Learn with real-time examples

  • Translate

  • It’s Me






  • My Certificates

  • Links

    My Acclaim Certification : Credly Profile
    My Oracle ACE Pro Profile

  • Achievements

    Awarded Top 100 Oracle Blogs from Worldwide - #RANK 39
  • VISITORS COUNT

  • Verified International Academic Qualification from World Education Service (WES)

    Verified International Academic Qualification from World Education Service (WES)

  • Jobs

How to Add a New LVM disk into existing Oracle Linux Server

Posted by Mir Sayeed Hassan on May 6th, 2020

How to add a new LVM disk into existing Oracle Linux Server

LVM (Logical Volume Management)  – It provides a flexible and high-level approach to managing disk space into the Linux Server.

Volume Group (VG) – It consists of the raw disk which holds one or more logical volumes &  physical volumes. 

Physical Volume (PV) – It represents a storage device.

Logical Volume (LV) – It’s equivalent to a disk partition & contain a file system.

 

Check the current disk status 

[root@DB ~]# df -h

Filesystem                 Size    Used   Avail   Use%   Mounted on
/dev/mapper/vg_db-root     22G     12G    9.1G    56%    /
tmpfs                      1.8G    76K    1.8G     1%    /dev/shm
/dev/sda1                  477M    79M    370M    18%    /boot

Find the current number of disk allocated to server

[root@DB ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0004b858

  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        3917    30944256   8e  Linux LVM

Disk /dev/mapper/vg_db-root: 23.3 GB, 23295164416 bytes
255 heads, 63 sectors/track, 2832 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_db-swap: 8388 MB, 8388608000 bytes
255 heads, 63 sectors/track, 1019 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

The storage team has added new disk into the this server, Scan & detect the new disk 

[root@DB ~]# echo "- - -" > /sys/class/scsi_host/host
host0/ host1/ host2/ 
[root@DB ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@DB ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@DB ~]# echo "- - -" > /sys/class/scsi_host/host2/scan

Check the status of the disk allocation

[root@DB ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0004b858

   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        3917    30944256   8e  Linux LVM

Disk /dev/mapper/vg_db-root: 23.3 GB, 23295164416 bytes
255 heads, 63 sectors/track, 2832 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_db-swap: 8388 MB, 8388608000 bytes
255 heads, 63 sectors/track, 1019 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: 75.2 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 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

Note:

We have allocated 75G into this server to add into it 

Create the partition of the new disk as LVM with fdisk command on “/dev/sdb”

[root@DB ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x0128a32f.
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): 1
First cylinder (1-9137, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-9137, default 9137): 
Using default value 9137
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): p
Disk /dev/sdb: 75.2 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 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: 0x0128a32f

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        9137    73392921   8e  Linux LVM

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Now verify the disk that has been partition

[root@DB ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0004b858

   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        3917    30944256   8e  Linux LVM

Disk /dev/mapper/vg_db-root: 23.3 GB, 23295164416 bytes
255 heads, 63 sectors/track, 2832 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_db-swap: 8388 MB, 8388608000 bytes
255 heads, 63 sectors/track, 1019 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: 75.2 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 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: 0x0128a32f
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        9137    73392921   8e  Linux LVM

Note: As per the above verification, The /dev/sdb is partition with LVM.

Create a physical volume using PVCREATE command.

[root@DB ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

Display the size of the physical volume (PV)

[root@DB ~]# pvdisplay /dev/sdb1

  "/dev/sdb1" is a new physical volume of "69.99 GiB”
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               69.99 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               qLmiO1-kd1E-H3k6-xVJG-txZi-XlI2-cioSLw

Create volume group (VG)

Note:

Here we have name vg name as “u02”

[root@DB ~]# vgcreate u02 /dev/sdb1
  Volume group "u02" successfully created

Display the details of volume group created

[root@DB ~]# vgdisplay u02

  --- Volume group ---
  VG Name               u02
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               69.99 GiB
  PE Size               4.00 MiB
  Total PE              17917
  Alloc PE / Size       0 / 0   
  Free  PE / Size       17917 / 69.99 GiB
  VG UUID               27KxKv-FAbF-uRdO-ioBY-OW2F-ZdXe-DMXCRU

Create logical volume with “u02” name

[root@DB ~]# lvcreate -n u02 -l 100%FREE u02
  Logical volume "u02" created.

Verify the logical volume (LV)

[root@DB ~]# lvs

  LV   VG    Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  u02  u02   -wi-a----- 69.99g                                                    
  root vg_db -wi-ao---- 21.70g                                                    
  swap vg_db -wi-ao----  7.81g   
[root@DB ~]# lvdisplay 

  --- Logical volume ---
  LV Path                /dev/u02/u02
  LV Name                u02
  VG Name                u02
  LV UUID                3DkAqO-FD7J-cbdI-hawM-5Cuu-LYxF-OpxGGt
  LV Write Access        read/write
  LV Creation host, time DB, 2020-05-04 13:53:52 +0430
  LV Status              available
  # open                 0
  LV Size                69.99 GiB
  Current LE             17917
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2

Format the Logical Volums (LV’s) to ext4 format

[root@DB ~]# mkfs.ext4 /dev/u02/u02 

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
4587520 inodes, 18347008 blocks
917350 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
560 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, 7962624, 11239424
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

Finally create a /u02 directory in “/“ with root login & mount the logical volume on boot.

Create a “/u02” directory with root login 

[root@testdb /]# mkdir /u02

Mount the “/u02” directory 

[root@DB ~]# mount /dev/u02/u02 /u02/

Verify the New disk allocated to existing server with LVM.

[root@DB ~]# df -h 

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_db-root
                       22G   12G  9.1G  56% /
tmpfs                 1.8G   76K  1.8G   1% /dev/shm
/dev/sda1             477M   79M  370M  18% /boot
/dev/mapper/u02-u02    69G   52M   66G   1% /u02

Note: 

Make sure you will add this entries into the “/etc/fstab”, Its important as if the server gets reboots.

=====Hence tested & verified in our test env=====