CentOS7 云服务器(ECS)挂载磁盘教程(简明完整梳理版)

本文详细介绍了如何在CentOS7云服务器上挂载新购买的磁盘,包括查看磁盘信息、分区、格式化、挂载及设置开机自动挂载的完整流程。

在我们部署云服务器的时候,通常情况都会把数据盘和系统分开,保证数据的安全,下面就来介绍一下如何操作。

在我们购买了云服务器之后,单独购买一个“云硬盘”,不同服务商的叫法可能不一样,但是本质是一样的,都是一个东西。购买了云硬盘后,有的服务器商会自动挂载到跟你购买的匹配的云服务器实例,有的需要去控制台操作,一般情况下同一个区,如华南,华东,同一个区都可以挂载。

因为每个服务商的挂载方式不尽相同,所以可以参照服务器商提供的文档操作,在此不做赘述,今天重点要讲的是挂载以后如何操作,使我们可以正常的使用。

一、流程梳理

在开始操作之前,我们简单把流程梳理一遍:

查看磁盘信息->磁盘分区->格式化->挂载分区

二、操作流程

1、首先我们需要在服务器上面查看磁盘信息、分区信息

可能用到的命令:

lsblk  #查看磁盘信息

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    253:0    0  40G  0 disk 
└─vda1 253:1    0  40G  0 part /
vdb    253:16   0  10G  0 disk 

lsblk -f  #查看磁盘信息简洁版

NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
vda                                                      
└─vda1 ext4         207b19eb-8170-4983-acb5-9098af381e72 /
vdb                                                      

fdisk -f #查看磁盘分区

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0002af06

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83886079    41942016   83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

2、磁盘分区\格式化

分区命令:fdisk /dev/vdb  参数说明:m 显示命令列表, n 新增分区, p 显示磁盘分区, d 删除分区, w写入并退出

[root@abc ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x96157659.

Command (m for help): n   #此处输入n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p #此处输入p
Partition number (1-4, default 1): #此处回车
First sector (2048-20971519, default 2048): #此处回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): #此处回车
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

分区成功.我们再输入lsblk命令,看到磁盘信息变化,多出一个vdb1分区:

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    253:0    0  40G  0 disk 
└─vda1 253:1    0  40G  0 part /
vdb    253:16   0  10G  0 disk 
└─vdb1 253:17   0  10G  0 part 

使用fdisk -l 命令查看分区信息:

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0002af06

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83886079    41942016   83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x96157659

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    20971519    10484736   83  Linux

在分区前和分区后分别使用lsblk 和fdisk命令查看对比前后变化。

然后格式化分区,使用ext4文件系统:

mkfs -t ext4 /dev/vdb1

挂载分区:

首先根据自己的需要,建立一个目录,也就是数据存放的地方,比如我这里使用:mkdir /data

建立好以后使用命令ls -l / 或者ll / 查看,已经建立好data目录。

挂载分区:

mount  /dev/vdb1 /data

查看磁盘使用情况:

df -h

#显示下面的信息即挂载成功
/dev/vdb1       9.8G   37M  9.2G   1% /data

永久挂载,避免重启后挂载点消失需要重新挂载:

vim /etc/fstab 追加内容并保存:/dev/vdb1 /data ext4 defaults 0 0

修改并保存etc/fstab文件后执行,mount -a 使操作生效,每次开机后都会自动挂载了。

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值