I put this little How-TO together from my need to add and manage LVM volumes on several headless servers. LVM is quite powerful, but you can also make your life hell how the road if certain things aren’t in place.
For this demonstration I have 2 Sata disks (sdc and sdd) that I’d like to join together to create one large space. I’m using Cent OS 5.2 which uses LVM 2. If you are using LVM 1, there are additional restrictions which I won’t cover here.
Step by step, here we go.
-
Partition each disk. I know LVM can use the whole raw disk, but if you ever want access to the data on the disk outside of LVM, you can access it if you create a partition first.
-
Next, you have to initialize the partitions.
[root@coral ~]# pvcreate /dev/sdc1
Physical volume “/dev/sdc1” successfully created
[root@coral ~]# pvcreate /dev/sdd1
Physical volume “/dev/sdd1” successfully created
[root@coral ~]#
-
Now we create a volume group with our newly initialized partitions.
[root@coral ~]# vgcreate Big_Vault /dev/sdc1 /dev/sdd1
Volume group “Big_Vault” successfully created
[root@coral ~]#
-
Now create a logical volume. While you can create many different volume types and sizes from this space, I’m going to make one large storage area.
First display the volume group
[root@coral ~]# vgdisplay Big_Vault
— Volume group —
VG Name Big_Vault
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 1.82 TB
PE Size 4.00 MB
Total PE 476932
Alloc PE / Size 0 / 0
Free PE / Size 476932 / 1.82 TB
VG UUID rAWi5p-yf50-0d7H-idWD-17j1-ZrTw-1dDbmw
[root@coral ~]#
Using the PE Size value we create our logical volume.
[root@coral ~]# lvcreate -l 476932 Big_Vault -n Storage
Logical volume “Storage” created
[root@coral ~]#
-
Your new Logical Volume can be found in /dev/mapper as /dev/mapper/Big_Vault-Storage.
For more info, check out The Linux Document Project at http://tldp.org. They have some great docs on LVM.
[root@coral ~]# 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.
The number of cylinders for this disk is set to 121601.
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)
Command (m for help): p
Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
As you can see, a fresh disk with no partitions on it. If you want to re purpose a whole disk, just remove the partitions first or just add a partition in the unused space. That’s the beauty of LVM, you an use any space on any disk.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-121601, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-121601, default 121601):
Using default value 121601
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83
Command (m for help): p
Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 121601 976760001 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@coral ~]#
I did the same steps for my other disk sdd.
This creates a volume descriptor at the start of the partition.
Leave a Reply