Note:
- This tutorial is available in an Oracle-provided free lab environment.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Configure Logical Volumes on Oracle Linux
Introduction
Logical Volume Management allows combining multiple individual hard drives or disk partitions into a single volume group (VG). That volume group can then be subdivided into logical volumes (LV) or used as a single large volume. Standard file systems, such as EXT4 or XFS, can be created on a logical volume.
This tutorial will work with the Oracle Linux Volume Manager utilities to create, mount and increase the capacity of logical volumes.
Objectives
- Create a logical volume
- Increase the capacity of a logical volume
Prerequisites
Any Oracle Linux 8 system with the following configurations:
- a non-root user with sudo permissions
- additional block volumes for use with LVM
Setup Lab Environment
Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.
-
If not already connected, open a terminal and connect via ssh to each instance mentioned above.
ssh oracle@<ip_address_of_instance>
-
Verify the block volumes exist.
sudo lsblk
The output for the free lab environment should show the
/dev/sda
for the existing file system, and the available disks/dev/sdb
,/dev/sdc
, and/dev/sdd
.
Physical Volume (PV)
-
Create the physical volumes (PV) using the available disks.
sudo pvcreate -v /dev/sd{b,c}
Run the command with the
-v
option to get verbose information. -
Verify PV creation.
sudo pvs
Example Output:
[oracle@ol-node01 ~]$ sudo pvs PV VG Fmt Attr PSize PFree /dev/sda3 ocivolume lvm2 a-- 45.47g 0 /dev/sdb lvm2 --- 50.00g 50.00g /dev/sdc lvm2 --- 50.00g 50.00g
For more detailed PV information run
pvdisplay
, or usepvscan
to scan all disks for physical volumes.
Volume Group (VG)
-
Create the volume group (VG) using the newly created physical volumes.
sudo vgcreate -v myvolg /dev/sd{b,c}
-
Verify VG creation.
sudo vgs
Example Output:
[oracle@ol-node01 ~]$ sudo vgs VG #PV #LV #SN Attr VSize VFree myvolg 2 0 0 wz--n- 99.99g 99.99g ocivolume 1 2 0 wz--n- 45.47g 0
For more detailed VG information run
vgdisplay
, or usevgscan
to scan all disks for volume groups.
Logical Volume (LV)
-
Create the linear logical volume (LV).
sudo lvcreate -v -L 5G -n myvol myvolg
-L
: Total size of the RAID array.-n
: Name of the RAID array.
Example Output:
[oracle@ol-node01 ~]$ sudo lvcreate -v -L 5G -n myvol myvolg Archiving volume group "myvolg" metadata (seqno 1). Creating logical volume myvol Creating volume group backup "/etc/lvm/backup/myvolg" (seqno 2). Activating logical volume myvolg/myvol. activation/volume_list configuration setting not defined: Checking only host tags for myvolg/myvol. Creating myvolg-myvol Loading table for myvolg-myvol (252:2). Resuming myvolg-myvol (252:2). Wiping known signatures on logical volume myvolg/myvol. Initializing 4.00 KiB of logical volume myvolg/myvol with value 0. Logical volume "myvol" created.
-
Verify LV creation.
sudo lvdisplay myvolg
The output shows all logical volumes contained within the myvolg VG.
Example Output:
[oracle@ol-node01 ~]$ sudo lvdisplay myvolg --- Logical volume --- LV Path /dev/myvolg/myvol LV Name myvol VG Name myvolg LV UUID 1gfINq-AcWq-Bhys-gafP-21RL-x39A-vR6hqE LV Write Access read/write LV Creation host, time ol-node01, 2022-05-20 23:27:38 +0000 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:2
For condensed VG information run
lvs
, or uselvscan
to scan all disks for volume groups. -
Display the LV type.
sudo lvs -o name,segtype /dev/myvolg/myvol
- The
lvs
command can take the full LV path as an option to narrow the results.
Example Output:
[oracle@ol-node01 ~]$ sudo lvs -o name,segtype /dev/myvolg/myvol LV Type myvol linear
- The
Create a File System
-
Create an EXT4 file system on the LV.
sudo mkfs.ext4 -F /dev/myvolg/myvol
-F
: Forces the overwrite of an existing file system.
Mount the LV
-
Mount the file system.
sudo mkdir -p /myvol sudo mount /dev/myvolg/myvol /myvol
-
Report the file system disk usage.
df -h
Example Output:
[oracle@ol-node01 ~]$ df -h Filesystem Size Used Avail Use% Mounted on ... /dev/mapper/myvolg-myvol 4.9G 20M 4.6G 1% /myvol
-
Update /etc/fstab.
echo "/dev/mapper/myvolg-myvol /myvol ext4 defaults 0 0" | sudo tee -a /etc/fstab > /dev/null
-
Unmount the LV.
sudo umount /myvol
-
Remount the LV using the /etc/fstab entry and verify the file system exists.
sudo mount -a df -h
Increase the Size of a Logical Volume
Using the available free space in the VG, increase the LV size to 10G.
-
Check if the VG has free space.
sudo vgs
The
myvolg
VG has 95G space free (VFree). -
Increase the LV capacity.
sudo lvextend -L 10G -r myvolg/myvol
-r
: Resizes the file system together with the logical volume usingfsadm(8)
.
Example Output:
[oracle@ol-node01 ~]$ sudo lvextend -L 10G -r myvolg/myvol Size of logical volume myvolg/myvol changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents). Logical volume myvolg/myvol successfully resized. resize2fs 1.45.6 (20-Mar-2020) Filesystem at /dev/mapper/myvolg-myvol is mounted on /myvol; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/mapper/myvolg-myvol is now 2621440 (4k) blocks long.
-
Verify the increased space on the file system.
df -h /myvol
The size of the file system is now 9.8G (Size) with 9.3G available (Avail).
Backup VG Metadata
LVM metadata contains configuration details about the volume groups. Oracle Linux automatically creates metadata backups after every VG and LV configuration change.
-
List backups and archives.
sudo ls -l /etc/lvm/backup sudo ls -l /etc/lvm/archive
-
Display the backup contents.
sudo head -n 10 /etc/lvm/backup/myvolg
The description states the backup was created after executing the
lvextend
command. -
Manually create a metadata backup.
sudo vgcfgbackup myvolg
Include the
-f
option along with a full path and file name (/var/tmp/myvolg-meta.bkp
) to backup the metadata to a different location.
See the vgcfgbackup(8)
and vgcfgrestore(8)
manual pages for more information.
Grow the VG and LV
Add an additional disk or partition to the VG and resize the LV.
Add Another Disk to a VG
-
Use the remaining available disk
/dev/sdd
to extend the VG.sudo vgextend -v myvolg /dev/sdd
Example Output:
[oracle@ol-node01 ~]$ sudo vgextend -v myvolg /dev/sdd Wiping signatures on new PV /dev/sdd. Set up physical volume for "/dev/sdd" with 104857600 available sectors. Zeroing start of device /dev/sdd. Writing physical volume data to disk "/dev/sdd". Physical volume "/dev/sdd" successfully created. Archiving volume group "myvolg" metadata (seqno 3). Adding physical volume '/dev/sdd' to volume group 'myvolg' Volume group "myvolg" will be extended by 1 new physical volumes Creating volume group backup "/etc/lvm/backup/myvolg" (seqno 4). Volume group "myvolg" successfully extended
-
Verify the VG.
sudo vgs myvolg
Example Output:
[oracle@ol-node01 ~]$ sudo vgs myvolg VG #PV #LV #SN Attr VSize VFree myvolg 3 1 0 wz--n- <149.99g <139.99g
Notice the increased PV count (#PV), capacity (VSize), and free space (VFree).
Resize the LV
-
Increase the size of the LV and the file system by 20G.
sudo lvresize -L +20G -r myvolg/myvol
-r
: Resizes the underlying file system together with the logical volume using fsadm(8).-L
: Changes or sets the logical volume size. The+
adds to the actual logical volume size.
-
Verify the increased space on the file system.
df -h /myvol
For More Information:
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Configure Logical Volumes on Oracle Linux
F45874-06
May 2022
Copyright © 2021, Oracle and/or its affiliates.