LVM Configuration - RHEL 8 (EX294)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28
At a glance
Powered by AI
The document outlines the steps to create and remove LVM.

The steps include creating partitions, changing their type to LVM, creating physical volumes, creating a volume group and logical volumes.

You create physical volumes on partitions using pvcreate, then create a volume group using vgcreate which uses the physical volumes. Logical volumes are then created within the volume group.

How to Create LVM ?

Step-1 First verify about hardisk status and current partiions ?

[root@localhost ~]# lsblk


NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1000M 0 part /boot
├─sda2 8:2 0 14.7G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
└─sda4 8:4 0 1K 0 part
sdb 8:16 0 10G 0 disk
sr0 11:0 1 6.6G 0 rom
[root@localhost ~]#
[root@localhost ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 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: 0xf085a991

Device Boot Start End Sectors Size Id Type


/dev/sda1 * 2048 2050047 2048000 1000M 83 Linux
/dev/sda2 2050048 32770047 30720000 14.7G 83 Linux
/dev/sda3 32770048 36866047 4096000 2G 82 Linux swap /
Solaris
/dev/sda4 36866048 62914559 26048512 12.4G 5 Extended

Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 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

Step-2 Go in your hardisk and create paritition with any Size ?

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

Welcome to fdisk (util-linux 2.32.1).


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 0x7cc59cad.

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-20971519, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default
20971519): +2G

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

Command (m for help): n


Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (4196352-20971519, default 4196352):
Last sector, +sectors or +size{K,M,G,T,P} (4196352-20971519, default
20971519): +1G

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

Command (m for help): p


Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 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: 0x7cc59cad

Device Boot Start End Sectors Size Id Type


/dev/sdb1 2048 4196351 4194304 2G 83 Linux
/dev/sdb2 4196352 6293503 2097152 1G 83 Linux

Command (m for help):


Command (m for help): t
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): t


Partition number (1,2, default 2): 2
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: 10 GiB, 10737418240 bytes, 20971520 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: 0x7cc59cad

Device Boot Start End Sectors Size Id Type


/dev/sdb1 2048 4196351 4194304 2G 8e Linux LVM
/dev/sdb2 4196352 6293503 2097152 1G 8e Linux LVM

Command (m for help): w


The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost ~]# partprobe /dev/sdb

Step-3 Create the Physical Volume on these partitions

[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2


Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
[root@localhost ~]#
[root@localhost ~]# pvdisplay

"/dev/sdb1" is a new physical volume of "2.00 GiB"


--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID N2SAxr-1Fmh-u4lQ-cYBj-ObTQ-sSg1-s2HH9Z

"/dev/sdb2" is a new physical volume of "1.00 GiB"


--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID PQEOHl-Kusq-BJZm-fMdv-MOpa-A3sv-nTfXiC

[root@localhost ~]# pvs


PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 2.00g 2.00g
/dev/sdb2 lvm2 --- 1.00g 1.00g
Step-4 Now create Volume group

[root@localhost ~]# vgcreate myvg1 /dev/sdb{1,2}


Volume group "myvg1" successfully created
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 myvg1 lvm2 a-- <2.00g <2.00g
/dev/sdb2 myvg1 lvm2 a-- 1020.00m 1020.00m
[root@localhost ~]#
[root@localhost ~]# vgdisplay

--- Volume group ---


VG Name myvg1
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 2.99 GiB
PE Size 4.00 MiB
Total PE 766
Alloc PE / Size 0 / 0
Free PE / Size 766 / 2.99 GiB
VG UUID FWnJqQ-W7jO-tnf7-ANWT-c8Ni-5P7X-S0tYE1

[root@localhost ~]# vgs


VG #PV #LV #SN Attr VSize VFree
myvg1 2 0 0 wz--n- 2.99g 2.99g

Step-5 Create LVMs from this Volume group as per needs ?

[root@localhost ~]# lvcreate -L +1G -n mylv1 /dev/myvg1


Logical volume "mylv1" created.
[root@localhost ~]#
[root@localhost ~]# lvcreate -L +500M -n mylv2 /dev/myvg1
Logical volume "mylv2" created.
[root@localhost ~]#
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 2 2 0 wz--n- 2.99g 1.50g
[root@localhost ~]#
[root@localhost ~]# lvdisplay

--- Logical volume ---


LV Path /dev/myvg1/mylv1
LV Name mylv1
VG Name myvg1
LV UUID d6dxnG-xKZI-bicU-i3JW-1nGs-x8u1-Lc1pUV
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-09-01 00:37:04
+0530
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

--- Logical volume ---


LV Path /dev/myvg1/mylv2
LV Name mylv2
VG Name myvg1
LV UUID 5fm2n9-h4Cw-1XKe-zGwL-rsL2-k0VG-0x9I1n
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-09-01 00:37:41
+0530
LV Status available
# open 0
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

[root@localhost ~]# lvs


LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-a----- 1.00g
mylv2 myvg1 -wi-a----- 500.00m
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
Now Format the LVms ?

[root@localhost ~]# mkfs.xfs /dev/myvg1/mylv1


meta-data=/dev/myvg1/mylv1 isize=512 agcount=4, agsize=65536
blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1,
rmapbt=0
= reflink=1
data = bsize=4096 blocks=262144,
imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-
count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]#
[root@localhost ~]# mkfs.ext4 /dev/myvg1/mylv2
mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 512000 1k blocks and 128016 inodes
Filesystem UUID: 712cbf9b-214a-415f-86fc-4eb689c972a2
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done


Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

[root@localhost ~]#

mount these volumes on any directory ??

[root@localhost ~]# mkdir /lvm1


[root@localhost ~]#
[root@localhost ~]# mkdir /lvm2
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# mount /dev/myvg1/mylv1 /lvm1
[root@localhost ~]#
[root@localhost ~]# mount /dev/myvg1/mylv2 /lvm2
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vim /etc/fstab
UUID=8122cb63-c8c7-4cd2-81be-4b49081bc6dc / xfs
defaults 0 0
UUID=1a9e8a07-533d-4f49-b547-4b21e42230b2 /boot xfs
defaults 0 0
UUID=362eabfd-9108-40a1-ba82-3fbdeff793ac swap swap
defaults 0 0
/dev/myvg1/mylv1 /lvm1 xfs defaults 0 0
/dev/myvg1/mylv2 /lvm2 ext4 defaults 0 0

:wq!

[root@localhost ~]# systemctl daemon-reload


[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# mount -a
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv1 xfs 1014M 40M 975M 4% /lvm1
/dev/mapper/myvg1-mylv2 ext4 477M 2.3M 445M 1% /lvm2
[root@localhost ~]#

[root@localhost ~]# rpm -qa device-mapper


device-mapper-1.02.155-6.el8.x86_64
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ll /dev/mapper
total 0
crw-------. 1 root root 10, 236 Sep 1 00:37 control
lrwxrwxrwx. 1 root root 7 Sep 1 00:40 myvg1-mylv1 -> ../dm-0
lrwxrwxrwx. 1 root root 7 Sep 1 00:41 myvg1-mylv2 -> ../dm-1
[root@localhost ~]#

How to test LVM ?

[root@localhost ~]# du -sh /etc


29M /etc
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cp -rf /etc /lvm1
[root@localhost ~]#
[root@localhost ~]# cp -rf /etc /lvm2
[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv1 xfs 1014M 90M 925M 9% /lvm1
/dev/mapper/myvg1-mylv2 ext4 477M 28M 420M 7% /lvm2

[root@localhost ~]# lsblk


NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1000M 0 part /boot
├─sda2 8:2 0 14.7G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
└─sda4 8:4 0 1K 0 part
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 2G 0 part
│ ├─myvg1-mylv1 253:0 0 1G 0 lvm /lvm1
│ └─myvg1-mylv2 253:1 0 500M 0 lvm /lvm2
└─sdb2 8:18 0 1G 0 part
sr0 11:0 1 6.6G 0 rom

How to Extend LVM Size ?

First task:- If Filesystem type is in XFS -------- Till -rhel-7

root@localhost ~]# lvextend -L +200M /dev/myvg1/mylv1


[root@localhost ~]# xfs_growfs /dev/myvg1/mylv1
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv2 ext4 477M 28M 420M 7% /lvm2
/dev/mapper/myvg1-mylv1 xfs 1.2G 71M 1.2G 6% /lvm1
[root@localhost ~]#

OR

Note: IN rhel8 you will run lvresize command directly rather then
lvextend and xfs_growfs

Second Task task:- If Filesystem type is in Ext-2, Ext-3 & Ext-4 -----
--Support in Rhel-7 + RHEL8

[root@localhost ~]# lvextend -L +300M /dev/myvg1/mylv2


Size of logical volume myvg1/mylv2 changed from 500.00 MiB (125
extents) to 800.00 MiB (200 extents).
Logical volume myvg1/mylv2 successfully resized.
[root@localhost ~]#
[root@localhost ~]# resize2fs /dev/myvg1/mylv2
resize2fs 1.44.3 (10-July-2018)
Filesystem at /dev/myvg1/mylv2 is mounted on /lvm2; on-line resizing
required
old_desc_blocks = 4, new_desc_blocks = 7
The filesystem on /dev/myvg1/mylv2 is now 819200 (1k) blocks long.

[root@localhost ~]# df -Th


Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv2 ext4 767M 29M 698M 4% /lvm2
/dev/mapper/myvg1-mylv1 xfs 1.2G 71M 1.2G 6% /lvm1
[root@localhost ~]#

How to Extend LVM Size by using LVRESIZE Command ?

[root@localhost ~]# lvresize -L 1400M -r /dev/myvg1/mylv1


Size of logical volume myvg1/mylv1 changed from 1.17 GiB (300
extents) to <1.37 GiB (350 extents).
Logical volume myvg1/mylv1 successfully resized.
meta-data=/dev/mapper/myvg1-mylv1 isize=512 agcount=5, agsize=65536
blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1,
rmapbt=0
= reflink=1
data = bsize=4096 blocks=313344,
imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-
count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 313344 to 358400
[root@localhost ~]#

[root@localhost ~]# lvresize -L 900M -r /dev/myvg1/mylv2


Size of logical volume myvg1/mylv2 changed from 800.00 MiB (200
extents) to 900.00 MiB (225 extents).
Logical volume myvg1/mylv2 successfully resized.
resize2fs 1.44.3 (10-July-2018)
Filesystem at /dev/mapper/myvg1-mylv2 is mounted on /lvm2; on-line
resizing required
old_desc_blocks = 7, new_desc_blocks = 8
The filesystem on /dev/mapper/myvg1-mylv2 is now 921600 (1k) blocks
long.

[root@localhost ~]# df -Th


Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv2 ext4 864M 29M 791M 4% /lvm2
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
[root@localhost ~]#

How to Reduce LVM Size ?

[root@localhost ~]# lvresize -L 600M -r /dev/myvg1/mylv2


Do you want to unmount "/lvm2" ? [Y|n] y
fsck from util-linux 2.32.1
/dev/mapper/myvg1-mylv2: 1902/229616 files (0.2% non-contiguous),
66054/921600 blocks
resize2fs 1.44.3 (10-July-2018)
Resizing the filesystem on /dev/mapper/myvg1-mylv2 to 614400 (1k)
blocks.
The filesystem on /dev/mapper/myvg1-mylv2 is now 614400 (1k) blocks
long.

Size of logical volume myvg1/mylv2 changed from 900.00 MiB (225


extents) to 600.00 MiB (150 extents).
Logical volume myvg1/mylv2 successfully resized.

[root@localhost ~]# df -Th


Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
/dev/mapper/myvg1-mylv2 ext4 574M 28M 515M 6% /lvm2
[root@localhost ~]#

[root@localhost ~]# lvresize -L 800M -r /dev/myvg1/mylv2


Size of logical volume myvg1/mylv2 changed from 600.00 MiB (150
extents) to 800.00 MiB (200 extents).
Logical volume myvg1/mylv2 successfully resized.
resize2fs 1.44.3 (10-July-2018)
Filesystem at /dev/mapper/myvg1-mylv2 is mounted on /lvm2; on-line
resizing required
old_desc_blocks = 5, new_desc_blocks = 7
The filesystem on /dev/mapper/myvg1-mylv2 is now 819200 (1k) blocks
long.

[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# lvresize -L 500M -r /dev/myvg1/mylv2
Do you want to unmount "/lvm2" ? [Y|n] y
fsck from util-linux 2.32.1
/dev/mapper/myvg1-mylv2: 1902/203200 files (0.2% non-contiguous),
62726/819200 blocks
resize2fs 1.44.3 (10-July-2018)
Resizing the filesystem on /dev/mapper/myvg1-mylv2 to 512000 (1k)
blocks.
The filesystem on /dev/mapper/myvg1-mylv2 is now 512000 (1k) blocks
long.
Size of logical volume myvg1/mylv2 changed from 800.00 MiB (200
extents) to 500.00 MiB (125 extents).
Logical volume myvg1/mylv2 successfully resized.
[root@localhost ~]#

[root@localhost ~]# df -Th


Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
[root@localhost ~]#

How to Extend Volume Group Size ?

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

Welcome to fdisk (util-linux 2.32.1).


Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n


Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (6293504-20971519, default 6293504):
Last sector, +sectors or +size{K,M,G,T,P} (6293504-20971519, default
20971519): +2G

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

Command (m for help): t


Partition number (1-3, default 3): 3
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: 10 GiB, 10737418240 bytes, 20971520 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: 0x7cc59cad

Device Boot Start End Sectors Size Id Type


/dev/sdb1 2048 4196351 4194304 2G 8e Linux LVM
/dev/sdb2 4196352 6293503 2097152 1G 8e Linux LVM
/dev/sdb3 6293504 10487807 4194304 2G 8e Linux LVM

Command (m for help): w


The partition table has been altered.
Syncing disks.

[root@localhost ~]# partprobe /dev/sdb


[root@localhost ~]#
[root@localhost ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created.
[root@localhost ~]#
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 myvg1 lvm2 a-- <2.00g 300.00m
/dev/sdb2 myvg1 lvm2 a-- 1020.00m 864.00m
/dev/sdb3 lvm2 --- 2.00g 2.00g
[root@localhost ~]#

[root@localhost ~]# vgextend myvg1 /dev/sdb3


Volume group "myvg1" successfully extended
[root@localhost ~]#
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 myvg1 lvm2 a-- <2.00g 300.00m
/dev/sdb2 myvg1 lvm2 a-- 1020.00m 864.00m
/dev/sdb3 myvg1 lvm2 a-- <2.00g <2.00g

[root@localhost ~]# vgs


VG #PV #LV #SN Attr VSize VFree
myvg1 3 2 0 wz--n- <4.99g 3.13g
[root@localhost ~]#

How to Activate or Deactivate any Volumes ?

[root@localhost ~]# df -Th


Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# umount /lvm2
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-a----- 500.00m
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# lvchange -an /dev/myvg1/mylv2
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi------- 500.00m

[root@localhost ~]# lvchange -ay /dev/myvg1/mylv2


[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
[root@localhost ~]#
[root@localhost ~]# mount -a
[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2

How to merge two Volume Group ?

Note:- First we will create one more Volume group to perform this
operation.

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

Welcome to fdisk (util-linux 2.32.1).


Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n


Partition type
p primary (3 primary, 0 extended, 1 free)
e extended (container for logical partitions)
Select (default e): e

Selected partition 4
First sector (10487808-20971519, default 10487808): Blank Enter
Last sector, +sectors or +size{K,M,G,T,P} (10487808-20971519, default
20971519): Blank Enter

Created a new partition 4 of type 'Extended' and of size 5 GiB.

Command (m for help): n


All primary partitions are in use.
Adding logical partition 5
First sector (10489856-20971519, default 10489856):
Last sector, +sectors or +size{K,M,G,T,P} (10489856-20971519, default
20971519): +2G

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

Command (m for help): t


Partition number (1-5, default 5): 5
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w


The partition table has been altered.
Failed to add partition 5 to system: Device or resource busy
The kernel still uses the old partitions. The new table will be used
at the next reboot.
Syncing disks.

[root@localhost ~]#

We need to reboot the machine here if we are using the fdisk command
but
if you will try same thing with parted command , will not give you the
errors.
Simple you can run #partprobe /dev/sdb { to update the partition
table }

after the reboot

next steps:----

[root@localhost ~]# partprobe /dev/sdb


[root@localhost ~]#
[root@localhost ~]# pvcreate /dev/sdb5
Physical volume "/dev/sdb5" successfully created.
[root@localhost ~]#
[root@localhost ~]# vgcreate myvg2 /dev/sdb5
Volume group "myvg2" successfully created
[root@localhost ~]#
[root@localhost ~]# lvcreate -L +1G -n mylv3 /dev/myvg2
Logical volume "mylv3" created.
[root@localhost ~]#
[root@localhost ~]# mkfs.xfs /dev/myvg2/mylv3
meta-data=/dev/myvg2/mylv3 isize=512 agcount=4, agsize=65536
blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1,
rmapbt=0
= reflink=1
data = bsize=4096 blocks=262144,
imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-
count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]#

[root@localhost ~]# mkdir /lvm3


[root@localhost ~]#
[root@localhost ~]# mount /dev/myvg2/mylv3 /lvm3
[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
/dev/sda1 xfs 994M 165M 830M 17% /boot
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg2-mylv3 xfs 1014M 40M 975M 4% /lvm3
[root@localhost ~]#

Now we can perform the Volume group merging operation ?

[root@localhost ~]# umount /lvm3


[root@localhost ~]#
[root@localhost ~]# lvchange -an /dev/myvg2/mylv3
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
mylv3 myvg2 -wi------- 1.00g
[root@localhost ~]#

[root@localhost ~]# lvs


LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
mylv3 myvg2 -wi------- 1.00g
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vgchange -an /dev/myvg2
0 logical volume(s) in volume group "myvg2" now active
[root@localhost ~]#
[root@localhost ~]# vgmerge /dev/myvg1 /dev/myvg2
Volume group "myvg2" successfully merged into "myvg1"
[root@localhost ~]#
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 4 3 0 wz--n- 6.98g <4.13g
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
mylv3 myvg1 -wi------- 1.00g
[root@localhost ~]#
[root@localhost ~]# lvchange -ay /dev/myvg1/mylv3

[root@localhost ~]# mount /dev/myvg1/mylv3 /lvm3


[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
/dev/sda1 xfs 994M 165M 830M 17% /boot
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv3 xfs 1014M 40M 975M 4% /lvm3
[root@localhost ~]#

[root@localhost ~]# vim /etc/fstab

dev/myvg1/mylv1 /lvm1 xfs defaults 0 0


/dev/myvg1/mylv2 /lvm2 ext4 defaults 0 0
/dev/myvg1/mylv3 /lvm3 xfs defaults 0 0

:wq!

[root@localhost ~]# mount -a


[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
/dev/sda1 xfs 994M 165M 830M 17% /boot
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv3 xfs 1014M 40M 975M 4% /lvm3

Next Task:-

Create a new LVM ?

Vgname must be: fedora

Lvnmae must be: redhat

1 PE : 8 MB

Total LVM Size: 20 LE

Format : ext3

mount : /lvm4

root@localhost ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).


Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n


All primary partitions are in use.
Adding logical partition 6
First sector (14686208-20971519, default 14686208):
Last sector, +sectors or +size{K,M,G,T,P} (14686208-20971519, default
20971519): +190M

Created a new partition 6 of type 'Linux' and of size 190 MiB.

Command (m for help): t


Partition number (1-6, default 6): 6
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w


The partition table has been altered.
Syncing disks.

[root@localhost ~]#
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# pvcreate /dev/sdb6
Physical volume "/dev/sdb6" successfully created.
[root@localhost ~]#

[root@localhost ~]# vgcreate -s 8M fedora /dev/sdb6


Volume group "fedora" successfully created
[root@localhost ~]#
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name fedora
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 184.00 MiB
PE Size 8.00 MiB
Total PE 23
Alloc PE / Size 0 / 0
Free PE / Size 23 / 184.00 MiB
VG UUID Pqen99-hDOf-ysXg-ObDV-3fIP-wDg3-eOu4Dy

[root@localhost ~]# lvcreate -l 20 -n redhat /dev/fedora


Logical volume "redhat" created.
[root@localhost ~]#
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/fedora/redhat
LV Name redhat
VG Name fedora
LV UUID AgFMDi-tuDF-s6yR-0GmO-tegA-V5bu-RL8lAi
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-09-01 01:49:26
+0530
LV Status available
# open 0
LV Size 160.00 MiB
Current LE 20
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3

[root@localhost ~]# mkfs.ext3 /dev/fedora/redhat


mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 163840 1k blocks and 40960 inodes
Filesystem UUID: 06fb5c34-2eea-4798-9c16-76b79438b84b
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Allocating group tables: done


Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

[root@localhost ~]#

[root@localhost ~]# mkdir /lvm4


[root@localhost ~]#
[root@localhost ~]# mount /dev/fedora/redhat /lvm4
[root@localhost ~]#
[root@localhost ~]# vim /etc/fstab

add this line bottom of this file

/dev/fedora/redhat /lvm4 ext3 defaults 0 0

:wq!

[root@localhost ~]# mount -a


[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0%
/sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
/dev/sda1 xfs 994M 165M 830M 17% /boot
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv3 xfs 1014M 40M 975M 4% /lvm3
/dev/mapper/fedora-redhat ext3 151M 1.6M 142M 2% /lvm4
[root@localhost ~]#

How to Recover any LVMs from any Restore Points ?

[root@localhost ~]# touch /lvm4/abc{1..3}


[root@localhost ~]#
[root@localhost ~]# ls /lvm4
abc1 abc2 abc3 lost+found
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# umount /lvm4
[root@localhost ~]#
[root@localhost ~]# lvremove /dev/fedora/redhat
[root@localhost ~]# lvremove /dev/fedora/redhat
Do you really want to remove active logical volume fedora/redhat?
[y/n]: y
Logical volume "redhat" successfully removed
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
mylv3 myvg1 -wi-ao---- 1.00g
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
fedora 1 0 0 wz--n- 184.00m 184.00m
myvg1 4 3 0 wz--n- 6.98g <4.13g
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vgcfgrestore -l /dev/fedora
.....................
...................
...................

File: /etc/lvm/archive/fedora_00004-1374339324.vg
VG name: fedora
Description: Created *before* executing 'lvremove
/dev/fedora/redhat'
Backup Time: Sun Sep 1 01:55:22 2019

File: /etc/lvm/backup/fedora
VG name: fedora
Description: Created *after* executing 'lvremove
/dev/fedora/redhat'
Backup Time: Sun Sep 1 01:55:22 2019
....................
......................
Note: Copy "before" indexing numbner and paste it into this
command
[root@localhost ~]# vgcfgrestore -f /etc/lvm/archive/fedora_00004-
1374339324.vg fedora

root@localhost ~]# vgs


VG #PV #LV #SN Attr VSize VFree
fedora 1 1 0 wz--n- 184.00m 24.00m
myvg1 4 3 0 wz--n- 6.98g <4.13g
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# lvchange -ay /dev/fedora/redhat
[root@localhost ~]#
[root@localhost ~]# mount -a
[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0%
/sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
/dev/sda1 xfs 994M 165M 830M 17% /boot
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv3 xfs 1014M 40M 975M 4% /lvm3
/dev/mapper/fedora-redhat ext3 151M 1.6M 142M 2% /lvm4
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ls /lvm4
abc1 abc2 abc3 lost+found
[root@localhost ~]#

How to Restore LVMs and Volume Group both at a time ?

[root@localhost ~]# umount /lvm4


[root@localhost ~]#
[root@localhost ~]# lvremove /dev/fedora/redhat
Do you really want to remove active logical volume fedora/redhat?
[y/n]: y
Logical volume "redhat" successfully removed
[root@localhost ~]#
[root@localhost ~]# vgremove /dev/fedora
Volume group "fedora" successfully removed
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
mylv3 myvg1 -wi-ao---- 1.00g
[root@localhost ~]#
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 4 3 0 wz--n- 6.98g <4.13g
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ls /etc/lvm/archive
fedora_00000-1881183348.vg fedora_00006-548712493.vg myvg1_00005-
2032552833.vg myvg1_00011-1131536323.vg
fedora_00001-1875769932.vg myvg1_00000-1410521865.vg myvg1_00006-
1487183730.vg myvg1_00012-1834110746.vg
fedora_00002-1926894782.vg myvg1_00001-218746988.vg myvg1_00007-
1960231459.vg myvg1_00013-442805358.vg
fedora_00003-1614268251.vg myvg1_00002-1462748636.vg myvg1_00008-
1093497607.vg myvg2_00000-2057712933.vg
fedora_00004-1374339324.vg myvg1_00003-41900610.vg myvg1_00009-
200884927.vg myvg2_00001-1664548345.vg
fedora_00005-967194627.vg myvg1_00004-1075299481.vg myvg1_00010-
807307922.vg myvg2_00002-1750129711.vg
[root@localhost ~]#

[root@localhost ~]# vgcfgrestore -l fedora


...........................
............................

File: /etc/lvm/archive/fedora_00005-967194627.vg
VG name: fedora
Description: Created *before* executing 'lvremove
/dev/fedora/redhat'
Backup Time: Sun Sep 1 02:01:12 2019

File: /etc/lvm/archive/fedora_00006-548712493.vg
VG name: fedora
Description: Created *before* executing 'vgremove /dev/fedora'
Backup Time: Sun Sep 1 02:01:17 2019

Note: First we will restore the volume group after then LVM....

Copy the indexing number of volume group first...

[root@localhost ~]# vgcfgrestore -f /etc/lvm/archive/fedora_00006-


548712493.vg fedora
Restored volume group fedora.
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vgcfgrestore -f /etc/lvm/archive/fedora_00005-
967194627.vg fedora
Restored volume group fedora.
[root@localhost ~]#

[root@localhost ~]# vgs


[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
fedora 1 1 0 wz--n- 184.00m 24.00m
myvg1 4 3 0 wz--n- 6.98g <4.13g
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
redhat fedora -wi------- 160.00m
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
mylv3 myvg1 -wi-ao---- 1.00g
[root@localhost ~]#

[root@localhost ~]# lvchange -ay /dev/fedora/redhat


[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log
Cpy%Sync Convert
redhat fedora -wi-a----- 160.00m
mylv1 myvg1 -wi-ao---- <1.37g
mylv2 myvg1 -wi-ao---- 500.00m
mylv3 myvg1 -wi-ao---- 1.00g
[root@localhost ~]#
[root@localhost ~]# mount -a
[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0%
/sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
/dev/sda1 xfs 994M 165M 830M 17% /boot
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv3 xfs 1014M 40M 975M 4% /lvm3
/dev/mapper/fedora-redhat ext3 151M 1.6M 142M 2% /lvm4
[root@localhost ~]#
[root@localhost ~]# ls /lvm4
abc1 abc2 abc3 lost+found
*****************************************************

Commands Help

[root@localhost ~]# man lvm


[root@localhost ~]# man vgrename
[root@localhost ~]#

************************************************

How to Remove LVM Step by Step from the machine....

[root@localhost ~]# df -Th


Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0%
/sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/mapper/myvg1-mylv2 ext4 477M 28M 423M 7% /lvm2
/dev/sda1 xfs 994M 165M 830M 17% /boot
/dev/mapper/myvg1-mylv1 xfs 1.4G 72M 1.3G 6% /lvm1
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
/dev/mapper/myvg1-mylv3 xfs 1014M 40M 975M 4% /lvm3
/dev/mapper/fedora-redhat ext3 151M 1.6M 142M 2% /lvm4
[root@localhost ~]#
[root@localhost ~]# umount /lvm1
[root@localhost ~]# umount /lvm2
[root@localhost ~]# umount /lvm3
[root@localhost ~]# umount /lvm4
[root@localhost ~]#
[root@localhost ~]# vim /etc/fstab

delete the last entry....

save this file

:wq

[root@localhost ~]# mount -a


[root@localhost ~]#
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 15G 3.9G 11G 27% /
/dev/sda1 xfs 994M 165M 830M 17% /boot
tmpfs tmpfs 376M 16K 376M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/0
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# lvremove /dev/fedora/redhat
Do you really want to remove active logical volume fedora/redhat?
[y/n]: y
Logical volume "redhat" successfully removed
[root@localhost ~]#
[root@localhost ~]# lvremove /dev/myvg1/mylv3
Do you really want to remove active logical volume myvg1/mylv3? [y/n]:
y
Logical volume "mylv3" successfully removed
[root@localhost ~]#
[root@localhost ~]# lvremove /dev/myvg1/mylv2
Do you really want to remove active logical volume myvg1/mylv2? [y/n]:
y
Logical volume "mylv2" successfully removed
[root@localhost ~]#
[root@localhost ~]# lvremove /dev/myvg1/mylv1
Do you really want to remove active logical volume myvg1/mylv1? [y/n]:
y
Logical volume "mylv1" successfully removed
[root@localhost ~]#
[root@localhost ~]# lvs
[root@localhost ~]#
[root@localhost ~]# vgremove /dev/fedora
Volume group "fedora" successfully removed
[root@localhost ~]#
[root@localhost ~]# vgremove /dev/myvg1
Volume group "myvg1" successfully removed
[root@localhost ~]#
[root@localhost ~]#

[root@localhost ~]# pvremove /dev/sdb1 /dev/sdb2 /dev/sdb3


/dev/sdb5 /dev/sdb6
Labels on physical volume "/dev/sdb1" successfully wiped.
Labels on physical volume "/dev/sdb2" successfully wiped.
Labels on physical volume "/dev/sdb3" successfully wiped.
Labels on physical volume "/dev/sdb5" successfully wiped.
Labels on physical volume "/dev/sdb6" successfully wiped.
[root@localhost ~]#
[root@localhost ~]# pvs
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).


Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Partition number (1-6, default 6): 6

Partition 6 has been deleted.

Command (m for help): d


Partition number (1-5, default 5): 5

Partition 5 has been deleted.

Command (m for help): d


Partition number (1-4, default 4): 4

Partition 4 has been deleted.


Command (m for help): d
Partition number (1-3, default 3): 3

Partition 3 has been deleted.

Command (m for help): d


Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): d


Selected partition 1
Partition 1 has been deleted.

Command (m for help): w


The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost ~]#
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#
[root@localhost ~]# udevadm settle
[root@localhost ~]#

**************************End *********************************

You might also like