Wednesday, December 14, 2011

Logical Volume Group (LVM)

Aptitude install lvm2
To running Lvm on ubuntu, we must have lvm2, if you don't have, then install it
# aptitude install lvm2

Initializing disks or disk partitions
Before you can use a disk or disk partition as a physical volume you will have to initialize it:
# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
Now create a volume group descriptor at the start of the /dev/sda3 partition.
# pvcreate /dev/sda3 /dev/sda4
Physical volume "/dev/sda3" successfully created Physical volume "/dev/sda4" successfully created
Above command line is using when we want creating pvdisk from 2 partitions at once

Setup a Volume Group
# vgcreate vgm-disk /dev/sda3
Volume group "vgm-disk" successfully created
Or if you want creating volume group from more than one partitions, you can using command bellow
# vgcreate vgm-disk /dev/sda3 /dev/sda4
Volume group "vgm-disk" successfully created

Run vgscan and vgdisplay to verify volume group
# vgscan
Reading all physical volumes. This may take a while... Found volume group "vgm-disk" using metadata type lvm2
# vgdisplay
--- Volume group --- VG Name vgm-disk System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 110.86 GiB PE Size 4.00 MiB Total PE 28381 Alloc PE / Size 0 / 0 Free PE / Size 28381 / 110.86 GiB VG UUID A9fOwN-y7Xm-cFDE-ruFK-1xl1-kbRI-fp9IdN

The most important things to verify are that the first three items are correct and that the VG Size item is the proper size for the amount of space in all four of your disks.

Creating the Logical Volume
# lvcreate -n lvm-disk -l 28381 vgm-disk
Logical volume "lvm-disk" created -n is name of logical volume -l is PE (pyshical extend) 28381 size on volume group (vgm-disk), in this situation, I want it to use all partition.

Create the File System
# mkfs.ext3 /dev/vgm-disk/lvm-disk
mke2fs 1.41.11 (14-Mar-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 7266304 inodes, 29062144 blocks 1453107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 887 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 33 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

Test the File System
Mount the file system on the logical volume
# mount /dev/vgm-disk/lvm-disk /mnt/lvm 
Now check it, If everything worked properly, you should now have a logical volume mounted at /mnt/lvm
# df -ah
Filesystem Size Used Avail Use% Mounted on /dev/sda1 37G 1.5G 34G 5% / proc 0 0 0 - /proc none 0 0 0 - /sys none 0 0 0 - /sys/fs/fuse/connections none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security none 1002M 208K 1002M 1% /dev none 0 0 0 - /dev/pts none 1006M 0 1006M 0% /dev/shm none 1006M 288K 1006M 1% /var/run none 1006M 0 1006M 0% /var/lock none 1006M 0 1006M 0% /lib/init/rw /dev/sdc1 147G 117G 23G 84% /mnt/sdc1 /dev/mapper/vgm--disk-lvm--disk 110G 188M 104G 1% /mnt/lvm
Adding a new disk
Current situation
# pvdisplay
--- Physical volume --- PV Name /dev/sda3 VG Name vgm-disk PV Size 110.86 GiB / not usable 352.50 KiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 28381 Free PE 0 Allocated PE 28381 PV UUID mYSSjb-a50Y-GOcP-m30k-1BHL-430G-fFUzAb
# lvdisplay
--- Logical volume --- LV Name /dev/vgm-disk/lvm-disk VG Name vgm-disk LV UUID P5KCpv-2fBq-UKk5-TObN-ZySO-MMW0-ALmpmQ LV Write Access read/write LV Status available # open 0 LV Size 110.86 GiB Current LE 28381 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 251:0
# pvscan
PV /dev/sda3 VG vgm-disk lvm2 [110.86 GiB / 0 free] Total: 1 [110.86 GiB] / in use: 1 [110.86 GiB] / in no VG: 0 [0 ]

Adding new pyshical volume /dev/sdb1.
# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created PV /dev/sda3 VG vgm-disk lvm2 [110.86 GiB / 0 free] PV /dev/sdb1 lvm2 [931.51 GiB] Total: 2 [1.02 TiB] / in use: 1 [110.86 GiB] / in no VG: 1 [931.51 GiB]
# pvdisplay
--- Physical volume --- PV Name /dev/sda3 VG Name vgm-disk PV Size 110.86 GiB / not usable 352.50 KiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 28381 Free PE 0 Allocated PE 28381 PV UUID mYSSjb-a50Y-GOcP-m30k-1BHL-430G-fFUzAb "/dev/sdb1" is a new physical volume of "931.51 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 931.51 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID W570RU-hvnL-Ipdm-Jo1P-vN2n-TjRJ-GPTCOm

Add the new disks to the volume groups
# vgextend vgm-disk /dev/sdb1
Volume group "vgm-disk" successfully extended

Checking
# vgdisplay
--- Volume group --- VG Name vgm-disk System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 1.02 TiB PE Size 4.00 MiB Total PE 266847 Alloc PE / Size 28381 / 110.86 GiB Free PE / Size 238466 / 931.51 GiB VG UUID A9fOwN-y7Xm-cFDE-ruFK-1xl1-kbRI-fp9IdN

Extend volume groups
# lvextend -l +238466 /dev/vgm-disk/lvm-disk
Extending logical volume lvm-disk to 931.51 GiB Logical volume lvm-disk successfully resized
# vgdisplay
--- Volume group --- VG Name vgm-disk System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 1.02 TiB PE Size 4.00 MiB Total PE 266847 Alloc PE / Size 266847 / 1.02 TiB Free PE / Size 0 / 0 VG UUID A9fOwN-y7Xm-cFDE-ruFK-1xl1-kbRI-fp9IdN

Increase the file system size After you have extended the logical volume it is necessary to increase the file system size to match. how you do this depends on the file system you are using.

Before resizing files ystem sizes.
# df -ah
Filesystem Size Used Avail Use% Mounted on /dev/sda1 37G 1.5G 34G 5% / proc 0 0 0 - /proc none 0 0 0 - /sys none 0 0 0 - /sys/fs/fuse/connections none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security none 1002M 208K 1002M 1% /dev none 0 0 0 - /dev/pts none 1006M 0 1006M 0% /dev/shm none 1006M 288K 1006M 1% /var/run none 1006M 0 1006M 0% /var/lock none 1006M 0 1006M 0% /lib/init/rw /dev/sdc1 147G 117G 23G 84% /mnt/sdc1 /dev/mapper/vgm--disk-lvm--disk 110G 188M 104G 1% /mnt/lvm
# e2fsck -f /dev/vgm-disk/lvm-disk
e2fsck 1.41.11 (14-Mar-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/vgm-disk/lvm-disk: 11/7266304 files (0.0% non-contiguous), 504100/29062144 blocks
# resize2fs /dev/vgm-disk/lvm-disk
resize2fs 1.41.11 (14-Mar-2010) Resizing the filesystem on /dev/vgm-disk/lvm-disk to 273251328 (4k) blocks. The filesystem on /dev/vgm-disk/lvm-disk is now 273251328 blocks long
# mount /dev/vgm-disk/lvm-disk /mnt/lvm/
# df -ah
Filesystem Size Used Avail Use% Mounted on /dev/sda1 37G 1.5G 34G 5% / proc 0 0 0 - /proc none 0 0 0 - /sys none 0 0 0 - /sys/fs/fuse/connections none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security none 1002M 208K 1002M 1% /dev none 0 0 0 - /dev/pts none 1006M 0 1006M 0% /dev/shm none 1006M 288K 1006M 1% /var/run none 1006M 0 1006M 0% /var/lock none 1006M 0 1006M 0% /lib/init/rw /dev/sdc1 147G 117G 23G 84% /mnt/sdc1 /dev/mapper/vgm--disk-lvm--disk 1.1T 200M 974G 1% /mnt/lvm
Editing /etc/fstab file to match new filesystem
# cat /etc/fstab

/dev/sda1 / ext3 defaults 0 1 /dev/sda2 swap swap defaults 0 0 /dev/vgm-disk/lvm-disk /mnt/lvm lvm noatime 0 2 /dev/sdb1 /mnt/sdb1 ext3 defaults 1 1 proc /proc proc nodev,noexec,nosuid 0 0

Done

No comments: