Linux系统中云硬盘扩容后处理
<p class="shortdesc">本章节主要介绍基于Linux系统的云硬盘扩容后,如何进行分区扩容。</p>
<section class="section context"><div class="tasklabel"><h2 class="doc-tairway">背景信息</h2></div>
<p class="p">Linux操作系统版本为CentOS7.2_64bit,已经挂载一块数据盘</p>
<p class="p">扩容前的数据盘只有一个主分区(/dev/vdb1),ext3文件系统,挂载点/mnt,扩容前20G,扩容后30G,扩容完成后数据盘仍只有一个主分区。</p>
</section>
<section><div class="tasklabel"><h2 class="doc-tairway">操作步骤</h2></div><ol class="ol steps"><li class="li step stepexpand">
<span class="ph cmd">远程连接云服务器ECS实例。</span>
</li><li class="li step stepexpand">
<span class="ph cmd">查看磁盘当前的挂载信息。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>df -TH</code></pre>
<img class="image" id="expansionlinux__image_dpk_nwl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-1e4626dd9522.png" width="800">
<p class="p">从显示信息中可以看到,/dev/vdb1当前容量是20G ,文件系统类型为ext3,挂载路径为/mnt。</p>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd"> 卸载该磁盘分区。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>umount /dev/vdb1</code></pre>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">新建分区</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>fdisk /dev/vdb</code></pre>
<img class="image" id="expansionlinux__image_pd2_pwl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-125234e896f9.png" width="800">
<ol class="ol" type="a" id="expansionlinux__ol_q5m_jkr_rlb">
<li class="li">输入<code class="ph codeph"><strong class="ph b">d</strong></code>,删除原有分区删除 /dev/vdb1。<img class="image" id="expansionlinux__image_k4m_qwl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-1dfd8ef89790.png"><div class="note important note_important"><span class="note__title">重要:</span> 删除分区会导致磁盘中的数据丢失。如果磁盘有多个分区不建议此操作。</div></li>
<li class="li">输入 <code class="ph codeph"><strong class="ph b">n</strong></code>键,然后按下回车键,开始创建新的分区。<img class="image" id="expansionlinux__image_x2l_swl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-1804ac6a9740.png"><p class="p" id="expansionlinux__p_wd3_slr_rlb">其中,<code class="ph codeph"><strong class="ph b">p</strong></code>表示主分区,<code class="ph codeph"><strong class="ph b">e</strong></code>表示扩展分区。本示例以创建主分区为例。</p></li>
<li class="li">
<p class="p" id="expansionlinux__d9e114"> 输入<code class="ph codeph"><strong class="ph b">p</strong></code>,按回车键,创建一个主分区。</p>
<img class="image" id="expansionlinux__d9e121" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171845-1398a75a98ad.png">
<p class="p" id="expansionlinux__d9e123">其中,<code class="ph codeph"><strong class="ph b">Partition
number</strong></code>表示主分区编号,范围是1~4。默认值为1。</p>
</li>
<li class="li">
<p class="p">输入数值并按下回车键,或者直接按下回车键系统代入默认值1。</p>
<img class="image" id="expansionlinux__image_r5l_5wl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-14f530839e4d.png">
<p class="p"> 其中,<code class="ph codeph"><strong class="ph b">First
sector</strong></code>表示初始扇区编号,范围是2048~20971519,默认值为2048。</p>
</li>
<li class="li">
<p class="p">输入数值并按下回车键,或者直接按下回车键系统代入默认值2048。</p>
<img class="image" id="expansionlinux__image_l2m_bxl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-1df4ffd69d05.png">
<p class="p">其中,<code class="ph codeph"><strong class="ph b">Last
sector</strong></code>表示最后一个扇区编号,范围是2048~62914559,默认为62914559。</p>
</li>
<li class="li">输入数值并按下回车键,或者直接按下回车键系统代入默认值62914559。<img class="image" id="expansionlinux__image_qq5_cxl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-1d8860bb9145.png"><p class="p">表示分区完成,为容量为30GB的数据盘创建了一个分区。</p></li>
<li class="li">输入<code class="ph codeph"><strong class="ph b">w</strong></code>并按下回车键,将分区结果写入分区表中。<img class="image" id="expansionlinux__image_w3f_fvj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171845-1b9f6d499626.png"><p class="p">如果出现上述信息,说明分区成功。</p><div class="note note note_note"><span class="note__title">说明:</span> 在上述操作过程中,如果操作有误,可以输入<code class="ph codeph"><strong class="ph b">q</strong></code>,推出分区操作过程,之前的分区结果不会保留。</div></li>
<li class="li">
<p class="p">执行 <code class="ph codeph"><strong class="ph b">fdisk -l</strong></code>命令查看新的分区。</p>
</li>
</ol>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">检查文件系统的正确性。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>e2fsck -f /dev/vdb1</code></pre>
<img class="image" id="expansionlinux__image_nkt_gxl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-158a0cd39ed4.png">
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">刷新文件系统大小。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>resize2fs /dev/vdb1</code></pre>
<img class="image" id="expansionlinux__image_k53_lxl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-17c0b39291b4.png">
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">将新分区挂载到/mnt目录下。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>mount /dev/vdb1 /mnt</code></pre>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">查看挂载结果。</span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>df -TH</code></pre>
<img class="image" id="expansionlinux__image_wdn_qxl_slb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20200707171847-1e7441ec9ff4.png">
<p class="p">从显示信息中,可以看出,当前挂载的分区大小为30G,挂载目录为/mnt。</p>
</div>
</li></ol></section>
提交成功!非常感谢您的反馈,我们会继续努力做到更好!