文章目录

  • 1、前言
  • 2、步骤
  • 3、分多个主区

1、前言

新买的服务器发现看不到数据盘,查了文档发现原来是没有挂载。

2、步骤

检查磁盘挂载

[root@AlexWong /]# fdisk -l
Disk /dev/vda: 40 GiB, 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
Disklabel type: dos
Disk identifier: 0x5d6e4b6bDevice     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886079 83884032  40G 83 LinuxDisk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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
[root@AlexWong /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  8.5M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1        40G  2.3G   35G   7% /
tmpfs           374M     0  374M   0% /run/user/0

Disk /dev/vda:磁盘1,已挂载

Disk /dev/vdb:磁盘2,未挂载

磁盘分区

100GB数据硬盘待分区

fdisk /dev/vdb
参数说明:
n:新建分区p: 主分区e: 扩展分区
上面可以默认回车,最后输入w (write)将操作写入磁盘按顺序输入`n、p、1、w`
[root@AlexWong /]# fdisk /dev/vdbWelcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xdb040091.Command (m for help): mHelp:DOS (MBR)a   toggle a bootable flagb   edit nested BSD disklabelc   toggle the dos compatibility flagGenericd   delete a partitionF   list free unpartitioned spacel   list known partition typesn   add a new partitionp   print the partition tablet   change a partition typev   verify the partition tablei   print information about a partitionMiscm   print this menuu   change display/entry unitsx   extra functionality (experts only)ScriptI   load disk layout from sfdisk script fileO   dump disk layout to sfdisk script fileSave & Exitw   write table to disk and exitq   quit without saving changesCreate a new labelg   create a new empty GPT partition tableG   create a new empty SGI (IRIX) partition tableo   create a new empty DOS partition tables   create a new empty Sun partition tableCommand (m for help): n
Partition typep   primary (0 primary, 0 extended, 4 free)e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199):Created a new partition 1 of type 'Linux' and of size 100 GiB.Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

格式化刚划分的磁盘,格式成ext4格式

[root@AlexWong /]# mkfs.ext4 /dev/vdb

挂载文件目录

# 新建文件夹
[root@AlexWong /]# mkdir data
# 把挂载的分区写入/etc/fstab,这样在开机的时候能自动挂载
[root@AlexWong /]# echo "/dev/vdb /data ext4 defaults 0 0" >> /etc/fstab

重新加载fstable,并查看磁盘是否加载成功

# mount -a 初次分区有用,在已经挂载分区后,不再重新生效
[root@AlexWong /]# mount -a
[root@AlexWong /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  8.5M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1        40G  2.3G   35G   7% /
tmpfs           374M     0  374M   0% /run/user/0
/dev/vdb         98G   61M   93G   1% /data# 如果二次修改分区,需要先移除挂载目录,然后再添加
[root@AlexWong /]# umount /dev/vdb /data
[root@AlexWong /]# mount /dev/vdb /home
[root@AlexWong home]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  8.8M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1        40G  8.2G   29G  22% /
overlay          40G  8.2G   29G  22%
/dev/vdb         98G   61M   93G   1% /home

挂载成功。

3、分多个主区

100G分三个,一个20G,另外两个40G

Units = sectors of 1 * 512 = 512 bytes
sectors:
20GB = 20 * 1024 * 1024 * 2 = 41943040
40GB = 40 * 1024 * 1024 * 2 = 83886080
40GB = 40 * 1024 * 1024 * 2 = 83886080
[root@AlexWong /]# fdisk -l
Disk /dev/vda: 40 GiB, 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
Disklabel type: dos
Disk identifier: 0x5d6e4b6bDevice     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886079 83884032  40G 83 LinuxDisk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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
----------------------------------20GB----------------------------------------
# 分第一个20G,分配给/share
#以新挂载的数据盘/dev/vdb为例
[root@AlexWong /]# fdisk /dev/vdb
# 输入“n”,按“Enter”,开始新建分区
Command (m for help): n
Partition typep   primary (0 primary, 0 extended, 4 free)e   extended (container for logical partitions)
# 表示磁盘有两种分区类型:
# “p”表示主分区
# “e”表示扩展分区
# 磁盘使用MBR分区形式,最多可以创建4个主分区,或者3个主分区加1个扩展分区,扩展分区不可以直接使用,需要划分成若干个逻辑分区才可以使用
# 磁盘使用GPT分区形式时,没有主分区、扩展分区以及逻辑分区之分
# 以创建一个主要分区为例,输入“p”,按“Enter”,开始创建一个主分区
Select (default p): p
# “Partition number”表示主分区编号,可以选择1-4
Partition number (1-4, default 1): 1
# “First sector”表示起始磁柱值,可以选择2048-209715199,默认为2048
First sector (2048-209715199, default 2048): 2048
# “Last sector”表示截止磁柱值,可以选择2048-209715199,默认为209715199
Last sector, +sectors or +size{K,M,G,T,P} (41943040-209715199, default 209715199): 41943040
# 表示20GB的分区已经建立成功
Created a new partition 1 of type 'Linux' and of size 20 GiB.# 输入“p”,按“Enter”,查看新建分区的详细信息
Command (m for help): p
Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0xb2fef9e3Device     Boot Start      End  Sectors Size Id Type
/dev/vdb1        2048 41943040 41940993  20G 83 Linux# 输入“w”,按“Enter”,将分区结果写入分区表中
Command (m for help): w
The partition table has been altered.
Syncing disks.
# 分区创建完成
----------------------------------40GB----------------------------------------
# 开始创建40GB的分区
[root@AlexWong /]# fdisk /dev/vdbWelcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): n
Partition typep   primary (1 primary, 0 extended, 3 free)e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (41943041-209715199, default 41945088):
# Last sector = 41945088 + 83886080 = 125831168 区间值
Last sector, +sectors or +size{K,M,G,T,P} (41945088-209715199, default 209715199): 125831168Created a new partition 2 of type 'Linux' and of size 40 GiB.Command (m for help): p
Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0xb2fef9e3Device     Boot    Start       End  Sectors Size Id Type
/dev/vdb1           2048  41943040 41940993  20G 83 Linux
/dev/vdb2       41945088 125831168 83886081  40G 83 LinuxCommand (m for help): w
The partition table has been altered.
Syncing disks.
----------------------------------40GB----------------------------------------
# 开始创建最后一个40G分区
[root@AlexWong /]# fdisk /dev/vdbWelcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): n
Partition typep   primary (2 primary, 0 extended, 2 free)e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
# 最后一个硬盘,sector默认enter即可
First sector (41943041-209715199, default 125833216):
Last sector, +sectors or +size{K,M,G,T,P} (125833216-209715199, default 209715199):Created a new partition 3 of type 'Linux' and of size 40 GiB.Command (m for help): p
Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0xb2fef9e3Device     Boot     Start       End  Sectors Size Id Type
/dev/vdb1            2048  41943040 41940993  20G 83 Linux
/dev/vdb2        41945088 125831168 83886081  40G 83 Linux
/dev/vdb3       125833216 209715199 83881984  40G 83 LinuxCommand (m for help): w
The partition table has been altered.
Syncing disks.
# 执行以下命令,将新的分区表变更同步至操作系统。
[root@AlexWong /]# partprobe
# 执行以下命令,将新建分区文件系统设为系统所需格式。
# mkfs -t 文件系统格式 /dev/vdb1
[root@AlexWong /]# mkfs -t ext4 /dev/vdb1
mke2fs 1.45.6 (20-Mar-2020)
/dev/vdb1 is apparently in use by the system; will not make a filesystem here!
# 报错,系统已占用
[root@AlexWong /]# cat /proc/partitions
major minor  #blocks  name253        0   41943040 vda253        1   41942016 vda1253       16  104857600 vdb253       17   20970496 vdb1253       18   41943040 vdb2253       19   41940992 vdb3
# 上面可以看到dm工具确实在用
[root@AlexWong /]# dmsetup remove_all
[root@AlexWong /]# dmsetup status
No devices found
# 此时对vdb1进行格式化操作
[root@AlexWong /]# mkfs.ext4 /dev/vdb1
[root@AlexWong /]# mkfs.ext4 /dev/vdb2
[root@AlexWong /]# mkfs.ext4 /dev/vdb3----------------------------------------------------------
此时发生了重大事故,我重启了机器,发现无法登陆。原因就是
我之前已经把/dev/vdb格式化并挂载过。此时再分区才导致如此的问题。
我把/dev/vdb /home ext4 defaults 0 0
写入了/etc/fstab,重启后无法SSH登陆。
之后把/dev/vdb重新分区,却我忘记删除/etc/fstab的自动挂载。
UUID=f1e9feb2-4a28-4c57-a03b-3a732954b724 /    ext4    defaults        1 1
#/dev/vdb /home ext4 defaults 0 0
#/dev/vdb1 /home ext4 defaults 0 0
----------------------------------------------------------
# 挂载硬盘
[root@AlexWong /]# mount /dev/vdb1 /share
[root@AlexWong /]# mount /dev/vdb2 /docker
[root@AlexWong /]# mount /dev/vdb3 /project
[root@AlexWong /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  9.0M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1        40G   17G   21G  44% /
/dev/vdb1        20G   45M   19G   1% /share
/dev/vdb2        40G   49M   38G   1% /docker
/dev/vdb3        40G   49M   38G   1% /project----------------------------------------------------------
# 把挂载的分区写入/etc/fstab,这样在开机的时候能自动挂载
# 建议使用UUID的方式挂载
[root@AlexWong /]# blkid
/dev/vda1: UUID="f1e9feb2-4a28-4c57-a03b-3a732954b724" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="5d6e4b6b-01"
/dev/vdb1: UUID="85c07779-b50b-4397-8b4f-5fc608cd027b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b2fef9e3-01"
/dev/vdb2: UUID="245b254d-00c4-4666-9adb-a0fffca46a7e" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b2fef9e3-02"
/dev/vdb3: UUID="6420d65e-7946-49ea-b87c-90c25dc790a6" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="b2fef9e3-03"
# 0 不检测硬盘, 根分区是1,数据盘是0
[root@AlexWong /]# echo "UUID=85c07779-b50b-4397-8b4f-5fc608cd027b /share ext4 defaults 0 0" >> /etc/fstab
[root@AlexWong /]# echo "UUID=245b254d-00c4-4666-9adb-a0fffca46a7e /docker ext4 defaults 0 0" >> /etc/fstab
[root@AlexWong /]# echo "UUID=6420d65e-7946-49ea-b87c-90c25dc790a6 /project ext4 defaults 0 0" >> /etc/fstab
[root@AlexWong /]# cat /etc/fstab
# /etc/fstab
# Created by anaconda on Sat Dec 12 11:50:01 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=f1e9feb2-4a28-4c57-a03b-3a732954b724 /                       ext4    defaults        1 1
UUID=85c07779-b50b-4397-8b4f-5fc608cd027b /share                  ext4    defaults        0 0
UUID=245b254d-00c4-4666-9adb-a0fffca46a7e /docker                 ext4    defaults        0 0
UUID=6420d65e-7946-49ea-b87c-90c25dc790a6 /project                ext4    defaults        0 0
----------------------------------------------------------
# 发现一个问题,挂载硬盘后,原有文件丢失
[root@AlexWong docker]# ll
total 20
drwx------ 2 root root 16384 Jan  5 15:59 lost+found
drwxr-xr-x 4 root root  4096 Jan  5 17:54 volumes
[root@AlexWong docker]# umount /dev/vdb2 /docker
umount: /docker: target is busy.
umount: /docker: target is busy.
# 被占用
[root@AlexWong docker]# umount -l /dev/vdb2 /docker
# 移除挂载后,重新退出文件目录,再次进入,文件还在

华为云/dev/vdb磁盘挂载相关推荐

  1. 分享-阿里云快速硬盘(磁盘)挂载教程

    很多新用户买到服务器以后对数据盘怎么硬盘挂载使用比较迷惑,我们今天给大家介绍怎么快速的把硬盘挂载到系统上 注意事项:先进行硬盘挂载再安装环境 Linux硬盘挂载是比较常见的管理操作之一.默认情况下数据 ...

  2. linux挂载华为存储设备,Centos7华为云对象存储obsfs挂载到Linux服务器【显哥出品,必为精品】...

    一.部署安装obsfs 1.下载obsfs软件包并安装 #下载obsfs软件包 wget https://obs-community.obs.cn-north-1.myhuaweicloud.com/ ...

  3. 阿里云磁盘挂载,挂载点提示异常:mount: /data: wrong fs type, bad option, bad superblock on /dev/vdb, missing codepag

    场景 在阿里云上买了一台新的ecs,同时买了一块200GB的磁盘,装的Centos 8系统.第一次开机进入到命令行,输入 df -h并没有发现我买的200GB的磁盘有自动挂载,就只有40GB的系统盘: ...

  4. 华为云磁盘挂载与分区扩容

    华为云磁盘挂载 华为云磁盘挂载 创建分区过程 华为云分区扩容 华为云磁盘挂载 华为云磁盘满了怎么挂载新增磁盘 查看磁盘使用情况 df -hl 查看购买磁盘 fdisk -l 创建挂载目录: mkdir ...

  5. 【华为云】磁盘挂载操作

    磁盘满了 默认的华为云服务器,在创建时如果没有指定磁盘大小,默认是40G 实例运行后发现磁盘小了,这时如果想扩容,可以这样操作 磁盘扩容的两种方式 1. 新增磁盘 一般来说,训练使用的或者普通计算使用 ...

  6. 天翼云centos7.5系统挂载磁盘

    天翼云:云硬盘 - 天翼云 阿里云:分区格式化数据盘(Linux) - 云服务器 ECS - 阿里云 azure虚拟机挂载数据盘:azure虚拟机挂载数据盘_u011442726的博客-CSDN博客 ...

  7. 华为云CCE集群节点磁盘告警处理

    目录 一.告警问题 二.问题分析 三.问题处理 四.结果验证 一.告警问题 监控在华为云CCE节点磁盘空间不足告警,节点磁盘使用率100%,看到告警有两种可能: 1.CCE节点磁盘空间不足 2.CCE ...

  8. linux共享磁盘给指定ip,Linux 磁盘挂载和mount共享

    其中根据文章http://blog.163.com/luoxiaoyu1010@126/blog/static/16581022720108162830579/也配置 原文:http://blog.c ...

  9. oracle 磁盘挂载格式化,Linux简单磁盘挂载

    临时挂载: 1.fdisk /dev/sda ---磁盘名根据实际情况 2.n --添加新分区,linux要求最多四个主分区,最少一个主分区,最多一个扩展分区,所以一般设置为三个主分区和一个扩展分区, ...

  10. 【SAP解决方案干货合集】满满的干货,是您了解华为云SAP解决方案的必备利器

    [SAP解决方案干货合集]满满的干货,是您了解华为云SAP解决方案的必备利器 https://bbs.huaweicloud.com/forum/forum.php?mod=viewthread&am ...

最新文章

  1. mysql lbs 附近的人_一口气说出 4种 LBS “附近的人” 实现方式,面试官笑了
  2. 求一批整数中出现最多的个位数字_C语言经典100例007-求低n-1位的数
  3. BAT 才不关心币价,19年的5大重点在这里!
  4. Activiti中具有单独数据库模式的多租户
  5. HFS远程命令执行漏洞复现
  6. 瓦片经纬度及行列号转换_ArcGIS根据最大最小坐标换算瓦片行列号
  7. 平滑阴影blender_【Blender笔记】简单的创建一个平平无奇的石头
  8. mysql postgresql nav_Mysql/postgreSQL
  9. react在部分安卓手机浏览器无法加载页面或页面空白
  10. 用友U8打开起初采购入库单报错
  11. 静态码率(CBR)和动态码率(VBR)
  12. 迷茫的我,学了Photoshop能做什么工作?
  13. 相信我,我们离成为废物阶级不远了!
  14. java中英文排序_Java 中英文数字排序
  15. 《SolidWorks 2014中文版完全自学手册》——1.4 SolidWorks工作环境设置
  16. 设置了cursor:pointer,在某个部分不显示
  17. 月圆之夜-体验报告(完稿时间2021/6/11)
  18. 用源码论述Eclipse学习体会
  19. 详解去中心化的DIM即时通讯协议
  20. 什么是哈希冲突?怎么解决哈希冲突。

热门文章

  1. Android实现微信查看附近的人
  2. 2018今日头条内推笔试1
  3. Spinnaker第七节—Orca代码详解
  4. 梁宁-产品思维30讲-痛点、爽点和痒点都是产品机会
  5. Locust学习笔记5——登录接口参数关联
  6. linux 内核---------董昊 ( Robin Dong ) and OenHan
  7. Oracle Linux 9 发布 -- Oracle 提供支持 RHEL 兼容发行版
  8. 期待只在最美的时光遇见你
  9. 蓝桥杯2014年(第5届)省赛b组c/c++ 史丰收速算
  10. QQ城市达人接口编程及经验分享2--新接口