Linux云服务器磁盘不见了?解决方案在这里,云服务器磁盘挂载

2023-05-25,,

用过诸多种云以后,发现有个通病,就是新买的数据盘在机器中找不到。本篇总结一下此类问题的解决方法,望各位点赞,有问题评论区见

一、云服务和物理机一样,你买了云服务器的数据盘以后,就相当于把数据盘直接安装硬盘到物理机上。

二、查看硬盘是否正确安装。

使用“fdisk -l”命令查看硬盘代号。

root@Whel000010010:/home/share# fdisk -l  
  
Disk /dev/sda: 500.1 GB, 500107862016 bytes  
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors  
Units = 扇区 of 1 * 512 = 512 bytes  
Sector size (logical/physical): 512 bytes / 4096 bytes  
I/O size (minimum/optimal): 4096 bytes / 4096 bytes  
Disk identifier: 0x000aab9b  
  
   设备 启动      起点          终点     块数   Id  系统  
/dev/sda1   *        2048   488282111   244140032   83  Linux  
/dev/sda2       488284158   976771071   244243457    5  扩展  
Partition 2 does not start on physical sector boundary.  
/dev/sda5       488284160   820314111   166014976   83  Linux  
/dev/sda6       820316160   976771071    78227456   82  Linux 交换 / Solaris  
  
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.  
  
  
Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes  
255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 sectors  
Units = 扇区 of 1 * 512 = 512 bytes  
Sector size (logical/physical): 512 bytes / 4096 bytes  
I/O size (minimum/optimal): 4096 bytes / 4096 bytes  
Disk identifier: 0x00000000  
  
   设备 启动      起点          终点     块数   Id  系统  
/dev/sdb1               1  4294967295  2147483647+  ee  GPT  
Partition 1 does not start on physical sector boundary. 

可以看到我新增了的硬盘标识为sdb。

三、将硬盘分区。

1、当硬盘小于等于2T时,可以用fdisk。

fdisk /dev/sdb
1、查看帮助。
输入:m
2、新建分区。
输入:n
3、创建逻辑分区
输入:p
4、输入分区号以及指定分区大小
依照提示,回车表示默认。
5、检查分区情况(此时还未执行分区操作)
Command(m for help):p
6、保存退出
Command(m for help):w

这个是小盘分区的方式

2、当硬盘大于2T时,用parted命令。

选择要分区的硬盘:parted /dev/sdb

使用print 对磁盘信息进行查看:

可以看到磁盘还没有进行分区。

create the GPT disklabel – in other words, create the partitioning tables to support GPT:
建立GPT的磁盘标签,换句话说就是创建磁盘分区表支持GPT
使用(parted) mklabel gpt

创建分区,并分配合适的大小
create a partition:创建一个分区,这个步骤总是有错,选择cancle.

这一步就用到了对齐的概念。
然而其实我并不是只想要一个分区,所以我们将上面的分区删除,然后重新进行分区:
使用rm 编号 命令进行删除。

从图中打印的信息可以看到上面的分区已经删除,回到之前未进行分区的状态。

使用mkpart primary 0% n%创建主分区,n为要分的分区占整个磁盘的百分比.(mkpart extended创建扩展分区).
例如我这里想要把这个8T的硬盘分成三块,其中前两块分别占2T,最后一块占4T,则可以写为:
mkpart primary 0% 25%
mkpart primary 26% 50%
mkpart primary 51% 100%

可用print 命令对分区进行查看。

分区格式化
可 将硬盘格式化为ext4格式,具体各格式的区别见ext2、ext3与ext4的区别

将三块分区分别进行格式化。硬盘比较大时时间可能也较长等待ing。

真实案例走一波:

1. 第一步:查看磁盘状态:

 [root@wrhelpc0e2urb:/root]#
#-> fdisk -l Disk /dev/sdc: 4000.8 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. Disk /dev/sdd: 256.1 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: gpt
Disk identifier: 2AA8840C--42C0-BC74-BB6BC3E245B3 # Start End Size Type Name
512M EFI System EFI System Partition
512M Microsoft basic
215G Linux LVM
.4G Linux swap Disk /dev/sda: 4000.8 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/sdb: 4000.8 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/vg00-lv00: 230.9 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes

2. 第二步:开始分区

 [root@wrhelpc0e2urb:/root]#
#-> parted /dev/sda
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: /dev/sda: unrecognised disk label
Model: ATA ST4000NM0033-9ZM (scsi)
Disk /dev/sda: 4001GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) mktable gpt
(parted) p
Model: ATA ST4000NM0033-9ZM (scsi)
Disk /dev/sda: 4001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: Number Start End Size File system Name Flags (parted) mkpart
Partition name? []?
File system type? [ext2]? ext4
Start? %
End? %
(parted) p
Model: ATA ST4000NM0033-9ZM (scsi)
Disk /dev/sda: 4001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: Number Start End Size File system Name Flags
1049kB 4001GB 4001GB (parted) quit
Information: You may need to update /etc/fstab. [root@wrhelpc0e2urb:/root]#

四、格式化分区。

 [root@wrhelpc0e2urb:/root]#
#-> mkfs.ext4 /dev/sda1
mke2fs 1.42. (-Dec-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , , ,
, , , , , , ,
, , , , Allocating group tables: done
Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done

mkfs.ext4 /dev/sdb1

五、将硬盘挂载到文件夹下。

1、手动挂载。

新建一个文件夹:mkdir /bioinfo1

挂载:mount /dev/sdb1 /bioinfo1

2、开机自动挂载。

输入:vi /etc/fstab

编辑完fstab的内容后,不必重启执行该命令也可自动挂载:,mount -a    

在最后加入:

/dev/sdb1    /bioinfo1    ext4    defaults    1    1

更换为 Linux 系统后,比如更换为 Centos,对于 NTFS 格式的数据盘默认是无法识别的,可以通过 ntfs-3g 进行识别。

    执行如下命令安装 ntfs-3g:
    yum install -y ntfs-3g

    安装成功后通过如下命令进行挂载,结果如下:
    mount -t ntfs-3g /dev/xvdb5 /mnt

    为保证开机能自动挂载,在 /etc/fstab 里面添加如下配置:
    只读方式挂载:
    echo "/dev/xvdb5 /mnt ntfs-3g ro,umask=0222,defaults 0 0" >> /etc/fstab
    读写方式挂载:
    echo "/dev/xvdb6 /mnt ntfs-3g rw,umask=0000,defaults 0 0" >>/etc/fstab

** 说明:** Ubuntu 系统已经自带了ntfs-3g 模块,可以直接参阅上述步骤 2、3 进行挂载操作即可。

方法2

Linux 通过网络挂载 windows 下 NTFS 文件格式。Linux 系统通过内网 IP 挂载 Windows 系统共享目录命令是:
mount -t cifs -o username="Administrator",passwd="xxxxx" //10.x.x.x/test /mnt
其中 x 内容表示隐藏,跟进实际情况填写即可。

如果 mount 有异常的报错,核实是否有安装 cifs 组件。如果没有安装,则执行* **yum install cifs-utils -y *进行安装然后重试。

Linux云服务器磁盘不见了?解决方案在这里,云服务器磁盘挂载的相关教程结束。

《Linux云服务器磁盘不见了?解决方案在这里,云服务器磁盘挂载.doc》

下载本文的Word格式文档,以方便收藏与打印。