使新挂载的云盘在ECS Linux上可用

问题描述

给ECS实例(Linux系统)新挂载一块云盘后,如何让其在系统内可以使用

问题分析

将新云盘挂载到ECS实例后,该云盘将显示为块储存设备,您可以使用任何文件系统将卷格式化,然后进行挂载。

解决方案

已经在控制台创建了新的云盘并挂载到了实例,下面所有步骤为登录到实例后操作:

1.使用 lsblk 命令可查看可用磁盘设备及其挂载点,以帮助您确定要使用的正确设备名称。lsblk 的输出从完整的设备路径中去掉了 /dev/ 前缀,如下:

root@wanyix:~# lsblk
NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda   252:0   0 40G 0 disk 
└─vda1 252:1   0 40G 0 part /
vdb   252:16  0 31G 0 disk 
└─vdb1 252:17  0 31G 0 part 
vdc   252:32  0 20G 0 disk 

上面输出中vdc是新加的卷。

2.确定卷上是否存在文件系统

新卷为原始的块储存设备,您必须先在这种设备上创建文件系统,然后才能够挂载并使用它们。

使用 file -s 命令获取有关特定设备的信息,例如其文件系统类型。如果输出仅显示 data(如上面示例输出所示),则说明设备上没有文件系统,如下:

root@wanyix:~# file -s /dev/vdc
/dev/vdc: data

3、执行 fdisk /dev/vda 对磁盘进行分区,如下:

root@wanyix:~# fdisk /dev/vdc
 
Welcome to fdisk (util-linux 2.31.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 0x50c3ef90.
 
Command (m for help): m
 
Help:
 
 DOS (MBR)
  a  toggle a bootable flag
  b  edit nested BSD disklabel
  c  toggle the dos compatibility flag
 
 Generic
  d  delete a partition
  F  list free unpartitioned space
  l  list known partition types
  n  add a new partition
  p  print the partition table
  t  change a partition type
  v  verify the partition table
  i  print information about a partition
 
 Misc
  m  print this menu
  u  change display/entry units
  x  extra functionality (experts only)
 
 Script
  I  load disk layout from sfdisk script file
  O  dump disk layout to sfdisk script file
 
 Save & Exit
  w  write table to disk and exit
  q  quit without saving changes
 
 Create a new label
  g  create a new empty GPT partition table
  G  create a new empty SGI (IRIX) partition table
  o  create a new empty DOS partition table
  s  create a new empty Sun partition table
 
 
Command (m for help): n
Partition type
  p  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-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 
 
Created a new partition 1 of type 'Linux' and of size 20 GiB.
 
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@wanyix:~# partprobe #将新的分区表同步到操作系统

然后使用lsblk进行查看,可以看出已经新建立了vdc1分区,如下:

root@wanyix:~# lsblk
NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda   252:0   0 40G 0 disk 
└─vda1 252:1   0 40G 0 part /
vdb   252:16  0 31G 0 disk 
└─vdb1 252:17  0 31G 0 part 
vdc   252:32  0 20G 0 disk 
└─vdc1 252:33  0 20G 0 part 

4.然后使用 mkfs -t 命令在该卷上创建一个xfs文件系统。

root@wanyix:~# mkfs -t xfs /dev/vdc1
meta-data=/dev/vdc1             isize=512   agcount=4, agsize=1310656 blks
        =                      sectsz=512  attr=2, projid32bit=1
        =                      crc=1       finobt=1, sparse=0, rmapbt=0, reflink=0
data    =                      bsize=4096  blocks=5242624, imaxpct=25
        =                      sunit=0     swidth=0 blks
naming  =version 2             bsize=4096  ascii-ci=0 ftype=1
log     =internal log          bsize=4096  blocks=2560, version=2
        =                      sectsz=512  sunit=0 blks, lazy-count=1
realtime =none                  extsz=4096  blocks=0, rtextents=0

然后使用file -s进行查看,如下:

root@wanyix:~# file -s /dev/vdc1
/dev/vdc1: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)

可以发现/dev/vdc1 已经为xfs文件系统

5.挂载使用

root@wanyix:~# mount /dev/vdc1 /data
root@wanyix:~# lsblk
NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda   252:0   0 40G 0 disk 
└─vda1 252:1   0 40G 0 part /
vdb   252:16  0 31G 0 disk 
└─vdb1 252:17  0 31G 0 part 
vdc   252:32  0 20G 0 disk 
└─vdc1 252:33  0 20G 0 part /data

可以看到卷已经挂载,可以使用。

如果您有其他问题,欢迎您联系火山引擎技术支持服务

377
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论