初始化云硬盘(Linux系统)

<p class="shortdesc">当云硬盘作为数据盘挂载到云服务器ECS上后,默认为脱机状态,您需要将数据盘进行格式化、分区及创建文件系统等初始化操作后,才能正常使用数据盘。</p> <section class="section prereq" id="inilinux__prereq_i1g_2z3_rlb"><div class="tasklabel"><h2 class="doc-tairway">前提条件</h2></div> <ul class="ul" id="inilinux__ul_qnn_2z3_rlb"> <li class="li">已经创建并登录基于Linux操作系统的云服务器ECS。</li> <li class="li">已经将云硬盘作为数据盘挂在载上述实例中,且数据盘未初始化。</li> </ul> </section> <section class="section context" id="inilinux__context_a5d_fz3_rlb"><div class="tasklabel"><h2 class="doc-tairway">背景信息</h2></div> <p class="p">本示例中,新挂载的数据盘为20GB,磁盘名称为/dev/vdb,创建一个单分区数据盘并格式化为ext4文件系统。使用的是I/O优化实例,操作系统为CentOS 7.6。</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>ls /dev/vd*</code></pre> <img class="image" id="inilinux__image_idd_s5j_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173409-14d5d0be9f76.png"> <p class="p">其中,/dev/vda为系统盘,/dev/vdb为本次挂载的数据盘。</p> </div> </li><li class="li step stepexpand"> <span class="ph cmd">查看待初始化磁盘信息。</span> <div class="itemgroup info"> <pre class="pre codeblock"><code>fdisk -l /dev/vdb</code></pre> <img class="image" id="inilinux__image_bw3_t5j_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173409-1d03e5e89f92.png"> </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="inilinux__image_s1f_55j_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173409-122383539de7.png"> <ol class="ol" type="a" id="inilinux__ol_rgs_nz3_rlb"> <li class="li"> <p class="p" id="inilinux__p_d4b_slr_rlb">输入<code class="ph codeph"><strong class="ph b">n</strong></code>,按回车键,开始新建分区。</p> <img class="image" id="inilinux__image_zt5_x5j_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-1c50702998c2.png"> <p class="p" id="inilinux__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" id="inilinux__li_lxm_xwl_slb"> <p class="p" id="inilinux__p_fsc_tlr_rlb"> 输入<code class="ph codeph"><strong class="ph b">p</strong></code>,按回车键,创建一个主分区。</p> <img class="image" id="inilinux__image_c5m_z5j_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-10678c88950f.png"> <p class="p" id="inilinux__p_f4j_tlr_rlb">其中,<code class="ph codeph"><strong class="ph b">Partition number</strong></code>表示主分区编号,范围是1~4。默认值为1。</p> </li> <li class="li"> <p class="p" id="inilinux__p_ek4_tlr_rlb">输入数值并按下回车键,或者直接按下回车键系统代入默认值1。</p> <img class="image" id="inilinux__image_d4l_1vj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-11355b619536.png"> <p class="p" id="inilinux__p_cx5_tlr_rlb"> 其中,<code class="ph codeph"><strong class="ph b">First sector</strong></code>表示初始扇区编号,范围是2048~20971519,默认值为2048。</p> </li> <li class="li"> <p class="p" id="inilinux__p_njd_5lr_rlb">输入数值并按下回车键,或者直接按下回车键系统代入默认值2048。</p> <img class="image" id="inilinux__image_ulr_bvj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-1bdaab7f954b.png"> <p class="p" id="inilinux__p_nc3_5lr_rlb">其中,<code class="ph codeph"><strong class="ph b">Last sector</strong></code>表示最后一个扇区编号,范围是2048~41943039,默认为41943039。</p> </li> <li class="li"> <p class="p" id="inilinux__p_nbn_5lr_rlb">输入数值并按下回车键,或者直接按下回车键系统代入默认值41943039。</p> <img class="image" id="inilinux__image_xxt_cvj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-1f5aacb79663.png"> <p class="p" id="inilinux__p_ugs_5lr_rlb">表示分区完成,为容量为20GB的数据盘创建了一个分区。</p> </li> <li class="li"> <p class="p" id="inilinux__p_q4w_5lr_rlb">输入<code class="ph codeph"><strong class="ph b">p</strong></code>并按下回车键查看分区情况。</p> <img class="image" id="inilinux__image_d13_2vj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-19f81ecd964a.png"> <p class="p" id="inilinux__p_okc_vlr_rlb">其中,/dev/vdb1为刚刚创建的新分区。</p> </li> <li class="li"> <p class="p" id="inilinux__p_fdh_vlr_rlb"> 输入<code class="ph codeph"><strong class="ph b">w</strong></code>并按下回车键,将分区结果写入分区表中。</p> <img class="image" id="inilinux__image_w3f_fvj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-1793bb8c91f8.png"> <p class="p" id="inilinux__p_dby_vlr_rlb">如果出现上述信息,说明分区成功。</p> <div class="note note note_note" id="inilinux__note_qmd_wlr_rlb"><span class="note__title">说明:</span> 在上述操作过程中,如果操作有误,可以输入<code class="ph codeph"><strong class="ph b">q</strong></code>,退出分区操作过程,之前的分区结果不会保留。</div> </li> <li class="li"> <p class="p" id="inilinux__p_fjk_wlr_rlb">执行 <code class="ph codeph"><strong class="ph b">fdisk -l</strong></code>命令查看新的分区。</p> <img class="image" id="inilinux__image_yws_hvj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-12acd0cc9659.png"> </li> </ol> </div> </li><li class="li step stepexpand"> <span class="ph cmd">在新建分区上创建一个文件系统。</span> <div class="itemgroup info"> <pre class="pre codeblock"><code>mkfs -t ext4 /dev/vdb1</code></pre> <img class="image" id="inilinux__image_edl_xvw_vmb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-1a84c6ce9f95.png" width="800"> </div> </li><li class="li step stepexpand"> <span class="ph cmd">备份 <code class="ph codeph"><strong class="ph b">etc/fstab</strong></code>文件。</span> <div class="itemgroup info"> <pre class="pre codeblock"><code>cp /etc/fstab /etc/fstab.bak</code></pre> <img class="image" id="inilinux__image_knf_bww_vmb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-115ed1e69b1c.png"> </div> </li><li class="li step stepexpand"> <span class="ph cmd">向 <code class="ph codeph"><strong class="ph b">/etc/fstab</strong></code>写入新分区信息。</span> <div class="itemgroup info"> <div class="note note note_note"><span class="note__title">说明:</span> <p class="p">磁盘被手动挂载之后都必须把挂载信息写入/etc/fstab这个文件中,否则下次开机启动时仍然需要重新挂载。</p> </div> <p class="p">有两种方式可以实现挂载:</p> <ul class="ul" id="inilinux__ul_bkz_k1j_rlb"> <li class="li"> <p class="p">通过分区号挂载</p> <pre class="pre codeblock"><code>echo /dev/vdb1 /mnt ext4 defaults 0 0 >> /etc/fstab</code></pre> </li> <li class="li"> <p class="p">通过UUID号挂载</p> <p class="p">执行 <code class="ph codeph"><strong class="ph b">blkid /dev/vdb1</strong></code>命令查看UUID信息。</p> <img class="image" id="inilinux__image_x3f_4vj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-12d660b591bd.png"> <pre class="pre codeblock"><code>echo UUID=b7fc63da-be58-4aa5-bf6e-3651e3bb59bd /mnt ext4 defaults 0 0 >> /etc/fstab</code></pre> </li> </ul> </div> </li><li class="li step stepexpand"> <span class="ph cmd"> 查看 <code class="ph codeph"><strong class="ph b">/etc/fstab</strong></code>文件中写入的分区信息。</span> <div class="itemgroup info"><pre class="pre codeblock"><code>cat /etc/fstab</code></pre>mount<img class="image" id="inilinux__image_ucc_mvj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-1d9cdf3090b7.png"></div> </li><li class="li step stepexpand"> <span class="ph cmd">挂载文件系统。</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 -h</code></pre> <img class="image" id="inilinux__image_f1w_rwj_rlb" src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20203108173410-1acc0f179eb3.png"> </div> </li></ol></section>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

工单支持

解决云产品相关技术问题