{"id":3818,"date":"2023-11-22T14:14:05","date_gmt":"2023-11-22T06:14:05","guid":{"rendered":"https:\/\/www.servergigabit.com\/guide\/?post_type=kb&#038;p=3818"},"modified":"2025-12-26T15:51:37","modified_gmt":"2025-12-26T07:51:37","slug":"lvm-a-comprehensive-guide-to-managing-storage-on-linux-systems","status":"publish","type":"kb","link":"https:\/\/www.servergigabit.com\/guide\/kb\/lvm-a-comprehensive-guide-to-managing-storage-on-linux-systems","title":{"rendered":"LVM: A Comprehensive Guide to Managing Storage on Linux Systems"},"content":{"rendered":"<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-3819\" src=\"https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-300x169.jpeg\" alt=\"LVM\" width=\"731\" height=\"412\" srcset=\"https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-300x169.jpeg 300w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-1024x576.jpeg 1024w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-768x432.jpeg 768w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-1536x864.jpeg 1536w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-2048x1152.jpeg 2048w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-370x208.jpeg 370w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-1230x692.jpeg 1230w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-800x450.jpeg 800w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/aaa-390x219.jpeg 390w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/p>\n<div class=\"markdown markdown-main-panel\" dir=\"ltr\">\n<p data-sourcepos=\"5:1-5:320\"><a href=\"https:\/\/askubuntu.com\/questions\/3596\/what-is-lvm-and-what-is-it-used-for\" target=\"_blank\" rel=\"noopener\">LVM<\/a>, or Logical Volume Manager, is a powerful tool for managing storage on Linux systems. It allows you to create and manage logical volumes, which are virtual partitions that can span multiple physical disks. This can be useful for a number of reasons, such as:<\/p>\n<ul data-sourcepos=\"7:1-10:0\">\n<li data-sourcepos=\"7:1-7:77\">Creating larger partitions than are available on a single physical disk<\/li>\n<li data-sourcepos=\"8:1-8:46\">Easily extending or shrinking partitions<\/li>\n<li data-sourcepos=\"9:1-10:0\">Improving disk performance by spreading data across multiple disks<\/li>\n<\/ul>\n<h2 data-sourcepos=\"7:1-7:20\"><strong>LVM Architecture<\/strong><\/h2>\n<p data-sourcepos=\"9:1-9:38\">LVM consists of three main components:<\/p>\n<ul>\n<li><strong>Physical Volumes: <\/strong>Physical volumes are the basic building blocks of LVM. They represent physical storage devices, such as hard drives or SSDs. Before you can use a physical volume in LVM, you must first create a physical volume using the pvcreate command.<\/li>\n<li><strong>Volume Groups: <\/strong>Volume groups are collections of one or more physical volumes. They are used to group physical volumes together so that they can be managed as a single unit. Volume groups are created using the vgcreate command.<\/li>\n<li><strong>Logical Volumes: <\/strong>Logical volumes are the virtual partitions that are created using LVM. They are created using the lvcreate command. Logical volumes can be resized and expanded using the lvextend command.<\/li>\n<\/ul>\n<h2 data-sourcepos=\"27:1-27:25\"><strong>Benefits of Using LVM<\/strong><\/h2>\n<p data-sourcepos=\"29:1-29:48\">There are many benefits to using LVM, including:<\/p>\n<ul>\n<li>Flexibility:\u00a0LVM allows you to create flexible and scalable storage configurations.<\/li>\n<li>Ease of use:\u00a0LVM is easy to use and manage.<\/li>\n<li>Security:\u00a0LVM provides additional security features, such as the ability to create RAID volumes.<\/li>\n<\/ul>\n<h2 data-sourcepos=\"19:1-19:28\"><strong>Getting Started with LVM<\/strong><\/h2>\n<h4 data-sourcepos=\"21:1-21:18\"><strong>Installing LVM<\/strong><\/h4>\n<p data-sourcepos=\"23:1-23:95\">If LVM is not already installed on your system, you can install it using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">sudo apt-get install lvm2\r\n<\/code><\/pre>\n<\/div>\n<h4 data-sourcepos=\"29:1-29:30\"><strong>Creating a Physical Volume<\/strong><\/h4>\n<p data-sourcepos=\"31:1-31:130\">Before you can use a physical disk with LVM, you must first create a physical volume. You can do this using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">pvcreate \/dev\/sdb1\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"37:1-37:74\">This command will create a physical volume from the partition <code>\/dev\/sdb1<\/code>.<\/p>\n<h4 data-sourcepos=\"39:1-39:27\"><strong>Creating a Volume Group<\/strong><\/h4>\n<p data-sourcepos=\"41:1-41:127\">Once you have created one or more physical volumes, you can create a volume group. You can do this using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">vgcreate myvg \/dev\/sdb1\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"47:1-47:90\">This command will create a volume group named <code>myvg<\/code> from the physical volume <code>\/dev\/sdb1<\/code>.<\/p>\n<h4 data-sourcepos=\"49:1-49:29\"><strong>Creating a Logical Volume<\/strong><\/h4>\n<p data-sourcepos=\"51:1-51:126\">Once you have created a volume group, you can create one or more logical volumes. You can do this using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">lvcreate -L 10G -n mylv myvg\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"57:1-57:103\">This command will create a logical volume named <code>mylv<\/code> with a size of 10 GB in the volume group <code>myvg<\/code>.<\/p>\n<h4 data-sourcepos=\"59:1-59:31\"><strong>Formatting a Logical Volume<\/strong><\/h4>\n<p data-sourcepos=\"61:1-61:119\">Before you can use a logical volume, you must format it with a filesystem. You can do this using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">mkfs.ext4 \/dev\/myvg\/mylv\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"67:1-67:86\">This command will format the logical volume <code>\/dev\/myvg\/mylv<\/code> with the ext4 filesystem.<\/p>\n<h4 data-sourcepos=\"69:1-69:29\"><strong>Mounting a Logical Volume<\/strong><\/h4>\n<p data-sourcepos=\"71:1-71:138\">Once you have formatted a logical volume, you can mount it to a directory in your filesystem. You can do this using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">sudo mount \/dev\/myvg\/mylv \/mnt\/mylv\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"77:1-77:89\">This command will mount the logical volume <code>\/dev\/myvg\/mylv<\/code> to the directory <code>\/mnt\/mylv<\/code>.<\/p>\n<h4 data-sourcepos=\"79:1-79:29\"><strong>Resizing a Logical Volume<\/strong><\/h4>\n<p data-sourcepos=\"81:1-81:60\">You can resize a logical volume using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">lvextend -L +10G \/dev\/myvg\/mylv\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"87:1-87:84\">This command will increase the size of the logical volume <code>\/dev\/myvg\/mylv<\/code> by 10 GB.<\/p>\n<h4 data-sourcepos=\"89:1-89:50\"><strong>Removing a Physical Volume from a Volume Group<\/strong><\/h4>\n<p data-sourcepos=\"91:1-91:81\">You can remove a physical volume from a volume group using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">vgreduce myvg \/dev\/sdb1\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"97:1-97:86\">This command will remove the physical volume <code>\/dev\/sdb1<\/code> from the volume group <code>myvg<\/code>.<\/p>\n<h4 data-sourcepos=\"99:1-99:29\"><strong>Removing a Logical Volume<\/strong><\/h4>\n<p data-sourcepos=\"101:1-101:60\">You can remove a logical volume using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">lvremove \/dev\/myvg\/mylv\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"107:1-107:61\">This command will remove the logical volume <code>\/dev\/myvg\/mylv<\/code>.<\/p>\n<h2 data-sourcepos=\"3:1-3:39\"><strong>Extending an Existing LVM Partition<\/strong><\/h2>\n<p data-sourcepos=\"5:1-5:34\">If you want to extend an existing LVM partition, you can do so by using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">lvextend -L +10G \/dev\/myvg\/mylv\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"11:1-11:84\">This command will increase the size of the logical volume <code class=\"\">\/dev\/myvg\/mylv<\/code> by 10 GB. If the new space is not immediately available, you will need to resize the filesystem using the following command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">resize2fs \/dev\/myvg\/mylv\r\n<\/code><\/pre>\n<\/div>\n<h2 data-sourcepos=\"17:1-17:39\"><strong>Shrinking an Existing LVM Partition<\/strong><\/h2>\n<p data-sourcepos=\"19:1-19:207\">Shrinking an LVM partition requires careful planning and execution. It is crucial to first unmount the filesystem and then resize the logical volume before resizing the filesystem back. Here&#8217;s the procedure:<\/p>\n<p>Unmount the filesystem using the\u00a0<code class=\"\">umount<\/code>\u00a0command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">umount \/dev\/myvg\/mylv\r\n<\/code><\/pre>\n<\/div>\n<p>Resize the logical volume using the\u00a0<code class=\"\">lvreduce<\/code>\u00a0command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">lvreduce -L 30G \/dev\/myvg\/mylv\r\n<\/code><\/pre>\n<\/div>\n<p>Resize the filesystem back to the new size using the\u00a0<code class=\"\">resize2fs<\/code>\u00a0command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">resize2fs \/dev\/myvg\/mylv\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"39:1-39:97\">Once the filesystem has been resized, you can unmount it and then mount it back to the directory.<\/p>\n<h2 data-sourcepos=\"41:1-41:50\"><strong>Removing a Physical Volume from a Volume Group<\/strong><\/h2>\n<p data-sourcepos=\"43:1-43:161\">Before you can remove a physical volume from a volume group, you must make sure no data is stored on the physical volume you want to remove. Here&#8217;s how to do it:<\/p>\n<p>Use the\u00a0<code class=\"\">pvmove<\/code>\u00a0command to move all data from the physical volume you want to remove to other available volumes in the group:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">pvmove \/dev\/sdb1\r\n<\/code><\/pre>\n<\/div>\n<p>Remove the physical volume from the volume group using the\u00a0<code class=\"\">vgreduce<\/code>\u00a0command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">vgreduce myvg \/dev\/sdb1\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"57:1-57:161\">Once the physical volume has been removed from the volume group, you can add it to another volume group or fully remove it from LVM using the <code class=\"\">pvremove<\/code> command:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<pre><code class=\"code-container no-decoration-radius\" role=\"text\">pvremove \/dev\/sdb1\r\n<\/code><\/pre>\n<\/div>\n<h2 data-sourcepos=\"19:1-19:33\"><strong style=\"font-size: 3.2143rem; letter-spacing: -0.3px;\">Additional Tips<\/strong><\/h2>\n<p data-sourcepos=\"54:1-54:45\">Here are a few additional tips for using LVM:<\/p>\n<ul>\n<li>Always back up your data before making any changes to your LVM configuration.<\/li>\n<li>Use the lvreduce command to shrink a logical volume before shrinking the corresponding file system.<\/li>\n<li>Use the pvmove command to move data from one physical volume to another before removing the physical volume from an LVM configuration.<\/li>\n<\/ul>\n<h2 data-sourcepos=\"99:1-99:14\"><strong>Conclusion<\/strong><\/h2>\n<p data-sourcepos=\"101:1-101:272\">LVM is a powerful tool that can be used to manage storage on <a href=\"https:\/\/www.servergigabit.com\/linux-vps-hosting\/\">Linux systems<\/a>. It allows you to create and manage logical volumes, which can be resized and expanded as needed. This makes it a valuable tool for administrators who need to manage complex storage configurations.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>LVM, or Logical Volume Manager, is a powerful tool for managing storage on Linux systems. It allows you to create and manage logical volumes, which are virtual partitions that can span multiple physical disks. This can be useful for a number of reasons, such as: Creating larger partitions than are available on a single physical disk Easily extending or shrinking&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"kbtopic":[1099],"kbtag":[1158,1157],"class_list":["post-3818","kb","type-kb","status-publish","hentry","kbtopic-tutorials","kbtag-linux","kbtag-lvm"],"_links":{"self":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/comments?post=3818"}],"version-history":[{"count":5,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3818\/revisions"}],"predecessor-version":[{"id":4257,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3818\/revisions\/4257"}],"wp:attachment":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/media?parent=3818"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=3818"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtag?post=3818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}