登录
  • 欢迎来到免费部落,在这里你可以看到各类实用的资源

linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘

VPS技巧 admin 202次浏览 0个评论

以下操作均在root环境下运行。

1.查看硬盘

<span class="com"># fdisk -l</span>

发现硬盘为/dev/sdb 大小4T

2.如果此硬盘以前有过分区,则先对磁盘格式化:

<span class="com"># mkfs -t ext4 /dev/sdb</span>

此命令会对整个磁盘格式化

3.对新磁盘进行分区,由于fdisk仅支持2T以内磁盘分区,但该磁盘大于2T,所以使用parted进行GPT格式分区:

linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘
<span class="com"># parted /dev/sdb</span>

<span class="pun">(</span><span class="pln">parted</span><span class="pun">)</span><span class="pln"> help</span><span class="pun">                </span><span class="com"># 可以查看帮助信息</span>

<span class="pun">(</span><span class="pln">parted</span><span class="pun">)</span><span class="pln"> mklabel gpt</span><span class="pun">              </span><span class="com"># 执行命令mklabel gpt,把sdb改成gpt大分区格式</span>

<span class="typ">Warning</span><span class="pun">:</span> <span class="typ">The</span><span class="pln"> existing disk label on </span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdb will be destroyed </span><span class="kwd">and</span><span class="pln"> all data on </span><span class="kwd">this</span><span class="pln"> disk will be lost</span><span class="pun">.</span> <span class="typ">Do</span><span class="pln"> you

want to </span><span class="kwd">continue</span><span class="pun">?</span>

<span class="typ">Yes</span><span class="pun">/</span><span class="typ">No</span><span class="pun">?</span><span class="pln"> yes

</span><span class="pun">(</span><span class="pln">parted</span><span class="pun">)</span><span class="pln"> mkpart primary </span><span class="lit">0</span> <span class="lit">4001GB</span><span class="pun">      </span><span class="com"># 创建分区</span>

<span class="typ">Warning</span><span class="pun">:</span> <span class="typ">The</span><span class="pln"> resulting partition </span><span class="kwd">is</span> <span class="kwd">not</span><span class="pln"> properly aligned </span><span class="kwd">for</span><span class="pln"> best performance</span><span class="pun">.</span>

<span class="typ">Ignore</span><span class="pun">/</span><span class="typ">Cancel</span><span class="pun">?</span><span class="pln"> cancel</span><span class="pun">            </span><span class="com"># 注意,此处提示为磁盘为对齐,会影响性能,所以在此处要进行对齐</span>
linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘

4.查看磁盘参数:

linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘
<span class="com"># cat /sys/block/sdb/queue/optimal_io_size</span>

<span class="lit">0</span>

<span class="com"># cat /sys/block/sdb/queue/minimum_io_size</span>

<span class="lit">4096</span>

<span class="com"># cat /sys/block/sdb/alignment_offset</span>

<span class="lit">0</span>

<span class="com"># cat /sys/block/sdb/queue/physical_block_size</span>

<span class="lit">4096</span>
linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘

如果optimal_io_size不为0,暂定是1048576,则可以用optimal_io_size的值加上alignment_offset的值,

然后除以physical_block_size的值,就是起始扇区的位置了,如上面的例子中,可以用这个公式算出来起始扇区的设定值:

<span class="pun">(</span><span class="lit">1048576</span> <span class="pun">+</span> <span class="lit">0</span><span class="pun">)</span> <span class="pun">/</span> <span class="lit">512</span> <span class="pun">=</span> <span class="lit">2048</span>

如果optimal_io_size为0,那么我们最好直接使用起始扇区的默认值2048。

5. 最后在分区的时候使用以下的命令进行分区就可以了,不会报warning:

linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘
<span class="pun">(</span><span class="pln">parted</span><span class="pun">)</span><span class="pln"> mkpart primary </span><span class="lit">2048s</span> <span class="lit">100</span><span class="pun">%</span>

<span class="pun">(</span><span class="pln">parted</span><span class="pun">)</span> <span class="kwd">print</span>

<span class="typ">Model</span><span class="pun">:</span><span class="pln"> ATA WDC WD40EFRX</span><span class="pun">-</span><span class="lit">68N</span> <span class="pun">(</span><span class="pln">scsi</span><span class="pun">)</span>
<span class="typ">Disk</span> <span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdb</span><span class="pun">:</span> <span class="lit">4001GB</span>
<span class="typ">Sector</span><span class="pln"> size </span><span class="pun">(</span><span class="pln">logical</span><span class="pun">/</span><span class="pln">physical</span><span class="pun">):</span> <span class="lit">512B</span><span class="pun">/</span><span class="lit">4096B</span>
<span class="typ">Partition</span> <span class="typ">Table</span><span class="pun">:</span><span class="pln"> gpt
</span><span class="typ">Disk</span> <span class="typ">Flags</span><span class="pun">:</span>

<span class="typ">Number</span>  <span class="typ">Start</span>   <span class="typ">End</span>     <span class="typ">Size</span>    <span class="typ">File</span><span class="pln"> system  </span><span class="typ">Name</span>     <span class="typ">Flags</span>
 <span class="lit">1</span>      <span class="lit">1049kB</span>  <span class="lit">4001GB</span>  <span class="lit">4001GB</span><span class="pln">               primary

</span><span class="pun">(</span><span class="pln">parted</span><span class="pun">)</span><span class="pln"> align</span><span class="pun">-</span><span class="pln">check optimal </span><span class="lit">1</span><span class="pun">                 </span><span class="com"># 此命令会检查对齐与否</span>

<span class="lit">1</span><span class="pln"> aligned

</span><span class="pun">(</span><span class="pln">parted</span><span class="pun">)</span><span class="pln"> quit</span>
linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘

6.查看磁盘情况:

<span class="com"># fdisk -l</span>

7.再次格式化磁盘:

<span class="com"># mkfs.ext4 -F /dev/sdb</span>

8.挂载新磁盘到/home

linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘
<span class="com"># cd /mnt</span>

<span class="com"># mkdir home</span>

<span class="com"># mount /dev/sdb /mnt/home</span>

<span class="com"># cp -a /home/* home</span>

<span class="com"># rm -rf /home/*</span>

<span class="com"># umount /dev/sdb</span>
linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘

9.设置自动挂载/home

<span class="com"># vim /etc/fstab</span>

在最后一行加:

<span class="str">/dev/</span><span class="pln">sdb                </span><span class="pun">/</span><span class="pln">home                   ext4    defaults        </span><span class="lit">1</span> <span class="lit">2</span>

# 保存退出

<span class="pun">:</span><span class="pln">wq</span>

10. 查看是否挂载/home

linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘
<span class="com"># df -h</span>

<span class="typ">Filesystem</span>               <span class="typ">Size</span>  <span class="typ">Used</span> <span class="typ">Avail</span> <span class="typ">Use</span><span class="pun">%</span> <span class="typ">Mounted</span><span class="pln"> on
</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">mapper</span><span class="pun">/</span><span class="pln">centos</span><span class="pun">-</span><span class="pln">root  </span><span class="lit">100G</span>  <span class="lit">5.4G</span>   <span class="lit">95G</span>   <span class="lit">6</span><span class="pun">%</span> <span class="str">/
devtmpfs                  32G     0   32G   0% /</span><span class="pln">dev
tmpfs                     </span><span class="lit">32G</span>   <span class="lit">29M</span>   <span class="lit">32G</span>   <span class="lit">1</span><span class="pun">%</span> <span class="str">/dev/</span><span class="pln">shm
tmpfs                     </span><span class="lit">32G</span>   <span class="lit">12M</span>   <span class="lit">32G</span>   <span class="lit">1</span><span class="pun">%</span> <span class="str">/run
tmpfs                     32G     0   32G   0% /</span><span class="pln">sys</span><span class="pun">/</span><span class="pln">fs</span><span class="pun">/</span><span class="pln">cgroup
</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda2               </span><span class="lit">1014M</span>  <span class="lit">221M</span>  <span class="lit">794M</span>  <span class="lit">22</span><span class="pun">%</span> <span class="str">/boot
/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda1                </span><span class="lit">200M</span>  <span class="lit">9.8M</span>  <span class="lit">191M</span>   <span class="lit">5</span><span class="pun">%</span> <span class="str">/boot/</span><span class="pln">efi
</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">mapper</span><span class="pun">/</span><span class="pln">centos</span><span class="pun">-</span><span class="pln">home   </span><span class="lit">74G</span>   <span class="lit">52M</span>   <span class="lit">74G</span>   <span class="lit">1</span><span class="pun">%</span> <span class="str">/home
tmpfs                    6.3G   56K  6.3G   1% /</span><span class="pln">run</span><span class="pun">/</span><span class="pln">user</span><span class="pun">/</span><span class="lit">1000</span>
linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘

未挂载!

11. 挂载fstab中未挂载的磁盘

<span class="com"># mount -a</span>

12. 再次查看是否挂载/home

linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘
<span class="com"># df -h</span>

<span class="typ">Filesystem</span>               <span class="typ">Size</span>  <span class="typ">Used</span> <span class="typ">Avail</span> <span class="typ">Use</span><span class="pun">%</span> <span class="typ">Mounted</span><span class="pln"> on
</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">mapper</span><span class="pun">/</span><span class="pln">centos</span><span class="pun">-</span><span class="pln">root  </span><span class="lit">100G</span>  <span class="lit">5.4G</span>   <span class="lit">95G</span>   <span class="lit">6</span><span class="pun">%</span> <span class="str">/
devtmpfs                  32G     0   32G   0% /</span><span class="pln">dev
tmpfs                     </span><span class="lit">32G</span>   <span class="lit">29M</span>   <span class="lit">32G</span>   <span class="lit">1</span><span class="pun">%</span> <span class="str">/dev/</span><span class="pln">shm
tmpfs                     </span><span class="lit">32G</span>   <span class="lit">12M</span>   <span class="lit">32G</span>   <span class="lit">1</span><span class="pun">%</span> <span class="str">/run
tmpfs                     32G     0   32G   0% /</span><span class="pln">sys</span><span class="pun">/</span><span class="pln">fs</span><span class="pun">/</span><span class="pln">cgroup
</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda2               </span><span class="lit">1014M</span>  <span class="lit">221M</span>  <span class="lit">794M</span>  <span class="lit">22</span><span class="pun">%</span> <span class="str">/boot
/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda1                </span><span class="lit">200M</span>  <span class="lit">9.8M</span>  <span class="lit">191M</span>   <span class="lit">5</span><span class="pun">%</span> <span class="str">/boot/</span><span class="pln">efi
</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdb                 </span><span class="lit">3.6T</span>  <span class="lit">140M</span>  <span class="lit">3.4T</span>   <span class="lit">1</span><span class="pun">%</span> <span class="str">/home
tmpfs                    6.3G   56K  6.3G   1% /</span><span class="pln">run</span><span class="pun">/</span><span class="pln">user</span><span class="pun">/</span><span class="lit">1000</span>
linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘

挂载成功!


免费部落 , 版权所有丨如未注明 , 均为原创丨 转载请注明linux新手教程:centos7挂载新加4T硬盘到/home目录,让centos支持大硬盘
喜欢 (0)

您必须 登录 才能发表评论!