• 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 » Create and Expand LVM Volumes – Step by Step Guide

Create and Expand LVM Volumes – Step by Step Guide

October 27, 2020 - by Zsolt Agoston - last edited on October 28, 2020

Below is a quick summary on how to create and administer volume groups and volumes in LVM.

1. Create LVM volume from start to finish

Starting scenario: we have two new disks added to our system

[root@lvm ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   32G  0 disk
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   31G  0 part
  ├─cl-root 253:0    0 27.8G  0 lvm  /
  └─cl-swap 253:1    0  3.2G  0 lvm  [SWAP]
sdb           8:16   0    5G  0 disk
sdc           8:32   0    5G  0 disk
sr0          11:0    1 1024M  0 rom 

In the following steps we configure them to be a part of LVM and go through the steps to finally have a volume that spans through the disks and which is then mounted in our filesystem.

Add disks to LVM

# If you have only one disk, add only that to LVM
pvcreate /dev/sdb /dev/sdc

Verify that they have been added:

Create and Expand LVM Volumes – Step by Step Guide

Create LV

Create a logical volume in the new volume group. We can specify a specific size for it, like 2G. Alternatively we can use the whole available space in the volume group. In this example we go with the latter

# Create a new volume
# Switches:
# -n: name
# -L: size in bytes
# -l: size in extents (the smallest data unit the PV handles. By default, it is 4MiB)

# Create a volume with 1G size
lvcreate -n vol01 -L 1G vg01

# Create a volume that uses all the available space
lvcreate -n vol01 -l +100%FREE vg01

Check the new volume is present:

Create and Expand LVM Volumes – Step by Step Guide

2. Add the new volume to the filesystem

Create filesystem on the volume

mkfs.ext4 /dev/vg01/vol01

Mount the volume in the root filesystem

As the finishing step we create a directory in the root filesystem and mount the new volume there.

# Create the directory where we mount the volume
mkdir /vol01

# Mount vol01
mount /dev/vg01/vol01 /vol01
Create and Expand LVM Volumes – Step by Step Guide

3. Add extra disk to a VG and expand an LV

A new disk is added to the system, called /dev/sdd. First we add it to LVM, then to our existing volume group. Then we'll expand our logical volume easily.

Create and Expand LVM Volumes – Step by Step Guide

Adding a disk to the existing "vg01" VG

# Add /dev/sdd to LVM
pvcreate /dev/sdd

# Add /dev/sdd to vg01
vgextend vg01 /dev/sdd
Create and Expand LVM Volumes – Step by Step Guide

Expand existing LV

Now extend the existing volume by 2G. The command below also automatically expands the filesystem on the volume

lvextend -L +2G --resizefs /dev/vg01/vol01
Create and Expand LVM Volumes – Step by Step Guide

We're done!

Reader Interactions

Comments Cancel reply

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

Primary Sidebar

Tools

Secondary Sidebar

CONTENTS

  • 1. Create LVM volume from start to finish
  • Add disks to LVM
  • Create LV
  • 2. Add the new volume to the filesystem
  • Create filesystem on the volume
  • Mount the volume in the root filesystem
  • 3. Add extra disk to a VG and expand an LV
  • Adding a disk to the existing “vg01” VG
  • Expand existing LV

  • 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}