{"id":74,"date":"2013-09-27T13:59:09","date_gmt":"2013-09-27T13:59:09","guid":{"rendered":"http:\/\/muse.oneshot.in\/?p=74"},"modified":"2013-09-27T13:59:09","modified_gmt":"2013-09-27T13:59:09","slug":"shrink-size-of-ext4-lvm-logical-volume","status":"publish","type":"post","link":"https:\/\/muse.oneshot.in\/?p=74","title":{"rendered":"Shrink size of ext4 LVM logical volume"},"content":{"rendered":"<div><\/div>\n<p>LVM, the Logical Volume Manager, is extremely flexible and provides numerous advantages over standard partitions. One of those advantages consists in resizing logical volumes.<\/p>\n<p>In this post I&#8217;ll go over the required steps to reduce the size of an LVM logical volume formatted as an ext4 filesystem. This is achieved can be achieved in a few steps:<br \/>\n1) Unmount the logical volume (or boot into a live CD if the logical volume contains the root filesystem)<br \/>\n2) Check the filesystem for errors<br \/>\n3) Shrink the filesystem to the desired size<br \/>\n4) Reduce the size of the underlying logical volume<br \/>\n5) Check if the resulting logical volume and filesystem are ok<br \/>\n6) Re-mount the logical volume<\/p>\n<p>To illustrate the procedure assume a volume group name vg_d620 which contains the lv_example logical group. The objective will be to shrink the lv_example logical group that is formatted with ext4 to 30G.<\/p>\n<h3>1) Unmount the logical volume<\/h3>\n<p>Change to the superuser and unmount the logical volume filesystem that is to be resized:<\/p>\n<ol>\n<li><code>$ su<\/code><\/li>\n<li><code># umount \/dev\/mapper\/vg_d620-lv_example<\/code><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3>2) Check the filesystem for errors<\/h3>\n<p>e2fsck checks a Linux ext2\/ext3\/ext4 filesystem for errors, in this case the -f switch is used to force the check even if the filesystem appears to be clean:<\/p>\n<ol>\n<li><code># e2fsck -f \/dev\/mapper\/vg_d620-lv_example<\/code><\/li>\n<li><code>e2fsck 1.41.12 (17-May-2010)<br \/>\nPass 1: Checking inodes, blocks, and sizes<br \/>\nPass 2: Checking directory structure<br \/>\nPass 3: Checking directory connectivity<br \/>\nPass 4: Checking reference counts<br \/>\nPass 5: Checking group summary information<\/code><code>\/dev\/mapper\/vg_d620-lv_example: 11448\/3678208 files (1.5% non-contiguous), 4768046\/14704640 blocks<\/code><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3>3) Shrink the filesystem to the desired size<\/h3>\n<p>resize2fs is used to shrink our unmounted filesystem located on vol_d620-lv_example. The -p switch is prints out percentage completion bars for the resize operation. Here the ext4 filesystem is reduced to the desired filesystem final size, in this case I want it to be of 30 gigabytes:<\/p>\n<ol>\n<li><code># resize2fs -p \/dev\/mapper\/vg_d620-lv_example 30G<\/code><\/li>\n<li><code>resize2fs 1.41.12 (17-May-2010)<br \/>\nResizing the filesystem on \/dev\/mapper\/vg_d620-lv_example to 7864320 (4k) blocks.<br \/>\nBegin pass 2 (max = 16894)<br \/>\nRelocating blocks\u00a0\u00a0 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br \/>\nBegin pass 3 (max = 449)<br \/>\nScanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br \/>\nBegin pass 4 (max = 1866)<br \/>\nUpdating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<\/code><code>The filesystem on \/dev\/mapper\/vg_d620-lv_example is now 7864320 blocks long.<\/code><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3>4) Reduce the size of the underlying logical volume<\/h3>\n<p>Having shrunk the ext4 filesystem it is time to reduce the logical volume size accordingly. To achieve this the lvreduce tool is employed. The -L switch specifies final size of the logical volume which should match the size of the ext4 filesystem.<\/p>\n<ol>\n<li><code># lvreduce -L 30G \/dev\/mapper\/vg_d620-lv_example<\/code><\/li>\n<li><code>WARNING: Reducing active logical volume to 30.00 GiB<br \/>\nTHIS MAY DESTROY YOUR DATA (filesystem etc.)<br \/>\nDo you really want to reduce lv_example? [y\/n]: y<br \/>\nReducing logical volume lv_example to 30.00 GiB<\/code><code>Logical volume lv_example successfully resized<\/code><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3>5) Check if the resulting logical volume and filesystem are ok<\/h3>\n<p>Everything should have proceeded as planned however let&#8217;s verify things. e2fsck and resize2fs are used verify the new filesystem, respectively. Notice that this time the resize2fs doesn&#8217;t specify any size, the goal here is to have the filesystem match the size of the logical volume.<\/p>\n<ol>\n<li><code># e2fsck -f \/dev\/mapper\/vg_d620-lv_example<\/code><\/li>\n<li><code>e2fsck 1.41.12 (17-May-2010)<br \/>\nPass 1: Checking inodes, blocks, and sizes<br \/>\nPass 2: Checking directory structure<br \/>\nPass 3: Checking directory connectivity<br \/>\nPass 4: Checking reference counts<br \/>\nPass 5: Checking group summary information<\/code><code>\/dev\/mapper\/vg_d620-lv_example: 11448\/1966080 files (1.5% non-contiguous), 4658570\/7864320 blocks<\/code><\/li>\n<li><code># resize2fs -p \/dev\/mapper\/vg_d620-lv_example<\/code><\/li>\n<li><code>resize2fs 1.41.12 (17-May-2010)<\/code><code>The filesystem is already 7864320 blocks long. Nothing to do!<\/code><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3>6) Re-mount the logical volume<\/h3>\n<div>Finally, mount the updated logical volume:<\/div>\n<p>&nbsp;<\/p>\n<ol>\n<li><code># mount \/dev\/mapper\/vg_d620-lv_example \/mnt\/example<\/code><\/li>\n<\/ol>\n<p>It should be noted that if in step 4 e2fsck fails because the partition is tool small lvextend can be used to extend the logical volume until e2fsck completes with success.<\/p>\n<p>Further information on lvm, lvreduce, lvextend,e2fsck and resize2fs can be obtained in the associated man pages.<\/p>\n<p>&nbsp;<\/p>\n<p>Courtesy: http:\/\/linux-bsd-sharing.blogspot(dot)in\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LVM, the Logical Volume Manager, is extremely flexible and provides numerous advantages over standard partitions. One of those advantages consists in resizing logical volumes. In this post I&#8217;ll go over the required steps to reduce the size of an LVM logical volume formatted as an ext4 filesystem. This is achieved can be achieved in a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-information-technology","category-redhat"],"_links":{"self":[{"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":1,"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":75,"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/75"}],"wp:attachment":[{"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/muse.oneshot.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}