Logical Volume Management (LVM)
LVM – logical volume manager can allow you to manage the space allocated to appropriate directories. As an example, assume the /var and /home directories are configured on separate logical volumes (LV). If extra space is available on the volume associated with the /var directory, you can reallocate space to the volume associated with the /home directory.
Alternatively, if you are managing a server on a growing network, new users will be common. Periodically, more room may be needed on a volume associated with the /home directory. With LVM, you can add a new physical disk and allocate its storage capacity to an existing /home directory.
Definitions in LVM
To work with LVM, you need to understand how partitions configured for that purpose are used. First, with the fdisk and parted utilities, you need to create partitions configured to the LVM partition type.
These are some of the definitions in LVM Physical volume (PV), Physical extent, Logical extent, Volume group (VG), Logical volume (LV)
Create a physical volume
The first step in LVM is to start with a physical partition. Create a partition using fdisk or parted. Assume that partition is /dev/sda1. To set up a new PV on a properly configured partition, apply pvcreate command,
#pvcreate /dev/sda1
If more than one partition configured as a PV,
#pvcreate /dev/sda1 /dev/sda2 /dev/sdb1
Create a volume group
#vgcreate MyVol0 /dev/sda1 /dev/sda2
To include additional PV or to extend a VG,
#vgextend MyVol0 /dev/sdb1
Create a logical volume
#lvcreate -L 3G MyVol0 -n home
Use of Logical Volume
Create a mount point and mount LV home to mount point.
Ex.
#mkdir /Test
#mount /dev/MyVol0/home /Test
Remove a LV,
#umount /dev/MyVol0/home
#lvremove /dev/ MyVol0/home
Resize Logical Volumes
Backup existing data on LV mounted directory for example /home and unmount it.
First extend the VG, if it doesn’t have more space.
#vgextend MyVol0 /dev/sdc1
#vgdisplay MyVol0 - to view total of VG
Then extend LV,
#lvextend -L 200M /dev/MyVol0/home
Then resize the LV with resize2fs
#resize2fs /dev/MyVol0/home
Or to use just a part of LV,
#resize2fs /dev/MyVol0/home 1500M - this command suggests a format of 1500M, means you are only using 1500MB from total size of LV.
In other case, you can reformat the entire LV and restore the data.
#mkfs.ext4 /dev/MyVol0/home
#mount /de/MyVol0/home /Test
No comments:
Post a Comment