Showing posts with label LVM. Show all posts
Showing posts with label LVM. Show all posts

Tuesday, October 23, 2012

Step by Step guide: Resizing File System on the Linux Virtual Machine

Assumptions made:
You must have basic knowledge of LVM to follow the instruction.
Linux Environment : I have done this on SLES 11; However the LVM commands used are the generic Linux commands. Thus, this instruction should work on wide flavors of Linux.
Volume Group (VG) name: testvg
Logical Volume(LV) name: testlv
Root file system is on /dev/testvg/testlv file system  and I want to increase the file system size by 5 GB.


Step1: Provision an extra disk space to the Virtual Machine [ i.e Increase the VMDK size of the VM via vSphere client if you are on VMWare environment]

[Note: If you provision an additional disk (some VMs doesn't allow to increase the VMDK size), check if you can see that additional disk. Say an additional disk is /dev/sdb. Then, run the command  #fdisk -l   . It should show  /dev/sdb. If you cannot see /dev/sdb, then reboot the system and run #fdisk -l  command again]

Step2: Partition the additional disk space you just added [ Say your system sees disk as /dev/sda ]
           # fdisk   /dev/sda
    • Create a new partition (primary if possible) Let's say  /dev/sda4
    • Define size
    • Change the partition type from 83 (EXT3) to 8e (LVM)
    • Write the change
Step3: Create a Physical Volume 
            # pvcreate <partition_name>
                    Example: # pvcreate  /dev/sda4

If you get an error reporting that system can't see the partition, reboot the Virtual Machine.

And re-run the pvcreate command once the system is back up. 

Note: You can run #vgdisplay command to check what Volume Groups are available
Step4: Extend the Volume Group [ i.e Add the physical volume we just created to the existing volume group]
           # vgextend    <vgname>   <partition_name>
                 Example: # vgextend   testvg   /dev/sda4

Note: You can run #lvdisplay command to check what logical volumes  are available
Step5: Extend the Logical Volume  [ Say increase by 5GB ]
           #lvextend   -L     +5G    /dev/<vgname>/<lvname>   <partition_name>
                   Example: #lvextend   -L   +5G   /dev/testvg/testlv     /dev/sda4

Warning!!! Check if a space is free in the physical volume or not. You can run the command #pvdisplay  and check how much free space is available in the physical partition. 

Step6: Resize the file system
          #resize2fs     /dev/<vgname>/<lvname>
                Example: #resize2fs    /dev/testvg/testlv

Note: If resizze2fs doesn't work, reboot the system. For example: SLES 10 doesn't support online resize of the mounted file-system. Thus, SLES10 requires reboot after 'lvextend' of root file-system. 

Validate if the size of the file system has been increased or not. 
         #df  -h

Best of Luck! 




Sunday, April 19, 2009

Extending and Reducing LV in LINUX

Lets extend the size of  testlv

[root@localhost ~]# lvdisplay /dev/testvg/testlv
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                100.00 MB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0


[root@localhost ~]# umount /dev/testvg/testlv 

[root@localhost ~]# fsck -f /dev/testvg/testlv 
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
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/testvg/testlv: 11/25792 files (9.1% non-contiguous), 8927/102400 blocks

[root@localhost ~]# lvextend -L +150M /dev/testvg/testlv 
  Rounding up size to full physical extent 152.00 MB
  Extending logical volume testlv to 252.00 MB
  Logical volume testlv successfully resized


[root@localhost ~]# resize2fs /dev/testvg/testlv 
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/testvg/testlv to 258048 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 258048 blocks long.


[root@localhost ~]# lvdisplay /dev/testvg/testlv 
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                252.00 MB
  Current LE             63
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0



****************************************************
After we are done with increasing the size of testlv, let's reduce the size of testlv

[root@localhost ~]# umount /dev/testvg/testlv

[root@localhost ~]# fsck -f /dev/testvg/testlv
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
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/testvg/testlv: 11/63488 files (9.1% non-contiguous), 14193/258048 blocks

[root@localhost ~]# resize2fs /dev/testvg/testlv 150M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/testvg/testlv to 153600 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 153600 blocks long.


[root@localhost ~]# lvreduce -L 150M /dev/testvg/testlv 
  Rounding up size to full physical extent 152.00 MB
  WARNING: Reducing active logical volume to 152.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testlv? [y/n]: y
  Reducing logical volume testlv to 152.00 MB
  Logical volume testlv successfully resized

[root@localhost ~]# lvdisplay /dev/testvg/testlv 
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                152.00 MB
  Current LE             38
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0



(have u noticed the sequence of commands: lvextend and resize2fs commands are in different order for two different operations. Keep only one thing in mind, resize2fs should be run before lvextend while reducing the size of LV )

Sunday, April 12, 2009

Step by Step guide: Manage additional disk on Linux using LVM

Let's we have physical drive connected in slave of secondary IDE i.e /dev/hdd

#fdisk /dev/hdd (and create following partitions with id:8e)

Device Boot Start End Blocks Id System
/dev/hdd1 1 1000 503968+ 8e Linux LVM
/dev/hdd2 1001 2000 504000 8e Linux LVM

[root@localhost ~]# pvcreate /dev/hdd1 /dev/hdd2
Physical volume "/dev/hdd1" successfully created
Physical volume "/dev/hdd2" successfully created

[root@localhost ~]# pvdisplay [compare with the o/p of same command after creating f/s of LV]
"/dev/hdd1" is a new physical volume of "492.16 MB"
--- NEW Physical volume ---
PV Name /dev/hdd1
VG Name
PV Size 492.16 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID lanTX2-t6KC-MTID-Ag8V-un2g-R6a9-janMLC

"/dev/hdd2" is a new physical volume of "492.19 MB"
--- NEW Physical volume ---
PV Name /dev/hdd2
VG Name
PV Size 492.19 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID W29vIo-K2SN-07Zl-3Xn8-1pDX-hkxQ-P3gk2h


[root@localhost ~]# vgcreate testvg /dev/hdd1 /dev/hdd2
Volume group "testvg" successfully created


[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 980.00 MB
PE Size 4.00 MB
Total PE 245
Alloc PE / Size 0 / 0
Free PE / Size 245 / 980.00 MB
VG UUID TbRxlH-zYl9-Y3zz-tsEH-1ASj-1uma-qhVLo8


[root@localhost ~]# lvcreate -L 124M -n testlv testvg [creating LV of size 124M with name testlv ]
Logical volume "testlv" created

[root@localhost ~]# lvdisplay /dev/testvg/testlv
--- Logical volume ---
LV Name /dev/testvg/testlv
VG Name testvg
LV UUID jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
LV Write Access read/write
LV Status available
# open 0
LV Size 124.00 MB
Current LE 31
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0


[root@localhost ~]# mkfs -t ext3 /dev/testvg/testlv [ creating filesystem ]
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
31744 inodes, 126976 blocks
6348 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
16 block groups
8192 blocks per group, 8192 fragments per group
1984 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@localhost lvmmntpt]# pvdisplay
--- Physical volume ---
PV Name /dev/hdd1
VG Name testvg
PV Size 492.16 MB / not usable 4.16 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 122
Free PE 122
Allocated PE 0
PV UUID lanTX2-t6KC-MTID-Ag8V-un2g-R6a9-janMLC

--- Physical volume ---
PV Name /dev/hdd2
VG Name testvg
PV Size 492.19 MB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 123
Free PE 92
Allocated PE 31
PV UUID W29vIo-K2SN-07Zl-3Xn8-1pDX-hkxQ-P3gk2h

[root@localhost lvmmntpt]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 980.00 MB
PE Size 4.00 MB
Total PE 245
Alloc PE / Size 31 / 124.00 MB
Free PE / Size 214 / 856.00 MB
VG UUID TbRxlH-zYl9-Y3zz-tsEH-1ASj-1uma-qhVLo8

[root@localhost lvmmntpt]# lvdisplay /dev/testvg/testlv
--- Logical volume ---
LV Name /dev/testvg/testlv
VG Name testvg
LV UUID jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
LV Write Access read/write
LV Status available
# open 1 [ here open is 1 because it's mounted]
LV Size 124.00 MB
Current LE 31
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

[root@localhost ~]# vi /etc/fstab
…....
…....
/dev/testvg/testlv /lvmmntpt ext3 defaults 0 0


[root@localhost ~]# mount -a

[root@localhost ~]# cd /lvmmntpt/

[root@localhost lvmmntpt]# ls
lost+found
(It indicates successful mounting of newly created LV )

Sunday, March 29, 2009

LVM2

Logical Volume Manager

LVM is a tool for logical volume management which includes allocating disks, striping, mirroring
and resizing logical volumes

LVM version 2, or LVM2, is the default for Red Hat Enterprise Linux 5, which uses the device
mapper driver contained in the 2.6 kernel.

Steps required to configure LVM include:

• Creating physical volumes from the hard drives.
• Creating volume groups from the physical volumes.
• Creating logical volumes from the volume groups and assign the logical volumes mount
points.

PHYSICAL VOLUMES ---> VOLUME GROUP ---> LOGICAL VOLUME ---> MOUNT POINT/FILE SYSTEMS

(note: For Red Hat Enterprise Linux, LVM is the default method for disk partitioning: To verify it, try to use the default installation and see the File Systems, you can see LVM )
Let me walk you through the manual LVM configuration while linu installation:
Lets say my system has 2 IDE drives each of 3.0GB; As we know for linux installation, minimally we need to create following 3 partitions
/boot : it can't be created in logical volume
swap
/
(note: The physical volumes are combined into logical volumes, with the exception of the /boot/partition. The /boot/ partition cannot be on a logical volume group because the boot loadercannot read it. If the root (/) partition is on a logical volume, create a separate /boot/ partitionwhich is not a part of a volume group. )
......... will be discussed in detailed in lab............