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

 

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

 

 更多IT系统运维、项目管理、商务英语及应用知识,扫描下方二维码关注公众号了解更多!!!

                                                    

 

 

 

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

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

使用“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. 第一步:查看磁盘状态:

 1 [root@wrhelpc0e2urb:/root]#
 2 #-> fdisk -l
 3 
 4 Disk /dev/sdc: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors
 5 Units = sectors of 1 * 512 = 512 bytes
 6 Sector size (logical/physical): 512 bytes / 512 bytes
 7 I/O size (minimum/optimal): 512 bytes / 512 bytes
 8 
 9 WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
10 
11 Disk /dev/sdd: 256.1 GB, 256060514304 bytes, 500118192 sectors
12 Units = sectors of 1 * 512 = 512 bytes
13 Sector size (logical/physical): 512 bytes / 512 bytes
14 I/O size (minimum/optimal): 512 bytes / 512 bytes
15 Disk label type: gpt
16 Disk identifier: 2AA8840C-1246-42C0-BC74-BB6BC3E245B3
17 
18 
19 # Start End Size Type Name
20 1 2048 1050623 512M EFI System EFI System Partition
21 2 1050624 2099199 512M Microsoft basic
22 3 2099200 453070847 215G Linux LVM
23 4 453070848 500117503 22.4G Linux swap
24 
25 Disk /dev/sda: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors
26 Units = sectors of 1 * 512 = 512 bytes
27 Sector size (logical/physical): 512 bytes / 512 bytes
28 I/O size (minimum/optimal): 512 bytes / 512 bytes
29 
30 
31 Disk /dev/sdb: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors
32 Units = sectors of 1 * 512 = 512 bytes
33 Sector size (logical/physical): 512 bytes / 512 bytes
34 I/O size (minimum/optimal): 512 bytes / 512 bytes
35 
36 
37 Disk /dev/mapper/vg00-lv00: 230.9 GB, 230896435200 bytes, 450969600 sectors
38 Units = sectors of 1 * 512 = 512 bytes
39 Sector size (logical/physical): 512 bytes / 512 bytes
40 I/O size (minimum/optimal): 512 bytes / 512 bytes

 

2. 第二步:开始分区

 1 [root@wrhelpc0e2urb:/root]#
 2 #-> parted /dev/sda
 3 GNU Parted 3.1
 4 Using /dev/sda
 5 Welcome to GNU Parted! Type 'help' to view a list of commands.
 6 (parted) p
 7 Error: /dev/sda: unrecognised disk label
 8 Model: ATA ST4000NM0033-9ZM (scsi)
 9 Disk /dev/sda: 4001GB
10 Sector size (logical/physical): 512B/512B
11 Partition Table: unknown
12 Disk Flags:
13 (parted) mktable gpt
14 (parted) p
15 Model: ATA ST4000NM0033-9ZM (scsi)
16 Disk /dev/sda: 4001GB
17 Sector size (logical/physical): 512B/512B
18 Partition Table: gpt
19 Disk Flags:
20 
21 Number  Start  End  Size  File system  Name  Flags
22 
23 (parted) mkpart
24 Partition name?  []? 1
25 File system type?  [ext2]? ext4
26 Start? 0%
27 End? 100%
28 (parted) p
29 Model: ATA ST4000NM0033-9ZM (scsi)
30 Disk /dev/sda: 4001GB
31 Sector size (logical/physical): 512B/512B
32 Partition Table: gpt
33 Disk Flags:
34 
35 Number  Start   End     Size    File system  Name  Flags
36  1      1049kB  4001GB  4001GB               1
37 
38 (parted) quit
39 Information: You may need to update /etc/fstab.
40 
41 [root@wrhelpc0e2urb:/root]#

 

四、格式化分区。

 

 1 [root@wrhelpc0e2urb:/root]#
 2 #-> mkfs.ext4 /dev/sda1
 3 mke2fs 1.42.9 (28-Dec-2013)
 4 Filesystem label=
 5 OS type: Linux
 6 Block size=4096 (log=2)
 7 Fragment size=4096 (log=2)
 8 Stride=0 blocks, Stripe width=0 blocks
 9 244195328 inodes, 976754176 blocks
10 48837708 blocks (5.00%) reserved for the super user
11 First data block=0
12 Maximum filesystem blocks=3124756480
13 29809 block groups
14 32768 blocks per group, 32768 fragments per group
15 8192 inodes per group
16 Superblock backups stored on blocks:
17         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
18         4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
19         102400000, 214990848, 512000000, 550731776, 644972544
20 
21 Allocating group tables: done
22 Writing inode tables: done
23 Creating journal (32768 blocks): done
24 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 进行识别。

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

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

     

  3. 为保证开机能自动挂载,在 /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 *进行安装然后重试。

 

 更多IT系统运维、项目管理、商务英语及应用知识,扫描下方二维码关注公众号了解更多!!!

                                                    

如果解决了你的燃眉之急,希望点赞支持,谢谢!



 

posted @ 2019-11-25 12:01  KévinX  阅读(1820)  评论(0编辑  收藏  举报