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

CentOS7.6挂载硬盘

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

主机哥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禁用ipv6方法

有些vps会同时存在ipv4和ipv6,如果我们不想用ipv6可以禁用ipv6地址。此方法在debian10和CentOS7下测试可用!用nano或vi命令编辑配置文件nano /etc/sysctl.conf在末尾添加如下两行:net.ipv6.conf.all.disable_ipv6...

消耗VPS流量命令

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

VPS基础信息及跑分测试脚本

上次主机哥分享过一款测评脚本里其实也带跑分测试,但是主机哥发现在某些VPS跑分测不出来,于是再分享一个脚本。wget --no-check-certificate https://github.com/teddysun/across/raw/master/unixbench.sh...

锐速/BBRPLUS/BBR2一键脚本:Linux-NetSpeed

锐速/BBRPLUS/BBR2一键脚本:Linux-NetSpeed

项目地址:https://github.com/younasiqw/Linux-NetSpeed-New 原项目地址:https://github.com/ylx2016/Linux-NetSpeed/ 原作者博客:https://blog.ylx.me/archives/783...

Debian9/10/11下磁盘挂载及开机启动设置教程

检查磁盘空间即剩余情况本文是在实际使用过程中真实操作,用于交流和学习1. 使用fdisk -l命令查看当前磁盘的大小,其中/dev/sda磁盘发现并未使用;使用时,需要切换到root权限   其中,系统默认磁盘是在/dev/sdb1上root@****# fdisk&n...

纯ipv6小机debian/ubuntu/centos及alpine系统的初始安装配置教程

纯ipv6小机debian/ubuntu/centos及alpine系统的初始安装配置教程

主机哥今天购买了一台纯IPV6的小机,自带系统是alpine而且没有其他诸如debian、centos之类的系统,由于之前一直没接触过这个系统,做个教程记录一下百度了一下才知道alpine是只用非常节省资源的Linux发行版,难怪我买的71MB内存2GB硬盘的LXC小机就只能用这个系统了首次开通机器...