<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lvm &#8211; richliu&#039;s blog</title>
	<atom:link href="https://blog.richliu.com/tag/lvm/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Sat, 08 May 2021 16:33:57 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>LVM 筆記</title>
		<link>https://blog.richliu.com/2005/03/24/140/lvm_/</link>
					<comments>https://blog.richliu.com/2005/03/24/140/lvm_/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Thu, 24 Mar 2005 08:52:57 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[lvm]]></category>
		<guid isPermaLink="false">http://blog.richliu.com/2005/03/24/140/</guid>

					<description><![CDATA[<p>這幾天因為有會在資料在 Partition 移來移去, 分割, 整合的需求,所以就選用用 LVM 做我的 Fi [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2005/03/24/140/lvm_/">LVM 筆記</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>這幾天因為有會在資料在 Partition 移來移去, 分割, 整合的需求,<br />所以就選用用 LVM 做我的 File System</p>



<p>結果比較白爛的事情是, Reiser4 的 resize tool 沒有寫好, 所以我只能先搬到另一<br />顆 DISK ,將原來的 File System 改成 Reiser3 再搬回來. 又多花了半天.</p>



<p>增大 Partition 到是沒有花很多時間. 就 fdisk 直接切 size 之後<br />直接用 resize_reiserfs 去修就可以了</p>



<p>懶得打指令集了, 指令如下</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>624 pvcreate /dev/hde<br />625 pvdisplay<br />626 vgdisplay<br />627 vgextend data /dev/hde<br />628 lvdisplay<br />629 vgdisplay<br />634 lvextend -L457G /dev/data/data_lv<br />635 lvdisplay<br />636 vgdisplay<br />637 fdisk /dev/data/data_lv<br />643 resize_reiserfs /dev/data/data_lv</p></blockquote>



<p>相關指令在我的 <a href="http://wiki.richliu.com" target="_blank" rel="noopener">wiki</a> 有 <a href="http://wiki.richliu.com/index.php/LVM" target="_blank" rel="noopener">LVM 指令說明</a></p>



<p>Update: pvcreate 建 device 時，需要移除所有的 partition 或是沒有任何資料</p>



<p>2021/05/08<br /><br />沒想到今天又回頭用 LVM 了，因為最近有動態增加硬碟的需求，大部份和前面一樣，這邊就筆記一下過程，後面可以查閱</p>



<h3 class="wp-block-heading">Create VG</h3>



<p>新增一個叫 data 的 VG ，並且加入 /dev/sdc and /dev/sdd (時隔十六年，hdx 都變 sdx 了)</p>



<pre class="wp-block-code"><code>$ vgcreate data /dev/sdc /dev/sdd
$ vgdisplay</code></pre>



<pre class="wp-block-preformatted">&nbsp;--- Volume group ---
&nbsp;&nbsp;VG Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data
&nbsp;&nbsp;System ID
&nbsp;&nbsp;Format&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lvm2
&nbsp;&nbsp;Metadata Areas&nbsp; &nbsp; &nbsp; &nbsp; 2
&nbsp;&nbsp;Metadata Sequence No&nbsp; 1
&nbsp;&nbsp;VG Access &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; read/write
&nbsp;&nbsp;VG Status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resizable
&nbsp;&nbsp;MAX LV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0
&nbsp;&nbsp;Cur LV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0
&nbsp;&nbsp;Open LV &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0
&nbsp;&nbsp;Max PV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0
&nbsp;&nbsp;Cur PV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2
&nbsp;&nbsp;Act PV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2
&nbsp;&nbsp;VG Size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;3.64 TiB
&nbsp;&nbsp;PE Size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4.00 MiB
&nbsp;&nbsp;Total PE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 953864
&nbsp;&nbsp;Alloc PE / Size &nbsp; &nbsp; &nbsp; 0 / 0
&nbsp;&nbsp;Free&nbsp; PE / Size &nbsp; &nbsp; &nbsp; 953864 / &lt;3.64 TiB
&nbsp;&nbsp;VG UUID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Y3Zkxe-4hPi-Y7eN-W4c9-Y1GJ-t8pB-qCjqrx

</pre>



<h3 class="wp-block-heading">Create LV</h3>



<p>我們總共有 3.64T 的資料，這邊就建立到最大 3.6T 的 LV</p>



<pre class="wp-block-code"><code>$ lvcreate --name data_ext --size 3.6T data<br />Rounding up size to full physical extent 3.60 TiB<br />&nbsp;&nbsp;Logical volume "data_ext" created.<br />$ lvdisplay</code></pre>



<pre class="wp-block-preformatted">--- Logical volume ---
&nbsp;&nbsp;LV Path&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /dev/data/data_ext
&nbsp;&nbsp;LV Name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data_ext
&nbsp;&nbsp;VG Name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data
&nbsp;&nbsp;LV UUID&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s6dS7a-Ah2s-f3og-1WOm-4fLE-jd1C-bAGX3l
&nbsp;&nbsp;LV Write Access&nbsp; &nbsp; &nbsp; &nbsp; read/write
&nbsp;&nbsp;LV Creation host, time RL-T1, 2021-05-08 14:27:27 +0800
&nbsp;&nbsp;LV Status&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; available
&nbsp;&nbsp;# open &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0
&nbsp;&nbsp;LV Size&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3.60 TiB
&nbsp;&nbsp;Current LE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 943719
&nbsp;&nbsp;Segments &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2
&nbsp;&nbsp;Allocation &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inherit
&nbsp;&nbsp;Read ahead sectors &nbsp; &nbsp; auto
&nbsp;&nbsp;- currently set to &nbsp; &nbsp; 256
&nbsp;&nbsp;Block device &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 253:0
</pre>



<p>接下來就可以用 mkfs.ext4 /dev/data/data_ext 當成一個實體硬碟來用</p>



<h3 class="wp-block-heading">增加一顆硬碟到 VG 內</h3>



<p>如果這時候要新增一顆硬碟，可以再利用 pvcreate 之後再用 vgextend 將其納入 vg 內<br />$ pvcreate /dev/sda<br />&nbsp;&nbsp;Device /dev/sda excluded by a filter.<br />如果出現了錯誤訊息，原因是因為之前可能有 boot disk 之類的 label ，這時用 parted 的 mklabel 指令將 partition 改成 msdos 之後，再執行一次就可以了</p>



<pre class="wp-block-code"><code>$ vgextend data /dev/sda
  Volume group "data" successfully extended
$ vgdisplay</code></pre>



<pre class="wp-block-preformatted">--- Volume group ---
&nbsp;&nbsp;VG Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data
&nbsp;&nbsp;System ID
&nbsp;&nbsp;Format&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lvm2
&nbsp;&nbsp;Metadata Areas&nbsp; &nbsp; &nbsp; &nbsp; 3
&nbsp;&nbsp;Metadata Sequence No&nbsp; 3
&nbsp;&nbsp;VG Access &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; read/write
&nbsp;&nbsp;VG Status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resizable
&nbsp;&nbsp;MAX LV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0
&nbsp;&nbsp;Cur LV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1
&nbsp;&nbsp;Open LV &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1
&nbsp;&nbsp;Max PV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0
&nbsp;&nbsp;Cur PV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3
&nbsp;&nbsp;Act PV&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3
&nbsp;&nbsp;VG Size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;5.46 TiB
&nbsp;&nbsp;PE Size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4.00 MiB
&nbsp;&nbsp;Total PE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1430796
&nbsp;&nbsp;Alloc PE / Size &nbsp; &nbsp; &nbsp; 943719 / 3.60 TiB
&nbsp;&nbsp;Free&nbsp; PE / Size &nbsp; &nbsp; &nbsp; 487077 / &lt;1.86 TiB
&nbsp;&nbsp;VG UUID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Y3Zkxe-4hPi-Y7eN-W4c9-Y1GJ-t8pB-qCjqrx
</pre>



<p>這邊可以看到總容量是 5.46T ，僅使用 3.60T 也就是之前規劃的，接下來擴大容量</p>



<pre class="wp-block-code"><code>$ lvextend -L5.4T /dev/data/data_ext
  Rounding size to boundary between physical extents: 5.40 TiB.
  Size of logical volume data/data_ext changed from 3.60 TiB (943719 extents) to 5.40 TiB (1415578 extents).
  Logical volume data/data_ext successfully resized.</code></pre>



<p>接下來再用 resize2fs /dev/data_ext 就可以了，ext4 可以線上 extend，只是速度慢一點而已</p>



<pre class="wp-block-preformatted">$ resize2fs /dev/data/data_ext
 resize2fs 1.45.5 (07-Jan-2020)
 Filesystem at /dev/data/data_ext is mounted on /home/chia/nfs; on-line resizing required
 old_desc_blocks = 461, new_desc_blocks = 692
 The filesystem on /dev/data/data_ext is now 1449551872 (4k) blocks long.</pre>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2005/03/24/140/lvm_/">LVM 筆記</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.richliu.com/2005/03/24/140/lvm_/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
