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

您所在的位置:网站首页 数据盘挂载data CentOS7 云服务器(ECS)挂载磁盘教程(简明完整梳理版)

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

2023-11-10 12:47| 来源: 网络整理| 查看: 265

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

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

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

一、流程梳理

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

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

二、操作流程

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 使操作生效,每次开机后都会自动挂载了。

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3