How to use LVM (pvcreate, pvscan, pvdisplay, vgcreate, lvcreate)

Configurare noua (How To)

Situatie

LVM = Logical Volume Manager.

You can create logical partitions with LVM that can span across one or multiple physical hard drives.

Hard drives are divided into physical volumes, then those physical volumes are combined together to create the volume group and next the logical volumes which is created from the volume group.

Macro steps.

  • Identify the physical hard drives to be used and create Physical Volumes
  • Create the Volume Group from Physical Volumes
  • Create Logical Volumes from Volume Group

Solutie

Pasi de urmat

Identify the physical hard drives to be used and create Physical Volumes

  • fdisk -l
[root@OL4SAP001 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d0fac

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 73408511 35654656 8e Linux LVM

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

 

  • pvcreate
[root@OL4SAP001 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.

  • pvscan
[root@OL4SAP001 ~]# pvscan
PV /dev/sda2 VG vgroot00 lvm2 [34.00 GiB / 4.00 MiB free]
PV /dev/sdb lvm2 [50.00 GiB]
Total: 2 [84.00 GiB] / in use: 1 [34.00 GiB] / in no VG: 1 [50.00 GiB]
  • pvdisplay
 
[root@OL4SAP001 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vgroot00
PV Size 34.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 8704
Free PE 1
Allocated PE 8703
PV UUID HIgsAg-cTg6-oWMR-Bo3w-fQQ5-5ySM-kalVsW

"/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 ECenAQ-yUms-AQiF-UEYZ-Tk7s-eJqG-6EphAw

[root@OL4SAP001 ~]#

 

Create the Volume Group from Physical Volumes

  • vgcreate <vg_name> <pv_device>
[root@OL4SAP001 ~]# vgcreate vgoracleO19 /dev/sdb
Volume group "vgoracleO19" successfully created
  • vgdisplay
[root@OL4SAP001 ~]# vgdisplay -v vgoracleO19
--- Volume group ---
VG Name vgoracleO19
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 <50.00 GiB
PE Size 4.00 MiB
Total PE 12799
Alloc PE / Size 0 / 0
Free PE / Size 12799 / <50.00 GiB
VG UUID kj1kTA-6cSQ-9YGo-4yZ8-urw4-hSCc-dAGUsO

--- Physical volumes ---
PV Name /dev/sdb
PV UUID ECenAQ-yUms-AQiF-UEYZ-Tk7s-eJqG-6EphAw
PV Status allocatable
Total PE / Free PE 12799 / 12799

 

Create Logical Volumes from Volume Group

  • lvcreate
[root@OL4SAP001 ~]# lvcreate -l 2000 -n lvoracleO19 vgoracleO19
Logical volume "lvoracleO19" created.
  • lvdisplay
[root@OL4SAP001 ~]# lvdisplay vgoracleO19
--- Logical volume ---
LV Path /dev/vgoracleO19/lvoracleO19
LV Name lvoracleO19
VG Name vgoracleO19
LV UUID 2j3cIl-Ac3H-M0eI-h5Hz-L8ED-CYWS-4NsBqr
LV Write Access read/write
LV Creation host, time OL4SAP001.myenv.com, 2018-02-26 18:02:37 +0200
LV Status available
# open 0
LV Size 7.81 GiB
Current LE 2000
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 249:2

Create and mount the file system

  • mkfs
[root@OL4SAP001 ~]# mkfs.ext3 /dev/vgoracleO19/lvoracleO19 -L /oracle/O19
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=/oracle/O19
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
512064 inodes, 2048000 blocks
102400 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2097152000
63 block groups
32768 blocks per group, 32768 fragments per group
8128 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

[root@OL4SAP001 ~]#
  • assigning a Label with e2label (check the label with tune2fs)

/sbin/e2label /dev/vgoracleO19/lvoracleO19 /oracle/O19 <=== LABEL=/oracle/O19

— check :
/sbin/tune2fs -l /dev/vgoracleO19/lvoracleO19 | grep -i volume

[root@OL4SAP001 ~]# /sbin/e2label /dev/vgoracleO19/lvoracleO19 /oracle/O19
[root@OL4SAP001 ~]# /sbin/tune2fs -l /dev/vgoracleO19/lvoracleO19 | grep -i volume
Filesystem volume name: /oracle/O19
  • /etc/fstab
vi /etc/fstab 
add line : 
LABEL=/oracle/O19 /oracle/O19 ext3 acl,user_xattr 1 2
  • mount the new file system:
# mkdir -p /oracle/O19
# chown oracle:oinstall /oracle/O19
# mount /dev/vgoracleO19/lvoracleO19 /oracle/O19
# df

 

 

Tip solutie

Permanent

Voteaza

(3 din 5 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?