Experience LINUX LVM (Logical Volume Manager) with real time examples

1.) What LVM is?

2.) Terminology

3.) Creation of Physical Vol, Volume Group, Logical Volume, Filesystem creation, Mount and making the FS entry in /etc/fstab

4.) Add new disk under existing Volume Group

5.) Filesystem extension in Linux

6.) Filesystem shrinking in Linux

7.) Removing disk from existing Volume Group

8.) Special Note

 

 

1.) What LVM is?

LVM stands for Logical Volume Manger, Its a way of presenting Harddrivers/Storage to Operating System in a well defined, user understandale, logical way.
OR
LVM is a method of allocating hard drive space into logical volumes that can be easily resized instead of partitions.
OR
With LVM, the hard drive or set of hard drives is allocated to one or more physical volumes.

2.) Terminology:

a.) Harddrive/Storage Luns —> The physical media where are read and writes occured.

b.) Physical Volume —> The actual harddrive or a partition of harddrive can be assigned to Physical Volume. Its the smallest building unit in Linux LVM.

c.) Volume group —> The combination of Physical Volume is used to make a Volumegroup. You can think Volumegroup as a Pool of harddrives/partiotions.

d.) Logical Volume —> We can create Logical Volume on any Volumegroup which indeed are created on Physical Volume which indeed are on Physical disks.

e.) Mountpoint —> The Filesystem is created on Logical Volume and is mounted on mountpoint which is only a simple directory to make the Filesystem open to world for read write operations.

In simple:

PHYSICAL MEDIA ——->

PHYSICALVOLUME——>

VOLUMEGROUP ———>

LOGICALVOLUME ——>

MOUNTPOINT—>

ALL READY FOR YOU.:-)

Hard-disk, LUN Harddisk or partition Logical-storage-pool Base for Filesystem creation

 

3.) Creation of Physical Vol, Volume Group, Logical Volume, Filesystem creation, Mount and making the FS entry in /etc/fstab

In our previous post “Basis Filesystem Management in Linux” we have already covered the base of Linux FS so here we will concentrate more on LVM part. Before

proceeding I would like to make all Linux Beginners familiar with Partition Types, In Linux after making partition we have to choose the Partition Type according to the Filesystem we are going to create and use.

Linux-specific partitions would normally be one of the following types:
• 5 (or f) — Extended
• 82 — Linux swap
• 83 — Linux
• 8e — Linux LVM
• fd — Linux RAID auto

Commands used:

pvcreate
pvdisplay

vgcreate
vgdisplay

lvcreate -L or -l (by default is 4MB in Linux) -n
lvdisplay /dev/vgname/logicalvol-name

In example I am using 2 harddrive /dev/sdb & /dev/sdc for presenting LVM in Linux. I will use /dev/sdb to create PV, VG & LV and latter point of time I will add /dev/sdc in the existing VG and then we will perform online Filesystem resizing (extension and shrinking).

You can use complete disk or a portion of disk, I am taking complete disk in the example under primary partition 1.

yogesh-Linux#fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes ————————–> First Drive
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn’t contain a valid partition table

Disk /dev/sdc: 2147 MB, 2147483648 bytes ————————–> second Drive
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn’t contain a valid partition table
yogesh-Linux#

yogesh-Linux#cat /proc/partitions
major minor #blocks name

8 0 10485760 sda
8 1 104391 sda1
8 2 10377990 sda2
8 16 2097152 sdb
8 32 2097152 sdc
253 0 9306112 dm-0
253 1 1048576 dm-1
yogesh-Linux#

yogesh-Linux#fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id ————————> To change partition ID
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 83 Linux ————> Here the ID is 83 for simple Linux FS.

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L

0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris
1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx
5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data
6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
f W95 Ext’d (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
14 Hidden FAT16 we have changed it to 8e as per Linux Kernel Architecture

Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 8e Linux LVM ———–> 8e for Linux LVM

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
yogesh-Linux#
yogesh-Linux#
yogesh-Linux#cat /proc/partitions
major minor #blocks name

8 0 10485760 sda
8 1 104391 sda1
8 2 10377990 sda2
8 16 2097152 sdb
8 17 2096451 sdb1
8 32 2097152 sdc
253 0 9306112 dm-0
253 1 1048576 dm-1

yogesh-Linux#partprobe /dev/sdb1
yogesh-Linux#

yogesh-Linux#fdisk /dev/sdc ——————————> Similar process for 2nd disk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel 
Building a new DOS disklabel.

Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdc1 1 261 2096451 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
yogesh-Linux#
yogesh-Linux#cat /proc/partitions
major minor #blocks name

8 0 10485760 sda
8 1 104391 sda1
8 2 10377990 sda2
8 16 2097152 sdb
8 17 2096451 sdb1
8 32 2097152 sdc
8 33 2096451 sdc1
253 0 9306112 dm-0
253 1 1048576 dm-1
yogesh-Linux#partprobe /dev/sdc1
yogesh-Linux#

yogesh-Linux#pvcreate /dev/sdb1 —————————–> Physical Volume Creation
Physical volume “/dev/sdb1” successfully created
yogesh-Linux#

yogesh-Linux#vgcreate gurkulgroup /dev/sdb1 ——————–> Volume group creation
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device ‘/dev/cdrom’ which is not open.
Volume group “gurkulgroup” successfully created
yogesh-Linux#
yogesh-Linux#

yogesh-Linux#pvdisplay /dev/sdb1
— Physical volume —
PV Name /dev/sdb1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 511
Allocated PE 0
PV UUID 90ikep-gxVd-oLkf-1YGO-s0dl-JkqQ-zTqY7a

yogesh-Linux#vgdisplay gurkulgroup
— Volume group —
VG Name gurkulgroup
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 2.00 GB
PE Size 4.00 MB ——————-> This PE is the physical extents (Physical Volumes are defined with Phyisical Extents of a fixed size)
Total PE 511
Alloc PE / Size 0 / 0
Free PE / Size 511 / 2.00 GB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc

yogesh-Linux#lvcreate -L 1.5g -n gurkulvolume gurkulgroup —————-> Logical Volume Creation
Logical volume “gurkulvolume” created
yogesh-Linux#

yogesh-Linux#lvdisplay /dev/gurkulgroup/gurkulvolume
— Logical volume —
LV Name /dev/gurkulgroup/gurkulvolume
VG Name gurkulgroup
LV UUID BAS7wh-VZDt-l9rg-mdcf-srQr-yEY2-q9dTsK
LV Write Access read/write
LV Status available
# open 0
LV Size 1.50 GB
Current LE 384
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2

yogesh-Linux#mkfs -t ext3 /dev/gurkulgroup/gurkulvolume ——————–> Filesystem creation
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
196608 inodes, 393216 blocks
19660 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=402653184
12 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

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

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

yogesh-Linux#mkdir /gurkultest —————————————> Mountpoint
yogesh-Linux#

yogesh-Linux#mount /dev/gurkulgroup/gurkulvolume /gurkultest ———–> FS mounted
yogesh-Linux#

yogesh-Linux#df -h /gurkultest
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest

yogesh-Linux# vi /etc/fstab
yogesh-Linux#more /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
LINUX1:/yogesh /nfstest nfs defaults 0 0
#/dev/sdc1 /yogesh-primary-test ext3 defaults 0 0
#/dev/sdc5 /yogesh-extended-test ext3 defaults 0 0
#/dev/raidgroup/raidvol /test-raid ext3 defaults 0 0
/dev/gurkulgroup/gurkulvolume /gurkultest ext3 defaults 0 0 ————-> entry in fstab, to make FS persistent across reboots
yogesh-Linux#

Test on the Permanent existence of Mountpoint created:

yogesh-Linux#umount /gurkultest
yogesh-Linux#

yogesh-Linux#mount -a
mount: mount to NFS server ‘LINUX1’ failed: System Error: No route to host.
yogesh-Linux#

yogesh-Linux#df -h /gurkultest
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest
yogesh-Linux#

 

 

4.) Add new disk under existing Volume Group:

Here in this section we will add one new disk under our existing volumegroup. This is the practical situation where some SA’s needs to extend and shrink Filesystems on regular basis, before proceeding with the Online resizing SA needs to take the disk under OS control and then assign it to existing VG. The process is same as we mentioned above but some commands will be changed as now we are expanding already existed VG.

yogesh-Linux#df -h /gurkultest
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest

yogesh-Linux#vgdisplay gurkulgroup
— Volume group —
VG Name gurkulgroup
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 2.00 GB ——————————> VG size is 2GB i.e the size of /dev/sdb disk
PE Size 4.00 MB
Total PE 511
Alloc PE / Size 384 / 1.50 GB
Free PE / Size 127 / 508.00 MB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc

yogesh-Linux#fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 8e Linux LVM

Disk /dev/sdc: 2147 MB, 2147483648 bytes ————————————————> extra disk to add under VG
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdc1 1 261 2096451 8e Linux LVM
yogesh-Linux#

yogesh-Linux#pvcreate /dev/sdc1 ———————————–> Physical volume create for /dev/sdc
Physical volume “/dev/sdc1” successfully created
yogesh-Linux#

yogesh-Linux#pvdisplay ——————-> I have my rootdisk under LVM so dont get confused with /dev/sda (its my rootdisk), just concentarte on /dev/sd{b,c}
— Physical volume —
PV Name /dev/sdb1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 127
Allocated PE 384
PV UUID 90ikep-gxVd-oLkf-1YGO-s0dl-JkqQ-zTqY7a

— Physical volume —
PV Name /dev/sda2
VG Name VolGroup00
PV Size 9.90 GB / not usable 22.76 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 316
Free PE 0
Allocated PE 316
PV UUID md04K8-UyPp-X8G8-KZ7F-Vvm0-jbev-x0SClg

“/dev/sdc1” is a new physical volume of “2.00 GB” ———————-> its not yet assigned to any VG
— NEW Physical volume —
PV Name /dev/sdc1
VG Name
PV Size 2.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID JN8wPA-8mAt-9P2E-DYM0-QLYR-uubc-HeeOqb

yogesh-Linux#

yogesh-Linux#vgextend gurkulgroup /dev/sdc1 ———————> Volumegroup has been added with one new PV.
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device ‘/dev/cdrom’ which is not open.
Volume group “gurkulgroup” successfully extended
yogesh-Linux#

yogesh-Linux#vgdisplay gurkulgroup
— Volume group —
VG Name gurkulgroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
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 3.99 GB ——————————-> The size has been increasedto 4Gb as our disk are 2GB each.
PE Size 4.00 MB
Total PE 1022
Alloc PE / Size 384 / 1.50 GB
Free PE / Size 638 / 2.49 GB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc

yogesh-Linux#

yogesh-Linux#df -h /gurkultest/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest
yogesh-Linux#

 

 

5.) Filesystem extension in Linux (How to grow Filesystem Online in Linux i.e Online resizing)

The online resizing in Linux is very simple but needs to be perform with full caution.

At this point of time we have VG of 4GB with two PV’s and our Filesystem is of 1.5GB, we will increase it to 3GB and will check what the results will be. Kindly refer above outputs before proceeding.

Add new storage —-> Partition it —-> Create PV —-> Take PV under existing VG i.e extend VG —-> Extend Logical Volume —-> resize Filesystem —-> Allready with No Downtime.

yogesh-Linux#lvextend -L +1.5g /dev/gurkulgroup/gurkulvolume
Extending logical volume gurkulvolume to 3.00 GB
Logical volume gurkulvolume successfully resized
yogesh-Linux#

yogesh-Linux#df -h /gurkultest —————-> At this point of tme only Volume has been extended, we also need to resize the FS to reflect the results
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1.5G 35M 1.4G 3% /gurkultest

yogesh-Linux#resize2fs /dev/gurkulgroup/gurkulvolume
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/gurkulgroup/gurkulvolume is mounted on /gurkultest; on-line resizing required
Performing an on-line resize of /dev/gurkulgroup/gurkulvolume to 786432 (4k) blocks.
The filesystem on /dev/gurkulgroup/gurkulvolume is now 786432 blocks long.

yogesh-Linux#df -h /gurkultest ———————————–> Our filesystem is increased to 3GB now :)
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
3.0G 35M 2.8G 2% /gurkultest
yogesh-Linux#

6.) Filesystem shrinking in Linux: (How to reduce Filesystem):

In any OS the Shrinking should be peformed with extracare. It you will try to reduce the Filesystem more than space which is free in the FS, dataloss will occur.

Suppose your FS is of 3GB and out of which 2.5GB is used, here if you will try to reduce the FS to 2GB the dataloss will occur.

So best plan before proceeding with any FS shrinking operations, recommended would be to take the Backup before going ahead.

Below I am taking some backups in /gurkultest FS to show that no dataloss will occur if will reduce the FS if space is not used. I will reduce the Filesystem to 1GB.

Unmount the FS —-> Run Fsck —-> resize FS —-> resize existing volume —-> MountFS —-> All Done (Filesystem wont be available during the operation) i.e downtime for the FS is required.

yogesh-Linux#cp -p /var/log/messages /gurkultest

yogesh-Linux#df -h /gurkultest/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
3.0G 35M 2.8G 2% /gurkultest
yogesh-Linux#

yogesh-Linux#resize2fs /dev/gurkulgroup/gurkulvolume 1g —————-> Reduction wont allowed unless and until you will umount the FS
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/gurkulgroup/gurkulvolume is mounted on /gurkultest; on-line resizing required
On-line shrinking from 786432 to 262144 not supported.
yogesh-Linux#

yogesh-Linux#umount /gurkultest
yogesh-Linux#

yogesh-Linux#resize2fs /dev/gurkulgroup/gurkulvolume 1g ————> We have to proceed with fsck to check any dada inconsistency for the FS
resize2fs 1.39 (29-May-2006)
Please run ‘e2fsck -f /dev/gurkulgroup/gurkulvolume’ first.
yogesh-Linux#

yogesh-Linux#e2fsck -f /dev/gurkulgroup/gurkulvolume
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/gurkulgroup/gurkulvolume: 13/393216 files (7.7% non-contiguous), 21147/786432 blocks
yogesh-Linux#

yogesh-Linux#resize2fs /dev/gurkulgroup/gurkulvolume 1g
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/gurkulgroup/gurkulvolume to 262144 (4k) blocks.
The filesystem on /dev/gurkulgroup/gurkulvolume is now 262144 blocks long.
yogesh-Linux#

yogesh-Linux#lvreduce /dev/gurkulgroup/gurkulvolume -L 1g ——————> I am reducing Logical Vol to 1GB
WARNING: Reducing active logical volume to 1.00 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce gurkulvolume? [y/n]: y
Reducing logical volume gurkulvolume to 1.00 GB
Logical volume gurkulvolume successfully resized
yogesh-Linux#

yogesh-Linux#mount /dev/gurkulgroup/gurkulvolume /gurkultest/
yogesh-Linux#

yogesh-Linux#df -h /gurkultest/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/gurkulgroup-gurkulvolume
1008M 34M 933M 4% /gurkultest

yogesh-Linux#cd /gurkultest/
yogesh-Linux#ls

lost+found messages test

yogesh-Linux#ls -lrt —————————————-> No dataloss occured, messages file is preserved
total 104
drwx—— 2 root root 16384 Aug 17 19:22 lost+found
-rw——- 1 root root 74125 Aug 17 19:24 messages
-rw-r–r– 1 root root 0 Aug 17 19:37 test
yogesh-Linux#

7.) Removing disk from existing Volume Group:

Lets check the complete outputs before proceeding with the Disk removal from VG.

yogesh-Linux#pvdisplay
— Physical volume —
PV Name /dev/sdb1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 255
Allocated PE 256
PV UUID 90ikep-gxVd-oLkf-1YGO-s0dl-JkqQ-zTqY7a

— Physical volume —
PV Name /dev/sdc1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 511
Allocated PE 0
PV UUID JN8wPA-8mAt-9P2E-DYM0-QLYR-uubc-HeeOqb

— Physical volume —
PV Name /dev/sda2
VG Name VolGroup00
PV Size 9.90 GB / not usable 22.76 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 316
Free PE 0
Allocated PE 316
PV UUID md04K8-UyPp-X8G8-KZ7F-Vvm0-jbev-x0SClg

yogesh-Linux#vgdisplay
— Volume group —
VG Name gurkulgroup
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 3.99 GB
PE Size 4.00 MB
Total PE 1022
Alloc PE / Size 256 / 1.00 GB
Free PE / Size 766 / 2.99 GB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc

— Volume group —
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 9.88 GB
PE Size 32.00 MB
Total PE 316
Alloc PE / Size 316 / 9.88 GB
Free PE / Size 0 / 0
VG UUID 53YyKs-D2uQ-0gVY-My3w-6QOi-KDQ8-9dFUjF

yogesh-Linux#lvdisplay
— Logical volume —
LV Name /dev/gurkulgroup/gurkulvolume
VG Name gurkulgroup
LV UUID BAS7wh-VZDt-l9rg-mdcf-srQr-yEY2-q9dTsK
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2

— Logical volume —
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID XE3qZL-Ke6Z-3zN7-z1aD-3eee-BY6E-qdVmLz
LV Write Access read/write
LV Status available
# open 1
LV Size 8.88 GB
Current LE 284
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0

— Logical volume —
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID LT743f-Oy1u-Zq1Z-lKxM-czRy-hG9x-2H7RI3
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:1

yogesh-Linux#

yogesh-Linux#vgreduce gurkulgroup /dev/sdb1 ————> I tried to remove the disk having data, the LVM is so intelligent that it throw errors as
Physical volume “/dev/sdb1” still in use

yogesh-Linux#vgreduce gurkulgroup /dev/sdc1 —————–> disk removed from VG Removed “/dev/sdc1” from volume group “gurkulgroup”
yogesh-Linux#

yogesh-Linux#pvremove /dev/sdc1 ————————> disk removed from PV i.e complete LVM
/dev/cdrom: open failed: Read-only file system
Attempt to close device ‘/dev/cdrom’ which is not open.
Labels on physical volume “/dev/sdc1” successfully wiped
yogesh-Linux#

yogesh-Linux#pvdisplay /dev/sdc1
No physical volume label read from /dev/sdc1
Failed to read physical volume “/dev/sdc1”
yogesh-Linux#

yogesh-Linux#vgdisplay
— Volume group —
VG Name gurkulgroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 2.00 GB
PE Size 4.00 MB
Total PE 511
Alloc PE / Size 256 / 1.00 GB
Free PE / Size 255 / 1020.00 MB
VG UUID OBnNzV-RWvO-Gvy0-L1rb-Brh1-IiIH-33Mpnc

— Volume group —
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 9.88 GB
PE Size 32.00 MB
Total PE 316
Alloc PE / Size 316 / 9.88 GB
Free PE / Size 0 / 0
VG UUID 53YyKs-D2uQ-0gVY-My3w-6QOi-KDQ8-9dFUjF

yogesh-Linux#pvdisplay
— Physical volume —
PV Name /dev/sdb1
VG Name gurkulgroup
PV Size 2.00 GB / not usable 3.32 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 511
Free PE 255
Allocated PE 256
PV UUID 90ikep-gxVd-oLkf-1YGO-s0dl-JkqQ-zTqY7a

— Physical volume —
PV Name /dev/sda2
VG Name VolGroup00
PV Size 9.90 GB / not usable 22.76 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 316
Free PE 0
Allocated PE 316
PV UUID md04K8-UyPp-X8G8-KZ7F-Vvm0-jbev-x0SClg

yogesh-Linux#lvdisplay
— Logical volume —
LV Name /dev/gurkulgroup/gurkulvolume
VG Name gurkulgroup
LV UUID BAS7wh-VZDt-l9rg-mdcf-srQr-yEY2-q9dTsK
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2

— Logical volume —
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID XE3qZL-Ke6Z-3zN7-z1aD-3eee-BY6E-qdVmLz
LV Write Access read/write
LV Status available
# open 1
LV Size 8.88 GB
Current LE 284
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0

— Logical volume —
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID LT743f-Oy1u-Zq1Z-lKxM-czRy-hG9x-2H7RI3
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:1

yogesh-Linux#

8.) Special Note:

a.) You can use -l with lvcreate if you wish to use extend instead of size.
b.) Extents size can be changed as per desire.
c.) The physical volumes are combined into logical volume groups, with the exception of the /boot/ partition. The /boot/ partition can not be on a logical volume group

because the boot loader can not read it. If the root / partition is on a logical volume, create a separate /boot/ partition which is not a part of a volume group.
d.) Untill here only LVM is covered so no data redundancy is there as any disk failure will case the dataloss if data is present in the failed disk. So better take backups.

We will come up with the Software RAID in Linux soon in our next post so that we can show you the data redundancy via mirroring in Linux.   

Yogesh Raheja

Yogesh working as a Consultant in Unix Engineering by profession. And he has multiple years experience in Solaris, Linux , AIX and Veritas Administration. He has been certified for SCSA9, SCSA10, SCNA10, VXVM, VCS, ITILv3. He is very much passionate about sharing his knowledge with others. Specialties: Expertize in Unix/Solaris Server, Linux (RHEL), AIX, Veritas Volume Manager, ZFS, Liveupgrades, Storage Migrations, Cluster deployment (VCS and HACMP) and administration and upgrade on Banking, Telecom, IT Infrastructure, and Hosting Services.

37 Responses

  1. Soon we will come up with Software RAID, so that complete FS Management with LVM will be completed for Linux at our Gurkul-India database. Though their is already a doc for RAID at our Gurkul. But we will try to present a more simpler version with complete examples.

  2. Thanks you Avijit Patra dada..

  3. Bhopinder says:

    Awsome article for linux beginners who are migrating from Solaris. Will be more helpful if you could add procedure how to mirror etc.

  4. Hi Bhopinder, we will bring the post where we will take up the software Raid in Linux and we present how to mirror the disk in Linux with LVM.

  5. Arunabha says:

    Hi Yogesh, Please keep in mind that we can extend online file system RHEL 5 onwards. Prior to RHEL 5 you need to unmount the file system before resizing. So you need a downtime for that.

  6. Yogesh Raheja says:

    yes, you are right Arunabha.

  7. seema says:

    Hello Yogesh i am newbie to linux and this is my first work ….. host i am working is Red Hat Enterprise Linux ES release 4 (Nahant) so for this release i need to unmount the file system then extend it correct !!! which needs the downtime from the apps team !!

  8. @Seema, extension can be done online. Downtime only required when you are doing Shrinking. You can go through the above post and will get maximum information regarding LVM.

  9. seema says:

    I have read the posts by you on LVM they are too good for newbie but from the comments from arunabha for RHEL 4 need to unmount the FS which means APPLICATION FS will be unavailable during extending !!!

  10. seema says:

    @yogesh # man rezise2fs
    No manual entry for rezise2fs

    and when i was trying to do it
    i got an error -bash: resize2fs: command not found ….Though i have checked my PATH
    …. Is there a way to get out of it ….

  11. seema says:

    I checked the man for ext2online and it worked ……. i.e ext2online will increase the file system which is mounted . ext2online can be used only after extending LV by lvextend command …. once done can be verifed by df -g /FS name ………….. Thanks Yogesh ….

  12. Ramdev Ramdev says:

    @seema — # man rezise2fs you have a typo in resize2fs .. please try again.

  13. Yogesh Raheja says:

    @Seema, you dont required sowntime while Extension. Its true for RHEL 4 as well. FS should be unmounted only in case of shrinking. You should be able to find resize2fs in RHEL 4 also. Try find / -name resize2fs -print to search the command path. Hope this helps.

  14. Michael Michael says:

    @ Seema  you can extend the ext2/ext3 online but that is not providing a good means of shrniking the FS online .resize2fs command can be used to extend the FS online provided if the kernel supports  on-line resizing. As per from , the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 only.If your kernel is not supporting then you cannot extend the FS even online you require a downtime 

  15. seema says:

    @ramdev # man resize2fs
    No manual entry for resize2fs …. I did used find thats my first option …However i was able to do it using ext2online …. Thanks all for the replies

  16. seema says:

    Ramdev i just want to clarify myself —-> I can use resize2fs on Red Hat Enterprise Linux ES release 3 (Taroon Update 7) but i cannot do it on Red Hat Enterprise Linux ES release 4 (Nahant) … i did used which and find command and also checked PATH … IS this because of the release .. I know this is not a really really issue but to get a clarification ….

  17. Yogesh Raheja says:

    @Seema, as far as I remembered resize2fs work in RHEL 4. I dont know why you are unable to get in your system. just provide me with the output of uname -a & redhat-release version.

  18. aim target says:

    Hello Yogesh,

    after i proceed with extend the lvm as below on my zimbra mail-server :

    ==================================================================

    [root@mail VolGroup00]# lvm lvextend -l+8937 /dev/VolGroup00/LogVol00    Extending logical volume LogVol00 to 482.00 GB  Logical volume LogVol00 successfully resized
    [root@mail VolGroup00]#
    [root@mail VolGroup00]# resize2fs /dev/VolGroup00/LogVol00
    resize2fs 1.39 (29-May-2006)
    Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing re                                                                                  quiredPerforming an on-line resize of /dev/VolGroup00/LogVol00 to 126353408 (4k)                                                                                   blocks.The filesystem on /dev/VolGroup00/LogVol00 is now 126353408 blocks long.

    [root@mail VolGroup00]# dateSun Nov 27 00:15:31 MYT 2011

    [root@mail ~]# cat /proc/partitionsmajor minor  #blocks  name
       8     0  214719488 sda   8     1     104391 sda1   8     2  214612335 sda2   8    16  292852736 sdb   8    17  292848853 sdb1   8    32  241172480 sdc   8    33     120456 sdc1   8    34  241047292 sdc2   8    48 1073741824 sdd   8    64  113582080 sde   8    65     939771 sde1   8    80  241172480 sdf 253     0  505413632 dm-0 253     1    2031616 dm-1   8    96 1073741824 sdg   8    97    8040501 sdg1   8   112  113582080 sdh   8   144  976762584 sdj   8   145  976758784 sdj1[root@mail ~]#
    ==================================================================

    Now I getting dis error… actually i need to extend my current vg00 only :

    [root@mail ~]# vgdisplay  WARNING: Duplicate VG name VolGroup00: Existing 813rD3-NwqG-Mwxc-Mc1N-79lQ-Lym0-IG3WPz (created here) takes precedence over nKVmhd-EsYe-aj9L-dQ7z-YYaw-kEh1-bcvnmr  /dev/sdd: read failed after 0 of 4096 at 0: Input/output error  /dev/sdf: read failed after 0 of 4096 at 0: Input/output error  /dev/sdh: read failed after 0 of 4096 at 0: Input/output error  — Volume group —  VG Name               VolGroup00  System ID  Format                lvm2  Metadata Areas        1  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                1  Act PV                1  VG Size               229.88 GB  PE Size               32.00 MB  Total PE              7356  Alloc PE / Size       7355 / 229.84 GB  Free  PE / Size       1 / 32.00 MB  VG UUID               nKVmhd-EsYe-aj9L-dQ7z-YYaw-kEh1-bcvnmr
      — Volume group —  VG Name               VolGroup00  System ID  Format                lvm2  Metadata Areas        2  Metadata Sequence No  5  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               483.94 GB  PE Size               32.00 MB  Total PE              15486  Alloc PE / Size       15486 / 483.94 GB  Free  PE / Size       0 / 0  VG UUID               813rD3-NwqG-Mwxc-Mc1N-79lQ-Lym0-IG3WPz
    [root@mail ~]#

    Kindly advise and revert.

    regards,
    -AimTarget-
    aimyatim07@gmail.com
    FB: Aim Target’s
    YM: aim_yatim
    Skype: ibrahim281181

  19. Arunabha says:

    @aim targe, Please show us the output of ( cat /etc/redhat-release / fdisk -l | grep -i disk / pvscan / vgscan / pvs / vgs / cat /etc/lvm/backup/VolGroup00)

  20. Ramdev Ramdev says:

    @Arunabha – Thanks for responding for this request. Appreciate it.
    @aim Target – Please provide the information requested, so that other geeks can help you on this.

  21. Bava says:

    Nice article..

  22. Yogesh Raheja says:

    @Bava, thanks..

  23. Raghuram says:

    Nice post…

  24. Yogesh Raheja says:

    @Raghuram, thanks.

  25. SDN says:

    Nice artcle

  26. shekar says:

    Hi Yogesh

    Why i can’t use resize2fs to incease the FS on Red Hat Enterprise Linux AS release 4 (Nahant Update 8) pl advise ? ( exactly same problem faced by Seem )

    Thanks

  27. Ramdev Ramdev says:

    Hi Shekar, I could guess only two reasons in your case 

    If the resize2fs command missing from your machine  then the kernel might be older than 2.6.  And alternatively you can use ext2online.
    If the command is there and it is not working then there is a redhat bug report about that, which was fixed little later – https://bugzilla.redhat.com/show_bug.cgi?id=454872

    Sorry, we dont have RHEL4 machines to give you the exact answer.

  28. shekar says:

    Thanks Ram ,i too extended using ext2online .

    I want to check the psuedo Disk speed of read and write assigned to Linux server ,is there any tool available for liunx ?

    I can check the speed using hdparam -t /dev/sda ( if is is SATA ,ATA etc( , how will i check in the case of /dev/emcpowerx ?

  29. Mahesh Vijapure says:

    Hi Ram,

    Pls check out below two places where you need corrections –

    You missed to use “8e” while creating partition system type for the first disk(/dev/sdb).

    Also
    You are pointing to wrong line, pls see below-
    VG Size 3.99 GB
    PE Size 4.00 MB ——————————-> The size has been increasedto 4Gb as our disk are 2GB each.

    I believe you will not mind that I had pointed out this.

    Thanks,
    Mahesh Vijapure.

  30. Ganesha says:

    Nice article

  31. Ganesha says:

    Gettin following error in suse linux

    # pvcreate /dev/sdb1
    Warning: lvmetad is running but disabled. Restart lvmetad before enabling it!
    lvmetad: unknown service

  32. Ajay says:

    Hi Do you have any steps on how to rename a VG without umounting the Filesystem

  1. May 20, 2014

    […] Reference 1 –   Linux Admin Reference for  LVM2 Administration […]

  2. September 15, 2015

    […] Experience LINUX LVM (Logical Volume Manager) with real time examples […]

  3. September 17, 2015

    […] Experience LINUX LVM (Logical Volume Manager) with real time examples […]

Leave a Reply to Avijit Patra on Facebook Cancel reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us