How to merge two disks in Linux?

1. Overview

LVM (Logical Volume Management) is a concept that splits up one virtual partition into numerous chunks. Also, these chunks can be on different physical partitions or drives.

In this tutorial, we’ll learn how to combine two logical volumes on a single physical volume with LVM.

2. The Concept of LVM

The concept of LVM entails that we can group physical volumes (partitions) into a volume group. Further, we can split the volume group into logical volumes, which look like the system’s normal physical partitions, but can use any number of physical devices.

Thus, we can set up these logical volumes to consist of mountable filesystems:


Install hard drive

If there is not enough space in the volume group on the existing hard drive(s) in the system to add the desired amount of space it may be necessary to add a new hard drive and create the space to add to the Logical Volume. First, install the physical hard drive, and then perform the following steps.

Following the diagram, our target is to combine the logical volumes

We can check out the setup via lsblk

Hard disk of 20GB.

Create Physical Volume from hard drive

It is first necessary to create a new Physical Volume (PV). Use the command below, which assumes that the new hard drive is assigned as /dev/sdb

  • pvcreate /dev/sdb1
  • pvcreate /dev/sdb2

Create volume group

Creating logical volumes

First create the Logical Volume (LV) from existing free space within the Volume Group. The command below creates a LV with a size of 7.8GB . The Volume Group name is My Sdb1 and the Logical Volume Name is Stuff.

  • lvcreate -l 2000 -n lv2 vg2

Create the filesystem

Creating the Logical Volume does not create the filesystem. That task must be performed separately. The command below creates an EXT4 filesystem that fits the newly created Logical Volume.

  • mkfs.ext4 /dev/vg2/lv2
Mount the filesystem
  • mkdir /test1
  • mkdir /test2
  • mount /dev/vg1/lv1 /test1
  • mount /dev/vg2/lv2 /test2
Unmounting File Systems

Have the volume group with which we have to match and with the second one we will deactive it so if you .want to see so many details, then you can run the command end which can you will get to see all the details, so now

now vg2 detective

  • vgchange -an vg2
  • lvscan

Merge/split volume groups

we took this much and we simplay merged booth the groups

  • vgmerge vg1 vg2
  • vgs
  • lvscan

Now vg2 active

  • lvchange -ay /dev/vg1/lv2
  • lvscan

Wrap up

So we looked at logical volumes as a whole, the three kinds of logical volumes that LVM allows you to create, and how to configure these volumes. LVM allows you to create a storage unit to fit almost any need you may have as an administrator, and that’s what makes it such a great utility. I recommend that you give LVM a try the next time you need to accomplish any disk manipulation. In my opinion, there is no better tool for the job!

1 thought on “How to merge two disks in Linux?”

Leave a Comment