inGuide | Digital Marketing, Online Business & WordPress
  • Home
  • Blog
  • Deals
  • Services
  • Forum
    • New Forum
  • Free Resources
    • inSend: Mailwizz
  • Contact
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
Linux

LVM commands to create, extend & delete partition

What is the Meaning of LVM?

LVM stands for logical volume manager aka logical volume management. In simple words, it’s a management solution to manage your disk smartly. With LVM partition you can any time create, extend, shrink, resize, or delete a volume without hampering your ongoing work.

You can also add another SSD or HDD and grow your LVM volume easily.

The process to create LVM volume begins with attaching SSD/HDD to your system.

Create Physical Volume

Physical Volumes (PV) are the base of the LVM structure. It can be a partition on the disk or the whole disk itself. The first step would be to identify the disk attached. Run the following command to get the list of disks.

[root@mail ~]# lsblk

As can be seen in the above picture sdc is a newly attached disk.

Now to create physical volume execute the following command.

[root@mail ~]# pvcreate /dev/sdc

You should get output like Physical volume "/dev/sdc" successfully created.

If you have more than one disk you can run the command like below to create PV

[root@mail ~]# pvcreate /dev/sdc /dev/sdd

You can also get information about created/existing physical volume by

[root@mail ~]# pvscan
  PV /dev/sdc                      lvm2 [20.00 GiB]
  Total: 1 [20.00 GiB] / in use: 0 [0   ] / in no VG: 1 [20.00 GiB]

If you need more information like size, or free space you can simply execute the following command

[root@mail ~]# pvdisplay /dev/sdc
  "/dev/sdc" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               bBTp1Z-YxGT-6JSw-Gihv-DYpg-mCRv-RoCx9f

You can further use pvdisplay to display all the volumes.

Create Volume Group

The next step is to create a volume group. Imagine you have created a bunch of physical volumes from partition/bare disk. Now you want to use all of them like one disk. Voila! Volume Group is the answer to your problem. VG is nothing but a bunch of physical volumes clubbed together.

This also means you can attach a partition later to the system, create PV and add to the volume group. Simple isn’t it?

Let’s create a VG with only one PV at present.

[root@mail ~]# vgcreate vg1 /dev/sdc
  Volume group "vg1" successfully created

If you want to view detailed information about specific VG

[root@mail ~]# vgdisplay -v vg1
  --- Volume group ---
  VG Name               vg1
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <20.00 GiB
  PE Size               4.00 MiB
  Total PE              5119
  Alloc PE / Size       0 / 0
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               MXwoM2-eifP-UXG1-blcs-854T-Ih3i-aHinwB

  --- Physical volumes ---
  PV Name               /dev/sdc
  PV UUID               bBTp1Z-YxGT-6JSw-Gihv-DYpg-mCRv-RoCx9f
  PV Status             allocatable
  Total PE / Free PE    5119 / 5119

If you want to view information of all VG, vgdisplay is the command.

Create Logical Volume

After creating VG, it’s time to create Logical Volume (LV). You can create multiple LV inside VG. Or, you can simply create one LV to occupy all space of VG.

Let’s say you want to carve 10GB out of 20GB. Then use the following command.

[root@mail ~]# lvcreate -L 10g -n lv1 vg1
  Logical volume "lv1" created.

L: To Specify Volume Size
n: To Logical Volume Name

If you want to use 100% of the free space in VG to create a logical volume, use the following command

[root@mail ~]# lvcreate -l 100%FREE -n lv2 vg1
  Logical volume "lv2" created.

Now to view the logical volumes created

[root@mail ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                0UcqUR-EotB-t3Eh-5w3V-rtA4-SALb-uffk0P
  LV Write Access        read/write
  LV Creation host, time mail.onedashline.com, 2022-06-05 10:30:48 +0000
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg1/lv2
  LV Name                lv2
  VG Name                vg1
  LV UUID                MzAnEW-eaqW-q4Y0-0De2-uUq5-Cn9H-Txth1B
  LV Write Access        read/write
  LV Creation host, time mail.onedashline.com, 2022-06-05 10:52:15 +0000
  LV Status              available
  # open                 0
  LV Size                <10.00 GiB
  Current LE             2559
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

If you want to view detail of just one logical volume

[root@mail ~]# lvdisplay -v /dev/vg1/lv1
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                0UcqUR-EotB-t3Eh-5w3V-rtA4-SALb-uffk0P
  LV Write Access        read/write
  LV Creation host, time mail.onedashline.com, 2022-06-05 10:30:48 +0000
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

Create Filesystem

Now logical volume is ready, create filesystem

[root@mail ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Mount Filesystem

Now you can mount the filesystem and make use of it.

[root@mail ~]# mkdir /newspace

Now to mount simply

[root@mail ~]# mount /dev/vg1/lv1 /newspace

If you want to make this mount permanent, which most of all will do, find UUID with the following command

[root@mail ~]# blkid /dev/vg1/lv1
/dev/vg1/lv1: UUID="f13b083c-3b85-4ab5-8903-e60a0584dfda" TYPE="ext4"

After that edit /etc/fstab and make entries to it.

UUID=f13b083c-3b85-4ab5-8903-e60a0584dfda /newspace ext4    defaults 0 0

Extend LVM

Extending LVM is one of the biggest reasons for its popularity. You can extend it in a few commands without any downtime. Let’s see how it can be done!!

First, create a physical volume and of course, you can check for disk by lsblk

[root@mail ~]# lsblk
NAME      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda         8:0    0 79.5G  0 disk /
sdb         8:16   0  512M  0 disk [SWAP]
sdc         8:32   0   20G  0 disk
├─vg1-lv1 253:0    0   10G  0 lvm  /newspace
└─vg1-lv2 253:1    0   10G  0 lvm
sdd         8:48   0   20G  0 disk
[root@mail ~]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created.

Next, extend the volume group with the following commands.

[root@mail ~]# vgextend vg1 /dev/sdd
  Volume group "vg1" successfully extended

After that, you can verify the volume group details

[root@mail ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               vg1
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               0
  Allocated PE          5119
  PV UUID               bBTp1Z-YxGT-6JSw-Gihv-DYpg-mCRv-RoCx9f

  --- Physical volume ---
  PV Name               /dev/sdd
  VG Name               vg1
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               5119
  Allocated PE          0
  PV UUID               EZw0va-6Z03-iLTi-0FO8-bReZ-K4eV-kstTQo

Finally, you can extend the Logical Volume with the following command. In this command I have added 2.5GB to lv1

[root@mail ~]# lvextend -L +2.5G -r /dev/vg1/lv1
  Size of logical volume vg1/lv1 changed from 10.00 GiB (2560 extents) to 12.50 GiB (3200 extents).
  Logical volume vg1/lv1 successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg1-lv1 is mounted on /newspace; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/mapper/vg1-lv1 is now 3276800 blocks long.

You can verify the details by

[root@mail ~]# lvdisplay /dev/vg1/lv1
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                0UcqUR-EotB-t3Eh-5w3V-rtA4-SALb-uffk0P
  LV Write Access        read/write
  LV Creation host, time mail.onedashline.com, 2022-06-05 10:30:48 +0000
  LV Status              available
  # open                 1
  LV Size                12.50 GiB
  Current LE             3200
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

If you could scroll up you would earlier size of lv1 was 10 GB.

Now let’s say you want to use the remaining vg1 space to increase another logical volume lv2

[root@mail ~]# lvextend -l +100%FREE -r /dev/vg1/lv2
fsck from util-linux 2.23.2
/dev/mapper/vg1-lv2: clean, 11/655360 files, 83137/2620416 blocks
  Size of logical volume vg1/lv2 changed from <10.00 GiB (2559 extents) to 27.49 GiB (7038 extents).
  Logical volume vg1/lv2 successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vg1-lv2 to 7206912 (4k) blocks.
The filesystem on /dev/mapper/vg1-lv2 is now 7206912 blocks long.

Let’s check the lv2 space

[root@mail ~]# lvdisplay /dev/vg1/lv2
  --- Logical volume ---
  LV Path                /dev/vg1/lv2
  LV Name                lv2
  VG Name                vg1
  LV UUID                MzAnEW-eaqW-q4Y0-0De2-uUq5-Cn9H-Txth1B
  LV Write Access        read/write
  LV Creation host, time mail.onedashline.com, 2022-06-05 10:52:15 +0000
  LV Status              available
  # open                 0
  LV Size                27.49 GiB
  Current LE             7038
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

You can see its size has been increased from 9.99 GB to 27.49 GB.

Reduce LVM

Occasionally you want to reduce the size of the logical volume. It’s simple.

[root@mail ~]# lvreduce -L -7.5G -r /dev/vg1/lv2
fsck from util-linux 2.23.2
/dev/mapper/vg1-lv2: clean, 11/1802240 files, 157151/7206912 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vg1-lv2 to 5240832 (4k) blocks.
The filesystem on /dev/mapper/vg1-lv2 is now 5240832 blocks long.

  Size of logical volume vg1/lv2 changed from 27.49 GiB (7038 extents) to 19.99 GiB (5118 extents).
  Logical volume vg1/lv2 successfully resized.

Conclusion

This is how you create, extend, shrink, and resize the logical volumes using LVM. I hope now it would have been quite clear to you. Let me know in comments if I miss anything.

June 5, 2022/0 Comments/by Dhiraj Rahul
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://inguide.in/wp-content/uploads/2021/02/inguide_logo_red_340_156-300x138.png 0 0 Dhiraj Rahul https://inguide.in/wp-content/uploads/2021/02/inguide_logo_red_340_156-300x138.png Dhiraj Rahul2022-06-05 11:31:032022-06-05 11:31:54LVM commands to create, extend & delete partition
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

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

Table of Contents

Search Search

Recent Posts

  • Install Mattermost on Ubuntu/Debian
  • 17 Popular Free & Paid Mail Transfer Agents
  • Top 10 VPN Service Providers & Why!!
  • 15 Best Canva Alternatives for Graphic Design [Free & Paid]
  • 12 Best third-party SEO tools for your website
  • Best NFT Marketplace For Beginners
  • Best WordPress ad management plugin
  • What is Domain Name System blacklist (DNSBL)?
  • Introduction to the Basics of Linux
  • What is Proxy Server?

Categories

  • Chat & Collaboration
  • Domain
  • Email Marketing
  • Email Service
  • Graphic Design
  • Hosting
  • Learning Management System
  • Linux
  • Miscellaneous
  • Proxy
  • Search Engine Optimization
  • SMS
  • SMTP server
  • WooCommerce
  • Wordpress
  • WP Security
Popular
  • Postal-smtp-server
    Build Postal SMTP Server & Send Bulk Emails Step by...March 25, 2021 - 5:19 am
  • install-configure-powermta-centos-8
    Install & Configure PowerMTA on CentOS with IP rot...February 15, 2021 - 4:23 am
  • postal-create-SMTP-add-domain-SSL
    Simplest Way to Configure Postal & Create SMTP + Install...March 27, 2021 - 9:20 am
  • Install CyberPanel on Ubuntu and Create WordPress Websi...September 22, 2021 - 10:05 am
  • Create Mail Server on Windows with Open Source hMailSer...June 13, 2021 - 10:15 am
  • zimbra-free-ssl-certificate-install
    How to Install Free SSL Certificate on Zimbra Mail Serv...May 9, 2021 - 2:21 pm
  • install-zimbra-mail-server-on-centos-8
    Install Zimbra Mail Server on CentOS 7/8 Step by StepMay 9, 2021 - 6:05 am
  • Install and Configure MailCow – Best Self Hosted Mail...May 12, 2021 - 10:32 am
  • lets-encypt-certificate
    Installing Let’s Encrypt Free SSL Certificate on ...March 24, 2021 - 7:36 am
  • install-wordpress-cloud-hosting
    Super Easy Way to Install WordPress on Cloud Hosting in...March 30, 2021 - 1:35 am
Comments
  • vikasCannot "Build a new mail server" #3295 On a fresh installation...May 15, 2025 - 1:19 pm by vikas
  • SivaHow can find about aol blocking and know about email inbox...February 26, 2025 - 7:04 pm by Siva
  • RAKESH GUPTAWe want to change our default CentOS Mail Server to something...December 5, 2024 - 7:15 am by RAKESH GUPTA
  • LavisHey, Can you help me to choose good SMTP server between...November 18, 2024 - 11:12 am by Lavis
  • ApostleThis question is never answeredOctober 29, 2024 - 6:19 am by Apostle
Tags
Ahrefs Aol Canva dkim dkim generator dkim powermta dmarc generator easyengine email deliverability free Gmail install docker ubuntu install free ssl zimbra install mailcow install mailwizz install wordpress install wordpress on google install zimbra centos 8 iredmail mailcow Mailu mailu docker compose mailwizz Memberpress MTA open source chat app outlook Plugin Postal postal server postal smtp private chat server rocket.chat SEO smtp server spf generator Talos VPN WooCommerce WordPress wordpress on cloud hosting Yahoo zimbra zimbra mail server zimbra ssl

Follow us on Facebook

X Logo X Logo Followon X

Information

  • About
  • Account
  • Blog
  • Contact
  • Deals
  • List of VPS Hosting that Provides Open Port 25
  • Login
  • Newsletter
  • Privacy Policy
  • Terms of Service
  • Thank You
  • Verify Account

Resources

  • Account
  • Deals
  • Downloads
  • List of VPS Hosting that Provides Open Port 25
  • Login
  • Services
  • Thank You
  • Verify Account

Categories

  • Chat & Collaboration
  • Domain
  • Email Marketing
  • Email Service
  • Graphic Design
  • Hosting
  • Learning Management System
  • Linux
  • Miscellaneous
  • Proxy
  • Search Engine Optimization
  • SMS
  • SMTP server
  • WooCommerce
  • Wordpress
  • WP Security

Archive

  • November 2025
  • July 2023
  • June 2023
  • May 2023
  • January 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • September 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
© Copyright - inGuide | Digital Marketing, Online Business & WordPress
  • Terms of Service
  • Privacy Policy
Link to: Best Self Hosted Email Marketing Software in 2022 Link to: Best Self Hosted Email Marketing Software in 2022 Best Self Hosted Email Marketing Software in 2022 Link to: 23 Best Cold Email WarmUp Tools in 2022 (Free + Paid) Link to: 23 Best Cold Email WarmUp Tools in 2022 (Free + Paid) 23 Best Cold Email WarmUp Tools in 2022 (Free + Paid)
Scroll to top Scroll to top Scroll to top