当前位置:首页 > VPS教程 > 正文内容

CentOS7.6挂载硬盘

23vps2年前 (2022-10-22)VPS教程424

主机哥VPS自带一个硬盘没有被挂载,需要手工来挂载,下面方法适用于CentOS7.6系统。

查看已挂载的硬盘

阿里云限量代金券 | 此广告位出租25元/月
# 使用 fdisk -l 命令查看所有磁盘信息
[root@ecs-Up5 ~]# fdisk -l

Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0000425c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/vdb: 85.9 GB, 85899345920 bytes, 167772160 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 /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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#显示参数说明/dev/vda 是正常使用的硬盘
/dev/vdb 是未被使用的硬盘

对未被使用的硬盘进行分区

#使用 fdisk /dev/vdb 命令对未使用的硬盘进行分区
[root@ecs-Up5 ~]# 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 0xc9cfb4bc.

Command (m for help): n    # 表示创建分区Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p    # 表示创建主分区Partition number (1-4, default 1): 1    # 表示创建1号分区First sector (2048-167772159, default 2048):     # 表示起始分区,默认Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-167772159, default 167772159):     # 表示结束分区,默认是全部容量Using default value 167772159
Partition 1 of type Linux and of size 80 GiB is setCommand (m for help): w    # 表示写入分区,生效The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.
# 使用 fdisk -l 命令查看分区结果
[root@ecs-Up5 ~]# fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0000425c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/vdb: 85.9 GB, 85899345920 bytes, 167772160 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: 0xc9cfb4bc

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   167772159    83885056   83  Linux

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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#显示参数说明成功创建 /dev/vdb1

格式化分区

#使用 mkfs.xfs -f /dev/vdb1 命令进行格式化分区
[root@ecs-Up5 ~]# mkfs.xfs -f /dev/vdb1(这里创建的是xfs系统,也可以输入命令:#mkfs.ext4 /dev/vdb1 创建ext4文件系统)
meta-data=/dev/vdb1              isize=512    agcount=4, agsize=5242816 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=20971264, imaxpct=25         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=10239, version=2         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

挂载分区

#使用mount -t xfs /dev/vdb1 /data命令进行磁盘挂载。把新加入的磁盘分区挂载到/DATA目录下
#在根目录下创建文件夹”data“
[root@ecs-Up5 ~]# mkdir /data
[root@ecs-Up5 ~]# mount -t xfs /dev/vdb1 /data
[root@ecs-Up5 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  1.9G   16G  12% /
devtmpfs                 909M     0  909M   0% /dev
tmpfs                    920M   12K  920M   1% /dev/shm
tmpfs                    920M  8.6M  912M   1% /run
tmpfs                    920M     0  920M   0% /sys/fs/cgroup
/dev/vda1               1014M  143M  872M  15% /boot
tmpfs                    184M     0  184M   0% /run/user/0
/dev/vdb1                 80G   33M   80G   1% /data

开机自动挂载分区

#编辑 /etc/fstab 加入开机自动挂载语句
[root@ecs-Up5 ~]# vi /etc/fstab
/dev/vdb1 /data                                 xfs     defaults        0 0

(如果是ext4格式请将xfs替换掉)

将上面最后一行代码加到fstab文件末尾就可以了


如果想格式化已有文件系统请先卸载分区,否则格式化时会提示:mkfs.xfs: /dev/vdb1 contains a mounted filesystem

umount /dev/vdb1

格式化分区

mkfs.xfs -f /dev/vdb1

重新挂载分区

mount -t xfs /dev/vdb1 /data


本网站由提供服务

扫描二维码推送至手机访问。

版权声明:本文由主机测评网发布,如需转载请注明出处。

本文链接:https://23vps.com/post/55.html

标签: linux技巧
分享给朋友:

“CentOS7.6挂载硬盘” 的相关文章

linux vps回程路由检测脚本

linux vps回程路由检测脚本

不知道自己的vps回程网络怎么看可以用这个脚本:curl https://raw.githubusercontent.com/zhucaidan/mtr_trace/main/mtr_trace.sh|bash项目地址:https://github.com/zhucaidan/mtr_tr...

测试linux vps基础信息io和网络:SuperBench

测试linux vps基础信息io和网络:SuperBench

可测试linux vps基础信息io及网络,第一次运行需等待半分钟左右wget -qO- --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/superbenc...

消耗VPS流量命令

主机哥闲着无聊写了一个流量消耗命令,运行这个命令后可以把VPS流量全部都消耗光!这样不仅仅是无聊,而是一定程度上可以测试出主机商是否能否长期跑带宽,因为有些主机商会在你带宽持续占用一定时间后限制你的速度。此脚本适合所有linux vps系统使用方法:安装screen命令apt-get is...

linux vps连接工具putty

linux vps连接工具putty

putty 简介简单的说 putty 是一个开源程序,用来连接服务器。最早的时候,仅仅在window系统上可以使用,后来在其他的系统上也可以运行,比如 类unix, mac 。putty 不仅仅是一个软件而是一个软件集(文章最后会列出这个软件集),其中最常用的是 putty ,用来连接 linxu...

ping.pe替代品ping.sx

ping.pe替代品ping.sx

近日主机哥发现用于检测小鸡网络的ping.pe已经没有国内检测节点了(只剩一个腾讯云节点了),对于检测国内连通性来说已经不够用了,有个替代网站就是https://ping.sx/网站截图:...