Tuesday, 29 October 2019

LVM - Create Mirrored Logical Volumes

1.Checking which disks to use for mirror

[root@rifle ~]# lvmdiskscan
  /dev/centos_rifle/root   [      <6.20 GiB]
  /dev/sda1                [       1.00 GiB]
  /dev/centos_rifle/swap   [     820.00 MiB]
  /dev/sda2                [      <7.00 GiB] LVM physical volume
  /dev/vg_mydata/lv_mydata [       1.50 GiB]
  /dev/sdb                 [      <1.04 GiB] LVM physical volume
  /dev/sdc                 [     519.34 MiB] LVM physical volume
  /dev/sdd                 [      <1.99 GiB]
  /dev/sde                 [       2.00 GiB]
  5 disks
  1 partition
  2 LVM physical volume whole disks
  1 LVM physical volume

In my case I have two almost identical disks: /dev/sdd and /dev/sde.

2. Creating Physical Volume

[root@rifle ~]# pvcreate /dev/sdd   /dev/sde
  Physical volume "/dev/sdd" successfully created.
  Physical volume "/dev/sde" successfully created.

Checking physical volumes
[root@rifle ~]# pvs
  PV         VG           Fmt  Attr PSize   PFree
  /dev/sda2  centos_rifle lvm2 a--   <7.00g     0
  /dev/sdb   vg_mydata    lvm2 a--    1.03g     0
  /dev/sdc   vg_mydata    lvm2 a--  516.00m 32.00m
  /dev/sdd                lvm2 ---   <1.99g <1.99g
  /dev/sde                lvm2 ---    2.00g  2.00g

3. Creating Volume Group named vg_mirror

[root@rifle ~]# vgcreate vg_mirror /dev/sdd /dev/sde
  Volume group "vg_mirror" successfully created

Check VG
[root@rifle ~]# vgs
  VG           #PV #LV #SN Attr   VSize  VFree
  centos_rifle   1   2   0 wz--n- <7.00g     0
  vg_mirror      2   0   0 wz--n-  3.98g  3.98g
  vg_mydata      2   1   0 wz--n- <1.54g 32.00m

I created new virtual group vg_mirror with two PVs and no LVs in it.

4.Creating a new mirrored Logical Volume 

[root@rifle ~]# lvcreate -m 1 -l100%FREE -n lv_mirror vg_mirror
  Logical volume "lv_mirror" created.

Where parameters are:
-m 1                - have one mirror copy of data
-l100%FREE  - use all free space on the volume group

Check status of the new logical volume:
[root@rifle ~]# lvs /dev/vg_mirror/lv_mirror
  LV        VG        Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_mirror vg_mirror rwi-a-r--- 1.98g                                    100.00

100.00 - means that both copies are in sync

5.Creating file systems

[root@rifle ~]# mkfs -t ext4 /dev/vg_mirror/lv_mirror
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
129792 inodes, 519168 blocks
25958 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=532676608
16 block groups
32768 blocks per group, 32768 fragments per group
8112 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

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

6.Creating mount point and mount

[root@rifle ~]# mkdir /mirrored_data
[root@rifle ~]# mount /dev/vg_mirror/lv_mirror /mirrored_data/

Checking file system size:
[root@rifle ~]# df -h /mirrored_data/
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg_mirror-lv_mirror  2.0G  6.0M  1.8G   1% /mirrored_data

No comments: