LVM(Logical Volume Manager) is a useful tool in linux to manage the disk
volume. The main purpose is to dynamically manage the disks in linux. You can
use LVM to extend or shrink the disks in OS without rebooting.
Key
components:
Physical volume (PV): Partition on hard disk (or even hard disk
itself or loopback file) on which you can have volume groups
Volume group (VG): Group of physical volumes that are
used as storage volume.
Logical volume (LV): A "virtual/logical
partition" that resides in a volume group, it can be used to as a
traditional partition and mounted to the mount point.
The picture is from internet.
0. Create a partition using fdisk.
(this is omitted as not related with LVM), but make sure it’s type set to Linux LVM (8e)1. Create PV from disk partition:
commands: pvcreate [device partition]2. Create the VG.
Then you
need to create the volume group using the PV.
Commands:
vgcreate [volume
ground name] PV //create the new VG
vgcreate [volume
ground name] PV //add the PV to new
VG
eg:
vgcreate
newvg /dev/sdb1
vgextend newvg
/dev/sdc1
3. Create the logic volume (LV) from VG.
Commands:
#lvcreate –L size [VG] –n [LVname]
4. view the device
Now you can view the device by
#ls –l /dev/mapper/[VG]-[LV]
#ls –l /dev/[VG]/[LV]
5. Make file system and mount the files
mkfs.[filesystem format] [LV]
mount [LV] [mount-point]
6. Extend the LV size (expand the file system capacity as well)
Commands:
Lvextend –L [size] [lv]
Resize2fs [lv]
Eg:
lvextend -L 200m /dev/newvg/lvhome
resize2fs /dev/newvg/lvhome
This is the basic usage of LVM, there are other advanced usages such as shrink, remove PV, snapshots, you can refer to other online documents.
No comments:
Post a Comment