Difference between revisions of "Logical Volume Manager"
From Christoph's Personal Wiki
(→Creating a logical volume) |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
This article will explain how to use the '''Logical Volume Manager''' ('''LVM''') in [[Linux]]. | This article will explain how to use the '''Logical Volume Manager''' ('''LVM''') in [[Linux]]. | ||
| − | ''Note: This article will cover how to use LVM under RedHat-style distros. Everything was tested using [[CentOS]] 6.5.'' | + | ''Note: This article will cover how to use LVM under RedHat-style distros. Everything was tested using [[CentOS]] 6.5. Some of the features shown are only available for LVM2.'' |
==Logical volume stack== | ==Logical volume stack== | ||
| Line 42: | Line 42: | ||
$ ls -l /dev/mapper/vgname-lvname | $ ls -l /dev/mapper/vgname-lvname | ||
| − | *Make a filesystem | + | *Make a filesystem (<code>ext4</code> in this example) inside the above logical volume: |
$ mkfs.ext4 /dev/vgname/lvname | $ mkfs.ext4 /dev/vgname/lvname | ||
| Line 54: | Line 54: | ||
$ mount -a | $ mount -a | ||
| + | ===Miscellaneous=== | ||
| + | |||
| + | If you see the following error message: | ||
| + | vgscan -- no volume groups found | ||
| + | |||
| + | Try the following: | ||
| + | |||
| + | * Check integrity of your VGs (note: obviously, you can not have an open LVs inside your VGs): | ||
| + | $ vgchange -an # deactivate any active VGs | ||
| + | $ vgscan | ||
| + | $ vgchange -ay # re-activate VGs | ||
| + | |||
| + | Or, you could try using (the very old) "[http://www.tldp.org/HOWTO/LVM-HOWTO/uuidfixer.html uuid_fixer]" (Careful! Can be dangerous!) | ||
| + | |||
| + | * Removing a logical volume (note: a logical volume must be closed before it can be removed): | ||
| + | |||
| + | $ umount /dev/vgname/lvname | ||
| + | $ lvremove /dev/vgname/lvname | ||
| + | lvremove -- do you really want to remove "/dev/vgname/lvname"? [y/n]: y | ||
| + | lvremove -- doing automatic backup of volume group "vgname" | ||
| + | lvremove -- logical volume "/dev/vgname/lvname" successfully removed | ||
| + | |||
| + | <!-- | ||
| + | The first builtin rule checks path prefixes and it gives preference | ||
| + | # based on this ordering (where "dev" depends on devices/dev setting): | ||
| + | # /dev/mapper > /dev/disk > /dev/dm-* > /dev/block | ||
| + | --> | ||
==External links== | ==External links== | ||
*[http://www.tldp.org/HOWTO/LVM-HOWTO/ LVM HOWTO] — by The Linux Documentation Project (TLDP) | *[http://www.tldp.org/HOWTO/LVM-HOWTO/ LVM HOWTO] — by The Linux Documentation Project (TLDP) | ||
[[Category:Linux Command Line Tools]] | [[Category:Linux Command Line Tools]] | ||
Latest revision as of 18:52, 16 April 2015
This article will explain how to use the Logical Volume Manager (LVM) in Linux.
Note: This article will cover how to use LVM under RedHat-style distros. Everything was tested using CentOS 6.5. Some of the features shown are only available for LVM2.
Contents
Logical volume stack
I like to think of logical volumes as a stack, with the physical part on the bottom and you are stacking each element on top:
filesystem (FS) Logical volume (LV) Volume group (VG) Physical volume (PV)
Another way to visualize this is like so (adapted {and inverted} from Erik Bågfors' diagram):
ext4 ext4 (filesystems)
| |
rootlv homelv (LVs)
\ /
\ /
diskvg (VG)
/ \
/ \
xvdb1 xvdb2 (PVs; on partitions or whole disks)
Examples
Creating a logical volume
- Prepare a physical volume:
$ fdisk -cu /dev/xvde $ pvcreate /dev/xvde1 $ pvdisplay /dev/xvde1 $ pvs
- Create a volume group:
$ vgcreate vgname /dev/xvde1 $ vgdisplay vgname $ vgs
- Create and use a new logical volume:
$ lvcreate -n lvname -L 1G vgname $ lvdisplay /dev/vgname/lvname $ lvs $ ls -l /dev/vgname/lvname $ #~OR~ $ ls -l /dev/mapper/vgname-lvname
- Make a filesystem (
ext4in this example) inside the above logical volume:
$ mkfs.ext4 /dev/vgname/lvname
- Test mount it:
$ mkdir /data $ mount /dev/vgname/lvname /data $ umount /data # un-mount it before proceeding
- Make it persistent by adding the following line to your
/etc/fstabfile and test mount it (again):
/dev/mapper/vgname-lvname /data ext4 defaults 1 2 $ mount -a
Miscellaneous
If you see the following error message:
vgscan -- no volume groups found
Try the following:
- Check integrity of your VGs (note: obviously, you can not have an open LVs inside your VGs):
$ vgchange -an # deactivate any active VGs $ vgscan $ vgchange -ay # re-activate VGs
Or, you could try using (the very old) "uuid_fixer" (Careful! Can be dangerous!)
- Removing a logical volume (note: a logical volume must be closed before it can be removed):
$ umount /dev/vgname/lvname $ lvremove /dev/vgname/lvname lvremove -- do you really want to remove "/dev/vgname/lvname"? [y/n]: y lvremove -- doing automatic backup of volume group "vgname" lvremove -- logical volume "/dev/vgname/lvname" successfully removed
External links
- LVM HOWTO — by The Linux Documentation Project (TLDP)