【华为云-上云之路】CentOS7 云耀云服务器(HECS)挂载磁盘教程(挂载后处理)

网友投稿 564 2022-05-28

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

我们购买了云耀云服务器之后,通常会单独购买一个“云硬盘”,这里需要注意的是购买云硬盘的时候,需要跟你云服务器实例在同一区,保证能挂载到你的云服务器实例。购买了云硬盘后,需要去控制台操作挂载,一般情况下同一个区,如北京,上海,同一个区都可以挂载。

挂载成功如上图所示。

今天重点要讲的是挂载后处理,也就是如何操作,使我们可以正常的使用。

一、流程梳理

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

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

二、操作流程

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写入并退出

【华为云-上云之路】CentOS7 云耀云服务器(HECS)挂载磁盘教程(挂载后处理)

[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

使操作生效,这样每次开机后都会自动挂载了。

CentOS 弹性云服务器 ECS

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:磁盘调度算法课程设计(附源代码)
下一篇:內固——n*n的棋盘上最多可以放多少个马
相关文章