初始化数据盘

<p><span style="font-size:16px"><strong>前提条件</strong></span></p> <ul> <li>已经创建并登录基于Linux操作系统的云服务器ECS。</li> <li>已经将云硬盘作为数据盘挂在载上述实例中,且数据盘未初始化</li> </ul> <p><span style="font-size:16px"><strong>背景信息</strong></span></p> <p>本示例中,新挂载的数据盘为20GB,磁盘名称为/dev/vdb,创建一个单分区数据盘并格式化为ext4文件系统。使用的是I/O优化实例,操作系统为CentOS 7.6。</p> <p><span style="font-size:16px"><strong>操作步骤</strong></span></p> <ol> <li>远程连接云服务器ECS实例。</li> <li>查看当前系统下的磁盘情况。&nbsp; <pre> <code>ls /dev/vd*</code></pre> <img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112021-12c1146a983d.png" style="height:45px; width:345px" /> <p>其中,/dev/vda为系统盘,/dev/vdb为本次挂载的数据盘。</p> </li> <li>查看待初始化磁盘信息。 <pre> <code>fdisk -l /dev/vdb</code></pre> <img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112046-155b16609c23.png" style="height:100px; width:489px" /></li> <li>对数据盘进行分区操作。 <pre> <code>fdisk /dev/vdb</code></pre> <img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112100-19d3a4cb946a.png" style="height:175px; width:549px" /></li> </ol> <p>a) 输入<code><strong>n</strong></code>,按回车键,开始新建分区。&nbsp;</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112122-179784f697d9.png" style="height:234px; width:487px" /></p> <p>其中,<code><strong>p</strong></code>表示主分区,<code><strong>e</strong></code>表示扩展分区。本示例以创建主分区为例。</p> <p>b) 输入<code><strong>p</strong></code>,按回车键,创建一个主分区。</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112133-1f74be2f9005.png" style="height:57px; width:332px" /></p> <p>其中,<code><strong>Partition number</strong></code>表示主分区编号,范围是1~4。默认值为1。</p> <p>c) 输入数值并按下回车键,或者直接按下回车键系统代入默认值1。</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112151-1ce0558b9bb6.png" style="height:44px; width:403px" /></p> <p>其中,<code><strong>First sector</strong></code>表示初始扇区编号,范围是2048~20971519,默认值为2048。</p> <p>d) 输入数值并按下回车键,或者直接按下回车键系统代入默认值2048。</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112203-1bb84c249729.png" style="height:63px; width:571px" /></p> <p>其中,<code><strong>Last sector</strong></code>表示最后一个扇区编号,范围是2048~41943039,默认为41943039。</p> <p>e) 输入数值并按下回车键,或者直接按下回车键系统代入默认值41943039。</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112216-16345ede90b1.png" style="height:82px; width:439px" /></p> <p>表示分区完成,为容量为20GB的数据盘创建了一个分区。</p> <p>f) 输入<code><strong>p</strong></code>并按下回车键查看分区情况。</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112228-13913d449b73.png" style="height:241px; width:524px" /></p> <p>其中,/dev/vdb1为刚刚创建的新分区。</p> <p>g) 输入<code><strong>w</strong></code>并按下回车键,将分区结果写入分区表中。</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112241-14e2fd8a9bc1.png" style="height:116px; width:509px" /></p> <p>如果出现上述信息,说明分区成功。</p> <p>说明: 在上述操作过程中,如果操作有误,可以输入<code><strong>q</strong></code>,退出分区操作过程,之前的分区结果不会保留。</p> <p>h) 执行 <code><strong>fdisk -l</strong></code>命令查看新的分区。</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112258-11329d559aae.png" style="height:371px; width:598px" /></p> <p>&nbsp; &nbsp; 5. 在新建分区上创建一个文件系统。</p> <pre> <code>mkfs -t ext4 /dev/vdb1</code></pre> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112317-12d0b984911d.png" style="height:423px; width:800px" /></p> <p>&nbsp; &nbsp; 6. 备份 <code><strong>etc/fstab</strong></code>文件。</p> <pre> <code>cp /etc/fstab /etc/fstab.bak</code></pre> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112339-15a83b519761.png" style="height:81px; width:592px" /></p> <p>&nbsp; &nbsp; 7. 向 <code><strong>/etc/fstab</strong></code>写入新分区信息。说明:</p> <p>磁盘被手动挂载之后都必须把挂载信息写入/etc/fstab这个文件中,否则下次开机启动时仍然需要重新挂载。</p> <p>有两种方式可以实现挂载:</p> <ul> <li> <p>通过分区号挂载</p> <pre> <code>echo /dev/vdb1 /mnt ext4 defaults 0 0 &gt;&gt; /etc/fstab</code></pre> </li> <li> <p>通过UUID号挂载</p> <p>执行 <code><strong>blkid /dev/vdb1</strong></code>命令查看UUID信息。</p> <img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112357-1edb7311962e.png" style="height:50px; width:554px" /> <pre> <code>echo UUID=b7fc63da-be58-4aa5-bf6e-3651e3bb59bd /mnt ext4 defaults 0 0 &gt;&gt; /etc/fstab</code></pre> </li> </ul> <p>&nbsp; &nbsp;8. 查看 <code><strong>/etc/fstab</strong></code>文件中写入的分区信息。</p> <pre> <code>cat /etc/fstab</code></pre> <p>mount<br /> <img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112413-1733028d9b2f.png" style="height:226px; width:919px" /></p> <p>&nbsp; &nbsp; 9. 挂载文件系统。</p> <pre> <code>mount /dev/vdb1 /mnt</code></pre> <p>&nbsp; &nbsp;10. 查看磁盘空间使用情况。&nbsp;</p> <pre> <code>df -h</code></pre> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20202412112427-176a6c769931.png" style="height:199px; width:921px" /></p> <p>&nbsp;</p>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

工单支持

解决云产品相关技术问题