If you are working as a Linux System Admin then resizing the file system size is an important task for you and you must know that.Here in this tutorial we are going to learn how to increase or extend lvm partition size.As we all know LVM provides us the facility to increase or reduce the of partition.
So here we will learn to increase lvm size using lvextend command,but before that we will create lvm first and mount it so that it is ready for use.
STEP1: Create Physical Volumes using pvcreate command.
[root@localhost ~]# pvcreate /dev/sda{5,6,7} Physical volume "/dev/sda5" successfully created Physical volume "/dev/sda6" successfully created Physical volume "/dev/sda7" successfully created
now check the create physical volume using pvscan.
[root@localhost ~]# pvscan PV /dev/sda5 lvm2 [964.81 MB] PV /dev/sda6 lvm2 [964.81 MB] PV /dev/sda7 lvm2 [831.46 MB] Total: 3 [2.70 GB] / in use: 0 [0 ] / in no VG: 3 [2.70 GB]
STEP2: create Volume Group using vgcreate command
[root@localhost ~]# vgcreate vg00 /dev/sda{5,6,7} Volume group "vg00" successfully created
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree vg00 3 0 0 wz--n- 2.69G 2.69G
[root@localhost ~]# pvscan PV /dev/sda5 VG vg00 lvm2 [964.00 MB / 964.00 MB free] PV /dev/sda6 VG vg00 lvm2 [964.00 MB / 964.00 MB free] PV /dev/sda7 VG vg00 lvm2 [828.00 MB / 828.00 MB free] Total: 3 [2.69 GB] / in use: 3 [2.69 GB] / in no VG: 0 [0 ] [root@localhost ~]#
STEP3: Create Logical Volume(lvm) name lv1 using lvcreate command.
[root@localhost ~]# lvcreate -L +1G -n lv1 vg00 Logical volume "lv1" created [root@localhost ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv1 vg00 -wi-a- 1.00G [root@localhost ~]#
[root@localhost ~]# lvdisplay --- Logical volume --- LV Name /dev/vg00/lv1 VG Name vg00 LV UUID YYXZk0-bs6F-wE8z-88P3-f67R-G4vj-IrohD2 LV Write Access read/write LV Status available # open 0 LV Size 1.00 GB Current LE 256 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@localhost ~]#
[root@localhost ~]# pvscan PV /dev/sda5 VG vg00 lvm2 [964.00 MB / 0 free] PV /dev/sda6 VG vg00 lvm2 [964.00 MB / 904.00 MB free] PV /dev/sda7 VG vg00 lvm2 [828.00 MB / 828.00 MB free] Total: 3 [2.69 GB] / in use: 3 [2.69 GB] / in no VG: 0 [0 ] [root@localhost ~]#
STEP4: Format and Mount it so that it is ready for use.
First format the file system using mkfs.ext3 command.
[root@localhost ~]# mkfs.ext3 /dev/vg00/lv1
Then create a directory to mount newly created File System.
[root@localhost ~]# mkdir /lvmdata
Now mount newly created file system using mount command to use.
[root@localhost ~]# mount /dev/vg00/lv1 /lvmdata
STEP5: View it’s size using lvs, lvdisplay or df -Th command.
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 25G 2.1G 22G 9% / tmpfs 1014M 0 1014M 0% /dev/shm /dev/mapper/vg00-lv1 1008M 34M 924M 4% /lvmdata [root@localhost ~]#
[root@localhost ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv1 vg00 -wi-ao 1.00G [root@localhost ~]#
STEP6:Before making change to lvm check the free available space in the volume group “vg00”.
[root@localhost ~]# vgdisplay vg00 --- Volume group --- VG Name vg00 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size 2.69 GB PE Size 4.00 MB Total PE 689 Alloc PE / Size 256 / 1.00 GB Free PE / Size 433 / 1.69 GB VG UUID vBYPKn-9Bpk-jvK2-tc2e-e78U-V5jq-lgbcbZ [root@localhost ~]#
STEP7:Use lvextend command to increase the size of lvm named “lv1”
[root@localhost ~]# lvextend -L +500M /dev/vg00/lv1 Extending logical volume lv1 to 1.49 GB Logical volume lv1 successfully resized
STEP8:check file system size using lvs or lvdisplay.
[root@localhost ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv1 vg00 -wi-ao 1.49G [root@localhost ~]#
You can see above output the file size increased here.
STEP9:Check Mounted file system size using df -h
[root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext3 25G 2.1G 22G 9% / tmpfs tmpfs 1014M 0 1014M 0% /dev/shm /dev/mapper/vg00-lv1 ext3 1008M 34M 924M 4% /lvmdata [root@localhost ~]#
but you can see File system size not updated here because to update it we need to run resize2fs command.
STEP10:Run resize2fs command to resize the file system size.
[root@localhost ~]# resize2fs /dev/vg00/lv1 resize2fs 1.39 (29-May-2006) Filesystem at /dev/vg00/lv1 is mounted on /lvmdata; on-line resizing required Performing an on-line resize of /dev/vg00/lv1 to 390144 (4k) blocks. The filesystem on /dev/vg00/lv1 is now 390144 blocks long. [root@localhost ~]#
STEP11: Again check mounted file system size using df -h.
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 25G 2.1G 22G 9% / tmpfs 1014M 0 1014M 0% /dev/shm /dev/mapper/vg00-lv1 1.5G 34M 1.4G 3% /lvmdata [root@localhost ~]#