How to create and manage LVM on OpenSUSE leap 42.3

To create and manage LVM on OpenSUSE Leap 42.3

LVM is a widely-used technique and extremely flexible disk management scheme for deploying logical rather than physical storage. With LVM, system administrator can easily resize and extend the logical drive when it is required. In this tutorial, you will learn the method to create and manage LVM on OpenSUSE Leap 42.3

 

Creating and Managing  LVM

First, add new hardisk of any size and to view it use the following command.

linuxhelp:~ # fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x0003044e
Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1          2048  4177919  4175872    2G 82 Linux swap / Solaris
/dev/sda2  *    4177920  4997119   819200  400M 83 Linux
/dev/sda3       4997120 41943039 36945920 17.6G 83 Linux
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 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

 

Next, you need to create a new Partiton using fdisk tool and select partition type as LVM. Refer the following command. 

linuxhelp:~ # fdisk /dev/sdb

Welcome to fdisk (util-linux 2.30.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xf6c29730.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-6291455, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-6291455, default 6291455): +1G

Created a new partition 1 of type ' Linux'  and of size 1 GiB.

Command (m for help): p
Disk /dev/sdb: 3 GiB, 3221225472 bytes, 6291456 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
Disklabel type: dos
Disk identifier: 0xf6c29730

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 2099199 2097152   1G 83 Linux

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

Command (m for help): p
Disk /dev/sdb: 3 GiB, 3221225472 bytes, 6291456 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
Disklabel type: dos
Disk identifier: 0xf6c29730

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 2099199 2097152   1G 8e Linux LVM

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

 

 

And then, you need to initialize the partition /dev/sdb1 as an LVM physical volume by making use of the following command.

 linuxhelp:~ # pvcreate /dev/sdb1
  Physical volume " /dev/sdb1"  successfully created.
linuxhelp:~ # pvs
  PV         VG Fmt  Attr PSize PFree
  /dev/sdb1     lvm2 ---  1.00g 1.00g

 

After that you need to run    pvdisplay and pvscan commands in the following manner to display the properties of LVM. 

linuxhelp:~ # pvdisplay
  " /dev/sdb1"  is a new physical volume of " 1.00 GiB" 
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               1.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               CWNuoW-xfe6-A3DY-27oo-fXtL-nV9I-4VlWpx
linuxhelp:~ # pvscan
  PV /dev/sdb1                      lvm2 [1.00 GiB]
  Total: 1 [1.00 GiB] / in use: 0 [0   ] / in no VG: 1 [1.00 GiB]

 

After that, you need to create volume group name vg1 and add /dev/sdb1 partition into the group with the help of the following command. 

linuxhelp:~ # vgcreate vg1 /dev/sdb1
Volume group " vg1"  successfully created

 

After that, you need to create a logical volume as follows. 

linuxhelp:~ # lvcreate -n lv1 -l 100%FREE vg1
Logical volume " lv1"  created.


And display the created logical volumes   by running the following command. 

linuxhelp:~ # lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                3aT3Iz-Ap3n-e22r-XaKT-eU4B-t3kB-BjsEt3
  LV Write Access        read/write
  LV Creation host, time linuxhelp, 2017-12-05 16:49:25 +0530
  LV Status              available
  # open                 0
  LV Size                1020.00 MiB
  Current LE             255
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0



Later, make use of the mkfs command to format the newly created LVM as follows . 

linuxhelp:~ # mkfs.ext4 /dev/vg1/lv1
mke2fs 1.43.7 (16-Oct-2017)
Creating filesystem with 261120 4k blocks and 65280 inodes
Filesystem UUID: d348b933-25b9-4dc0-aed3-9c15095fc05a
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

 

And then, create the mount point and mount the new LVM   as follows. 

linuxhelp:~ # mkdir -p /data
linuxhelp:~ # mount /dev/vg1/lv1 /data/


Finally, verify the new disk layout with the help of the following command. 

linuxhelp:~ # df -h
Filesystem           Size  Used Avail Use% Mounted on
udev                 441M     0  441M   0% /dev
tmpfs                 92M  6.6M   85M   8% /run
/dev/sda3             16G   12G  3.4G  78% /
tmpfs                456M     0  456M   0% /dev/shm
tmpfs                5.0M  4.0K  5.0M   1% /run/lock
tmpfs                456M     0  456M   0% /sys/fs/cgroup
/dev/sda1            453M   48M  378M  12% /boot
tmpfs                 92M   16K   92M   1% /run/user/1000
/dev/mapper/vg1-lv1  988M  2.6M  919M   1% /data

 

With this, this tutorial on creating and managing LVM on OpenSUSE leap 42.3 comes to an end. 

FAQ
Q
which command to display the created logical volume?
A
display the created logical volumes by running the following command
# lvdisplay
Q
What is LVM? And what is the purpose of using this?
A
LVM is a widely-used technique and extremely flexible disk management scheme
for deploying logical rather than physical storage. With LVM, system administrator can
easily resize and extend
Q
Do I need a special lvm2 kernel module?
A
No. You need device-mapper. The lvm2 tools use device-mapper to interface
with the kernel and do all their device mapping (hence the name device-mapper).
As long as you have device-mapper,
Q
Is it possible to increase the logical volume on fly?
A
Yes.We can increase the logical volume without umount it.
Q
How to reduce the logical volume ? is it possible to reduce on fly?
A
No.You can’t reduce the logical volume on fly. Here is the steps to reduce the logical volume on redhat Linux.