Reduce and Relocate Volume Groups on Oracle Linux
Introduction
Logical Volume Management allows for removing unused physical volumes (PVs) and for the moving of an entire volume group (VGs). The removal of a PV shrinks the overall size of the VG.
This tutorial will work with the Oracle Linux Volume Manager utilities to shrink a volume group by removing a physical volume and then transferring the volume group to another system.
Objectives
- Move a logical volume
- Shrink a volume group
- Transfer a volume group to another system
Prerequisites
Two Oracle Linux 8 systems 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 the ol-node01 instance.
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 root file system,/dev/sdb
for the demo volume group, and the available disks/dev/sdc
and/dev/sdd
.Show the consistent device name mappings.
The free lab environment uses consistent device name paths for the attached block volumes.
ll /dev/oracleoci/oraclevd*
Example Output:
[oracle@ol-node01 ~]$ ll /dev/oracleoci/oraclevd* lrwxrwxrwx. 1 root root 6 Jun 9 13:27 /dev/oracleoci/oraclevda -> ../sda lrwxrwxrwx. 1 root root 7 Jun 9 13:27 /dev/oracleoci/oraclevda1 -> ../sda1 lrwxrwxrwx. 1 root root 7 Jun 9 13:27 /dev/oracleoci/oraclevda2 -> ../sda2 lrwxrwxrwx. 1 root root 7 Jun 9 13:27 /dev/oracleoci/oraclevda3 -> ../sda3 lrwxrwxrwx. 1 root root 6 Jun 9 13:27 /dev/oracleoci/oraclevdb -> ../sdd lrwxrwxrwx. 1 root root 6 Jun 9 13:45 /dev/oracleoci/oraclevdd -> ../sdc
Notice that the consistent name endings defined in Oracle Cloud Infrastructure do not match one-for-one with the device names provided by the Linux OS. Knowing these mappings will be essential later when detaching and attaching block volumes in the Cloud Console.
Remove PV from VG
Before removing an active physical volume from a volume group, move any data and logical volumes on the physical volume to some other free PV.
Check the disk space used by the physical volumes.
sudo pvs -o+pv_used
Example Output:
[oracle@ol-node01 ~]$ sudo pvs -o+pv_used PV VG Fmt Attr PSize PFree Used /dev/sda3 ocivolume lvm2 a-- 45.47g 0 45.47g /dev/sdb labvolume lvm2 a-- 49.98g 47.98g 2.00g
The output shows the
/dev/sdb
PV uses 2g.Extend the volume group.
Add another physical volume by extending the volume group.
sudo vgextend labvolume /dev/sdc
Adding
/dev/sbc
provides a free physical volume to accept the transfer of data and logical volumes from the original/dev/sdb
physical volume.Verify the addition of the
/dev/sdc
physical volume.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 labvolume lvm2 a-- 49.98g 47.98g /dev/sdc labvolume lvm2 a-- 49.98g 49.98g
Move the existing data and logical volumes to the newly added free PV.
sudo pvmove /dev/sdb /dev/sdc
The
pvmove
command allows moving the allocated physical extents (PEs) on a source PV to one or more other PVs. The transfer uses the normal allocation rules for the volume group if a destination PV is not specified. The task is completed online without interruption, and the command line output shows progress.See the
pvmove(8)
manual for more details.Verify the move completed.
sudo pvs -o+pv_used
Example Output:
[oracle@ol-node01 ~]$ sudo pvs -o+pv_used PV VG Fmt Attr PSize PFree Used /dev/sda3 ocivolume lvm2 a-- 45.47g 0 45.47g /dev/sdb labvolume lvm2 a-- 49.98g 49.98g 0 /dev/sdc labvolume lvm2 a-- 49.98g 47.98g 2.00g
The output shows the
/dev/sdc
PV uses 2g and/dev/sdb
is unused.Release the original physical volume.
sudo vgreduce labvolume /dev/sdb
Confirm original physical volume is completely free.
sudo pvs -o+pv_used
Example Output:
[oracle@ol-node01 ~]$ sudo pvs -o+pv_used PV VG Fmt Attr PSize PFree Used /dev/sda3 ocivolume lvm2 a-- 45.47g 0 45.47g /dev/sdb lvm2 --- 50.00g 50.00g 0 /dev/sdc labvolume lvm2 a-- 49.98g 47.98g 2.00g
Notice the volume group name labvolume is no longer associated with the physical volume
/dev/sdb
and is now associated with/dev/sdc
.Remove the original physical volume.
sudo pvremove /dev/sdb
The physical volume
/dev/sdb
is now free to use in another volume group or be removed physically from the system.
Move PV Between Systems
LVM allows moving an entire volume group from one system to another. The example moves the volume group named labvolume
with a logical volume mounted at /u01
from ol-node01 to ol-node02.
Unmount the file system on ol-node01.
sudo umount /u01
Make the volume group inactive.
Marking the volume group inactive means the logical volumes in the group are not accessible and unable to change. This deactivation of the volume group further makes it unknown to the kernel.
sudo vgchange -an labvolume
Prepare the volume to be removed.
sudo vgexport labvolume
Determine the block volume device path.
The next step removes the physical volume
/dev/sdc
associated with the volume grouplabvolume
from instance ol-node01. To select the correct block device within the Cloud Console to detach, get the block device path nameoraclevd*
associated with the PV/dev/sdc
.ll /dev/oracleoci/oraclevd* | grep sdc
Remove the disk from the ol-node01 server.
With a physical server, shut down the system and unplug the disk. However, in the free lab environment, we must detach the volume from the instance.
Although there are several ways to accomplish this task, we'll use the Cloud Console.
Log in to the Cloud Console.
Open the navigation menu and click Compute. Under Compute, click Instances.
Click on the ol-node01 instance in the list.
Under Resources in the lower left of the page, select Attached block volumes.
Use the three-dot menu next to the block device Name associated with the physical volume
/dev/sdc
and select Detach.Important: The block device Name to choose is the one matching the Device path reported in the
Determine the block volume device pathstep above. It may not match the Name selected in the screenshot provided.https://luna.oracle.com/api/v1/labs/ee495d1a-4e00-4d77-9719-2f27591d1ecd/gitlab/tutorial/#s4
Select the Ok button in the pop-up window, and wait for the volume to detach.
Use the breadcrumbs at the top of the page, and select Instances.
Select the ol-node02 instance in the list.
Under Resources on the lower left, select Attached block volumes.
Click the Attach block volume button.
In the pop-up window, attach the block volume removed from ol-node01.
Select the block device Name previously detached from the ol-node01 instance for the Volume.
Then select oraclevdb for Device path, Paravirtualized for Attachment type, and Read/write for Access.
Click the Attach button, and wait for the volume to attach.
Open a new terminal and connect via ssh to the ol-node02 instance.
ssh oracle@<ip_address_of_instance>
Verify the new block volume exists.
sudo lsblk
The output for the free lab environment should show the
/dev/sda
for the root file system and/dev/sdb
for the volume group.Scan the attached volume.
Run an initial scan to recognize the attached LVM physical volumes.
sudo pvscan
Example Output:
[oracle@ol-node02 ~]$ sudo pvscan PV /dev/sdb is in exported VG labvolume [49.98 GiB / 47.98 GiB free] PV /dev/sda3 VG ocivolume lvm2 [45.47 GiB / 0 free] Total: 2 [<95.46 GiB] / in use: 2 [<95.46 GiB] / in no VG: 0 [0 ]
The scan shows the PV device
/dev/sdb
contains the volume group export from ol-node01.Import the volume group.
sudo vgimport labvolume
Activate the volume group.
sudo vgchange -ay labvolume
Mount the file system.
sudo mkdir /u01 sudo mount /dev/labvolume/data /u01
Verify the space on the file system.
df -h
Example Output:
[oracle@ol-node02 ~]$ df -h Filesystem Size Used Avail Use% Mounted on ... /dev/mapper/labvolume-data 2.0G 6.0M 1.8G 1% /u01