🔔 🔔 🔔 Duyuru: 24. Yılımıza özel indirimler sizleri bekliyor ! Kampanya Kodu : TDATA2024 | Detaylı bilgi için tıklayınız.

LVM configuration in Linux cpanel server


LVM configuration in Linux cpanel server


How to configure LVM in Linux cpanel server.

LVM or Logical Volume Management is a tool used by Unix/Linux administrators to manage disk resources.  LVM provides a layer of abstraction between the underlying physical disk/volume and the host operating system.  LVM partitions can span across physical hard drives and can be re-sized.

We can use the following steps to create LVM.

    Partitioning
    Physical volume(s) creation
    Volume group(s) creation
    Logical volume(s) creation
    Formatting of the file system
    Mounting of file system
    Updating fstab for automatic volume mounting

 

Create Partition

Use this LVM configuration in Linux cpanel server, LVM partitions must be of type 8e (Linux LVM.) Create new partition and make sure with ID 8e.

[root@localhost ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d5460

Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        1306    10484736   8e  Linux LVM

if not then you can create partition with the type of the file system to 8e using t option.

[root@localhost ~]# fdisk /dev/sda

Physical Volume (PV)

physical storage unit of an LVM logical volume is a block device such as a partition or whole disk. To use the device for an LVM logical volume the device must be initialized as a physical volume (PV).

Check whether any physical volumes (PV’s) already exist on the system.

[root@localhost ~]# pvdisplay

Use the following command to create Physical Volume

[root@localhost ~]#pvcreate /dev/sda1
Physical volume “/dev/sda1″ successfully created
[root@localhost ~]#

Volume Group (VG)

Physical volumes are combined into volume groups (VGs). This creates a pool of disk space out of which logical volumes can be allocated. Within a volume group, the disk space available for allocation is divided into units of a fixed-size called extents.

Check Volume Groups the are already present on the system

[root@localhost ~]# vgdisplay

Create Volume Group

[root@localhost ~]# vgcreate VolGroup /dev/sda1
Volume group “VolGroup” successfully created

[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name               VolGroup
System ID
Format                lvm2
Metadata Areas        2
Metadata Sequence No  3
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                2
Act PV                2
VG Size               10.70 GiB
PE Size               4.00 MiB
Total PE              4481
Alloc PE / Size       4481 / 10.70 GiB
Free  PE / Size       0 / 0
VG UUID               TGFbtz-ysqf-XE8e-fDb0-dRzh-hfzE-Jx484g

Logical Volume

we have a Volume Group created that has free physical extents, we are now ready to create our new Logical Volume (LV).  LV’s can be created using a number of extents (with the -l command line switch) or by total size (with the -L command line switch followed by KB, MB, GB or TB.)

just use this command to create LV with all the space from that VG.

lvcreate <lvname> <vgname>

[root@localhost ~]#lvcreate lv_home VolGroup
Logical volume “lv_home” created

[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Name                /dev/VolGroup/lv_home
VG Name                VolGroup
LV UUID                trHeKm-Cxbu-cApC-IaHd-gxRW-RMdC-dw4msV
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                10.54 GiB
Current LE             4233
Segments               2
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

If you need 4G of LV then define a new LV that is 4GB in size

[root@localhost ~]#lvcreate -L 4GB -n lv_home VolGroup
Logical volume “lv_home” created

To create LV with full disk space

[root@localhost ~]# lvcreate -n lv_home -l 100%FREE VolGroup
Logical volume “lv-home” created

Formatting a File System

Linux offers many different file systems, some distributions of Linux/Unix will tend to recommend EXT3 while others might recommend XFS or ReiserFS.

[root@localhost ~]#mke2fs -j /dev/VolGroup/lv_home

Mounting a File System

create and mount that drive for your directory.

[root@localhost ~]#mkdir /home

[root@localhost ~]#mount /dev/VolGroup/lv_home /home

Once completed view your mounted device.

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_home
10G  789M   8G   7% /home

Thats all!!!

To remove LV, you can use this command.

[root@gopal ~]# lvremove /dev/VolGroup/lv_home
Do you really want to remove active logical volume lv_home? [y/n]: y
Logical volume “lv_home” successfully removed

Using LVextend Command

Change the size of the logical volumes Using lvextend Command

We can extend the size of the logical volumes after creating it by using lvextend utility.

For example logical volume extend size of 100M

[root@gopal ~]# umount /dev/VolGroup/lv_home

Volume group free space will add to LV.

[root@gopal ~]#lvextend -L+100 /dev/VolGroup/lv_home
Extending logical volume lv_home to 100.00 MB
Logical volume lv_home successfully resized

[root@gopal ~]# e2fsck -f /dev/VolGroup/lv_home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VolGroup/lv_home: 12/131072 files (0.0% non-contiguous), 25388/524288 blocks

[root@gopal ~]# resize2fs /dev/VolGroup/lv_home
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/home2lvm-lv_home2 to 786432 (4k) blocks.
The filesystem on /dev/mapper/home2lvm-lv_home2 is now 786432 blocks long.

Mount that partition now.

[root@gopal ~]# mount /dev/VolGroup/lv_home /home2

/dev/mapper/home2lvm-lv_home2
3.0G   67M  2.8G   3% /home2

That’s All….

 

 

How to increase mounted partition size in LVM

Its is possible to grow a partition safely without unmounting and remounting your volume. These steps presume you have extra disk available on your volume which is currently unallocated.

Run pvscan to verify you have allocatable space in your target Logical Volume:

pvscan

PV /dev/sda2 VG VolGroup00 lvm2 [19.88 GB / 1020.00 MB free]
PV /dev/sdb VG VolGroup01 lvm2 [100.00 GB / 20.00 GB free]

From the output, you can see VolGroup01, which contains the partition want to grow, had some free space.

Run lvresize to add free space to your partition:

VG name : home2lvm

LVname :  lv_home2

[root@gopal ~]# lvresize -L+1.9G -n /dev/mapper/home2lvm-lv_home2
Rounding size to boundary between physical extents: 1.90 GiB
Extending logical volume lv_home2 to 4.90 GiB
Logical volume lv_home2 successfully resized

[root@gopal ~]# resize2fs /dev/home2lvm/lv_home2
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/home2lvm/lv_home2 is mounted on /home2; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/home2lvm/lv_home2 to 1285120 (4k) blocks.
The filesystem on /dev/home2lvm/lv_home2 is now 1285120 blocks long.

Verify the disk space added in your current volume.

df -h

How to use VGExtend ?

When you add new drive, you can extend Volume Group and resize LV with out unmount.

After new drive attached, create partition with LVM code 8e.

Create PV

[root@gopal ~]# pvcreate /dev/xvdc1
Physical volume “/dev/xvdc1″ successfully created
[root@gopal ~]# vgextend home2lvm /dev/xvdc1
Volume group “home2lvm” successfully extended

VGExtend

[root@gopal ~]# vgextend home2lvm /dev/xvdc1
Volume group “home2lvm” successfully extended

LVresize

[root@gopal ~]# lvresize -L+2.05G -n /dev/mapper/home2lvm-lv_home2
Rounding size to boundary between physical extents: 2.05 GiB
Extending logical volume lv_home2 to 6.95 GiB
Logical volume lv_home2 successfully resized

[root@gopal ~]# resize2fs /dev/mapper/home2lvm-lv_home2
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/home2lvm-lv_home2 is mounted on /home2; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/home2lvm-lv_home2 to 1822720 (4k) blocks.
The filesystem on /dev/mapper/home2lvm-lv_home2 is now 1822720 blocks long.

You are Done!!! Check with drive size

df -h

Bu cevap yeterince yardımcı oldu mu?

Diğer Dökümanlar


  • cPanel security settings checklist

    You always use cpanel recommended Security Settings to avoid hacking and other suspicious activity. These  cPanel Server Hardening & Security tips will help prevent from hacking. cPanel...

  • sendmail Not running with correct effective GID

    Wed Sep 04 04:11:11 2014] [error] [client 11.44.33.22] sendmail: Not running with correct effective GID.  Is sendmail binary setgid mailtrap?, It may be the problem with your sendmail binary...

  • How to enable NAT behind the cpanel ?

    Most of webhosting providers currently used NAT service for their users. When you install cPanel & WHM, the installer will detect whether your server is on a NAT-configured network. If the...

  • Unable to allocate memory for pool

    Warning: Unknown: Unable to allocate memory for pool. in Unknown on line 0 APC or Alternative PHP Cache (APC) is a free and open opcode cache for PHP. APC allows for caching of opcode generated...

  • Install FFmpeg, Mplayer, Mencoder, MP4Box, Flvtool2

    You can use the following tutorial to install ffmpeg and other video modules in your centos server. FFmpeg is an audio/video conversion tool. It includes libavcodec, the leading open source codec...