Expanding an LVM (Logical Volume Manager) when it is not the last partition on a disk requires a structured approach to ensure data integrity and successful volume extension. The outlined procedure provides step-by-step instructions to allocate additional storage by creating a new partition, adding it to the volume group, extending the logical volume, and finally resizing the filesystem. By following these steps, users can efficiently expand their storage capacity without disrupting the existing partitions. The key benefits of using these instructions include preventing partition overlap, ensuring proper allocation of free space, and maintaining the stability of the filesystem. Additionally, the process leverages built-in Linux commands such as lsblk
, fdisk
, pvcreate
, vgextend
, and lvextend
, making it accessible to system administrators managing LVM environments. This method is particularly valuable in virtualized environments where disk sizes are adjusted dynamically, enabling seamless scalability while preserving data integrity.
Verify each step to confirm changes before proceeding and ensure you have proper
backups in place before making modifications to disk partitions.
Follow these steps to extend an LVM when the LVM is not the last partition on the disk:
Here is an example of wanting to extend a LVM that is not the last partition.
1 >forward@test-fwd-fips-1 ~]$ lsblk
2 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
3 sda 8:0 0 150G 0 disk
4 ├─sda1 8:1 0 1M 0 part
5 ├─sda2 8:2 0 1G 0 part /boot
6 ├─sda3 8:3 0 100G 0 part
7 │ └─oracle-fwd_root 253:0 0 100G 0 lvm /
8 └─sda4 8:4 0 49G 0 part
9 └─extended-fwd_extended 253:1 0 49G 0 lvm /mnt/forward/extended
10 sr0 11:0 1 1024M 0 rom
In order to extend the oracle-fwd_root LVM, you will need to allocate storage to the /dev/sda disk
and create a 5th partition. Since oracle-fwd_root
has a partition after it (extended-fwd_extended), the oracle-fwd_root
partition can not be extended (can't overlap partitions).
As a result, we add a new partition. In this example 50G of additional space was added to the virtual disk
We can see that with this command:
>forward@test-fwd-fips-1 ~]$ sudo parted /dev/sda print free
Warning: Not all of the space available to /dev/sda appears to be used, you can f
Fix/Ignore? fix
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: pmbr_boot
Number Start End Size File system Name Flags
17.4kB 1049kB 1031kB Free Space
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 1076MB 1074MB xfs
3 1076MB 108GB 107GB lvm
4 108GB 161GB 52.6GB lvm
161GB 215GB 53.7GB Free Space
Also note that the GPT partition needed to be fixed in this example
We can see the additional 50G added at the bottom of the display. In order to add this the LVM, we will add that additional storage as an additional partition.
The “p” command will print the partitions. Here we see 4 partitions.
1 2
3 Welcome to fdisk (util-linux 2.32.1).
4 Changes will remain in memory only, until you decide to write them.
5 Be careful before using the write command.
6
7
8 Command (m for help): p
9 Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
10 Units: sectors of 1 * 512 = 512 bytes
11 Sector size (logical/physical): 512 bytes / 512 bytes
12 I/O size (minimum/optimal): 512 bytes / 512 bytes
13 Disklabel type: gpt
14 Disk identifier: 5C7E695C-C561-4445-9FB8-367F7E8871EE
15
16 Device Start End Sectors Size Type
17 /dev/sda1 2048 4095 2048 1M BIOS boot
18 /dev/sda2 4096 2101247 2097152 1G Linux filesystem
19 /dev/sda3 2101248 211816447 209715200 100G Linux LVM
20 /dev/sda4 211816448 314572766 102756319 49G Linux LVM
The “n” command creates a new partition. Select the defaults to create the next partition and consume all of the new allocated space.
1 Command (m for help): n
2 Partition number (5-128, default 5):
3 First sector (314572767-419430366, default 314572800):
4 Last sector, +sectors or +size{K,M,G,T,P} (314572800-419430366, default 419430366
5
6 Created a new partition 5 of type 'Linux filesystem' and of size 50 GiB.
7
8 Command (m for help): p
9 Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
10
11 Units: sectors of 1 * 512 = 512 bytes
12 Sector size (logical/physical): 512 bytes / 512 bytes
13 I/O size (minimum/optimal): 512 bytes / 512 bytes
14 Disklabel type: gpt
15 Disk identifier: 5C7E695C-C561-4445-9FB8-367F7E8871EE
16 Device Start End Sectors Size Type
17 /dev/sda1 2048 4095 2048 1M BIOS boot
18 /dev/sda2 4096 2101247 2097152 1G Linux filesystem
19 /dev/sda3 2101248 211816447 209715200 100G Linux LVM
20 /dev/sda4 211816448 314572766 102756319 49G Linux LVM
21 /dev/sda5 314572800 419430366 104857567 50G Linux filesystem
The “w” command writes the new partition and exits fdisk.
1 Command (m for help): w
2 The partition table has been altered.
3 Syncing disks.
So now that the additional storage is assigned to a partition, we are going to create a physical volume to add to the LVM.
Here is the physical volumes prior to adding a new one:
1 wforward@test-fwd-fips-1 ~]$ sudo pvdisplay
2 --- Physical volume ---
3 PV Name /dev/sda4
4 VG Name extended
5 PV Size <49.00 GiB / not usable 16.50 KiB
6 Allocatable yes (but full)
7 PE Size 4.00 MiB
8 Total PE 12543
9 Free PE 0
10 Allocated PE 12543
11 PV UUID przC0D-sorc-hUGR-fn7m-9cIB-O2dz-h2ij1E
12
13 --- Physical volume ---
14 PV Name /dev/sda3
15 VG Name oracle
16 PV Size 100.00 GiB / not usable 4.00 MiB
17 Allocatable yes (but full)
18
19 PE Size 4.00 MiB
20 Total PE 25599
21 Free PE 0
22 Allocated PE 25599
23 PV UUID mFGRyZ-DfLs-ojwR-yFIy-sBVa-dh5z-9y57i5
To create a new physical volume, enter the following:
1 wforward@test-fwd-fips-1 ~]$ sudo pvcreate /dev/sda5
2 WARNING: PMBR signature detected on /dev/sda5 at offset 510. Wipe it? ey/n]: y
3 Wiping PMBR signature on /dev/sda5.
4 Physical volume "/dev/sda5" successfully created.
Note that if a PMBR exists, it needs to be wiped prior to creating the new physical volume.
Running a new pvdisplay will show the new physical volume:
1 lforward@test-fwd-fips-1 ~]$ sudo pvdisplay
2 --- Physical volume ---
3 PV Name /dev/sda4
4 VG Name extended
5 PV Size <49.00 GiB / not usable 16.50 KiB
6 Allocatable yes (but full)
7 PE Size 4.00 MiB
8 Total PE 12543
9 Free PE 0
10 Allocated PE 12543
11
12 PV UUID przC0D-sorc-hUGR-fn7m-9cIB-O2dz-h2ij1E
13 --- Physical volume ---
14 PV Name /dev/sda3
15 VG Name oracle
16 PV Size 100.00 GiB / not usable 4.00 MiB
17 Allocatable yes (but full)
18 PE Size 4.00 MiB
19 Total PE 25599
20 Free PE 0
21 Allocated PE 25599
22 PV UUID mFGRyZ-DfLs-ojwR-yFIy-sBVa-dh5z-9y57i5
23
24 "/dev/sda5" is a new physical volume of "<50.00 GiB"
25 --- NEW Physical volume ---
26 PV Name /dev/sda5
27 VG Name
28 PV Size <50.00 GiB
29 Allocatable NO
30 PE Size 0
31 Total PE 0
32 Free PE 0
33 Allocated PE 0
34 PV UUID dCIyqb-8CdR-fj3P-evhN-nb1v-HRt5-INmCNV
We are now going to add the physical volume to the volume group. First let’s see what is in the volume group prior to the add:
1 hforward@test-fwd-fips-1 ~]$ sudo vgdisplay
2 --- Volume group ---
3 VG Name extended
4 System ID
5 Format lvm2
6 Metadata Areas 1
7 Metadata Sequence No 4
8 VG Access read/write
9 VG Status resizable
10 MAX LV 0
11 Cur LV 1
12 Open LV 1
13 Max PV 0
14 Cur PV 1
15 Act PV 1
16 VG Size <49.00 GiB
17 PE Size 4.00 MiB
18 Total PE 12543
19 Alloc PE / Size 12543 / <49.00 GiB
20 Free PE / Size 0 / 0
21 VG UUID e9hFpW-BhMj-Icf3-lPEb-obBK-J1mR-Vi1QRk
22
23 --- Volume group ---
24 VG Name oracle
25 System ID
26 Format lvm2
27 Metadata Areas 1
28 Metadata Sequence No 2
29 VG Access read/write
30 VG Status resizable
31 MAX LV 0
32 Cur LV 1
33 Open LV 1
34 Max PV 0
35 Cur PV 1
36 Act PV 1
37 VG Size <100.00 GiB
38 PE Size 4.00 MiB
39 Total PE 25599
40 Alloc PE / Size 25599 / <100.00 GiB
41 Free PE / Size 0 / 0/forward@test-fwd-fips-1 ~]$ sudo vgextend oracle /d
42 Volume group "oracle" successfully extended
43 VG UUID IjNJLe-Ppb3-SiEI-6yuk-tJ2Q-weOi-7avcet
The two volume groups are called “extended" and “oracle”. We want to extend the oracle volume groups which contains oracle-fwd_root
which we saw in the lsblk at the top of the document.
Now we are going to extend the Oracle volume group:
1 vforward@test-fwd-fips-1 ~]$ sudo vgextend oracle /dev/sda5
2 Volume group "oracle" successfully extended
3 forward@test-fwd-fips-1 ~]$ sudo vgdisplay
4 --- Volume group ---
5 VG Name extended
6 System ID
7 Format lvm2
8 Metadata Areas 1
9 Metadata Sequence No 4
10 VG Access read/write
11 VG Status resizable
12 MAX LV 0
13 Cur LV 1
14 Open LV 1
15 Max PV 0
16 Cur PV 1
17 Act PV 1
18 VG Size <49.00 GiB
19 PE Size 4.00 MiB
20 Total PE 12543
21 Alloc PE / Size 12543 / <49.00 GiB
22 Free PE / Size 0 / 0
23 VG UUID e9hFpW-BhMj-Icf3-lPEb-obBK-J1mR-Vi1QRk
24
25 --- Volume group ---
26 VG Name oracle
27 System ID
28 Format lvm2
29 Metadata Areas 2
30 Metadata Sequence No 3
31 VG Access read/write
32 VG Status resizable
33 MAX LV 0
34 Cur LV 1
35 Open LV 1
36 Max PV 0
37 Cur PV 2
38 Act PV 2
39 VG Size 149.99 GiB
40 PE Size 4.00 MiB
41 Total PE 38398
42 Alloc PE / Size 25599 / <100.00 GiB
43 Free PE / Size 12799 / <50.00 GiB
44 VG UUID IjNJLe-Ppb3-SiEI-6yuk-tJ2Q-weOi-7avcet
Running a pvdisplay right after the extend will show that 50G is now free in the oracle volume group Free PE
/ Size 12799 / <50.00 GiB
Now we want to extend the logical volume, but first lets display what the logical volume look like now:
1 oforward@test-fwd-fips-1 ~]$ sudo lvdisplay
2 --- Logical volume ---
3 LV Path /dev/extended/fwd_extended
4 LV Name fwd_extended
5 VG Name extended
6 LV UUID yy8lus-02Vw-mHCS-2uKv-bIJp-tfCe-NpNmJk
7 LV Write Access read/write
8 LV Creation host, time localhost.localdomain, 2024-12-04 03:54:41 +0000
9 LV Status available
10 # open 1
11 LV Size <49.00 GiB
12 Current LE 12543
13 Segments 1
14 Allocation inherit
15 Read ahead sectors auto
16 - currently set to 8192
17 Block device 253:1
18
19 --- Logical volume ---
20 LV Path /dev/oracle/fwd_root
21 LV Name fwd_root
22 VG Name oracle
23 LV UUID C7qHVs-xSWf-yUPt-Vi12-q0Y8-5qfb-a01Xx1
24 LV Write Access read/write
25 LV Creation host, time localhost.localdomain, 2024-12-04 03:54:41 +0000
26 LV Status available
27 # open 1
28 LV Size <100.00 GiB
29 Current LE 25599
30
31 Segments 1
32 Allocation inherit
33 Read ahead sectors auto
34 - currently set to 8192
35 Block device 253:0
We want to extend the /dev/oracle/fwd_root
logical volume by running this command:
1 tforward@test-fwd-fips-1 ~]$ sudo lvextend -l +100%FREE /dev/oracle/fwd_root
2 Size of logical volume oracle/fwd_root changed from <100.00 GiB (25599 extents)
3 Logical volume oracle/fwd_root successfully resized.
4 vforward@test-fwd-fips-1 ~]$ sudo lvdisplay
5 --- Logical volume ---
6 LV Path /dev/extended/fwd_extended
7 LV Name fwd_extended
8 VG Name extended
9 LV UUID yy8lus-02Vw-mHCS-2uKv-bIJp-tfCe-NpNmJk
10 LV Write Access read/write
11 LV Creation host, time localhost.localdomain, 2024-12-04 03:54:41 +0000
12 LV Status available
13 # open 1
14 LV Size <49.00 GiB
15 Current LE 12543
16 Segments 1
17 Allocation inherit
18 Read ahead sectors auto
19 - currently set to 8192
20 Block device 253:1
21
22 --- Logical volume ---
23 LV Path /dev/oracle/fwd_root
24 LV Name fwd_root
25 VG Name oracle
26 LV UUID C7qHVs-xSWf-yUPt-Vi12-q0Y8-5qfb-a01Xx1
27 LV Write Access read/write
28 LV Creation host, time localhost.localdomain, 2024-12-04 03:54:41 +0000
29 LV Status available
30 # open 1
31 LV Size 149.99 GiB
32 Current LE 38398
33 Segments 2
34 Allocation inherit
35 Read ahead sectors auto
36 - currently set to 8192
37 Block device 253:0
After running the command, running another lvdisplay shows that /dev/oracle/fwd_root
is now 150G vs 100G from before. The last step is to grow the filesystem into the remaining space just added. The commands vary depending on the format of the file system.
If the filesystem is XFS, then xfs_growfs is used.
If the filesystem is exto2 / 3 / 4] the resize2fs is used. The determine the filesystem type, run this command:
1 tforward@test-fwd-fips-1 ~]$ sudo lsblk -o NAME,FSTYPE,MOUNTPOINT /dev/sda
2 NAME FSTYPE MOUNTPOINT
3 sda
4 ├─sda1
5 ├─sda2 xfs /boot
6 ├─sda3 LVM2_member
7 │ └─oracle-fwd_root. xfs /
8 ├─sda4 LVM2_member
9 │ └─extended-fwd_extended ext4 /mnt/forward/extended
10 └─sda5 LVM2_member
11 └─oracle-fwd_root. xfs /
In this example, oracle-fwd_root
is XFS so we use xfs_growfs. If we were extending extended-
fwd_extended
we would use resize2fs
To grow the oracle-fwd_root
lvm, run the following command:
1 eforward@test-fwd-fips-1 ~]$ sudo xfs_growfs /dev/oracle/fwd_root
2 meta-data=/dev/mapper/oracle-fwd_root isize=512 agcount=4, agsize=6553344 blks
3 = sectsz=512 attr=2, projid32bit=1
4 = crc=1 finobt=1, sparse=1, rmapbt=0
5 = reflink=1 bigtime=0 inobtcount=0
6 data = bsize=4096 blocks=26213376, imaxpct=25
7 = sunit=0 swidth=0 blks
8 naming = version 2 bsize=4096 ascii-ci=0, ftype=1
9 log = internal log bsize=4096 blocks=12799, version=2
10 = sectsz=512 sunit=0 blks, lazy-count=1
11 realtime = none extsz=4096 blocks=0, rtextents=0
12 data blocks changed from 26213376 to 39319552
We can confirm the the new size by running lsblk:
1 Wforward@test-fwd-fips-1 ~]$ lsblk
2 NAME. MAJ:MIN M SIZE RO TYPE MOUNTPOINT
3 sda 8:0 0 200G 0 disk
4 ├─sda1 8:1 0 1M 0 part
5 ├─sda2. 8:2 0 1G 0 part /boot
6 ├─sda3 8:3 0 100G 0 part
7 │ └─oracle-fwd_root 253:0 0 150G 0 lvm /
8 ├─sda4 8:4 0 49G 0 part
9 │ └─extended-fwd_extended 253:1 0 49G 0 lvm /mnt/forward/extended
10 └─sda5 8:5 0 50G 0 part
11 └─oracle-fwd_root 253:0 0 150G 0 lvm /
14 sr0 11:0 1 1024M. 0 rom
Note oracle-fwd_root
is now 150G
By following this methodical approach, you can successfully extend an LVM when it is not the last partition on the disk, ensuring efficient storage expansion without data loss or partition conflicts. This process not only maximizes available disk space but also maintains system stability and performance. Whether managing a virtualized environment or scaling on-premises storage, these steps provide a reliable way to extend logical volumes with minimal risk. Always verify each step using the provided commands to confirm changes before proceeding, and ensure you have proper backups in place before making modifications to disk partitions. With this knowledge, you can confidently manage LVM extensions and optimize your system’s storage capacity for future needs.