Monday, February 1, 2010

Setup additional LVM in CentOS 5.2

SkyHi @ Monday, February 01, 2010

This post will cover a setup of an additional LVM in CentOS 5.2 running from XenServer Express Edition. I will not cover the installation of the LVM itself because I assume you have a copy of LVM installed. Lets begin.

1. Print out the partition of all hard disk using the following commands below: -

[root@ctos5264a ~]# fdisk -l

Disk /dev/xvda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 13 104391 83 Linux
/dev/xvda2 14 3916 31350847+ 8e Linux LVM

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

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

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

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

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

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

2. Next, create one new partition for /dev/xvdb using Linux LVM filesystem as below: -

[root@ctos5264a ~]# fdisk /dev/xvdb
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.

The number of cylinders for this disk is set to 1305.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

2a. In fdisk, press “n” to create a new partition. Next, press “p” to select primary partition as your choice and following press “1″ for first partition. Then, press “1″ again to select the first cylinder of the partition and follow by typing “1305″ to select the last cylinder of the partition. The partition will be created in a second.

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

2b. You are still in fdisk. Press “p” to print the partition.

Command (m for help): p <-- ENTER

Disk /dev/xvdb: 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/xvdb1 1 1305 10482381 83 Linux

2c. To change the partition filesystem, press “t” and follow by “L” to list out the codes.

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

0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot
1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris
2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx
6 FAT16 42 SFS 86 NTFS volume set da Non-FS data
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext 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 75 PC/IX

2d. Enter “8e” to select Linux LVM as the filesystem and lastly press “w” to save the partition.

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

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

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

3. Print out the partition of /dev/xvdb using the following commands below: -

[root@ctos5264a ~]# fdisk -l /dev/xvdb

Disk /dev/xvdb: 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/xvdb1 1 1305 10482381 8e Linux LVM

4. You can proceed to create one new partition for /dev/xvdc and /dev/xvde using the steps above.

5. After you have created the new partition, lets print out and verify using the command below: -

[root@ctos5264a ~]# fdisk -l

Disk /dev/xvda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 13 104391 83 Linux
/dev/xvda2 14 3916 31350847+ 8e Linux LVM

Disk /dev/xvdb: 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/xvdb1 1 1305 10482381 8e Linux LVM

Disk /dev/xvdc: 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/xvdc1 1 1305 10482381 8e Linux LVM

Disk /dev/xvde: 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/xvde1 1 1305 10482381 8e Linux LVM

6. Now lets create the new partitions for LVM using the command below: -


[root@ctos5264a ~]# pvcreate /dev/xvdb1 /dev/xvdc1 /dev/xvde1
Physical volume "/dev/xvdb1" successfully created
Physical volume "/dev/xvdc1" successfully created
Physical volume "/dev/xvde1" successfully created

7. You can verify the above command by printing the current state of your physical volumes using the command below: -


[root@ctos5264a ~]# pvdisplay
--- Physical volume ---
PV Name /dev/xvda2
VG Name VolGroup00
PV Size 29.90 GB / not usable 24.06 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 956
Free PE 0
Allocated PE 956
PV UUID ruUiO0-p9bU-HmZW-rmr6-3PTd-o0C3-4IhxBM

"/dev/xvdb1" is a new physical volume of "10.00 GB"
--- NEW Physical volume ---
PV Name /dev/xvdb1
VG Name
PV Size 10.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID SKcT8y-ufAJ-q7mq-LveO-YktC-tAdj-I76V6Y

"/dev/xvdc1" is a new physical volume of "10.00 GB"
--- NEW Physical volume ---
PV Name /dev/xvdc1
VG Name
PV Size 10.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID oS2omJ-KI9S-pKe0-DXfJ-5OSh-YU8b-CQGls3

"/dev/xvde1" is a new physical volume of "10.00 GB"
--- NEW Physical volume ---
PV Name /dev/xvde1
VG Name
PV Size 10.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID VWAZFc-HUFz-65SZ-2oOE-AXrG-i0vD-U4Gj8K

8. Next, create the volume group “VolGroup01″ and add /dev/xvdb1 /dev/xvdc1 /dev/xvde1 to “VolGroup01″ as below: -


[root@ctos5264a ~]# vgcreate VolGroup01 /dev/xvdb1 /dev/xvdc1 /dev/xvde1
Volume group "VolGroup01" successfully created

9. You can verify the volume group created by running the command below: -

[root@ctos5264a ~]# vgdisplay

--- Volume group ---
VG Name VolGroup01
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 0
Cur PV 3
Act PV 3
VG Size 29.99 GB
PE Size 4.00 MB
Total PE 7677
Alloc PE / Size 0 / 0
Free PE / Size 7677 / 29.99 GB
VG UUID OuaiF9-eSCk-CcQ4-3aXF-8FoD-zzUK-afIOWb

--- 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 29.88 GB
PE Size 32.00 MB
Total PE 956
Alloc PE / Size 956 / 29.88 GB
Free PE / Size 0 / 0
VG UUID eNFBwl-uedf-oODB-YFDG-Np7X-Lrt1-949pdv

10. You can also run the command below to verify the volume group created: -


[root@ctos5264a ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup01" using metadata type lvm2
Found volume group "VolGroup00" using metadata type lvm2

11. Next, create the logical volumes “share1″ with “20GB” size in the volume group “VolGroup01″ using the command below: -


[root@ctos5264a ~]# lvcreate --name share1 --size 20G VolGroup01
Logical volume "share1" created

12. Now, print out the overview of the logical volumes using the command below: -


[root@ctos5264a ~]# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup01/share1
VG Name VolGroup01
LV UUID MehBKd-sCqR-1jrl-yriX-QDU3-BP4I-qVc9LX
LV Write Access read/write
LV Status available
# open 0
LV Size 20.00 GB
Current LE 5120
Segments 3
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 DzwZu2-wmoH-2Bmu-eOoK-IlYZ-9OlC-R5TWGb
LV Write Access read/write
LV Status available
# open 1
LV Size 28.84 GB
Current LE 923
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 Zr53bA-djGf-Qdda-VsrX-7ewX-1RyY-6CapPj
LV Write Access read/write
LV Status available
# open 1
LV Size 1.03 GB
Current LE 33
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

13. You can also verify the logical volumes using the command below: -


[root@ctos5264a ~]# lvscan
ACTIVE '/dev/VolGroup01/share1' [20.00 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol00' [28.84 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [1.03 GB] inherit

14. Next, format the logical volume with ext3 filesystem using the command below: -


[root@ctos5264a ~]# mkfs.ext3 /dev/VolGroup01/share1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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 (32768 blocks): done
Writing superblocks and filesystem accounting information: done


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

15. Create a mount directory using the command below: -

[root@ctos5264a ~]# mkdir /mnt/share1

16. Finally, lets mount the logical volume using the command below: -

[root@ctos5264a ~]# mount /dev/VolGroup01/share1 /mnt/share1


REFERENCE

http://wingloon.com/2009/01/16/setup-additional-lvm-in-centos-52/comment-page-1/