• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
OpenTechTips

OpenTechTips

Comprehensive IT Guides for Pros and Enthusiasts

MENUMENU
  • HOME
  • ALL TOPICS
    • Exchange
    • InfoSec
    • Linux
    • Networking
    • Scripting
      • PowerShell
    • SSL
    • Tools
    • Virtualization
    • Web
    • Windows
  • ABOUT
  • SUBSCRIBE
Home » Expanding an LVM volume with a new disk

Expanding an LVM volume with a new disk

March 26, 2020 - by Zsolt Agoston - last edited on May 5, 2020

Time to time we can face the problem that our storage is running out of space on our Linux box. Now what options do we have?

We can attach a new storage to the system and mount it in the filesystem but that gives us less flexibility, let’s say we have 100GB free space left, and we have a 100GB disk to use. Now we can mount it in a subdirectory in our filesystem, but if we have a 150GB file to store on the machine, then we have a problem.

Luckily LVM is to the rescue. It let you expand a logical volume throughout multiple disks, behaving like spanned volumes in the Microsoft world, which writes data sequentially to the volume, filling up the physical devices one after another. Slower than a RAID0 type array, but safer in case of a disk failure. However, if needed stripping can be configured on LVM, more on this later.

In our example we start with a 2TB volume, consists of four 512GB physical disks, mounted in /BigVolume.

STARTING STATE

Let’s assume we are running out of space on the volume and we need 200GB more. The beauty of LVM is that we can add a new disk with any size to our virtual group, and expand our volume on the fly, without any downtime.

Expanding an LVM volume with a new disk

ADDING THE NEW DISK

We add a 200GB disk, not a regular 256GB sized as let’s say this is all we have. As the default physical extent size is 4MB by default that we use here, we can specify any sizes that are an increment of these extents.

Here is the system after adding the disk. Note, that after adding the disk to a virtual machine we can either reboot the box or we have the option to rescan the SCSI buses while powered up:

echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
…

Depending on how many “hostX” buses you have, these commands scan all the “channels, SCSI targets and LUNs” on each.

Expanding an LVM volume with a new disk

There we go, the disk is recognized as /dev/sdf

First we set it up as a physical disk for LVM, then add it to our existing virtual group called “MyVG”. Then we can expand our VOL volume from 2TB to 2.2TB, adding all the available extents (4MB) to it. As a last step we expand the EXT4 file system on the volume on the fly.

 # Set disk as a physical LVM disk
  pvcreate /dev/sdf
  
 # Add the disk to the VG group
  vgextend MyVG /dev/sdf
  
  # Expand the “VOL” volume to the maximum available size
  lvextend -l +100%FREE /dev/MyVG/VOL
  
 # Expand the filesystem to occupy the whole volume
  resize2fs /dev/MyVG/VOL
Expanding an LVM volume with a new disk

We have our volume intact, expanded by 200GB now, without any downtime 🙂

Reader Interactions

Comments Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tools

Secondary Sidebar

CONTENTS

  • STARTING STATE
  • ADDING THE NEW DISK

  • Terms of Use
  • Disclaimer
  • Privacy Policy
Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}
Manage your privacy
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}