Sunday 29 July 2012

Creating LVM in Linux

Creating Lvm in linux:-
======================

a) I have a disk named /dev/sdb which is of 25GB, using this We will
be creating a LVM. First we need to create physical volume, then
volume group then the logical volumes.

[root@rhel ~]# fdisk -l

Disk /dev/sda: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 65 522081 83 Linux
/dev/sda2 66 702 5116702+ 83 Linux
/dev/sda3 703 963 2096482+ 83 Linux
/dev/sda4 964 3263 18474750 5 Extended
/dev/sda5 964 1224 2096451 82 Linux swap
/dev/sda6 1225 1289 522081 83 Linux
/dev/sda7 1290 3263 15856123+ 83 Linux

Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


b. First will be creating 3 partition using the device /dev/sdb


[root@rhel ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 3133.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

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

Command (m for help): p

Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1242 9976333+ 83 Linux

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

0 Empty 1e Hidden W95 FAT1 75 PC/IX be Solaris boot
1 FAT12 24 NEC DOS 80 Old Minix bf Solaris
2 XENIX root 39 Plan 9 81 Minix / old Lin c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 82 Linux swap c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 83 Linux c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 84 OS/2 hidden C: c7 Syrinx
6 FAT16 42 SFS 85 Linux extended da Non-FS data
7 HPFS/NTFS 4d QNX4.x 86 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 87 NTFS volume set de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

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

Command (m for help): p

Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1242 9976333+ 8e Linux LVM
/dev/sdb2 1243 2484 9976365 83 Linux

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

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

Command (m for help): p

Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1242 9976333+ 8e Linux LVM
/dev/sdb2 1243 2484 9976365 8e Linux LVM
/dev/sdb3 2485 3133 5213092+ 83 Linux

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

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

Calling ioctl() to re-read partition table.
Syncing disks.


[root@rhel ~]# fdisk -l

Disk /dev/sda: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 65 522081 83 Linux
/dev/sda2 66 702 5116702+ 83 Linux
/dev/sda3 703 963 2096482+ 83 Linux
/dev/sda4 964 3263 18474750 5 Extended
/dev/sda5 964 1224 2096451 82 Linux swap
/dev/sda6 1225 1289 522081 83 Linux
/dev/sda7 1290 3263 15856123+ 83 Linux

Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1242 9976333+ 8e Linux LVM
/dev/sdb2 1243 2484 9976365 8e Linux LVM
/dev/sdb3 2485 3133 5213092+ 8e Linux LVM


c) Now we have created 3 Partition of type Linux LVM, then execute the partproble cmd
to inform the changes made on the partition table.

[root@rhel ~]# partprobe

d) Create the physical volume using the 3 partition which we have created now

[root@rhel ~]# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created

e) Check the list of physical volumes.

pvs - report information about physical volumes

[root@rhel ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 -- 9.51G 9.51G
/dev/sdb2 lvm2 -- 9.51G 9.51G
/dev/sdb3 lvm2 -- 4.97G 4.97G

f) Then create a volumne gruoup using these physical volumes, the attribute -p defines the maximum no.
of physical volumes can be added in this volume group, the /dev/orahome defines the name of the 
volumes group.

[root@rhel ~]# vgcreate -s 32 -p 100 /dev/orahome /dev/sdb1 /dev/sdb2 /dev/sdb3
Volume group "orahome" successfully created

e) Display and check the properties of the volume group which we have created.

[root@rhel ~]# vgdisplay -v orahome
Using volume group(s) on command line
Finding volume group "orahome"
--- Volume group ---
VG Name orahome
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 100
Cur PV 3
Act PV 3
VG Size 23.97 GB
PE Size 32.00 MB
Total PE 767
Alloc PE / Size 0 / 0
Free PE / Size 767 / 23.97 GB
VG UUID zMQhxU-3Epq-UV54-QKkU-YpkI-mNIj-6UGxI1

--- Physical volumes ---
PV Name /dev/sdb1
PV UUID itUG6n-E9Ug-AW27-s0JI-iinC-Z8BZ-f3XzDG
PV Status allocatable
Total PE / Free PE 304 / 304

PV Name /dev/sdb2
PV UUID 3Dr36J-QLNT-PkIL-iIHE-3wKM-wcFs-3ntguB
PV Status allocatable
Total PE / Free PE 304 / 304

PV Name /dev/sdb3
PV UUID ukv2D3-hfkO-nKYX-7bk6-gu2T-OEHO-uiiTgH
PV Status allocatable
Total PE / Free PE 159 / 159



f) Create the logical volumes using the volume group.

[root@rhel ~]# lvcreate -L 23G -n orabin /dev/orahome
Logical volume "orabin" created

g) Check the properties of the lvm.

[root@rhel ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy%
orabin orahome -wi-a- 23.00G

h) Now make the file system using the logical volume.


[root@rhel ~]# mke2fs -j /dev/orahome/orabin
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
3014656 inodes, 6029312 blocks
301465 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=8388608
184 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

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

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

i) Create an directory and mount the lvm to the directory

[root@rhel /]# mkdir optware
[root@rhel /]# mount /dev/orahome/orabin /optware
[root@rhel /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.9G 4.0G 626M 87% /
/dev/sda1 494M 17M 453M 4% /boot
none 506M 0 506M 0% /dev/shm
/dev/sda3 2.0G 36M 1.9G 2% /software
/dev/sda6 494M 11M 458M 3% /tmp
/dev/sda7 15G 70M 15G 1% /orafiles
/dev/mapper/orahome-orabin
23G 77M 22G 1% /optware


j) Add the entry in fstab system file.


[root@rhel /]# vi /etc/fstab
/dev/orahome/orabin /optware ext3 defaults 0 0

h) un mount the mount point and check whether it is mounting properly.

[root@rhel /]# umount /optware
[root@rhel /]# mount -a
[root@rhel /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.9G 4.0G 626M 87% /
/dev/sda1 494M 17M 453M 4% /boot
none 506M 0 506M 0% /dev/shm
/dev/sda3 2.0G 36M 1.9G 2% /software
/dev/sda6 494M 11M 458M 3% /tmp
/dev/sda7 15G 70M 15G 1% /orafiles
/dev/mapper/orahome-orabin
23G 77M 22G 1% /optware

i) Now the lvm is ready to use



II) Steps to increase the size of the logical volume.

a) As per the above the size of the /optware mount point is 23G, we will
add another 2 GB to the mount point.


[root@rhel ~]# fdisk -l

Disk /dev/sda: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 65 522081 83 Linux
/dev/sda2 66 702 5116702+ 83 Linux
/dev/sda3 703 963 2096482+ 83 Linux
/dev/sda4 964 3263 18474750 5 Extended
/dev/sda5 964 1224 2096451 82 Linux swap
/dev/sda6 1225 1289 522081 83 Linux
/dev/sda7 1290 3263 15856123+ 83 Linux

Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1242 9976333+ 8e Linux LVM
/dev/sdb2 1243 2484 9976365 8e Linux LVM
/dev/sdb3 2485 3133 5213092+ 8e Linux LVM

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

Disk /dev/sdc doesn't contain a valid partition table

b) We have device /dev/sdc with 2 GB , we need to add this to the existing 
VG inorder to increase the Logical volume.

c) Create partition on the /dev/sdc.

[root@rhel ~]# fdisk /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): 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): 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): t
Selected partition 1
Hex code (type L to list codes): L

0 Empty 1e Hidden W95 FAT1 75 PC/IX be Solaris boot
1 FAT12 24 NEC DOS 80 Old Minix bf Solaris
2 XENIX root 39 Plan 9 81 Minix / old Lin c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 82 Linux swap c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 83 Linux c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 84 OS/2 hidden C: c7 Syrinx
6 FAT16 42 SFS 85 Linux extended da Non-FS data
7 HPFS/NTFS 4d QNX4.x 86 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 87 NTFS volume set de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@rhel ~]# fdisk -l

Disk /dev/sda: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 65 522081 83 Linux
/dev/sda2 66 702 5116702+ 83 Linux
/dev/sda3 703 963 2096482+ 83 Linux
/dev/sda4 964 3263 18474750 5 Extended
/dev/sda5 964 1224 2096451 82 Linux swap
/dev/sda6 1225 1289 522081 83 Linux
/dev/sda7 1290 3263 15856123+ 83 Linux

Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1242 9976333+ 8e Linux LVM
/dev/sdb2 1243 2484 9976365 8e Linux LVM
/dev/sdb3 2485 3133 5213092+ 8e Linux LVM

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


c) Run the partprobe to inform the kernel about the modified partition.

d) Create a physical volume.

[root@rhel ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
[root@rhel ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 orahome lvm2 a- 9.50G 0
/dev/sdb2 orahome lvm2 a- 9.50G 0
/dev/sdb3 orahome lvm2 a- 4.97G 992.00M
/dev/sdc1 lvm2 -- 2.00G 2.00G


e) Increase the VG using the vgextend cmd.


[root@rhel ~]# vgextend orahome /dev/sdc1
Volume group "orahome" successfully extended
[root@rhel ~]# vgdisplay -v orahome
--- Volume group ---
VG Name orahome
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 100
Cur PV 4
Act PV 4
VG Size 25.94 GB
PE Size 32.00 MB
Total PE 830
Alloc PE / Size 736 / 23.00 GB
Free PE / Size 94 / 2.94 GB
VG UUID zMQhxU-3Epq-UV54-QKkU-YpkI-mNIj-6UGxI1

f) As per the above the total size of the VG is 25.94 GB , and the allocated
size is 23 GB and the free size is 2.94 GB.

g) Now increase the lvm using the lvextend cmd.

[root@rhel ~]# lvextend -L 25G /dev/orahome/orabin
Extending logical volume orabin to 25.00 GB
Logical volume orabin successfully resized

h) Now resize the mount point. You can try to resize online , if it failures
the un mount the file sysem then resize and then mount again.

[root@rhel ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.9G 4.5G 93M 99% /
/dev/sda1 494M 17M 453M 4% /boot
none 760M 0 760M 0% /dev/shm
/dev/sda3 2.0G 1.3G 637M 67% /software
/dev/sda6 494M 13M 457M 3% /tmp
/dev/sda7 15G 6.5G 7.7G 46% /orafiles
/dev/mapper/orahome-orabin
23G 8.3G 14G 39% /optware


[root@rhel ~]# umount /optware
[root@rhel ~]# resize2fs /dev/orahome/orabin
resize2fs 1.35 (28-Feb-2004)
Please run 'e2fsck -f /dev/orahome/orabin' first.


[root@rhel ~]# e2fsck -f /dev/orahome/orabin
e2fsck 1.35 (28-Feb-2004)
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/orahome/orabin: 58274/3014656 files (1.7% non-contiguous), 2259610/6029312 blocks


[root@rhel ~]# resize2fs /dev/orahome/orabin
resize2fs 1.35 (28-Feb-2004)
Resizing the filesystem on /dev/orahome/orabin to 6553600 (4k) blocks.
The filesystem on /dev/orahome/orabin is now 6553600 blocks long.

[root@rhel ~]# mount /dev/orahome/orabin /optware/
[root@rhel ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.9G 4.5G 93M 99% /
/dev/sda1 494M 17M 453M 4% /boot
none 760M 0 760M 0% /dev/shm
/dev/sda3 2.0G 1.3G 637M 67% /software
/dev/sda6 494M 13M 457M 3% /tmp
/dev/sda7 15G 6.5G 7.7G 46% /orafiles
/dev/mapper/orahome-orabin
25G 8.3G 16G 35% /optware


Now the /optware shows 25G.

No comments:

Post a Comment