{"id":51,"date":"2014-09-17T16:15:18","date_gmt":"2014-09-17T16:15:18","guid":{"rendered":"http:\/\/blogs.nrao.edu\/jmalone\/?p=51"},"modified":"2014-10-03T19:32:40","modified_gmt":"2014-10-03T19:32:40","slug":"moving-lvm2-logical-volumes-1","status":"publish","type":"post","link":"https:\/\/blogs.nrao.edu\/jmalone\/2014\/09\/17\/moving-lvm2-logical-volumes-1\/","title":{"rendered":"Moving LVM2 logical volumes from one physical volume to another &#8211; Part 1"},"content":{"rendered":"<p>So, on discovering a server that&#8217;s configured with the wrong disk layout, I find myself needing to consolidate all logical volumes onto a single physical volume (PV) so I can re-configure the other PV. The machine has the disk space, so it should be a matter of shuffling bits in a &#8220;shell-game&#8221; so I can clear off the second PV and re-build the disk array with the right RAID level.<\/p>\n<p>LVM2 has the utility pvmove that can move physical extents from one disk to another. Maybe I can make this work for me \ud83d\ude42<\/p>\n<p>First hurdle: all physical disk blocks are allocated to LVM physical volumes. I need to shrink my first PV to make room for blocks from my second PV. To see how many blocks on PV 1 are in use, I run<\/p>\n<pre>pvdisplay -m<\/pre>\n<p>Which reports that all extents up to 96640 are in use. So I should be able to shrink the PV down to, say, 100000 extents safely. With 32MiB extents, the command to do this should be<\/p>\n<pre>pvresize -t \/dev\/sda3 --setphysicalvolumesize 3200000M<\/pre>\n<p>but I&#8217;m too chicken to run this on a live system. I need to set up a test machine to verify that this works.<\/p>\n<p>UPDATE: So, it does work, but it turns out that a reboot is needed to update the kernel partition table after the next step, which is resizing the partitions.<\/p>\n<p>(It might have been easier to just resize the partition first and then resize the PV with &#8220;pvresize \/dev\/sda3&#8221; and let it fill the new partition.)<\/p>\n<p>After shrinking the sdb1 partition to match the new PV size, create a new partition, sda4, to hold the new PV. Create the new PV (I did it in system-config-lvm) and add it to the volume group (VG) of the logical volumes we want to move off of sdb1 as extents must be moved to a new PV in the same group.<\/p>\n<p>I&#8217;m testing this on a VM now. I&#8217;ve already determined this will require a reboot, so I&#8217;m less enthused about the process already. :-\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, on discovering a server that&#8217;s configured with the wrong disk layout, I find myself needing to consolidate all logical volumes onto a single physical volume (PV) so I can re-configure the other PV. The machine has the disk space, &hellip; <a class=\"more-link\" href=\"https:\/\/blogs.nrao.edu\/jmalone\/2014\/09\/17\/moving-lvm2-logical-volumes-1\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[7],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-linux","tag-lvm"],"_links":{"self":[{"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/posts\/51"}],"collection":[{"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":6,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":57,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/posts\/51\/revisions\/57"}],"wp:attachment":[{"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.nrao.edu\/jmalone\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}