What is LVM
If a system is partitioned with the ext3 file system, the hard drive is divided into partitions of defined sizes. If a partition becomes full, it is not easy to expand the size of the partition. Even if the partition is moved to another hard drive, the original hard drive space has to be reallocated as a different partition or not used
LVM Resize Actions
When shrinking, you should perform actions in this order
i) Resize the file system
ii) Resize the logical volume
When growing, you should perform actions in this order
i) Resize the logical volume
ii) Resize the file system
With the Help of LVM commands
a) To create LVM
To create a LVM volume we need to create Physical volume and volume group first.
# pvcreate /dev/sda1 /dev/sdb1
/dev/sdc1
# vgcreate new_vol_group /dev/sda1 /dev/sdb1 /dev/sdc1
# lvcreate -L 2 G -n
new_logical_volume new_vol_group
# mkfs.gfs2 -p lock_nolock
-j 1 /dev/new_vol_group/new_logical_volume
# mount
/dev/new_vol_group/new_logical_volume /mnt
b) To increase LVM size
# lvextend -L +100%FREE /dev/ubuntu-box-1-vg/root
# lvextend -L 100%FREE /dev/VolGroup00/lv_root
Note: When resizing a
logical volume with the following command, it is try to resize it to the number
of free extents, rather than the current size plus the number of free extents
Use the + symbol in
front of X%FREE to indicate the space should be added to the current size.
# lvextend -L +100%FREE /dev/volgroup/logvo
lvresize -rL 30G /dev/vg_proxy/lv_root
lvresize -rL +5G /dev/vg_proxy/lv_root
which mitigates the need to resize in a particular order and drastically reduces the potential for erro
c.1) How to reduce LVM size
To Reduce, the LVM we need to first unmount the volume
# umount
Then execute resize2fs command with the final size what we want eg: from 100GB to 80GB then
# umount
Then execute resize2fs command with the final size what we want eg: from 100GB to 80GB then
# resize2fs filesystem
<final size>
# After executing resize2fs command reduce the volume size, using lVM then mount it.
lvreduce -L 80G
Note : Partition types : lvm - 8e, swap - 82, linux - 83
lvresize --resizefs --size SIZE /dev/vg/vg_data
d) How to remove a physical volume
from a LVM
If there are enough free extents on the other physical volumes in the volume group, you can execute the pvmove command on the device you want to remove with no other options and the extents will be distributed to the other devices.
To check the usage of physical volumes
# pvs -o+pv_used
If free space is there, then use pvmove command to move the data from the volume
# pvmove /dev/sdb1
Then remove the physical volume from the volume group by using vgreduce command.
# vgreduce myvg /dev/sdb1
How to move data to a new HDD
There may be a case where
First create physical volume with the new disk
# pvcreate /dev/sdd1
Extend the Volume group with the new disk
# vgextend myvg /dev/sdd1
Now, move the data from OLD disk to NEW disk using pvmove command
# pvmove <Old Disk> <New Disk>
Now, move the data from OLD disk to NEW disk using pvmove command
# pvmove <Old Disk> <New Disk>
# pvmove /dev/sdb1 /dev/sdd1
Once if the data is copied, remove the old disk from volume group by using vgreduce command
# vgreduce myvg /dev/sdb1
How to LVM mirroring
Link
http://www.tecmint.com/lvm-storage-migration/ Steps works fine except for one
option.
We need some space for
mirror logs while mirroring so --mirrorlog core/--alloc anywhere option can be
used.
--mirrorlog core à The log can be kept in memory so that no
extra physical volume is needed to mirror the device
--alloc anywhere à the size
of the mirror has to be smaller than the size of total physical volumes because
the mirror log requires that free space.
@XXXXX~]# lvconvert -m 1
--mirrorlog core /dev/vgtest/lvtest /dev/sde
vgtest/lvtest: Converted: 0.6%
vgtest/lvtest: Converted: 8.7%
vgtest/lvtest: Converted: 26.4%
vgtest/lvtest: Converted: 63.9%
vgtest/lvtest: Converted: 100.0%
@XXXXX~]# lvconvert -m 0
/dev/vgtest/lvtest /dev/sdd
Logical volume lvtest converted.
@XXXXX~]# lvs -o +devices
LV
VG Attr LSize
Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices
lvvar
vgsystem -wi-ao---- 2.48g /dev/sda2(384)
lvvar
vgsystem -wi-ao---- 2.48g
/dev/sda2(896)
lvtest
vgtest -wi-ao---- 5.00g
/dev/sde(0)
@XXXXXtest]# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgtest-lvtest
4.8G 1.8G
2.8G 39% /test
Mirroring took hardly 3 mins
for 2G of data.
2) Using dmsetup command
dmsetup is low level LVM command. Using dmsetup we can manage LVM's
UUID duplicate error
2) Using dmsetup command
UUID duplicate error
Figured it out. I was using
kpartx for backups a few months ago and forgot to close the devices with kpartx
-d. I discover using partprobe that the lvm volumes wich belong to virtual
machines are "exported" to to the server,and fill /dev/mapper with
duplicates lvms,so i used kpartx -d to all devices in /dev/mapper and situation
return ok. lvs,pvs,vgs didn't give any error mess
uuidgen
tune2fs -U <output of
uuidgen> /dev/sdb1
Or if you're confident
uuidgen is going to work:
tune2fs -U `uuidgen`
/dev/sdb1
No comments:
Post a Comment