LVM basic configuration
In the following article, the basic configuration of LVs is explained. The used system is a Ubuntu Server 10.4 with the 2.6.32-24 kernel and the LVM-version 2.02.54(1) (2009-10-26). In the following, it is explained how to create partitions of Physical Volumes (PVs), a Volume Group (VG) and the Logical Volumes (LVs) built on top of them.
Creating partitions
First, the partitions for the PVs are created. The following points must be taken into account:
- Partition Alignment
- Switch display to sectors (Switch "-u")
- switch off DOS-compatible mode (Switch "-c")
- for later LVM management
- switch system ID of partition to "8e" (Switch "-t" bei fdisk)
After the changes, the partition table looks as follows:
root@ubuntu:/home/tktest# fdisk -lu Disk /dev/sda: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00051afd Device Boot Start End Blocks Id System /dev/sda1 * 2048 9920511 4959232 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 9922558 10483711 280577 5 Extended Partition 2 does not end on cylinder boundary. /dev/sda5 9922560 10483711 280576 82 Linux swap / Solaris Disk /dev/sdb: 2147 MB, 2147483648 bytes 22 heads, 16 sectors/track, 11915 cylinders, total 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x1673663d Device Boot Start End Blocks Id System /dev/sdb1 2048 4194303 2096128 8e Linux LVM Disk /dev/sdc: 2147 MB, 2147483648 bytes 22 heads, 16 sectors/track, 11915 cylinders, total 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xbd277faf Device Boot Start End Blocks Id System /dev/sdc1 2048 4194303 2096128 8e Linux LVM
Preparation of PVs
PVs also include meta data for the administration of volumes (see also LVM basics). 255 sectors (á 512 byte) are created for the meta data by default. Among other things, a meta data area that is too small can result in, for example, the inability to create snapshots anymore: Fix LVM VG vgname metadata too large for circular buffer. Therefore, it will make sense to configure a larger meta data area. If you want to enlargen your meta data area, the parameter "--metadatasize" must be added to the command "pvcreate" and then select the desired size at:
--metadatasize size
After that, the partitions are initialized as PV.
root@ubuntu:~# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created root@ubuntu:~# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created
The commands "pvs" and "pvdisplay" offer a variety of possibilities to display the current status of the PVs.
root@ubuntu:~# pvs PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 -- 2.00g 2.00g /dev/sdc1 lvm2 -- 2.00g 2.00g
Creating a VG
The PVs, that have been created before, are now summarized to a VG.
root@ubuntu:~# vgcreate vg00 /dev/sdb1 /dev/sdc1 Volume group "vg00" successfully created
The "pvdisplay" now shows that a VG was created with the PVs:
root@ubuntu:~# pvdisplay --- Physical volume --- PV Name /dev/sdb1 VG Name vg00 PV Size 2.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 511 Free PE 511 Allocated PE 0 PV UUID fl9ipM-bhhQ-V46G-2iH3-R3yZ-9DsN-JbRmY9 --- Physical volume --- PV Name /dev/sdc1 VG Name vg00 PV Size 2.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 511 Free PE 511 Allocated PE 0 PV UUID d1iY5L-ac3F-W5Sz-zyaE-uaT3-f66r-I3831o
vgdisplay also shows information on VG:
root@ubuntu:~# vgdisplay --- Volume group --- VG Name vg00 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 3.99 GiB PE Size 4.00 MiB Total PE 1022 Alloc PE / Size 0 / 0 Free PE / Size 1022 / 3.99 GiB VG UUID YTEj9f-9LCT-EOP5-JBEA-YHSz-c0R1-TMzVmy
What stands out here is, that the PE size is 4.00 MiB. Since the lvm2-format, the number of PEs is not limited anymore. According to the Man page of vgcreate, a high number of PEs can slow down the tools. However, the number of pEs does not have influence on the I/O-performance of the Logical Volumes. If you want to change the PE-size, add the parameter to "vgcreate"
-s, --physicalextentsize PhysicalExtentSize
Creating LVs
There are different possibilities to specify the size of the LV to be created. However, all LVs require the parameter "-l" or "-L".
- size specification in, for example, Gigabyte:
lvcreate -n data -L1G vg00
- Percentage of available storage in the VG:
lvcreate -n data -l100%VG vg00
- Percentage of free storage in the VG:
lvcreate -n data -l100%FREE vg00
The example in progress is continued by dividing the VG into two equally sized LVs:
root@ubuntu:~# lvcreate -n data -l50%VG vg00 Logical volume "data" created root@ubuntu:~# lvcreate -n data1 -l100%FREE vg00 Logical volume "data1" created
Now, the status of the Logical Volume can be taken into consideration:
root@ubuntu:~# lvdisplay --- Logical volume --- LV Name /dev/vg00/data VG Name vg00 LV UUID S1btrq-zQZQ-h9oU-2VE6-UNoT-hkqB-Fpv7pG LV Write Access read/write LV Status available # open 0 LV Size 2.00 GiB Current LE 511 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0 --- Logical volume --- LV Name /dev/vg00/data1 VG Name vg00 LV UUID Syaml9-d1Ax-RYTs-tSZy-vEyq-yzqW-VoOddZ LV Write Access read/write LV Status available # open 0 LV Size 2.00 GiB Current LE 511 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:1
Creating file system
Now, the LVs can be formatted with a file system and mounted afterwards:
mkfs.ext4 /dev/vg00/data mkdir data mount /dev/vg00/data data
Removing LV
If a LV should be removed, it can be removed via lvremove command:
root@ubuntu:~# lvremove /dev/vg00/data_snap Do you really want to remove active logical volume data_snap? [y/n]: y Logical volume "data_snap" successfully removed
The LV data_snap does no longer appear as an LV. However, the underlying partition is still listed as a PV:
--- Physical volume --- PV Name /dev/sde1 VG Name vg00 PV Size 2.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 511 Free PE 511 Allocated PE 0 PV UUID lKEW15-1YHu-dikC-S0Pm-72UJ-UMPg-fgiW0Y
If the partition should be released completely, the PV must be removed from the VG first:
root@ubuntu:~# vgreduce vg00 /dev/sde1 Removed "/dev/sde1" from volume group "vg00" root@ubuntu:~# pvdisplay "/dev/sde1" is a new physical volume of "2.00 GiB" --- NEW Physical volume --- PV Name /dev/sde1 VG Name PV Size 2.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID lKEW15-1YHu-dikC-S0Pm-72UJ-UMPg-fgiW0Y
Now, the PV can be also deleted completely to reformat, for example, the hard drive:
root@ubuntu:~# pvremove /dev/sde1 Labels on physical volume "/dev/sde1" successfully wiped
Author: Georg Schönberger
|
Translator: Alina Ranzinger Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.
|

