Linux 新增磁盤掛載與初始化


In this article, I will take you through the steps by which we can add the new raw hard disk to an existing Linux server such as RHEL/CentOS or Debian/Ubuntu.

本次需要在linux上面掛載新的硬盤並格式化,這次配置用到了 fdisk utility.

I have added a hard disk of 20GB capacity to be mounted as a /data partition.

我新增一塊20GB的硬盤需要掛在到 /data 路徑下:

fdisk is a command line utility to view and manage hard disks and partitions on Linux systems.

查看現有系統中成功添加的硬盤指令如下:

# fdisk -l

查詢效果如下:

加載硬盤前

然后將一塊20G的硬盤加載后:

加載硬盤后

New disk added is shown as /dev/xvdc. If we are adding physical disk it will show as /dev/sda based of the disk type. Here I used a virtual disk.

現在可以看到新增了一個 /dev/xvdc 的硬盤。如果我們增加了一塊物理硬盤,將會再/dev/sda中出現新的盤。這次我用了一個虛擬磁盤。

To partition a particular hard disk, for example /dev/xvdc.   

對這塊硬盤進行分區操作,具體指令如下:

# fdisk /dev/xvdc

Commonly used fdisk commands.  常用指令

n – Create partition           新建分區
p – print partition table      
d – delete a partition         刪除分區
q – exit without saving the changes             退出
wwrite the changes and exit.                    保存並退出

Here since we are creating a partition use n option.

新建分區

Create either primary/extended partitions. By default we can have upto 4 primary partitions.

創建主/拓展分區。一般默認能存在4個主分區

添加一個主分區

Give the partition number as desired. Recommended to go for the default value 1.

Give the value of the first sector. If it is a new disk, always select default value. If you are creating a second partition on the same disk, we need to add 1 to the last sector of the previous partition.

Give the value of the last sector or the partition size. Always recommended to give the size of the partition. Always prefix + to avoid value out of range error.

Save the changes and exit.

Now format the disk with mkfs command.

接下來格式化該硬盤分區

# mkfs.ext4 /dev/xvdc1
或者  # mkfs -t ext4 /dev/xvdc1



Once formatting has been completed, now mount the partition as shown below.
當格式化完成后,將其mount 到/data 路徑下即可
# mount /dev/xvdc1 /data
Make an entry in /etc/fstab file for permanent mount at boot time.
接下來需要添加一個自啟動識別該硬盤分區的設置(自動掛載)

首先,查看磁盤分區的UUID
$ sudo blkid
/dev/sda1: UUID="8048997a-16c9-447b-a209-82e4d380326e" TYPE="ext4"
/dev/sda5: UUID="0c5f073a-ad3f-414f-85c2-4af83f6a437f" TYPE="swap"
/dev/sdb1: UUID="11263962-9715-473f-9421-0b604e895aaa" TYPE="ext4"
/dev/xvdc1: UUID="12262346-1515-9458-1245-0b604e895bbb" TYPE="ext4"
然后,配置開機自動掛載:
vim /etc/fstab
添加
UUID=12262346-1515-9458-1245-0b604e895bbb     /data    ext4     defaults     0   1

格式如下:<fs spec>   <fs file>   <fs vfstype>   <fs mntops>   <fs freq>   <fs passno>

修改完成后保存,並運行
mount -a

驗證配置是否正確,配置不正確可能會導致系統無法正常啟動。

 
 

 





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM