Initialize an EBS Disk (Linux)
<p class="shortdesc">When an EBS disk is mounted to the ECS as a data disk, it is offline by default. You
need to initialize the data
disk
to
format and partition the data disk, and create a file system so as to use it normally. </p>
<section class="section prereq" id="inilinux__prereq_i1g_2z3_rlb"><div class="tasklabel"><h2 class="doc-tairway">Before you begin</h2></div>
<ul class="ul" id="inilinux__ul_qnn_2z3_rlb">
<li class="li">You have created and logged in to the ECS of Linux operating system. </li>
<li class="li">You have mounted the EBS disk to the aforementioned ECS instance as a data disk, and not initialized the data disk. </li>
</ul>
</section>
<section class="section context" id="inilinux__context_a5d_fz3_rlb"><div class="tasklabel"><h2 class="doc-tairway">About this task</h2></div>
<p class="p">In this example, the capacity of the newly mounted data disk is 20 GB and the disk name is /dev/vdb. Create a single partition data disk and format it into an ext3 file system. Optimized instance I/O is used, and the operating system is CentOS 7.6. </p>
</section>
<section><div class="tasklabel"><h2 class="doc-tairway">Procedure</h2></div><ol class="ol steps"><li class="li step stepexpand">
<span class="ph cmd">Connect to the ECS instance remotely. </span>
</li><li class="li step stepexpand">
<span class="ph cmd">View the disk details under the current system. </span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>1s /dev/vd*</code></pre>
<img class="image" id="inilinux__image_idd_s5j_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171844-19539bdf9b1e.png">
<p class="p">In the information displayed, /dev/vda is the system disk, and /dev/vdb is the data disk mounted this time. </p>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">View the information of the disk to be initialized. </span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>fdisk -1 /dev/vdb</code></pre>
<img class="image" id="inilinux__image_bw3_t5j_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171844-10d8598b9146.png">
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">Partition the data disk. </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://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-11cc6f889e35.png">
<ol class="ol" type="a" id="inilinux__ol_rgs_nz3_rlb">
<li class="li">
<p class="p" id="inilinux__p_d4b_slr_rlb">Type in <code class="ph codeph"><strong class="ph b">n</strong></code> and press Enter to create a new partition. </p>
<img class="image" id="inilinux__image_zt5_x5j_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-1b3f6720986e.png">
<p class="p" id="inilinux__p_wd3_slr_rlb">In the information displayed, <code class="ph codeph"><strong class="ph b">p</strong></code> represents a primary partition, and <code class="ph codeph"><strong class="ph b">e</strong></code> represents an extended partition. In this example, a primary partition will be created. </p>
</li>
<li class="li" id="inilinux__li_lxm_xwl_slb">
<p class="p" id="inilinux__p_fsc_tlr_rlb">Type in <code class="ph codeph"><strong class="ph b">p</strong></code> and press Enter to create a primary partition. </p>
<img class="image" id="inilinux__image_c5m_z5j_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-1f0cc00c925b.png">
<p class="p" id="inilinux__p_f4j_tlr_rlb">In the information displayed, <code class="ph codeph"><strong class="ph b">Partition number</strong></code> represents the serial number of the primary partition. The value range is from 1 to 4. The default value is 1. </p>
</li>
<li class="li">
<p class="p" id="inilinux__p_ek4_tlr_rlb">Type in the number and press Enter. Or press Enter directly and the system will use the default value 1. </p>
<img class="image" id="inilinux__image_d4l_1vj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-1b0b37529b89.png">
<p class="p" id="inilinux__p_cx5_tlr_rlb">In the information displayed, <code class="ph codeph"><strong class="ph b">First sector</strong></code> represents the serial number of the first sector. The value range is from 2048 to 20971519, and the default value is 2048.</p>
</li>
<li class="li">
<p class="p" id="inilinux__p_njd_5lr_rlb">Type in the number and press Enter. Or press Enter directly and the system will use the default value 2048.</p>
<img class="image" id="inilinux__image_ulr_bvj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-1f4197139d8e.png">
<p class="p" id="inilinux__p_nc3_5lr_rlb">In the information displayed, <code class="ph codeph"><strong class="ph b">Last sector</strong></code> represents the serial number of the last sector. The value range is from 2048 to 41943039, and the default value is 41943039. </p>
</li>
<li class="li">
<p class="p" id="inilinux__p_nbn_5lr_rlb">Type in the number and press Enter. Or press Enter directly and the system will use the default value 41943039.</p>
<img class="image" id="inilinux__image_xxt_cvj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-1cb70c349e33.png">
<p class="p" id="inilinux__p_ugs_5lr_rlb">A primary partition has been created for a data disk of 20 GB. </p>
</li>
<li class="li">
<p class="p" id="inilinux__p_q4w_5lr_rlb">Type in <code class="ph codeph"><strong class="ph b">p</strong></code> and press Enter to view details of the partition.</p>
<img class="image" id="inilinux__image_d13_2vj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-1269e25b921a.png">
<p class="p" id="inilinux__p_okc_vlr_rlb">In the information displayed, /dev/vdb1 is the newly created partition. </p>
</li>
<li class="li">
<p class="p" id="inilinux__p_fdh_vlr_rlb">Type in <code class="ph codeph"><strong class="ph b">w</strong></code> and press Enter to write the result to the partition table. </p>
<img class="image" id="inilinux__image_w3f_fvj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-149b91469556.png">
<p class="p" id="inilinux__p_dby_vlr_rlb">The above information indicates that the partition is successfully created. </p>
<div class="note note note_note" id="inilinux__note_qmd_wlr_rlb"><span class="note__title">Note:</span> In case that you make a mistake in the process, you can exit by entering <code class="ph codeph"><strong class="ph b">q</strong></code>, and the partition created before will be discarded. </div>
</li>
<li class="li">
<p class="p" id="inilinux__p_fjk_wlr_rlb">Run the command <code class="ph codeph"><strong class="ph b">fdisk -l</strong></code> to view the new partition. </p>
<img class="image" id="inilinux__image_yws_hvj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-1cbd71449bc2.png">
</li>
</ol>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">Create a file system on the newly created partition. </span>
<div class="itemgroup info">
<pre class="pre codeblock"><code>mkfs.ext3 /dev/vdb1</code></pre>
<img class="image" id="inilinux__image_z3y_3vj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-199f84c19ee8.png">
</div>
</li><li class="li step stepexpand"><strong>Optional: </strong>
<span class="ph cmd">Back up the file <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>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">Write information of the new partition to <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">Note:</span>
<p class="p">Information of the manually mounted disk must be written to the file /etc/fstab. Otherwise, if the server is restarted, you need to remount the disk. </p>
</div>
<p class="p">There are two ways for mounting: </p>
<ul class="ul" id="inilinux__ul_bkz_k1j_rlb">
<li class="li">
<p class="p">Mount the disk using the partition number. </p>
<pre class="pre codeblock"><code>echo /dev/vdb1 /mnt ext3 defaults 0 0 >> /etc/fstab</code></pre>
</li>
<li class="li">
<p class="p">Mount the disk using UUID.</p>
<p class="p">Run the command <code class="ph codeph"><strong class="ph b">blkid /dev/vdb1</strong></code> to view the information of UUID. </p>
<img class="image" id="inilinux__image_x3f_4vj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-10babbae9cf1.png">
<pre class="pre codeblock"><code>echo UUID=b7fc63da-be58-4aa5-bf6e-3651e3bb59bd /mnt ext3 defaults 0 0 >> /etc/fstab</code></pre>
</li>
</ul>
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">View the partition information written to the file <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>
<img class="image" id="inilinux__image_ucc_mvj_rlb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-1a332acd9049.png">
</div>
</li><li class="li step stepexpand">
<span class="ph cmd">Mount the file system. </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">View the disk space usage. </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://obs-cn-shanghai.yun.pingan.com/pcp-portal/20200707171845-12ef7ce2976e.png">
</div>
</li></ol></section>
Did the above content solve your problem?
Yes
No
Submitted successfully! Thank you for your feedback, we will try our best to do better and better!