{"id":7372,"date":"2018-05-03T23:40:29","date_gmt":"2018-05-03T15:40:29","guid":{"rendered":"http:\/\/rmohan.com\/?p=7372"},"modified":"2018-05-03T23:43:35","modified_gmt":"2018-05-03T15:43:35","slug":"lvm-volume-space-scaling-in-xfs-format-in-centos7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7372","title":{"rendered":"LVM volume space scaling in XFS format in centos7"},"content":{"rendered":"<p><strong>LVM volume space scaling in XFS format in centos7<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Originally on my CentOS 7 virtual machine, I created 2 partitions:<\/p>\n<p>sda1 for \/boot<br \/>\nsda2 with 1 volume group &#8220;centos&#8221; with 5 logical volumes:<br \/>\n\/<br \/>\n\/home<br \/>\n\/var<br \/>\n\/tmp<br \/>\nswap<\/p>\n<p>I noticed later that I had needed more space from \/home lvm. It was 15GB, it was only using 1.5GB, so I decided to reduce it down to 5GB:<\/p>\n<div>\n<div class=\"smallfont\">Code:<\/div>\n<pre class=\"bbcodeblock\" dir=\"ltr\"># lvreduce -L 5GB \/dev\/mapper\/centos-home<\/pre>\n<\/div>\n<p>It said successful so I rebooted.<\/p>\n<p>Upon reboot, I was sent to emergency mode, and noticed \/home was not listed under df, so I mounted everything in fstab but received an error:<\/p>\n<div>\n<div class=\"smallfont\">Code:<\/div>\n<pre class=\"bbcodeblock\" dir=\"ltr\">#mount -a \r\nmount: \/dev\/mapper\/centos-home: can't read superblock<\/pre>\n<\/div>\n<p>So I ran an<\/p>\n<div>\n<div class=\"smallfont\"><strong>Code:<\/strong><\/div>\n<pre class=\"bbcodeblock\" dir=\"ltr\"><strong># xfs_repair \/dev\/mapper\/centos-home<\/strong><\/pre>\n<\/div>\n<p>It gave me same issues about not being able to read the superblock.<\/p>\n<p>Oddly enough, the lvdisplay \/dev\/mapper\/centos-home works and now shows LV Size as 5.00GB down from 15.00GB with all the other information listed&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>This article describes the real-time process of adjusting the LVM volume space for xfs under centos7.<\/p>\n<p>Actual purpose:<\/p>\n<p>1. Reduce the logical volume \/dev\/mapper\/home from 178G to 10G<\/p>\n<p>2, empty 168G divided into logical volumes \/dev\/mapper\/root<\/p>\n<p>Actual process:<\/p>\n<p>1, back up important data in advance, xfs reduction will lead to data loss<\/p>\n<p>Backup can use xfsdump, data can also be backed up outside the machine (slightly here)<\/p>\n<p>Unmount the volume \/dev\/mapper\/home<\/p>\n<p>[root@localhost ~]# umount \/home<\/p>\n<p>3, reduce the volume \/ dev \/ mapper \/ homesize (this step will lead to data loss, see the first point)<\/p>\n<p>[root@localhost ~]# lvreduce -L 5G \/dev\/mapper\/home<\/p>\n<p>WARNING: Reducing active logical volume to 10.00 GiB.<\/p>\n<p>THIS MAY DESTROY YOUR DATA (filesystem etc.)<\/p>\n<p>Do you really want to reduce cl\/home? [y\/n]:y<\/p>\n<p>Size of logical volume cl\/home changed from 178.25 GiB (45633 extents) to 10.00 GiB (2560 extents).<\/p>\n<p>Logical volume cl\/home successfully resized.<\/p>\n<p>4, increase the volume \/dev\/mapper\/root size<\/p>\n<p>[root@localhost ~]# lvextend -l +100%FREE \/dev\/mapper\/root<\/p>\n<p>Size of logical volume cl\/root changed from 50.00 GiB (12800 extents) to 218.26 GiB (55874 extents).<\/p>\n<p>Logical volume cl\/root successfully resized.<\/p>\n<p>5, adjust the xfs file system size<\/p>\n<p>[root@localhost ~]# xfs_growfs \/dev\/mapper\/root<\/p>\n<p>6, re-mount, restore data<\/p>\n<p>If you directly mount an error message:<\/p>\n<p>[root@localhost ~]# mount \/dev\/mapper\/home\/home\/<\/p>\n<p>Mount: \/dev\/mapper\/home: can&#8217;t read superblock<\/p>\n<p>Need to format first<\/p>\n<p>[root@localhost ~]# mkfs.xfs -f \/dev\/mapper\/home<\/p>\n<p>Mount after formatting:<\/p>\n<p>[root@localhost ~]# mount \/dev\/mapper\/home\/home\/<\/p>\n<p>Recover data after mounting<\/p>\n<p>This step can be used xfsrestore, or manually copy (refer to the first point)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>$lvremove -v \/dev\/centos\/home<\/p>\n<p>Which returned the remaining free space to the volume group.<\/p>\n<p>I then used the $lvextend to extend the \/root lv<\/p>\n<p>$lvextend -L +900G \/dev\/centos\/root<\/p>\n<p>And<\/p>\n<p>$xfs_growfs \/dev\/centos\/root<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LVM volume space scaling in XFS format in centos7<\/p>\n<p>&nbsp;<\/p>\n<p>Originally on my CentOS 7 virtual machine, I created 2 partitions:<\/p>\n<p>sda1 for \/boot sda2 with 1 volume group &#8220;centos&#8221; with 5 logical volumes: \/ \/home \/var \/tmp swap<\/p>\n<p>I noticed later that I had needed more space from \/home lvm. It was 15GB, it [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7372"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7372"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7372\/revisions"}],"predecessor-version":[{"id":7376,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7372\/revisions\/7376"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}