You are here

Part13: Lvm Configuration. My Study Notes for Red Hat Certificate of Expertise in Clustering and Storage Management Exam (EX436)

LVM CONFIGURATION

Reverting changes in lvm:

We create a 1G lvol, reduce the lvol to 512Megas, but we forget to reduce the fs first, we use vgcfgrestore to fix it:
[root@centos-clase1 ~]# pvcreate clusterhd1
Device clusterhd1 not found (or ignored by filtering).
[root@centos-clase1 ~]# pvcreate /dev/mapper/clusterhd1
Physical volume "/dev/mapper/clusterhd1" successfully created
[root@centos-clase1 ~]# vgcreate /dev/vgcluster /dev/mapper/clusterhd1
Volume group "vgcluster" successfully created
[root@centos-clase1 ~]# lvcreate -L 2G -n lvol1 /dev/vgcluster
Volume group "vgcluster" has insufficient free space (511 extents): 512 required.
[root@centos-clase1 ~]# lvcreate -L 1G -n lvol1 /dev/vgcluster
Logical volume "lvol1" created
[root@centos-clase1 ~]# mkfs.ext4 /dev/vgcluster/lvol1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

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

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@centos-clase1 ~]# mount /dev/vgcluster/lvol1 /mnt
[root@centos-clase1 ~]# touch /mnt/lol
[root@centos-clase1 ~]# lvreduce -L 512M ^C
[root@centos-clase1 ~]# umount /mnt
[root@centos-clase1 ~]# lvreduce -L 512M /dev/vgcluster/lvol1
WARNING: Reducing active logical volume to 512.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvol1? [y/n]: y
Reducing logical volume lvol1 to 512.00 MiB
Logical volume lvol1 successfully resized
[root@centos-clase1 ~]# mount /dev/vgcluster/lvol1 /mnt
mount: wrong fs type, bad option, bad superblock on /dev/mapper/vgcluster-lvol1,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

[root@centos-clase1 ~]# vgcfgrestore --list /dev/vgcluster

File: /etc/lvm/archive/vgcluster_00000-1552729825.vg
VG name: vgcluster
Description: Created *before* executing 'vgcreate /dev/vgcluster /dev/mapper/clusterhd1'
Backup Time: Wed Sep 4 20:59:26 2013

File: /etc/lvm/archive/vgcluster_00001-1066868147.vg
VG name: vgcluster
Description: Created *before* executing 'lvcreate -L 1G -n lvol1 /dev/vgcluster'
Backup Time: Wed Sep 4 20:59:52 2013

File: /etc/lvm/archive/vgcluster_00002-938968910.vg
VG name: vgcluster
Description: Created *before* executing 'lvreduce -L 512M /dev/vgcluster/lvol1'
Backup Time: Wed Sep 4 21:01:06 2013

File: /etc/lvm/backup/vgcluster
VG name: vgcluster
Description: Created *after* executing 'lvreduce -L 512M /dev/vgcluster/lvol1'
Backup Time: Wed Sep 4 21:01:06 2013

[root@centos-clase1 ~]# vgcfgrestore -f /etc/lvm/archive/vgcluster_00002-938968910.vg
Please specify a *single* volume group to restore.
[root@centos-clase1 ~]# vgcfgrestore -f /etc/lvm/archive/vgcluster_00002-938968910.vg vgcluster
Restored volume group vgcluster
[root@centos-clase1 ~]# lvchange -a n /dev/vgcluster/lvol1
[root@centos-clase1 ~]# lvchange -a y /dev/vgcluster/lvol1
[root@centos-clase1 ~]# mount /dev/vgcluster/lvol1 /mnt
[root@centos-clase1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_rootvg-rootlv
3.9G 295M 3.4G 8% /
tmpfs 499M 23M 477M 5% /dev/shm
/dev/vda1 388M 33M 336M 9% /boot
/dev/mapper/vg_rootvg-usrlv
3.9G 1.4G 2.3G 38% /usr
/dev/mapper/vg_rootvg-varlv
2.9G 168M 2.6G 6% /var
/dev/mapper/vgcluster-lvol1
1008M 34M 924M 4% /mnt
[root@centos-clase1 ~]#

LVM SNAPSHOTS:

create lvm snapshot:

[root@centos-clase1 ~]# lvcreate -s -n lvsnap -L+100M /dev/vgcluster/lvol1
Logical volume "lvsnap" created
[root@centos-clase1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
rootlv vg_rootvg -wi------ 3.91g
swaplv vg_rootvg -wi------ 1.97g
usrlv vg_rootvg -wi------ 3.91g
varlv vg_rootvg -wi------ 2.94g
lvol1 vgcluster owi-aos-- 1.00g
lvsnap vgcluster swi-a-s-- 100.00m lvol1 0.01

Wi give the snapshot 100Ms of qcow space, so the snapshot can differ in 100megs before it starts writes to the snapshot, we can configure a snapshot auto_extend feature in /etc/lvm/lvm.conf:

# 'snapshot_autoextend_threshold' and 'snapshot_autoextend_percent' define
# how to handle automatic snapshot extension. The former defines when the
# snapshot should be extended: when its space usage exceeds this many
# percent. The latter defines how much extra space should be allocated for
# the snapshot, in percent of its current size.
#
# For example, if you set snapshot_autoextend_threshold to 70 and
# snapshot_autoextend_percent to 20, whenever a snapshot exceeds 70% usage,
# it will be extended by another 20%. For a 1G snapshot, using up 700M will
# trigger a resize to 1.2G. When the usage exceeds 840M, the snapshot will
# be extended to 1.44G, and so on.
#
# Setting snapshot_autoextend_threshold to 100 disables automatic
# extensions. The minimum value is 50 (A setting below 50 will be treated
# as 50).

snapshot_autoextend_threshold = 80
snapshot_autoextend_percent = 10

We modify the lvm.conf file, so when the snapshot gets to 80% it extends it by 10% of it's current space

We have to restart the lvm2-monitor so it refreshes the config:

[root@centos-clase1 ~]# service lvm2-monitor restart
Stopping monitoring for VG vg_rootvg: 4 logical volume(s) in volume group "vg_rootvg" unmonitored
[ OK ]
Stopping monitoring for VG vg_rootvg: 4 logical volume(s) in volume group "vg_rootvg" unmonitored
[ OK ]
Stopping monitoring for VG vgcluster: 2 logical volume(s) in volume group "vgcluster" unmonitored
[ OK ]
Starting monitoring for VG vg_rootvg: 4 logical volume(s) in volume group "vg_rootvg" monitored
[ OK ]
Starting monitoring for VG vg_rootvg: 4 logical volume(s) in volume group "vg_rootvg" monitored
[ OK ]
Starting monitoring for VG vgcluster: 2 logical volume(s) in volume group "vgcluster" monitored
[ OK ]

And now we can test it out:

[root@centos-clase1 mnt2]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
rootlv vg_rootvg -wi------ 3.91g
swaplv vg_rootvg -wi------ 1.97g
usrlv vg_rootvg -wi------ 3.91g
varlv vg_rootvg -wi------ 2.94g
lvol1 vgcluster owi-aos-- 1.00g
lvsnap vgcluster swi-aos-- 200.00m lvol1 50.24
[root@centos-clase1 mnt2]# dd if=/dev/zero of=80M bs=1M count=80
80+0 records in
80+0 records out
83886080 bytes (84 MB) copied, 0.498546 s, 168 MB/s
[root@centos-clase1 mnt2]# sync
[root@centos-clase1 mnt2]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
rootlv vg_rootvg -wi------ 3.91g
swaplv vg_rootvg -wi------ 1.97g
usrlv vg_rootvg -wi------ 3.91g
varlv vg_rootvg -wi------ 2.94g
lvol1 vgcluster owi-aos-- 1.00g
lvsnap vgcluster swi-aos-- 220.00m lvol1 82.19
[root@centos-clase1 mnt2]#

We can see how it grows automaticly from 200M to 220M when the threshold reached the 80%

We then remove the snapshot:
[root@centos-clase1 ~]# umount /mnt2
[root@centos-clase1 ~]# lvremove /dev/mapper/vgcluster-lvsnap
Do you really want to remove active logical volume lvsnap? [y/n]: y
Logical volume "lvsnap" successfully removed

We can also merge/promote the snapshot:

[root@centos-clase1 ~]# umount /mnt2
[root@centos-clase1 ~]# lvconvert --merge /dev/mapper/vgcluster-lvsnap
Can't merge over open origin volume
Merging of snapshot lvsnap will start next activation.
[root@centos-clase1 ~]# umount /mnt
[root@centos-clase1 ~]# lvchange -a n /dev/mapper/vgcluster-lvol1
[root@centos-clase1 ~]# lvchange -a y /dev/mapper/vgcluster-lvol1
[root@centos-clase1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
rootlv vg_rootvg -wi------ 3.91g
swaplv vg_rootvg -wi------ 1.97g
usrlv vg_rootvg -wi------ 3.91g
varlv vg_rootvg -wi------ 2.94g
lvol1 vgcluster Owi-a-s-- 1.00g
[root@centos-clase1 ~]# mount /dev/mapper/vgcluster-lvol1 /mnt
[root@centos-clase1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_rootvg-rootlv
3.9G 295M 3.4G 8% /
tmpfs 499M 23M 477M 5% /dev/shm
/dev/vda1 388M 33M 336M 9% /boot
/dev/mapper/vg_rootvg-usrlv
3.9G 1.4G 2.3G 38% /usr
/dev/mapper/vg_rootvg-varlv
2.9G 168M 2.6G 6% /var
/dev/mapper/vgcluster-lvol1
1008M 253M 705M 27% /mnt
[root@centos-clase1 ~]#

Unix Systems: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.

Fatal error: Class CToolsCssCache contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (DrupalCacheInterface::__construct) in /homepages/37/d228974590/htdocs/sites/all/modules/ctools/includes/css-cache.inc on line 52