{"id":2725,"date":"2013-02-06T17:19:50","date_gmt":"2013-02-06T17:19:50","guid":{"rendered":"http:\/\/really.zonky.org\/?p=2725"},"modified":"2013-02-06T17:19:50","modified_gmt":"2013-02-06T17:19:50","slug":"linux-volume-manager-growing-filesystems","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=2725","title":{"rendered":"Linux Volume Manager: Growing Filesystems"},"content":{"rendered":"<p>If you have previously used Linux&#8217;s volume manager (<a href=\"http:\/\/en.wikipedia.org\/wiki\/Logical_Volume_Manager_(Linux)\">LVM<\/a>) to set up disk storage, you may want to know about how to grow a filesystem safely.<\/p>\n<p>Which is probably the big feature of\u00a0<em>any<\/em> decent volume manager because accurately predicting the size of filesystems is a black art, and the only alternative &#8211; to make the root filesystem contain all of the storage is a dumb idea.<\/p>\n<p>It&#8217;s actually\u00a0<em>really<\/em> easy and can be done non-disruptively. It is done in two parts &#8211; effectively growing the &#8220;disk&#8221; device and then growing the filesystem itself.<\/p>\n<h2>Extending The Volume<\/h2>\n<p>First identify the volume you need to extend. You can of course simply run\u00a0<em>lvscan<\/em> which will show a list of the volumes, and if you have named them sensibly will allow you to pick out the volume to extend. But the simplest way is simply to run\u00a0<em>df<\/em> to look at the filesystem you want to extend :-<\/p>\n<pre>\/dev\/mapper\/ssd-opt \u00a0 \u00a0 \u00a0 \u00a0 7.9G \u00a05.5G \u00a02.1G \u00a073% \/opt<\/pre>\n<p>The device (in the first column) is what we extend. Now to decide how much to grow the volume by; just for the case of this example, we&#8217;ll assume that 2Gbytes is a sensible amount to grow the volume by. The command needed is :-<\/p>\n<pre>lvextend --size +2G \/dev\/mapper\/ssd-opt<\/pre>\n<p>And that&#8217;s it. No need to shut down the server, dismount the filesystem, etc. Of course we haven&#8217;t quite finished yet.<\/p>\n<h2>Growing The Filesystem<\/h2>\n<p>What we have done at this point is the equivalent of making the disk bigger. We also need to tell the filesystem it is sitting on a bigger disk, and to do so we need to know the type of the filesystem. The canonical place for checking that is the file\u00a0<em>\/etc\/fstab<\/em> (actually it&#8217;s the filesystem itself but that is going too far) :-<\/p>\n<pre>\r\n# grep opt \/etc\/fstab\r\n\/dev\/mapper\/ssd-opt\t\/opt\t\text4\tnoatime\t\t0 3\r\n<\/pre>\n<p>\nIt is <em>probable<\/em> that you are looking at growing an ext3, ext4, or xfs filesystem. If not you will have to look up the details yourself.<\/p>\n<p><h3>Growing ext3, or ext4 Filesystems<\/h3>\n<p>\nThis is done with the <em>resize2fs<\/em> command :-<\/p>\n<pre>\r\nresize2fs \/dev\/mapper\/ssd-opt\r\n<\/pre>\n<p>\nSeveral points :-<\/p>\n<ol>\n<li>Yes it <em>can<\/em> be done &#8220;online&#8221; whilst the filesystem is mounted (and applications are busy using it).\n<li>You need to specify the device containing the filesystem to grow and not the mount point.\n<li>There is no need to specify the size &#8230; the size will be determined from the size of the device underneath the filesystem.\n<\/ol>\n<p><h3>Growing xfs Filesystems<\/h3>\n<p>\nThis is done with the <em>xfs_growfs<\/em> command :-<\/p>\n<pre>\r\n# xfs_growfs \/opt\r\n<\/pre>\n<p>\nSeveral points :-<\/p>\n<ol>\n<li>Yes, it can be done &#8220;online&#8221;. In fact you <em>have<\/em> to do it with the filesystem mounted.\n<li>You need to specify the mountpoint of the filesystem and not the device. Irritatingly different from the above!\n<li>There is no need to specify the size.\n<\/ol>\n<p><h2>How Reliable Is This?<\/h2>\n<p>\nVery.<\/p>\n<p>\nThere is always the chance that something could go wrong especially if you are operating &#8220;at the edge&#8221; (say you have a filesystem that is unusually large &#8211; several petabytes). But I&#8217;ve done online filesystem resizing for years in countless circumstances without an issue.<\/p>\n<p>\nI&#8217;ll quite happily do it on the most important systems during working hours without losing a moment&#8217;s thought. However I do work in a place that takes backups seriously!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have previously used Linux&#8217;s volume manager (LVM) to set up disk storage, you may want to know about how to grow a filesystem safely. Which is probably the big feature of\u00a0any decent volume manager because accurately predicting the size of filesystems is a black art, and the only alternative &#8211; to make the <a href='https:\/\/really.zonky.org\/?p=2725' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[4,209,226],"tags":[1061,1062,539,485,1063],"class_list":["post-2725","post","type-post","status-publish","format-standard","hentry","category-it","category-linux-it","category-working-notes","tag-ext3","tag-ext4","tag-filesystems","tag-lvm","tag-xfs","category-4-id","category-209-id","category-226-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1f2KI-HX","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/2725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2725"}],"version-history":[{"count":4,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/2725\/revisions"}],"predecessor-version":[{"id":2729,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/2725\/revisions\/2729"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}