🌐 🇵🇱 Polski · 🇬🇧 EN
Creating a logical volume step by step. We select the disk on which the volume will be created and initialize it for use as a physical volume.
Step 1 - Initialize the disk
# pvcreate /dev/hdb
Physical volume “/dev/hdb” successfully created
Step 2 - Verify that the physical volume was created correctly
# pvdisplay /dev/hdb
“/dev/hdb” is a new physical volume of “8.00 GiB”
-- NEW Physical volume --
PV Name /dev/hdb
VG Name
PV Size 8.00 GiB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID QlCLgF-esaN-5PvR-PWWV-D6jZ-O207-rHg90j
Step 3 - Create a volume group
# vgcreate vg_group01 /dev/hdb
Volume group “vg_group01” successfully created
Step 4 - Verify the creation of the volume group
# vgdisplay -v vg_group01
Using volume group(s) on command line
Finding volume group “vg_group01”
-- Volume group --
VG Name vg_group01
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 8.00 GiB
PE Size 4.00 MiB
Total PE 2047
Alloc PE / Size 0 / 0
Free PE / Size 2047 / 8.00 GiB
VG UUID IvjXga-898Y-1vCC-azRt-pszL-PeWR-E5athz
-- Physical volumes --
PV Name /dev/sdb
PV UUID B0K2qH-0UF4-gphE-MLi3-RFXH-HEP9-9FMbA9
PV Status allocatable
Total PE / Free PE 2047 / 2047
Step 5 - Create a partition (logical volume) with a size of 3 GB
# lvcreate -L 3000 vg_group01
Logical volume “lvol0” created
Step 6 - Verify that the volume has been created.
# lvdisplay vg_group01
-- Logical volume --
LV Name /dev/vg_group01/lvol0
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 2.93 GiB
Current LE 750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
Step 7 - Display detailed information about the volume group and check for changes after adding the logical volume
# vgdisplay -v vg_group01
Using volume group(s) on command line
Finding volume group “vg_group01”
-- Volume group --
VG Name vg_group01
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 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 8.00 GiB
PE Size 4.00 MiB
Total PE 2047
Alloc PE / Size 750 / 2.93 GiB
Free PE / Size 1297 / 5.07 GiB
VG UUID IvjXga-898Y-1vCC-azRt-pszL-PeWR-E5athz
-- Logical volume --
LV Name /dev/vg_group01/lvol0
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 2.93 GiB
Current LE 750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
-- Physical volumes --
PV Name /dev/sdb
PV UUID B0K2qH-0UF4-gphE-MLi3-RFXH-HEP9-9FMbA9
PV Status allocatable
Total PE / Free PE 2047 / 1297
Step 8 - Alternatively, you can execute the following command:
# lvcreate –L 3000 –n SecretData vg_group01
A volume created in this way will have its own name assigned by the user during creation. For previously created volumes, you can change the name as follows:
# lvrename /dev/vg_group01/lvol0 /dev/vg_group01/SecretData
Renamed “lvol0” to “SecretData” in volume group “vg_group01”
Step 9 - Check what has changed after renaming
# lvdisplay vg_group01
-- Logical volume --
LV Name /dev/vg_group01/SecretData
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 2.93 GiB
Current LE 750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
Now you know how to create logical volumes and how to name or rename them.
At this point, it is worth considering how to achieve a partition layout where you divide a previously created volume group into a selected number of parts of exactly the same size?
Step 1 - Check available partitions.
Check available partitions:
[root@RHEL01 ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
8 16 8388608 sdb
8 17 2104483 sdb1
8 18 6281415 sdb2
253 0 18391040 dm-0
253 1 2064384 dm-1
Step 1 - Initialize the disk
# pvcreate /dev/hdb
Physical volume “/dev/hdb” successfully created
Step 2 - Verify that the physical volume was created correctly
# pvdisplay /dev/hdb
“/dev/hdb” is a new physical volume of “8.00 GiB”
-- NEW Physical volume --
PV Name /dev/hdb
VG Name
PV Size 8.00 GiB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID QlCLgF-esaN-5PvR-PWWV-D6jZ-O207-rHg90j
Keep in mind that physical volumes are limited to one physical disk or a partition on a physical disk.
Step 3 - Create a volume group
# vgcreate vg_group01 /dev/hdb
Volume group “vg_group01” successfully created
Step 4 - Verify the creation of the volume group
# vgdisplay -v vg_group01
Using volume group(s) on command line
Finding volume group “vg_group01”
-- Volume group --
VG Name vg_group01
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 8.00 GiB
PE Size 4.00 MiB
Total PE 2047
Alloc PE / Size 0 / 0
Free PE / Size 2047 / 8.00 GiB
VG UUID IvjXga-898Y-1vCC-azRt-pszL-PeWR-E5athz
-- Physical volumes --
PV Name /dev/sdb
PV UUID B0K2qH-0UF4-gphE-MLi3-RFXH-HEP9-9FMbA9
PV Status allocatable
Total PE / Free PE 2047 / 2047
Now you can configure a logical volume using the lvcreate command and specifying the size it should occupy on the partition where it is being created. You can specify the size in kilobytes, megabytes, gigabytes, or logical extents (LE). It is easiest to use MB.
Step 5 - Create a partition (logical volume) with a size of 3 GB
# lvcreate -L 3000 vg_group01
Logical volume “lvol0” created
Step 6 - Verify that the volume has been created.
# lvdisplay vg_group01
-- Logical volume --
LV Name /dev/vg_group01/lvol0
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 2.93 GiB
Current LE 750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
Step 7 - Display detailed information about the volume group and check for changes after adding the logical volume
# vgdisplay -v vg_group01
Using volume group(s) on command line
Finding volume group “vg_group01”
-- Volume group --
VG Name vg_group01
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 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 8.00 GiB
PE Size 4.00 MiB
Total PE 2047
Alloc PE / Size 750 / 2.93 GiB
Free PE / Size 1297 / 5.07 GiB
VG UUID IvjXga-898Y-1vCC-azRt-pszL-PeWR-E5athz
-- Logical volume --
LV Name /dev/vg_group01/lvol0
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 2.93 GiB
Current LE 750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
-- Physical volumes --
PV Name /dev/sdb
PV UUID B0K2qH-0UF4-gphE-MLi3-RFXH-HEP9-9FMbA9
PV Status allocatable
Total PE / Free PE 2047 / 1297
By default, all logical volumes will be named lvol#. You can change this and name volumes as you like by using the "-n" switch in the lvcreate command.
Step 8 - Alternatively, you can execute the following command:
# lvcreate –L 3000 –n SecretData vg_group01
A volume created in this way will have its own name assigned by the user during creation. For previously created volumes, you can change the name as follows:
# lvrename /dev/vg_group01/lvol0 /dev/vg_group01/SecretData
Renamed “lvol0” to “SecretData” in volume group “vg_group01”
Step 9 - Check what has changed after renaming
# lvdisplay vg_group01
-- Logical volume --
LV Name /dev/vg_group01/SecretData
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 2.93 GiB
Current LE 750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
Now you know how to create logical volumes and how to name or rename them.
At this point, it is worth considering how to achieve a partition layout where you divide a previously created volume group into a selected number of parts of exactly the same size?
Step 1 - Check available partitions.
Check available partitions:
[root@RHEL01 ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
8 16 8388608 sdb
8 17 2104483 sdb1
8 18 6281415 sdb2
253 0 18391040 dm-0
253 1 2064384 dm-1
Step 2 - Create a volume group from the sdb2 partition
[root@RHEL01 ~]# vgcreate vg_grupatestowa /dev/sdb2
Volume group "vg_grupatestowa" successfully created
Step 3 - Verify the creation of the new group:
[root@RHEL01 ~]# vgdisplay vg_grupatestowa
--- Volume group ---
VG Name vg_grupatestowa
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 5.99 GiB
PE Size 4.00 MiB
Total PE 1533
Alloc PE / Size 0 / 0
Free PE / Size 1533 / 5.99 GiB
VG UUID 0yRxMi-2q2y-X2WE-ZqIW-LEnA-Inc1-1pBkWZ
Step 4 - Create 3 logical volumes with perfectly equal parts.
From the previous step, we know that the volume group consists of Free PE / Size 1533 / 5.99 GiB and to get an exact, ideal division of its space into, say, 3 equal parts, we take the value: 1533, which after division equals 511 per logical volume.
Step 5 - Create 3 logical volumes of equal size.
[root@RHEL01 ~]# lvcreate -l 511 -n lv_test1 vg_grupatestowa
Logical volume "lv_test1" created
[root@RHEL01 ~]# lvcreate -l 511 -n lv_test2 vg_grupatestowa
Logical volume "lv_test2" created
[root@RHEL01 ~]# lvcreate -l 511 -n lv_test3 vg_grupatestowa
Logical volume "lv_test3" created
Step 6 - Verify the newly created logical volumes
[root@RHEL01 ~]# lvdisplay vg_grupatestowa
--- Logical volume ---
LV Name /dev/vg_grupatestowa/lv_test1
VG Name vg_grupatestowa
LV UUID VMZhvV-stJo-qK0A-QR9C-Yi2U-QhhQ-0ct8vK
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 253:2
--- Logical volume ---
LV Name /dev/vg_grupatestowa/lv_test2
VG Name vg_grupatestowa
LV UUID 1eWZSX-7Pwn-UEYc-JFZe-Jvwu-X4ro-XTT3Fc
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 253:3
--- Logical volume ---
LV Name /dev/vg_grupatestowa/lv_test3
VG Name vg_grupatestowa
LV UUID CNilMr-13Ds-IZ0k-9dNW-h1a5-dJ68-W0ktxZ
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 253:4
Now you also know how to divide a volume group into parts of equal size.
Earlier, when we display information about volume groups, we are given information about the physical block size - the cluster on the disk, which defaults to 4. How can you change the default block size (PE)?
[root@RHEL01 ~]# vgdisplay
--- Volume group ---
VG Name vg_grupatestowa
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 5.99 GiB
PE Size 4.00 MiB
Total PE 1533
Alloc PE / Size 1533 / 5.99 GiB
Free PE / Size 0 / 0
VG UUID 0yRxMi-2q2y-X2WE-ZqIW-LEnA-Inc1-1pBkWZ
Earlier, when we display information about volume groups, we are given information about the physical block size - the cluster on the disk, which defaults to 4. How can you change the default block size (PE)?
Step 1 - Display information about the volume group.
--- Volume group ---
VG Name vg_grupatestowa
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 5.99 GiB
PE Size 4.00 MiB
Total PE 1533
Alloc PE / Size 1533 / 5.99 GiB
Free PE / Size 0 / 0
VG UUID 0yRxMi-2q2y-X2WE-ZqIW-LEnA-Inc1-1pBkWZ
It is clearly visible that the PE size is 4MB.
Step 2 - Setting the PE size
When creating a new group, the physical extent (PE) block size can be set using the "-s" switch.
Let's set the PE size to 8MB:
[root@RHEL01 ~]# vgcreate -s 8M vg_grupatestowa /dev/sdb2
Volume group "vg_grupatestowa" successfully created
Step 3 - Check the PE size for the created group
[root@RHEL01 ~]# vgdisplay vg_grupatestowa
--- Volume group ---
VG Name vg_grupatestowa
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 5.98 GiB
PE Size 8.00 MiB
Total PE 766
Alloc PE / Size 0 / 0
Free PE / Size 766 / 5.98 GiB
VG UUID B9sBhs-oAqm-qsd4-TEzc-Oje7-nJ4w-kTc21l
The PE size has been set.
Comments