云服务器挂载数据盘

云服务器(ECS)是一种简单高效、安全可靠、处理能力可弹性伸缩的计算服务。目前,大部分云服务器购买的数据盘需要自行挂载,以阿里云为例,挂载数据盘的步骤为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
[root@appblog.cn ~]# df -hT  //查看分区格式及空间使用信息(-h空间使用-T分区格式)
Filesystem Type Size Used Avail Use% Mounted on
/dev/xvda1 ext4 20G 2.8G 16G 15% / //只有系统盘,数据盘还未挂载
tmpfs tmpfs 498M 0 498M 0% /dev/shm
[root@appblog.cn ~]# fdisk -l //查看磁盘信息

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078f9c

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 2611 20970496 83 Linux

Disk /dev/xvdb: 21.5 GB, 21474836480 bytes //可以看到分配有数据盘
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@appblog.cn ~]# fdisk /dev/xvdb //分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x41e88dbf.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): n //输入n
Command action
e extended
p primary partition (1-4)
p //输入p
Partition number (1-4): 1 //输入1
First cylinder (1-2610, default 1): //回车
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): //回车
Using default value 2610

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@appblog.cn ~]# fdisk -l //重新查看磁盘信息

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078f9c

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 2611 20970496 83 Linux

Disk /dev/xvdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x41e88dbf

Device Boot Start End Blocks Id System
/dev/xvdb1 1 2610 20964793+ 83 Linux //可以看到创建新分区/dev/xvdb1
[root@appblog.cn ~]# mkfs.ext4 /dev/xvdb1 //格式化
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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

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

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@appblog.cn ~]# mkdir /data //创建分区挂载目录
[root@appblog.cn ~]# echo '/dev/xvdb1 /data ext4 defaults 0 0' >> /etc/fstab //设置系统启动挂载新分区
[root@appblog.cn ~]# cat /etc/fstab //查看启动挂载分区信息

#
# /etc/fstab
# Created by anaconda on Thu Aug 14 21:16:42 2014
#
# 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=94e4e384-0ace-437f-bc96-057dd64f42ee / ext4 defaults,barrier=0 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
none /proc/xen xenfs defaults 0 0
/dev/xvdb1 /data ext4 defaults 0 0 //可以看到新添加的新分区
[root@appblog.cn ~]# mount -a //挂载所有分区
[root@appblog.cn ~]# df -hT //重新查看分区格式及空间使用情况
Filesystem Type Size Used Avail Use% Mounted on
/dev/xvda1 ext4 20G 2.8G 16G 15% /
tmpfs tmpfs 498M 0 498M 0% /dev/shm
/dev/xvdb1 ext4 20G 172M 19G 1% /data
[root@appblog.cn ~]#

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :