阿里云/CentOS如何挂载数据盘?

适用系统:非IO优化+SSD云盘Linux(Redhat , CentOS,Debian,Ubuntu)实例,Linux的云服务器数据盘未做分区和格式化,可以根据以下步骤进行分区以及格式化操作。

下面的操作将会把数据盘划分为一个分区来使用。

1、查看数据盘

在没有分区和格式化数据盘之前,使用“df –h”命令,是无法看到数据盘的,可以使用“fdisk -l”命令查看。

[[email protected]****************3523lxZ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G  1.5G   36G   4% /
devtmpfs        487M     0  487M   0% /dev
tmpfs           497M     0  497M   0% /dev/shm
tmpfs           497M  320K  496M   1% /run
tmpfs           497M     0  497M   0% /sys/fs/cgroup
tmpfs           100M     0  100M   0% /run/user/0
[[email protected]****************3523lxZ ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 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
Disk label type: dos
Disk identifier: 0x0008e3b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83886079    41942016   83  Linux

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 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

友情提示:若您执行fdisk -l命令,发现没有 /dev/xvdb 表明您的云服务无数据盘,那么您无需进行挂载,此时该教程对您不适用

2、 对数据盘进行分区

执行“fdisk -S 56 /dev/vdb”命令,对数据盘进行分区;

根据提示,依次输入“n”,“p”“1”,两次回车,“wq”,分区就开始了,很快就会完成。

[[email protected]****************3523lxZ ~]# fdisk -S 56 /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 0x8885c938.

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
First sector (2048-62914559, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559): 
Using default value 62914559
Partition 1 of type Linux and of size 30 GiB is set

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3、 查看新的分区

使用“fdisk -l”命令可以看到,新的分区vdb1已经建立完成了。

[[email protected]****************3523lxZ ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 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
Disk label type: dos
Disk identifier: 0x0008e3b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83886079    41942016   83  Linux

Disk /dev/vdb: 32.2 GB, 32212254720 bytes, 62914560 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: 0x8885c938

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    62914559    31456256   83  Linux

4、格式化新分区

以ext4为例:使用“mkfs.ext4 /dev/vdb1”命令对新分区进行格式化,格式化的时间根据硬盘大小有所不同。(也可自主决定选用其它文件格式,如ext3等)

使用df -Th可查看当前磁盘格式

[[email protected]m****************3523lxZ ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda1      ext4       40G  1.5G   36G   4% /
devtmpfs       devtmpfs  487M     0  487M   0% /dev
tmpfs          tmpfs     497M     0  497M   0% /dev/shm
tmpfs          tmpfs     497M  324K  496M   1% /run
tmpfs          tmpfs     497M     0  497M   0% /sys/fs/cgroup
tmpfs          tmpfs     100M     0  100M   0% /run/user/0

开始格式化

[[email protected]****************3523lxZ ~]# mkfs.ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1966080 inodes, 7864064 blocks
393203 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
240 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

5、添加分区信息

使用“echo '/dev/vdb1 /mnt ext4 defaults 0 0' >> /etc/fstab”(不含引号)命令写入新分区信息。
然后使用“cat /etc/fstab”命令查看,出现以下信息就表示写入成功。

注:ubuntu12.04不支持barrier,所以正确写法是:echo '/dev/xvdb1 /mnt ext4 barrier=0 0 0' >> /etc/fstab

* 如果需要把数据盘单独挂载到某个文件夹,比如单独用来存放网页,可以修改以上命令中的/mnt部分

[[email protected]****************3523lxZ ~]# echo '/dev/vdb1 /mnt ext4 defaults 0 0'>> /etc/fstab
[[email protected]****************3523lxZ ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Jun 25 07:16:25 2017
#
# 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
#
UUID=eb697457-a097-4263-8bbf-a75aa632d27c /                       ext4    defaults        1 1
/dev/vdb1 /mnt ext4 defaults 0 0

6、挂载新分区

使用“mount -a”命令挂载新分区,然后用“df -h”命令查看,出现以下信息就说明挂载成功,可以开始使用新的分区了。

[[email protected]****************3523lxZ ~]# mount -a
[[email protected]****************3523lxZ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G  1.5G   36G   4% /
devtmpfs        487M     0  487M   0% /dev
tmpfs           497M     0  497M   0% /dev/shm
tmpfs           497M  324K  496M   1% /run
tmpfs           497M     0  497M   0% /sys/fs/cgroup
tmpfs           100M     0  100M   0% /run/user/0
/dev/vdb1        30G   45M   28G   1% /mnt

Post Comment