{"id":1461,"date":"2011-11-17T16:28:10","date_gmt":"2011-11-17T08:28:10","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=1461"},"modified":"2023-10-21T13:38:07","modified_gmt":"2023-10-21T13:38:07","slug":"how-to-increase-the-size-of-logical-volume-lvm-on-linux","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-increase-the-size-of-logical-volume-lvm-on-linux\/","title":{"rendered":"How to Increase the Size of Logical Volume (LVM) on Linux"},"content":{"rendered":"<p>Logical Volume Management (LVM) is a flexible and advanced option available to manage hard disks in most Linux distributions. It provides a higher level of storage management than traditional partitioning. One of the main advantages of LVM is the ability to resize logical volumes dynamically as storage needs increase.<\/p>\n<p>In this tutorial, we will walk through the steps to increase the size of a logical volume on Linux. This can be particularly useful when you&#8217;re running out of space on a specific volume and have available unallocated space on your disk or a new disk. <\/p>\n<p>Let&#8217;s get started.<\/p>\n<h2>Step 1: Check Current Disk Usage<\/h2>\n<p>Use the command `df -lh` to view the current disk usage.<\/p>\n<pre>\r\ndf -lh\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\nFilesystem            Size  Used Avail Use% Mounted on\r\n\/dev\/sda3             5.8G  4.3G  1.2G  79% \/\r\n\/dev\/sda1              99M   12M   83M  13% \/boot\r\ntmpfs                 506M     0  506M   0% \/dev\/shm\r\n\/dev\/mapper\/VolGroup00-datavol\r\n                       13G  855M   12G   7% \/data\r\n\/dev\/mapper\/VolGroup01-optvol\r\n                       20G  173M   19G   1% \/opt\r\n<\/pre>\n<h2>Step 2: List All Partitions<\/h2>\n<p>To list all partitions on your system, use:<\/p>\n<pre>\r\nfdisk -lu\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\nDisk \/dev\/sda: 21.4 GB, 21474836480 bytes\r\n255 heads, 63 sectors\/track, 2610 cylinders, total 41943040 sectors\r\nUnits = sectors of 1 * 512 = 512 bytes\r\n\r\n   Device Boot      Start         End      Blocks   Id  System\r\n\/dev\/sda1   *          63      208844      104391   83  Linux\r\n\/dev\/sda2          208845     2313359     1052257+  82  Linux swap \/ Solaris\r\n\/dev\/sda3         2313360    14667344     6176992+  8e  Linux LVM\r\n\/dev\/sda4        14667345    41929649    13631152+  8e  Linux LVM\r\n\r\nDisk \/dev\/sdb: 26.8 GB, 26843545600 bytes\r\n255 heads, 63 sectors\/track, 3263 cylinders, total 52428800 sectors\r\nUnits = sectors of 1 * 512 = 512 bytes\r\n\r\n   Device Boot      Start         End      Blocks   Id  System\r\n\/dev\/sdb1              63    41929649    20964793+  8e  Linux LVM\r\n<\/pre>\n<h2>Step 3: Create a New Partition<\/h2>\n<p>If you have unallocated space on `\/dev\/sdb`, create a new partition:<\/p>\n<pre>\r\nfdisk \/dev\/sdb\r\n<\/pre>\n<p>Follow the on-screen instructions to create a new partition.<\/p>\n<p>Example:<\/p>\n<pre>\r\nThe number of cylinders for this disk is set to 3263.\r\nThere is nothing wrong with that, but this is larger than 1024,\r\nand could in certain setups cause problems with:\r\n1) software that runs at boot time (e.g., old versions of LILO)\r\n2) booting and partitioning software from other OSs\r\n   (e.g., DOS FDISK, OS\/2 FDISK)\r\n\r\nCommand (m for help): n\r\nCommand action\r\n   e   extended\r\n   p   primary partition (1-4)\r\np\r\nPartition number (1-4): 2\r\nFirst cylinder (2611-3263, default 2611):\r\nUsing default value 2611\r\nLast cylinder or +size or +sizeM or +sizeK (2611-3263, default 3263):\r\nUsing default value 3263\r\n\r\nCommand (m for help): t\r\nPartition number (1-4): 2\r\nHex code (type L to list codes): 8e\r\nChanged system type of partition 2 to 8e (Linux LVM)\r\n\r\nCommand (m for help): p\r\n\r\nDisk \/dev\/sdb: 26.8 GB, 26843545600 bytes\r\n255 heads, 63 sectors\/track, 3263 cylinders\r\nUnits = cylinders of 16065 * 512 = 8225280 bytes\r\n\r\n   Device Boot      Start         End      Blocks   Id  System\r\n\/dev\/sdb1               1        2610    20964793+  8e  Linux LVM\r\n\/dev\/sdb2            2611        3263     5245222+  8e  Linux LVM\r\n\r\nCommand (m for help): w\r\nThe partition table has been altered!\r\n\r\nCalling ioctl() to re-read partition table.\r\n\r\nWARNING: Re-reading the partition table failed with error 16: Device or resource busy.\r\nThe kernel still uses the old table.\r\nThe new table will be used at the next reboot.\r\nSyncing disks.\r\n<\/pre>\n<p>Reboot the server:<\/p>\n<pre>\r\nreboot\r\n<\/pre>\n<p>Verify disk usage:<\/p>\n<pre>\r\nFilesystem            Size  Used Avail Use% Mounted on\r\n\/dev\/sda3             5.8G  4.3G  1.2G  79% \/\r\n\/dev\/sda1              99M   12M   83M  13% \/boot\r\ntmpfs                 506M     0  506M   0% \/dev\/shm\r\n\/dev\/mapper\/VolGroup00-datavol\r\n                       13G  855M   12G   7% \/data\r\n\/dev\/mapper\/VolGroup01-optvol\r\n                       20G  173M   19G   1% \/opt\r\n<\/pre>\n<h2>Step 4: Format the New Partition<\/h2>\n<p>Once the partition is created, format it:<\/p>\n<pre>\r\nmke2fs -j \/dev\/sdb2\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\nmke2fs 1.39 (29-May-2006)\r\nFilesystem label=\r\nOS type: Linux\r\nBlock size=4096 (log=2)\r\nFragment size=4096 (log=2)\r\n656000 inodes, 1311305 blocks\r\n65565 blocks (5.00%) reserved for the super user\r\nFirst data block=0\r\nMaximum filesystem blocks=1346371584\r\n41 block groups\r\n32768 blocks per group, 32768 fragments per group\r\n16000 inodes per group\r\nSuperblock backups stored on blocks:\r\n        32768, 98304, 163840, 229376, 294912, 819200, 884736\r\n\r\nWriting inode tables: done\r\nCreating journal (32768 blocks): done\r\nWriting superblocks and filesystem accounting information: done\r\n\r\nThis filesystem will be automatically checked every 20 mounts or\r\n180 days, whichever comes first.  Use tune2fs -c or -i to override.\r\n<\/pre>\n<h2>Step 5: Create a Physical Volume<\/h2>\n<p>Now, create a physical volume on the new partition:<\/p>\n<pre>\r\npvcreate \/dev\/sdb2\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\n  Physical volume \"\/dev\/sdb2\" successfully created\r\n<\/pre>\n<h2>Step 6: Scan All Physical Volumes<\/h2>\n<p>To ensure the system recognizes the new PV, scan all physical volumes:<\/p>\n<pre>\r\npvscan\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\n  PV \/dev\/sdb1   VG VolGroup01      lvm2 [19.99 GB \/ 0    free]\r\n  PV \/dev\/sda4   VG VolGroup00      lvm2 [13.00 GB \/ 0    free]\r\n  PV \/dev\/sdb2                      lvm2 [5.00 GB]\r\n  Total: 3 [37.99 GB] \/ in use: 2 [32.99 GB] \/ in no VG: 1 [5.00 GB]\r\n<\/pre>\n<h2>Step 7: Extend the Volume Group<\/h2>\n<p>Extend your volume group (e.g., `VolGroup01`) to include the new PV:<\/p>\n<pre>\r\nvgextend VolGroup01 \/dev\/sdb2\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\n  Volume group \"VolGroup01\" successfully extended\r\n<\/pre>\n<h2>Step 8: Extend the Logical Volume<\/h2>\n<p>Now, increase the size of your logical volume:<\/p>\n<pre>\r\nlvextend -l +100%FREE \/dev\/VolGroup01\/optvol\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\n  Extending logical volume optvol to 24.99 GB\r\n  Logical volume optvol successfully resized\r\n<\/pre>\n<h2>Step 9: Resize the File System<\/h2>\n<p>After extending the logical volume, resize the file system:<\/p>\n<pre>\r\nresize2fs \/dev\/mapper\/VolGroup01-optvol\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\nresize2fs 1.39 (29-May-2006)\r\nFilesystem at \/dev\/mapper\/VolGroup01-optvol is mounted on \/opt; on-line resizing required\r\nPerforming an on-line resize of \/dev\/mapper\/VolGroup01-optvol to 6551552 (4k) blocks.\r\nThe filesystem on \/dev\/mapper\/VolGroup01-optvol is now 6551552 blocks long.\r\n<\/pre>\n<h2>Step 10: Verify the Changes<\/h2>\n<p>Finally, check the disk usage again to confirm the changes:<\/p>\n<pre>\r\ndf -lh\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\nFilesystem            Size  Used Avail Use% Mounted on\r\n\/dev\/sda3             5.8G  4.3G  1.2G  79% \/\r\n\/dev\/sda1              99M   12M   83M  13% \/boot\r\ntmpfs                 506M     0  506M   0% \/dev\/shm\r\n\/dev\/mapper\/VolGroup00-datavol\r\n                       13G  855M   12G   7% \/data\r\n\/dev\/mapper\/VolGroup01-optvol\r\n                       25G  173M   24G   1% \/opt\r\n<\/pre>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">df -lh<\/span> \u2013 Displays disk space usage<\/li>\n<li><span class=\"fw-bold\">fdisk -lu<\/span> \u2013 Lists all partitions<\/li>\n<li><span class=\"fw-bold\">fdisk \/dev\/sdb<\/span> \u2013 Creates a new partition on \/dev\/sdb<\/li>\n<li><span class=\"fw-bold\">mke2fs -j \/dev\/sdb2<\/span> \u2013 Formats the new partition<\/li>\n<li><span class=\"fw-bold\">pvcreate \/dev\/sdb2<\/span> \u2013 Creates a physical volume<\/li>\n<li><span class=\"fw-bold\">pvscan<\/span> \u2013 Scans all physical volumes<\/li>\n<li><span class=\"fw-bold\">vgextend VolGroup01 \/dev\/sdb2<\/span> \u2013 Extends the volume group<\/li>\n<li><span class=\"fw-bold\">lvextend -l +100%FREE \/dev\/VolGroup01\/optvol<\/span> \u2013 Extends the logical volume<\/li>\n<li><span class=\"fw-bold\">resize2fs \/dev\/mapper\/VolGroup01-optvol<\/span> \u2013 Resizes the file system<\/li>\n<\/ul>\n<h2>FAQ<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is LVM in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">LVM stands for Logical Volume Management. It&#8217;s a method of allocating space on hard drives into virtual partitions that can be easily resized unlike traditional disk partitioning. This provides greater flexibility and efficiency in disk management.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why would one need to resize a logical volume?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Resizing a logical volume is often necessary when a particular volume is running out of space, and there&#8217;s available unallocated space on the disk or another disk. LVM provides the flexibility to resize volumes dynamically based on storage needs.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Is it safe to resize logical volumes?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">While LVM provides the tools to resize volumes, it&#8217;s essential to take precautions. Always backup critical data before making changes, and ensure you follow the correct procedures to avoid data loss or corruption.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Can I reduce the size of a logical volume?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Yes, LVM allows both increasing and decreasing the size of logical volumes. However, reducing size requires extra caution to ensure data within the volume isn&#8217;t lost.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What&#8217;s the difference between a physical volume and a logical volume?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">In LVM, a physical volume (PV) refers to a storage device or a partition on a storage device, which can be used as part of LVM. It&#8217;s the foundational building block in the LVM hierarchy. On the other hand, a logical volume (LV) is a virtual partition created from space allocated from one or more physical volumes. It&#8217;s where your file systems can be created. Logical volumes offer the flexibility to be resized, moved, and modified as needed, unlike traditional partitions.<\/span>\n<\/p>\n<\/li>\n<\/ol>\n<h2>Conclusion<\/h2>\n<p>Increasing the size of a logical volume in Linux using LVM is a powerful feature that provides administrators with the flexibility to manage storage dynamically. This adaptability is especially beneficial in environments where storage needs can change, such as in cloud hosting or VPS server setups.<\/p>\n<p>However, while LVM offers many advantages, it&#8217;s crucial to approach the process with caution. Always ensure that you have a backup of essential data before making any changes to your storage configurations. Mistakes or unforeseen issues can lead to data loss, so it&#8217;s better to be safe than sorry.<\/p>\n<p>Furthermore, while this tutorial focused on increasing the size of a logical volume, LVM also supports other operations like reducing the size of a volume, migrating data between disks, and more. It&#8217;s a testament to the versatility and power of LVM in Linux.<\/p>\n<p>For those who manage web servers or host multiple websites, understanding LVM can be a game-changer. It&#8217;s not just about adding more space; it&#8217;s about optimizing and making the most of the resources you have. Whether you&#8217;re on a dedicated server or a shared hosting environment, mastering LVM can significantly enhance your server management capabilities.<\/p>\n<p>In conclusion, LVM is an indispensable tool for Linux administrators, offering a level of flexibility and control over storage that traditional partitioning methods can&#8217;t match. By following the steps outlined in this tutorial, you can efficiently manage and optimize your storage needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Logical Volume Management (LVM) is a flexible and advanced option available to manage hard disks in most Linux distributions. It provides a higher level of storage management than traditional partitioning&#8230;.<\/p>\n","protected":false},"author":6,"featured_media":369,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1002],"tags":[1445,1536,1965],"class_list":["post-1461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lvm","tag-how-to-increase-the-partition-size","tag-linux","tag-log"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=1461"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/369"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=1461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=1461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=1461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}