阿里云数据盘挂载和卸载

我们在阿里云买了一个数据盘,如果要使用这个数据盘,首先我们得先进行数据盘的挂载。

数据盘的挂载

Setp1. 检查阿里云服务器数据盘情况

运行fdisk -l命令,检查当前VPS的数据硬盘情况

[root@****** ~]# 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: 0x0008d73a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83884031    41940992   83  Linux

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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

在这里插入图片描述
这里我们可以看到有200GB左右的数据盘没有挂载,这就是我们买的数据盘。

Step2. 进行分区

运行fdisk /dev/vdb

[root@****** ~]# fdisk /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 0x0fecfcde.

Command (m for help):

输入 n, 新建一个新分区

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):

出现两个菜单e表示扩展分区,p表示主分区,然后输入 p

Select (default p): p
Partition number (1-4, default 1): 

输入p键出现提示:"Partition number (1-4): "选择主分区号
输入1表示第一个主分区

Partition number (1-4, default 1): 1
First sector (2048-419430399, default 2048):

直接按回车表示1柱面开始分区

First sector (2048-419430399, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):

提示最后一个柱面或大小

  1. 直接回车,表示剩余空间分给此主分区
  2. 输入+5620M 按回车,表示此分区为5G空间
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): 
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set

Command (m for help):

输入p查看一下分区,输入w保存退出

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

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

完毕之后,我们输入fdisk -l

[root@****** ~]# 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: 0x0008d73a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83884031    41940992   83  Linux

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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: 0x0fecfcde

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   419430399   209714176   83  Linux

正常是可以看到200GB已经完成分区为/dev/vdb1

Step3. 格式化分区及挂载目录

格式化挂载数据硬盘分区
输入mkfs.ext3 /dev/vdb1

[root@****** ~]# mkfs.ext3 /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
13107200 inodes, 52428544 blocks
2621427 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1600 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, 7962624, 11239424, 20480000, 23887872

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

创建目录挂载
我们要挂载/data目录下,原始目录没有此文件夹,我们先创建mkdir /data

挂载/dev/vdb1

mount /dev/vdb1 /data

查看分区
输入df -h

[root@******* ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G  1.5G   36G   4% /
devtmpfs        7.8G     0  7.8G   0% /dev
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           7.8G  340K  7.8G   1% /run
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
tmpfs           1.6G     0  1.6G   0% /run/user/0
/dev/vdb1       197G   60M  187G   1% /data

我们可以看到/dev/vdb1挂载到/data目录下了

但是仅仅这样还不够,当重启这个节点之后,新分配的空间又没有挂载上去。所以,需要设置下,让其每次开机自动挂载。
执行命令:

echo '/dev/vdb1  /data ext3    defaults    0  0' >> /etc/fstab

此刻,挂载完成。

数据盘的卸载

输入 umount /dev/vdb1
如果提示设备忙,无法挂载

fuser -km /dev/vdb1
umount /dev/vdb1

再删除/etc/fstab文件中,如下的数据

/dev/vdb1  /data ext3    defaults    0  0

此刻,卸载完成。

附上分区工具fdisk用法介绍
fdisk命令参数介绍
p、打印分区表。
n、新建一个新分区。
d、删除一个分区。
q、退出不保存。
w、把分区写进分区表,保存并退出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

PeakXin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值