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