Tag Archives: LVM

recover lvm metadata

Make sure you backups and make sure uuid is correct:

ls -l /etc/lvm/archive/
cat less /etc/lvm/archive/vg_test.vg
physical_volumes {
pv0 {
id = “gT7Kw0-bVoF-8reX-QVYs-9bvh-PMdo-bU5Vzo”

pvcreate –uuid “gT7Kw0-bVoF-8reX-QVYs-9bvh-PMdo-bU5Vzo” \
–restorefile /etc/lvm/archive/vg_test.vg

vgcfgrestore -f /etc/lvm/archive/vg_test.vg vg_test
vgchange -ay vg_test

lvm change cache mode

lvs -o+cache_mode,cache_settings /dev/centos/data
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert CacheMode CacheSettings
data centos Cwi-aoC— <2.54t [lv_cache] [data_corig] 3.16 0.09 0.00 writethrough

lvchange –cachemode writeback centos/data
Logical volume centos/data changed

lvs -o+cache_mode,cache_settings /dev/centos/data
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert CacheMode CacheSettings
data centos Cwi-aoC— <2.54t [lv_cache] [data_corig] 3.72 0.09 0.00 writeback

lvm snapshot to remote server

lvdisplay /dev/lvm-group/lv-name | grep Size
LV Size 60.00 GiB

take 10-20% of this space:
lvcreate –size 7G –snapshot –name lv-name-snap /dev/lvm-group/lv-name

copy and compress:
dd if=/dev/lvm-group/lv-name-snap | gzip -1 - | ssh root@storage.server.local dd of=/backups/lvm-images/lv-name-snap.gz

from backup server:
ssh user@remote "dd if=/dev/lvm-group/lv-name-snap | gzip -1 -" | dd of=/backups/lvm-images/lv-name-snap.gz

remove snapshot image:
lvremove /dev/lvm-group/lv-name-snap

Please be carefully with dd command, this command can be destructive.

mount lvm ntfs partition

mounting lvm nested partitons

lvdisplay /dev/kvm-group/vsv1098-0bzd-kujg5vyyvoa5sqyk
fdisk -l /dev/kvm-group/vsv1098-0bzd-kujg5vyyvoa5sqyk
kpartx -a /dev/kvm-group/vsv1098-0bzd-kujg5vyyvoa5sqyk
mkdir /mnt/vsv1098-0bzd-kujg5vyyvoa5sqyk1 && mount /dev/kvm-group/vsv1098-0bzd-kujg5vyyvoa5sqyk1 /mnt/vsv1098-0bzd-kujg5vyyvoa5sqyk1
ls /mnt/vsv1098-0bzd-kujg5vyyvoa5sqyk1

lvmcache

The cache logical volume type uses a small and fast LV to improve the performance of a large and slow LV. It does this by storing the frequently used blocks on the faster LV. LVM refers to the small fast LV as a cache pool LV. The large slow LV is called the origin LV. Due to requirements from dm-cache (the kernel driver), LVM further splits the cache pool LV into two devices – the cache data LV and cache metadata LV. The cache data LV is where copies of data blocks are kept from the origin LV to crease speed. The cache metadata LV holds the accounting information that specifies where data blocks are stored (e.g. on the origin LV or on the cache data LV). Users should be familiar with these LVs if they wish to create the best and most robust cached logical volumes. All of these associated LVs must be in the same VG.

removing vg and lvm after physical drive has been removed

lvs

/dev/vm_backups/backup read failed after 0 of 4096 at 995903864832: Input/output error
/dev/vm_backups/backup read failed after 0 of 4096 at 995903922176: Input/output error
/dev/vm_backups/backup read failed after 0 of 4096 at 0: Input/output error
/dev/vm_backups/backup read failed after 0 of 4096 at 4096: Input/output error

dmsetup remove vm_backups-backup

or:

vgreduce –removemissing

LVM advantages disadvantages

LVM advantages:

  • Use any number of disks as one big disk.
  • Have logical volumes stretched over several disks.
  • Create small logical volumes and resize them “dynamically” as they get more filled.
  • Resize logical volumes regardless of their order on disk. It does not depend on the position of the LV within VG, there is no need to ensure surrounding available space.
  • Resize/create/delete logical and physical volumes online. Filesystems on them still need to be resized, but some support online resizing.
  • Online migration of LV being used by services to different disks without having to restart services.
  • Snapshots allow you to backup a frozen copy of the filesystem, while keeping service downtime to a minimum.

LVM disadvantages:

  • Linux exclusive (almost). There is no official support in most other OS (FreeBSD, Windows..).
  • Additional steps in setting up the system, more complicated.
  • If you use the btrfs filesystem, its Subvolume feature will also give you the benefit of having a flexible layout. In that case, using the additional Abstraction layer of LVM may be unnecessary.

I recommend use LVM, because of great power.

device-mapper: device /dev/vda2 too small for target – LVM

You can face this problem after trying to resize your logical volume partitions:

lvresize -L +2G /dev/mapper/VolGroup-lv_root
Extending logical volume lv_root to 10.07 GiB
device-mapper: resume ioctl on failed: Invalid argument
Unable to resume VolGroup-lv_root (253:0)
Problem reactivating lv_root

you can fix this booted from rescue image:

fdisk /dev/vda
d 2
n 2
old_start new_end
t 2
8e (Linux LVM)
w

then:
lvextend -l +100%FREE /dev/VolGroup/lv_root
lvmdiskscan

LVM is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes.

With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes. LVM physical volumes can be placed on other block devices which might span two or more disks.

The physical volumes are combined into logical volumes, with the exception of the /boot/ partition. The /boot/ partition cannot be on a logical volume group because the boot loader cannot read it. If the root (/) partition is on a logical volume, create a separate /boot/ partition which is not a part of a volume group.

Since a physical volume cannot span over multiple drives, to span over more than one drive, create one or more physical volumes per drive.

lvg

The volume groups can be divided into logical volumes, which are assigned mount points, such as /home and / and file system types, such as ext2 or ext3. When “partitions” reach their full capacity, free space from the volume group can be added to the logical volume to increase the size of the partition. When a new hard drive is added to the system, it can be added to the volume group, and partitions that are logical volumes can be increased in size.

Read more http://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-lvm.html